ConditionForm.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. ////public SortedDictionary<string, object> Conditions { get => m_ConditionPanel.BaseConditions; }
  15. //private DockPanel m_DockPanel;
  16. //public DockPanel DockPanel { get => m_DockPanel; set => m_DockPanel = value; }
  17. private readonly ConditionPanel m_ConditionPanel;
  18. public ConditionForm(ConditionPanel conditionPanel)
  19. {
  20. InitializeComponent();
  21. if (conditionPanel is BasicToolBar)
  22. {
  23. this.Height = 80; uiPanelFooter.Visible = false;
  24. }
  25. else
  26. {
  27. this.SizeChanged += ConditionForm_SizeChanged;
  28. }
  29. m_ConditionPanel = conditionPanel;
  30. uiPanelContainer.Controls.Add(m_ConditionPanel);
  31. m_ConditionPanel.Dock = System.Windows.Forms.DockStyle.Fill;
  32. this.m_BtnCancel.Click += BtnOKCancel_Click;
  33. this.m_BtnOK.Click += BtnOKCancel_Click;
  34. this.Style = Sunny.UI.UIStyle.Gray;
  35. this.m_BtnCancel.Style = Sunny.UI.UIStyle.Gray;
  36. this.m_BtnOK.Style = Sunny.UI.UIStyle.Gray;
  37. this.m_ConditionPanel.Style = Sunny.UI.UIStyle.Gray;
  38. this.StartPosition = FormStartPosition.Manual;
  39. this.Location = new System.Drawing.Point(10, 100);
  40. if (!conditionPanel.IsShowPanelFooter) { uiPanelFooter.Enabled = false; uiPanelFooter.Visible = false; }
  41. }
  42. /// <summary>
  43. /// 窗口大小发生变化的时候调整两个按钮的位置
  44. /// ■■【确定按钮】■【取消按钮】■■
  45. /// </summary>
  46. /// <param name="sender"></param>
  47. /// <param name="e"></param>
  48. private void ConditionForm_SizeChanged(object sender, System.EventArgs e)
  49. {
  50. var btnsWidth = this.m_BtnOK.Width + this.m_BtnCancel.Width;
  51. this.m_BtnOK.Left = 2 * (this.Width - btnsWidth) / 5;
  52. this.m_BtnCancel.Left = this.m_BtnOK.Width + 3 * (this.Width - btnsWidth) / 5;
  53. }
  54. /// <summary>
  55. /// 关闭事件,触发子控件ConditionPanel的AfterClose事件
  56. /// </summary>
  57. /// <param name="e"></param>
  58. protected override void OnClosed(System.EventArgs e)
  59. {
  60. base.OnClosed(e);
  61. m_ConditionPanel.AfterClose();
  62. }
  63. /// <summary>
  64. /// 点击按钮事件
  65. /// </summary>
  66. /// <param name="sender"></param>
  67. /// <param name="e"></param>
  68. private void BtnOKCancel_Click(object sender, System.EventArgs e)
  69. {
  70. this.DialogResult = ((Sunny.UI.UISymbolButton)sender).DialogResult;
  71. if (DialogResult == System.Windows.Forms.DialogResult.Cancel)
  72. {
  73. m_ConditionPanel.AfterCloseWithCancel(); this.Close(); return;
  74. }
  75. //if (!this.m_ConditionPanel.ConditionValid())
  76. //{
  77. // this.m_ConditionPanel.IsConditionValid = true; return;
  78. //}
  79. if (DialogResult == System.Windows.Forms.DialogResult.OK)
  80. {
  81. //点击OK后,一句Do的返回值操作
  82. //返回false 则 显示 “执行失败” 不关闭查询窗体
  83. //返回true 则 显示“执行完成”
  84. // 如果不显示结果窗体 则直接关闭查询窗体
  85. m_ConditionPanel.SetConditions();
  86. ComsStatic.MessageInterface.ShowInfo("开始执行...");
  87. var dat = m_ConditionPanel.Do(ComsStatic.DockPanel);
  88. if (dat is bool && dat.GetType().Name == "Boolean") //如果返回False 执行失败 但不关闭查询框
  89. {
  90. if (!bool.Parse(dat.ToString())) { ComsStatic.MessageInterface.ShowError("执行失败。"); return; }
  91. }
  92. else if (dat is null) //如果返回null 执行成功 但不关闭查询窗体
  93. {
  94. ComsStatic.MessageInterface.ShowInfo("执行完成。"); return;
  95. }
  96. ComsStatic.MessageInterface.ShowInfo("执行完成。");
  97. if (this.m_ConditionPanel.IsShowResultWindow) //查询后是否需要显示查询结果窗体
  98. {
  99. string resultWinTxt = "执行结果";
  100. if (!string.IsNullOrEmpty(m_ConditionPanel.ConditionPanelName))
  101. {
  102. resultWinTxt = m_ConditionPanel.ConditionPanelName + "-执行结果";
  103. }
  104. m_ConditionPanel.ShowResult(dat, ComsStatic.DockPanel, resultWinTxt);
  105. }
  106. if (!this.m_ConditionPanel.IsConditionValid)//显示结果窗体后是否需要关闭ConditionForm查询窗体
  107. {
  108. this.m_ConditionPanel.IsConditionValid = true; return;
  109. }
  110. m_ConditionPanel.AfterCloseWithOK(); this.Close();
  111. }
  112. }
  113. }
  114. }