ConditionPanel.cs 9.2 KB

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