ConditionForm.cs 4.7 KB

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