ConditionPanel.cs 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. using System;
  2. using System.Data;
  3. using System.Collections.Generic;
  4. using System.Drawing;
  5. using System.Windows.Forms;
  6. using WeifenLuo.WinFormsUI.Docking;
  7. using WWPipeLine.MapBasic.Results;
  8. using SuperMap.Mapping;
  9. using SuperMap.UI;
  10. using SuperMap.Data;
  11. using Sunny.UI;
  12. namespace WWPipeLine.MapBasic.Conditions
  13. {
  14. public class ConditionPanel : Sunny.UI.UIPanel
  15. {
  16. #region BaseConditions的设置和获取
  17. protected SortedDictionary<string, object> m_BaseConditions = new SortedDictionary<string, object>();
  18. /// <summary>
  19. /// 获取所有条件
  20. /// </summary>
  21. public SortedDictionary<string, object> BaseConditions
  22. {
  23. get => m_BaseConditions;
  24. }
  25. /// <summary>
  26. /// 设置参数,子类实现即可,无须调用
  27. /// </summary>
  28. /// <returns></returns>
  29. public virtual SortedDictionary<string, object> SetConditions()
  30. {
  31. return m_BaseConditions;
  32. }
  33. #endregion
  34. /// <summary>
  35. /// 条件输入对话框的标题
  36. /// </summary>
  37. public virtual string ConditionPanelName { get; set; }
  38. #region 查询后是否需要显示查询结果窗体
  39. /// <summary>
  40. /// 查询后是否需要显示查询结果窗体
  41. /// </summary>
  42. public bool IsShowResultWindow { get => m_IsShowResultWindow; set => m_IsShowResultWindow = value; }
  43. private bool m_IsShowResultWindow = true;
  44. #endregion
  45. #region 是否显示查询窗口的底部Panel,包括确定和取消按钮
  46. /// <summary>
  47. /// 是否显示查询窗口的底部Panel,包括确定和取消按钮
  48. /// </summary>
  49. public bool IsShowPanelFooter { get => m_isShowPanelFooter; set => m_isShowPanelFooter = value; }
  50. private bool m_isShowPanelFooter = true;
  51. #endregion
  52. #region 条件是否有效,如果false,则不会关闭对话框
  53. /// <summary>
  54. /// 显示查询结果窗体后是否关闭条件对话框
  55. /// <para>不显示查询结果窗体,但是需要禁止关闭条件对话框,请返回null</para>
  56. /// </summary>
  57. public bool IsConditionValid { get => isConditionValid; set => isConditionValid = value; }
  58. private bool isConditionValid = true;
  59. ///// <summary>
  60. ///// 在BtnOKCancel_Click里面判断条件是否有效,如果false,则不会关闭对话框。此处可以继承实现,根据不同的条件进行设置
  61. ///// </summary>
  62. ///// <returns></returns>
  63. //public virtual bool ConditionValid()
  64. //{
  65. // return IsConditionValid;
  66. //}
  67. #endregion
  68. #region 设置大小ConditionPanel大小
  69. private Size m_ContainerSize;
  70. /// <summary>
  71. /// 设置大小,修改条件窗口ConditionForm的大小。默认尺寸是(500,400),其中ConditionPanel的尺寸是(500,315)
  72. /// <para>如果设置尺寸,需要在ConditionPanel的高度上增加85</para>
  73. /// </summary>
  74. /// <param name="width"></param>
  75. /// <param name="height"></param>
  76. protected void SetSize(int width, int height)
  77. {
  78. this.ParentChanged -= ConditionPanel_ParentChanged;
  79. this.ParentChanged += ConditionPanel_ParentChanged;
  80. m_ContainerSize = new Size(width, height);
  81. }
  82. /// <summary>
  83. /// 在父窗口发生变化时候的内容,设置父窗口的大小
  84. /// </summary>
  85. /// <param name="sender"></param>
  86. /// <param name="e"></param>
  87. private void ConditionPanel_ParentChanged(object sender, EventArgs e)
  88. {
  89. Control topParent = this;
  90. while (!(topParent is Form))
  91. {
  92. topParent = topParent.Parent;
  93. if (topParent == null) break;
  94. }
  95. if (topParent == null) return;
  96. topParent.Size = this.m_ContainerSize;
  97. }
  98. #endregion
  99. /// <summary>
  100. /// 实现此方法以进行计算
  101. /// </summary>
  102. /// <param name="dockPanel"></param>
  103. public virtual object Do(DockPanel dockPanel = null)
  104. {
  105. throw new Exception("未实现WWPipeLine.MapTools.ConditionPanel.Do方法");
  106. }
  107. /// <summary>
  108. /// 是否以模态形式显示查询面板
  109. /// </summary>
  110. /// <returns></returns>
  111. public virtual bool ShowModal()
  112. {
  113. return false;
  114. }
  115. protected ResultWindow m_ResultWindow;
  116. /// <summary>
  117. /// 创建结果窗口,大多数情况下子类无须实现
  118. /// </summary>
  119. protected virtual void CreateResultWindow()
  120. {
  121. var conditionFullName = this.GetType().FullName.Replace(".Conditions.", ".Results.") + ",WWPipeLine.MapTools";
  122. var type = Type.GetType(conditionFullName);
  123. if (type == null && !this.GetType().FullName.Contains("Statistics"))
  124. {
  125. Commons.LogHelper.Warn(conditionFullName + "CreateResultWindow 创建结果面板时未找到结果面板,使用RWWithDataGridView");
  126. type = Type.GetType("WWPipeLine.MapBasic.Results.RWWithDataGridView,WWPipeLine.MapBasic");
  127. }
  128. else if (type == null)
  129. {
  130. Commons.LogHelper.Warn(conditionFullName + "CreateResultWindow 创建结果面板时未找到结果面板,使用Statics.RWWithChartBar");
  131. type = Type.GetType("WWPipeLine.MapBasic.Results.RWWithChartBar,WWPipeLine.MapBasic");
  132. }
  133. m_ResultWindow = (ResultWindow)Activator.CreateInstance(type);
  134. //if (this.m_BaseConditions.ContainsKey("SelectLayerNameConditionPanel"))
  135. //{
  136. // m_ResultWindow.FindLayerName = m_BaseConditions["SelectLayerNameConditionPanel"].ToString();
  137. //}
  138. }
  139. /// <summary>
  140. /// 调用此方法实现结果的展示
  141. /// </summary>
  142. /// <param name="data"></param>
  143. /// <param name="ds"></param>
  144. public virtual void ShowResult(object data, DockPanel dp = null, string resultForm = "执行结果")
  145. {
  146. CreateResultWindow();
  147. if (m_ResultWindow == null)
  148. {
  149. Commons.LogHelper.Warn("ShowResult m_ResultWindow == null 显示结果时未找到结果面板"); return;
  150. }
  151. bool reShow = false;
  152. if (m_ResultWindow.IsDisposed)
  153. {
  154. reShow = true;
  155. CreateResultWindow();
  156. }
  157. m_ResultWindow.TabText = resultForm;
  158. m_ResultWindow.Text = resultForm;
  159. m_ResultWindow.ShowData(data);
  160. if (!reShow && m_ResultWindow.Visible) return;
  161. if (dp != null)
  162. {
  163. m_ResultWindow.Show(dp, DockState.DockRight);
  164. }
  165. else
  166. {
  167. m_ResultWindow.Show();
  168. }
  169. }
  170. /// <summary>
  171. /// 点击OK并关闭对话框后执行
  172. /// </summary>
  173. public virtual void AfterCloseWithOK() { }
  174. /// <summary>
  175. /// 点击Cancel并关闭对话框后执行
  176. /// </summary>
  177. public virtual void AfterCloseWithCancel() { }
  178. /// <summary>
  179. /// 关闭对话框后执行
  180. /// <para> 光标设置箭头光标,地图设置为漫游,地图刷新</para>
  181. /// </summary>
  182. public virtual void AfterClose()
  183. {
  184. MapControl.Map.TrackingLayer.Clear();
  185. MapControl.Action = SuperMap.UI.Action.Pan;
  186. MapControl.Map.RefreshEx(MapControl.Map.ViewBounds);
  187. }
  188. //protected IMessageInterface MessageInterface
  189. //{
  190. // get
  191. // {
  192. // if (this.BaseConditions.ContainsKey("IMessageInterface"))
  193. // return BaseConditions["IMessageInterface"] as IMessageInterface;
  194. // else
  195. // return null;
  196. // }
  197. //}
  198. //protected DockPanel DockPanelConditionPanel
  199. //{
  200. // get
  201. // {
  202. // if (this.BaseConditions.ContainsKey("DockPanelConditionPanel"))
  203. // return BaseConditions["DockPanelConditionPanel"] as DockPanel;
  204. // else
  205. // return null;
  206. // }
  207. //}
  208. //protected MapControl MapControl
  209. //{
  210. // get
  211. // {
  212. // if (this.BaseConditions.ContainsKey("MapControlConditionPanel"))
  213. // return BaseConditions["MapControlConditionPanel"] as MapControl;
  214. // else
  215. // return null;
  216. // }
  217. //}
  218. protected MapControl MapControl
  219. {
  220. get => ComsStatic.MapControl;
  221. }
  222. //protected string SelectLayerNameConditionPanel
  223. //{
  224. // get
  225. // {
  226. // if (this.BaseConditions.ContainsKey("SelectLayerNameConditionPanel"))
  227. // return BaseConditions["SelectLayerNameConditionPanel"] as string;
  228. // else
  229. // return null;
  230. // }
  231. //}
  232. protected DatasetVector dvJSLK_cp
  233. {
  234. get => ComsStatic.dvJSLK;
  235. }
  236. //protected EditHistory m_EditHistory = null;
  237. //public EditHistory EditHistory { get => m_EditHistory; set => m_EditHistory = value; }
  238. //public void EditHistoryUndo()
  239. //{
  240. // while (m_EditHistory.CanUndo)
  241. // {
  242. // m_EditHistory.Undo();
  243. // }
  244. //}
  245. private void InitializeComponent()
  246. {
  247. this.SuspendLayout();
  248. //
  249. // ConditionPanel
  250. //
  251. this.AutoSize = true;
  252. this.FillColor = System.Drawing.Color.FromArgb(((int)(((byte)(242)))), ((int)(((byte)(242)))), ((int)(((byte)(244)))));
  253. this.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
  254. this.Name = "ConditionPanel";
  255. this.RectColor = System.Drawing.Color.FromArgb(((int)(((byte)(140)))), ((int)(((byte)(140)))), ((int)(((byte)(140)))));
  256. this.Size = new System.Drawing.Size(87, 95);
  257. this.Style = Sunny.UI.UIStyle.Gray;
  258. this.ResumeLayout(false);
  259. }
  260. }
  261. }