ConditionPanel.cs 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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 特宽尺寸宽度1000 </para>
  79. /// <para>Title=35 Footer=50 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. m_ResultWindow = (ResultWindow)Activator.CreateInstance(type);
  136. }
  137. /// <summary>
  138. /// 调用此方法实现结果的展示
  139. /// </summary>
  140. /// <param name="data"></param>
  141. /// <param name="ds"></param>
  142. public virtual void ShowResult(object data, DockPanel dp = null, string resultForm = "执行结果")
  143. {
  144. CreateResultWindow();
  145. if (m_ResultWindow == null)
  146. {
  147. Commons.LogHelper.Warn(resultForm + " ShowResult m_ResultWindow == null 显示结果时未找到结果面板"); return;
  148. }
  149. bool reShow = false;
  150. if (m_ResultWindow.IsDisposed)
  151. {
  152. reShow = true;
  153. CreateResultWindow();
  154. }
  155. m_ResultWindow.TabText = resultForm;
  156. m_ResultWindow.Text = resultForm;
  157. m_ResultWindow.ShowData(data);
  158. if (!reShow && m_ResultWindow.Visible) return;
  159. if (dp != null)
  160. {
  161. m_ResultWindow.Show(dp, DockState.DockRight);
  162. }
  163. else
  164. {
  165. m_ResultWindow.Show();
  166. }
  167. }
  168. /// <summary>
  169. /// 点击OK并关闭对话框后执行
  170. /// </summary>
  171. public virtual void AfterCloseWithOK() { }
  172. /// <summary>
  173. /// 点击Cancel并关闭对话框后执行
  174. /// </summary>
  175. public virtual void AfterCloseWithCancel() { }
  176. /// <summary>
  177. /// 关闭对话框后执行
  178. /// </summary>
  179. public virtual void AfterClose()
  180. {
  181. MapControl.Map.TrackingLayer.Clear();
  182. //MapControl.Map.RefreshTrackingLayer();
  183. MapControl.Action = SuperMap.UI.Action.Pan;
  184. MapControl.Map.Refresh();
  185. }
  186. protected MapControl MapControl
  187. {
  188. get => ComsStatic.MapControl;
  189. }
  190. private void InitializeComponent()
  191. {
  192. this.SuspendLayout();
  193. //
  194. // ConditionPanel
  195. //
  196. this.AutoSize = true;
  197. this.FillColor = System.Drawing.Color.FromArgb(((int)(((byte)(242)))), ((int)(((byte)(242)))), ((int)(((byte)(244)))));
  198. this.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
  199. this.Name = "ConditionPanel";
  200. this.RectColor = System.Drawing.Color.FromArgb(((int)(((byte)(140)))), ((int)(((byte)(140)))), ((int)(((byte)(140)))));
  201. this.Size = new System.Drawing.Size(87, 95);
  202. this.Style = Sunny.UI.UIStyle.Gray;
  203. this.ResumeLayout(false);
  204. }
  205. }
  206. }