ConditionForm.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. using System.Collections.Generic;
  2. using System.Windows.Forms;
  3. using WeifenLuo.WinFormsUI.Docking;
  4. using WWPipeLine.MapBasic.Conditions;
  5. namespace WWPipeLine.MapBasic
  6. {
  7. /// <summary>
  8. /// 查询窗体
  9. /// </summary>
  10. public partial class ConditionForm : Sunny.UI.UIForm
  11. {
  12. private IMessageInterface m_MessageInterface;
  13. public IMessageInterface MessageInterface { get => m_MessageInterface; set => m_MessageInterface = value; }
  14. private readonly ConditionPanel m_ConditionPanel;
  15. public SortedDictionary<string, object> Conditions { get => m_ConditionPanel.BaseConditions; }
  16. private DockPanel m_DockPanel;
  17. public DockPanel DockPanel { get => m_DockPanel; set => m_DockPanel = value; }
  18. public ConditionForm(ConditionPanel conditionPanel)
  19. {
  20. InitializeComponent();
  21. if (conditionPanel is BasicToolBar)
  22. {
  23. this.Height = 80;
  24. uiPanelFooter.Visible = false;
  25. }
  26. else
  27. {
  28. this.SizeChanged += ConditionForm_SizeChanged;
  29. }
  30. m_ConditionPanel = conditionPanel;
  31. m_ConditionPanel.Dock = System.Windows.Forms.DockStyle.Fill;
  32. uiPanelContainer.Controls.Add(m_ConditionPanel);
  33. this.m_BtnCancel.Click += BtnOKCancel_Click;
  34. this.m_BtnOK.Click += BtnOKCancel_Click;
  35. this.Style = Sunny.UI.UIStyle.Gray;
  36. this.m_BtnCancel.Style = Sunny.UI.UIStyle.Gray;
  37. this.m_BtnOK.Style = Sunny.UI.UIStyle.Gray;
  38. this.m_ConditionPanel.Style = Sunny.UI.UIStyle.Gray;
  39. this.StartPosition = FormStartPosition.Manual;
  40. this.Location = new System.Drawing.Point(10, 200);
  41. var iconPath = Commons.Paths.ApplicationResourcesDir + "\\conditions.ico";
  42. if (System.IO.File.Exists(iconPath))
  43. {
  44. this.ShowIcon = true;
  45. this.ShowTitleIcon = true;
  46. this.Icon = new System.Drawing.Icon(iconPath);
  47. }
  48. }
  49. /// <summary>
  50. /// 窗口大小发生变化的时候调整两个按钮的位置
  51. /// ■■【确定按钮】■【取消按钮】■■
  52. /// </summary>
  53. /// <param name="sender"></param>
  54. /// <param name="e"></param>
  55. private void ConditionForm_SizeChanged(object sender, System.EventArgs e)
  56. {
  57. var btnsWidth = this.m_BtnOK.Width + this.m_BtnCancel.Width;
  58. this.m_BtnOK.Left = 2 * (this.Width - btnsWidth) / 5;
  59. this.m_BtnCancel.Left = this.m_BtnOK.Width + 3 * (this.Width - btnsWidth) / 5;
  60. }
  61. /// <summary>
  62. /// 关闭事件,触发子控件ConditionPanel的AfterClose事件
  63. /// </summary>
  64. /// <param name="e"></param>
  65. protected override void OnClosed(System.EventArgs e)
  66. {
  67. //if (!this.m_ConditionPanel.IsConditionValid)
  68. // return;
  69. base.OnClosed(e);
  70. m_ConditionPanel.AfterClose();
  71. }
  72. /// <summary>
  73. /// 点击按钮事件
  74. /// </summary>
  75. /// <param name="sender"></param>
  76. /// <param name="e"></param>
  77. private void BtnOKCancel_Click(object sender, System.EventArgs e)
  78. {
  79. this.DialogResult = ((Sunny.UI.UISymbolButton)sender).DialogResult;
  80. if (DialogResult == System.Windows.Forms.DialogResult.Cancel)
  81. {
  82. this.Close();
  83. m_ConditionPanel.AfterCloseWithCancel();
  84. return;
  85. }
  86. //if (!this.m_ConditionPanel.ConditionValid() || !this.m_ConditionPanel.IsConditionValid)
  87. //{
  88. // this.m_ConditionPanel.IsConditionValid = false;
  89. // return;
  90. //}
  91. if (!this.m_ConditionPanel.ConditionValid())
  92. {
  93. this.m_ConditionPanel.IsConditionValid = true;
  94. return;
  95. }
  96. if (DialogResult == System.Windows.Forms.DialogResult.OK)
  97. {
  98. m_ConditionPanel.SetConditions();
  99. this.m_MessageInterface.ShowInfo("开始执行...");
  100. var dat = m_ConditionPanel.Do(m_DockPanel);
  101. if (dat is bool && dat.GetType().Name == "Boolean")//如果返回False
  102. {
  103. if (!bool.Parse(dat.ToString()))
  104. {
  105. this.m_MessageInterface.ShowInfo("执行失败。");
  106. return;
  107. }
  108. }
  109. this.m_MessageInterface.ShowInfo("执行完成。");
  110. if (this.m_ConditionPanel.IsShowResultWindow)//查询后是否需要显示查询结果窗体
  111. {
  112. string resultWinTxt;
  113. if (string.IsNullOrEmpty(m_ConditionPanel.ConditionPanelName))
  114. {
  115. resultWinTxt = "执行结果";
  116. }
  117. else
  118. {
  119. resultWinTxt = m_ConditionPanel.ConditionPanelName + "-执行结果";
  120. }
  121. m_ConditionPanel.ShowResult(dat, m_DockPanel, resultWinTxt);
  122. if (!this.m_ConditionPanel.IsConditionValid)//显示结果窗体后是否需要关闭ConditionForm查询窗体
  123. {
  124. this.m_ConditionPanel.IsConditionValid = true;
  125. return;
  126. }
  127. m_ConditionPanel.AfterCloseWithOK();
  128. }
  129. this.Close();
  130. }
  131. }
  132. //private void btnMapActivate_Click(object sender, System.EventArgs e)
  133. //{
  134. // foreach (Form form in Application.OpenForms)
  135. // {
  136. // if (!(form.Tag is null) && form.Tag.ToString() == "FormMainRibbon")
  137. // {
  138. // form.Activate();
  139. // form.Focus();
  140. // form.Controls.Find("MapEx", true)[0].Focus();
  141. // break;
  142. // }
  143. // }
  144. //}
  145. }
  146. }