123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- using System.Collections.Generic;
- using System.Windows.Forms;
- using WeifenLuo.WinFormsUI.Docking;
- using WWPipeLine.MapBasic.Conditions;
- namespace WWPipeLine.MapBasic
- {
- /// <summary>
- /// 查询窗体
- /// </summary>
- public partial class ConditionForm : Sunny.UI.UIForm
- {
- //private IMessageInterface m_MessageInterface;
- //public IMessageInterface MessageInterface { get => m_MessageInterface; set => m_MessageInterface = value; }
- ////public SortedDictionary<string, object> Conditions { get => m_ConditionPanel.BaseConditions; }
- //private DockPanel m_DockPanel;
- //public DockPanel DockPanel { get => m_DockPanel; set => m_DockPanel = value; }
- private readonly ConditionPanel m_ConditionPanel;
- public ConditionForm(ConditionPanel conditionPanel)
- {
- InitializeComponent();
- if (conditionPanel is BasicToolBar)
- {
- this.Height = 80; uiPanelFooter.Visible = false;
- }
- else
- {
- this.SizeChanged += ConditionForm_SizeChanged;
- }
- m_ConditionPanel = conditionPanel;
- uiPanelContainer.Controls.Add(m_ConditionPanel);
- m_ConditionPanel.Dock = System.Windows.Forms.DockStyle.Fill;
- this.m_BtnCancel.Click += BtnOKCancel_Click;
- this.m_BtnOK.Click += BtnOKCancel_Click;
- this.Style = Sunny.UI.UIStyle.Gray;
- this.m_BtnCancel.Style = Sunny.UI.UIStyle.Gray;
- this.m_BtnOK.Style = Sunny.UI.UIStyle.Gray;
- this.m_ConditionPanel.Style = Sunny.UI.UIStyle.Gray;
- this.StartPosition = FormStartPosition.Manual;
- this.Location = new System.Drawing.Point(10, 100);
- if (!conditionPanel.IsShowPanelFooter) { uiPanelFooter.Enabled = false; uiPanelFooter.Visible = false; }
- }
- /// <summary>
- /// 窗口大小发生变化的时候调整两个按钮的位置
- /// ■■【确定按钮】■【取消按钮】■■
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void ConditionForm_SizeChanged(object sender, System.EventArgs e)
- {
- var btnsWidth = this.m_BtnOK.Width + this.m_BtnCancel.Width;
- this.m_BtnOK.Left = 2 * (this.Width - btnsWidth) / 5;
- this.m_BtnCancel.Left = this.m_BtnOK.Width + 3 * (this.Width - btnsWidth) / 5;
- }
- /// <summary>
- /// 关闭事件,触发子控件ConditionPanel的AfterClose事件
- /// </summary>
- /// <param name="e"></param>
- protected override void OnClosed(System.EventArgs e)
- {
- base.OnClosed(e);
- m_ConditionPanel.AfterClose();
- }
- /// <summary>
- /// 点击按钮事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnOKCancel_Click(object sender, System.EventArgs e)
- {
- this.DialogResult = ((Sunny.UI.UISymbolButton)sender).DialogResult;
- if (DialogResult == System.Windows.Forms.DialogResult.Cancel)
- {
- m_ConditionPanel.AfterCloseWithCancel(); this.Close(); return;
- }
- //if (!this.m_ConditionPanel.ConditionValid())
- //{
- // this.m_ConditionPanel.IsConditionValid = true; return;
- //}
- if (DialogResult == System.Windows.Forms.DialogResult.OK)
- {
- //点击OK后,一句Do的返回值操作
- //返回false 则 显示 “执行失败” 不关闭查询窗体
- //返回true 则 显示“执行完成”
- // 如果不显示结果窗体 则直接关闭查询窗体
- m_ConditionPanel.SetConditions();
- ComsStatic.MessageInterface.ShowInfo("开始执行...");
- var dat = m_ConditionPanel.Do(ComsStatic.DockPanel);
- if (dat is bool && dat.GetType().Name == "Boolean") //如果返回False 执行失败 但不关闭查询框
- {
- if (!bool.Parse(dat.ToString())) { ComsStatic.MessageInterface.ShowError("执行失败。"); return; }
- }
- else if (dat is null) //如果返回null 执行成功 但不关闭查询窗体
- {
- ComsStatic.MessageInterface.ShowInfo("执行完成。"); return;
- }
- ComsStatic.MessageInterface.ShowInfo("执行完成。");
- if (this.m_ConditionPanel.IsShowResultWindow) //查询后是否需要显示查询结果窗体
- {
- string resultWinTxt = "执行结果";
- if (!string.IsNullOrEmpty(m_ConditionPanel.ConditionPanelName))
- {
- resultWinTxt = m_ConditionPanel.ConditionPanelName + "-执行结果";
- }
- m_ConditionPanel.ShowResult(dat, ComsStatic.DockPanel, resultWinTxt);
- }
- if (!this.m_ConditionPanel.IsConditionValid)//显示结果窗体后是否需要关闭ConditionForm查询窗体
- {
- this.m_ConditionPanel.IsConditionValid = true; return;
- }
- m_ConditionPanel.AfterCloseWithOK(); this.Close();
- }
- }
- }
- }
|