ConditionForm.cs 4.2 KB

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