ResultWindow.cs 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. using SuperMap.Mapping;
  2. using SuperMap.UI;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Drawing;
  6. using System.Windows.Forms;
  7. using WeifenLuo.WinFormsUI.Docking;
  8. namespace WWPipeLine.MapBasic.Results
  9. {
  10. public partial class ResultWindow : ToolWindowExtend
  11. {
  12. /// <summary>
  13. /// 存储参数
  14. /// </summary>
  15. private SortedDictionary<string, object> m_BaseParams = new SortedDictionary<string, object>();
  16. /// <summary>
  17. /// 设置参数
  18. /// </summary>
  19. /// <param name="key">参数名</param>
  20. /// <param name="value">参数值</param>
  21. public void SetParams(string key, object value)
  22. {
  23. if (m_BaseParams.ContainsKey(key))
  24. {
  25. return;
  26. }
  27. m_BaseParams.Add(key, value);
  28. }
  29. protected MapControl MapControlResultWindow
  30. {
  31. get
  32. {
  33. if (m_BaseParams.ContainsKey("MapControlResultWindow"))
  34. return m_BaseParams["MapControlResultWindow"] as MapControl;
  35. return null;
  36. }
  37. }
  38. protected string SelectLayerNamelResultWindow
  39. {
  40. get
  41. {
  42. if (m_BaseParams.ContainsKey("SelectLayerNamelResultWindow"))
  43. return m_BaseParams["SelectLayerNamelResultWindow"] as string;
  44. return null;
  45. }
  46. }
  47. /// <summary>
  48. /// 构造并初始化查询结果ResultWindow窗体
  49. /// </summary>
  50. public ResultWindow()
  51. {
  52. InitializeComponent();
  53. ///关闭按钮可见、可用
  54. this.CloseButtonVisible = true;
  55. this.CloseButton = true;
  56. this.DockAreas = DockAreas.DockLeft
  57. | DockAreas.DockRight
  58. | DockAreas.DockTop
  59. | DockAreas.DockBottom
  60. | DockAreas.Document
  61. | DockAreas.Float;
  62. }
  63. /// <summary>
  64. /// 将DataGridView的数据导出至Excel
  65. /// </summary>
  66. /// <param name="dg"></param>
  67. public void ExportToExcel(System.Windows.Forms.DataGridView dg)
  68. {
  69. if (dg == null) return;
  70. var errMsg = Commons.ExportDgvToExcel.ExportExcel(string.Empty, dg, "雅黑", 14);
  71. if (!string.IsNullOrEmpty(errMsg))
  72. {
  73. if (errMsg == Commons.ExportDgvToExcel.CANCELRESULTSTRING)
  74. return;
  75. else
  76. Sunny.UI.UINotifier.Show(errMsg, Sunny.UI.UINotifierType.ERROR, "错误", false, 1000);
  77. }
  78. else
  79. {
  80. Sunny.UI.UINotifier.Show("导出成功", Sunny.UI.UINotifierType.OK, "消息", false, 1000);
  81. }
  82. }
  83. /// <summary>
  84. /// 将Control导出至Image
  85. /// </summary>
  86. /// <param name="ctrl"></param>
  87. public void ExportToImage(Control ctrl)
  88. {
  89. SaveFileDialog saveFileDialog = new SaveFileDialog
  90. {
  91. DefaultExt = "jpg",
  92. Filter = "图片文件(*.jpg)|*.jpg",
  93. RestoreDirectory = true,
  94. Title = "图片文件保存路径"
  95. };
  96. if (saveFileDialog.ShowDialog() == DialogResult.OK)
  97. {
  98. Bitmap bmp = new Bitmap(ctrl.Width, ctrl.Height);
  99. ctrl.DrawToBitmap(bmp, ctrl.ClientRectangle);
  100. bmp.Save(saveFileDialog.FileName);
  101. }
  102. }
  103. /// <summary>
  104. /// 显示数据非BasicToolBar 必须实现此方法
  105. /// </summary>
  106. /// <param name="data"></param>
  107. public virtual void ShowData(object data)
  108. {
  109. throw new Exception("未实现WWPipeLine.MapTools.Results.ResultWindow.ShowData");
  110. }
  111. /// <summary>
  112. /// 导出Excel按钮
  113. /// </summary>
  114. protected Sunny.UI.UISymbolButton uiSymbolButtonExportToExcel;
  115. /// <summary>
  116. /// 导出图片按钮
  117. /// </summary>
  118. protected Sunny.UI.UISymbolButton uiSymbolButtonExportToImage;
  119. /// <summary>
  120. /// 创建并添加,“导出到Excel”按钮
  121. /// </summary>
  122. protected void CreateExportExcelButton()
  123. {
  124. this.uiSymbolButtonExportToExcel = new Sunny.UI.UISymbolButton
  125. {
  126. Cursor = System.Windows.Forms.Cursors.Hand,
  127. Dock = System.Windows.Forms.DockStyle.Bottom,
  128. Font = new System.Drawing.Font("微软雅黑", 12F),
  129. Location = new System.Drawing.Point(0, 415),
  130. MinimumSize = new System.Drawing.Size(1, 1),
  131. Name = "uiSymbolButtonExportToExcel",
  132. Size = new System.Drawing.Size(800, 20),
  133. Symbol = 61582,
  134. TabIndex = 0,
  135. Text = "导出到Excel"
  136. };
  137. this.Controls.Add(this.uiSymbolButtonExportToExcel);
  138. }
  139. /// <summary>
  140. /// 创建并添加,“导出图片”和“导出到Excel”按钮
  141. /// </summary>
  142. protected void CreateExportImageAndExcelButton()
  143. {
  144. Sunny.UI.UIPanel panel = new Sunny.UI.UIPanel
  145. {
  146. Dock = System.Windows.Forms.DockStyle.Bottom,
  147. Height = 20
  148. };
  149. this.Controls.Add(panel);
  150. this.uiSymbolButtonExportToExcel = new Sunny.UI.UISymbolButton
  151. {
  152. Dock = System.Windows.Forms.DockStyle.Fill,
  153. Cursor = System.Windows.Forms.Cursors.Hand,
  154. Font = new System.Drawing.Font("微软雅黑", 12F),
  155. Location = new System.Drawing.Point(0, 415),
  156. MinimumSize = new System.Drawing.Size(1, 1),
  157. Name = "uiSymbolButtonExportToExcel",
  158. Size = new System.Drawing.Size(800, 20),
  159. Symbol = 61582,
  160. TabIndex = 0,
  161. Text = "导出到Excel",
  162. RectSides = System.Windows.Forms.ToolStripStatusLabelBorderSides.None,
  163. RadiusSides = Sunny.UI.UICornerRadiusSides.None
  164. };
  165. panel.Controls.Add(this.uiSymbolButtonExportToExcel);
  166. this.uiSymbolButtonExportToImage = new Sunny.UI.UISymbolButton
  167. {
  168. Dock = System.Windows.Forms.DockStyle.Left,
  169. Cursor = System.Windows.Forms.Cursors.Hand,
  170. Font = new System.Drawing.Font("微软雅黑", 12F),
  171. Location = new System.Drawing.Point(0, 415),
  172. MinimumSize = new System.Drawing.Size(1, 1),
  173. Name = "uiSymbolButtonExportToImage",
  174. Size = new System.Drawing.Size(800, 20),
  175. Symbol = 61893,
  176. TabIndex = 1,
  177. Text = "导出图片",
  178. RectSides = System.Windows.Forms.ToolStripStatusLabelBorderSides.None,
  179. RadiusSides = Sunny.UI.UICornerRadiusSides.None
  180. };
  181. panel.Controls.Add(this.uiSymbolButtonExportToImage);
  182. this.SizeChanged += ResultWindow_SizeChanged;
  183. }
  184. /// <summary>
  185. /// 窗体发生变化时候按钮自动缩放
  186. /// </summary>
  187. /// <param name="sender"></param>
  188. /// <param name="e"></param>
  189. private void ResultWindow_SizeChanged(object sender, EventArgs e)
  190. {
  191. uiSymbolButtonExportToExcel.Width = this.Width / 2;
  192. uiSymbolButtonExportToImage.Width = this.Width / 2;
  193. }
  194. private void ResultWindow_FormClosing(object sender, FormClosingEventArgs e)
  195. {
  196. this.MapControlResultWindow.Map.TrackingLayer.Clear();
  197. this.MapControlResultWindow.Map.Refresh();
  198. }
  199. }
  200. }