using System.Collections.Generic;
using System.Windows.Forms;
using WeifenLuo.WinFormsUI.Docking;
using WWPipeLine.MapBasic.Conditions;
namespace WWPipeLine.MapBasic
{
///
/// 查询窗体
///
public partial class ConditionForm : Sunny.UI.UIForm
{
private readonly ConditionPanel m_ConditionPanel;
public ConditionForm(ConditionPanel conditionPanel)
{
InitializeComponent();
this.Style = ComsStatic.uiStyleCom;
this.StartPosition = FormStartPosition.Manual;
this.Location = new System.Drawing.Point(10, 100);
if (conditionPanel is BasicToolBar)
{
this.Height = 80; uiPanelFooter.Visible = false;
}
else
{
this.SizeChanged += ConditionForm_SizeChanged;
}
m_ConditionPanel = conditionPanel;
m_ConditionPanel.Dock = DockStyle.Fill;
m_ConditionPanel.Radius = 0;
m_ConditionPanel.RadiusSides = Sunny.UI.UICornerRadiusSides.None;
m_ConditionPanel.Margin = new Padding(0);
m_ConditionPanel.Padding = new Padding(1);
m_ConditionPanel.Style = ComsStatic.uiStyleCom;
uiPanelContainer.Controls.Add(m_ConditionPanel);
uiPanelContainer.Padding = new Padding(0);
uiPanelContainer.Style = Sunny.UI.UIStyle.Gray;
m_BtnCancel.Style = ComsStatic.uiStyleCom;
m_BtnOK.Style = ComsStatic.uiStyleCom;
if (!conditionPanel.IsShowPanelFooter) { uiPanelFooter.Enabled = false; uiPanelFooter.Visible = false; }
}
private void ConditionForm_Load(object sender, System.EventArgs e)
{
if (m_ConditionPanel.IsLoadBtnOKClick)
{
object senderObj = m_BtnOK;
BtnOKCancel_Click(senderObj, null);
}
}
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 (DialogResult == System.Windows.Forms.DialogResult.OK)
{
ComsStatic.MessageInterface.ShowInfo("开始执行...");
m_BtnOK.Enabled = false;
//object dat = null;
//new WaitingForm((obj, args) => { dat = m_ConditionPanel.Do(ComsStatic.DockPanel); }, null).ShowDialog();
var dat = m_ConditionPanel.Do(ComsStatic.DockPanel);
m_BtnOK.Enabled = true;
if (dat is bool && dat.GetType().Name == "Boolean") //如果返回False 执行失败 但不关闭查询框
{
if (!bool.Parse(dat.ToString())) { ComsStatic.MessageInterface.ShowError("执行失败。"); return; }
}
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();
}
}
///
/// 窗口大小发生变化的时候调整两个按钮的位置
/// ■■【确定按钮】■【取消按钮】■■
///
///
///
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;
if (this.Width < 500)
{
this.m_BtnOK.Size = new System.Drawing.Size(70, 30);
this.m_BtnCancel.Size = new System.Drawing.Size(70, 30);
}
}
///
/// 关闭事件,触发子控件ConditionPanel的AfterClose事件
///
///
protected override void OnClosed(System.EventArgs e)
{
base.OnClosed(e);
m_ConditionPanel.AfterClose();
}
}
}