ResultWindow.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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 string SelectLayerNamelResultWindow
  30. //{
  31. // get
  32. // {
  33. // if (m_BaseParams.ContainsKey("SelectLayerNamelResultWindow"))
  34. // return m_BaseParams["SelectLayerNamelResultWindow"] as string;
  35. // return null;
  36. // }
  37. //}
  38. //public string FindLayerName { get; set; }
  39. /// <summary>
  40. /// 构造并初始化查询结果ResultWindow窗体
  41. /// </summary>
  42. public ResultWindow()
  43. {
  44. InitializeComponent();
  45. ///关闭按钮可见、可用
  46. this.CloseButtonVisible = true;
  47. this.CloseButton = true;
  48. this.DockAreas = DockAreas.DockLeft
  49. | DockAreas.DockRight
  50. | DockAreas.DockTop
  51. | DockAreas.DockBottom
  52. | DockAreas.Document
  53. | DockAreas.Float;
  54. }
  55. /// <summary>
  56. /// 将DataGridView的数据导出至Excel
  57. /// </summary>
  58. /// <param name="dg"></param>
  59. public void ExportToExcel(System.Windows.Forms.DataGridView dg)
  60. {
  61. if (dg == null) return;
  62. var errMsg = Commons.ExportDgvToExcel.ExportExcel(dg);
  63. if (string.IsNullOrEmpty(errMsg))
  64. {
  65. ComsStatic.ShowOKLog("导出Excel文件成功");
  66. }
  67. else
  68. {
  69. if (errMsg == Commons.ExportDgvToExcel.CANCELRESULTSTRING)
  70. return;
  71. else
  72. ComsStatic.ShowErrorLog("导出Excel文件失败,原因是" + errMsg);
  73. }
  74. }
  75. /// <summary>
  76. /// 将Control导出至Image
  77. /// </summary>
  78. /// <param name="ctrl"></param>
  79. public void ExportToImage(Control ctrl)
  80. {
  81. SaveFileDialog sfd = new SaveFileDialog
  82. {
  83. DefaultExt = "jpg",
  84. Filter = "图片文件(*.jpg)|*.jpg",
  85. RestoreDirectory = true,
  86. Title = "图片文件保存路径"
  87. };
  88. if (sfd.ShowDialog() == DialogResult.OK)
  89. {
  90. Bitmap bmp = new Bitmap(ctrl.Width, ctrl.Height);
  91. ctrl.DrawToBitmap(bmp, ctrl.ClientRectangle);
  92. bmp.Save(sfd.FileName);
  93. }
  94. }
  95. /// <summary>
  96. /// 显示数据非BasicToolBar 必须实现此方法
  97. /// </summary>
  98. /// <param name="data"></param>
  99. public virtual void ShowData(object data)
  100. {
  101. throw new Exception("未实现WWPipeLine.MapTools.Results.ResultWindow.ShowData");
  102. }
  103. /// <summary>
  104. /// 导出Excel按钮
  105. /// </summary>
  106. protected Sunny.UI.UISymbolButton uiSymbolButtonExportToExcel;
  107. /// <summary>
  108. /// 导出图片按钮
  109. /// </summary>
  110. protected Sunny.UI.UISymbolButton uiSymbolButtonExportToImage;
  111. /// <summary>
  112. /// 创建并添加,“导出到Excel”按钮
  113. /// </summary>
  114. protected void CreateExportExcelButton()
  115. {
  116. this.uiSymbolButtonExportToExcel = new Sunny.UI.UISymbolButton
  117. {
  118. Cursor = System.Windows.Forms.Cursors.Hand,
  119. Dock = System.Windows.Forms.DockStyle.Bottom,
  120. Font = new System.Drawing.Font("微软雅黑", 12F),
  121. Location = new System.Drawing.Point(0, 415),
  122. MinimumSize = new System.Drawing.Size(1, 1),
  123. Name = "uiSymbolButtonExportToExcel",
  124. Size = new System.Drawing.Size(800, 20),
  125. Symbol = 61582,
  126. TabIndex = 0,
  127. Style = Sunny.UI.UIStyle.Gray,
  128. Text = "导出到Excel"
  129. };
  130. this.Controls.Add(this.uiSymbolButtonExportToExcel);
  131. }
  132. /// <summary>
  133. /// 创建并添加,“导出图片”和“导出到Excel”按钮
  134. /// </summary>
  135. protected void CreateExportImageAndExcelButton()
  136. {
  137. Sunny.UI.UIPanel panel = new Sunny.UI.UIPanel
  138. {
  139. Dock = System.Windows.Forms.DockStyle.Bottom,
  140. Height = 20
  141. };
  142. this.Controls.Add(panel);
  143. this.uiSymbolButtonExportToExcel = new Sunny.UI.UISymbolButton
  144. {
  145. Dock = System.Windows.Forms.DockStyle.Fill,
  146. Cursor = System.Windows.Forms.Cursors.Hand,
  147. Font = new System.Drawing.Font("微软雅黑", 12F),
  148. Location = new System.Drawing.Point(0, 415),
  149. MinimumSize = new System.Drawing.Size(1, 1),
  150. Name = "uiSymbolButtonExportToExcel",
  151. Size = new System.Drawing.Size(800, 20),
  152. Symbol = 61582,
  153. TabIndex = 0,
  154. Style = Sunny.UI.UIStyle.Gray,
  155. Text = "导出到Excel",
  156. RectSides = System.Windows.Forms.ToolStripStatusLabelBorderSides.None,
  157. RadiusSides = Sunny.UI.UICornerRadiusSides.None
  158. };
  159. panel.Controls.Add(this.uiSymbolButtonExportToExcel);
  160. this.uiSymbolButtonExportToImage = new Sunny.UI.UISymbolButton
  161. {
  162. Dock = System.Windows.Forms.DockStyle.Left,
  163. Cursor = System.Windows.Forms.Cursors.Hand,
  164. Font = new System.Drawing.Font("微软雅黑", 12F),
  165. Location = new System.Drawing.Point(0, 415),
  166. MinimumSize = new System.Drawing.Size(1, 1),
  167. Name = "uiSymbolButtonExportToImage",
  168. Size = new System.Drawing.Size(800, 20),
  169. Symbol = 61893,
  170. TabIndex = 1,
  171. Style = Sunny.UI.UIStyle.Gray,
  172. Text = "导出图片",
  173. RectSides = System.Windows.Forms.ToolStripStatusLabelBorderSides.None,
  174. RadiusSides = Sunny.UI.UICornerRadiusSides.None
  175. };
  176. panel.Controls.Add(this.uiSymbolButtonExportToImage);
  177. this.SizeChanged += ResultWindow_SizeChanged;
  178. }
  179. /// <summary>
  180. /// 窗体发生变化时候按钮自动缩放
  181. /// </summary>
  182. /// <param name="sender"></param>
  183. /// <param name="e"></param>
  184. private void ResultWindow_SizeChanged(object sender, EventArgs e)
  185. {
  186. uiSymbolButtonExportToExcel.Width = this.Width / 2;
  187. uiSymbolButtonExportToImage.Width = this.Width / 2;
  188. }
  189. }
  190. }