| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048 |
-
- using System;
- using System.ComponentModel;
- using System.Threading;
- using System.Windows.Forms;
- using Dongke.WinForm.Utilities;
- namespace Dongke.WinForm.Controls
- {
- /// <summary>
- /// 窗体基类
- /// </summary>
- public partial class FormBase : Form, IDKForm
- {
- #region 事件声明
- #region AsyncBegin
- /// <summary>
- /// 当异步处理开始时发生。
- /// </summary>
- private static readonly object EventAsyncBegin = new object();
- /// <summary>
- /// 当异步处理开始时发生。
- /// </summary>
- [Description("当异步处理开始时发生。"), Category("CustomerEx")]
- public event CancelEventHandler AsyncBegin
- {
- add
- {
- base.Events.AddHandler(EventAsyncBegin, value);
- }
- remove
- {
- base.Events.RemoveHandler(EventAsyncBegin, value);
- }
- }
- /// <summary>
- /// 引发 异步处理开始 事件
- /// </summary>
- /// <param name="e">包含事件数据的 EventArgs</param>
- protected virtual void OnAsyncBegin(CancelEventArgs e)
- {
- CancelEventHandler eventHandler = (CancelEventHandler)base.Events[EventAsyncBegin];
- if (eventHandler != null)
- {
- eventHandler(this, e);
- }
- }
- #endregion
- #region AsyncEnd
- /// <summary>
- /// 当异步处理结束时发生。
- /// </summary>
- private static readonly object EventAsyncEnd = new object();
- /// <summary>
- /// 当异步处理结束时发生。
- /// </summary>
- [Description("当异步处理开始时发生。"), Category("CustomerEx")]
- public event AsyncEndEventHandler AsyncEnd
- {
- add
- {
- base.Events.AddHandler(EventAsyncEnd, value);
- }
- remove
- {
- base.Events.RemoveHandler(EventAsyncEnd, value);
- }
- }
- /// <summary>
- /// 引发 异步处理结束 事件
- /// </summary>
- /// <param name="e">包含事件数据的 EventArgs</param>
- protected virtual void OnAsyncEnd(AsyncEndEventArgs e)
- {
- AsyncEndEventHandler eventHandler = (AsyncEndEventHandler)base.Events[EventAsyncEnd];
- if (eventHandler != null)
- {
- eventHandler(this, e);
- }
- }
- #endregion
- #endregion
- #region 成员变量
- /// <summary>
- /// 异步等处理时,能否关闭窗体
- /// </summary>
- private bool _canClose = true;
- private bool _isClosing = false;
- private bool _isSaving = false;
- /// <summary>
- /// 是否取消异步处理。
- /// </summary>
- private bool _cancelAsync = false;
- /// <summary>
- /// 正在异步处理。
- /// </summary>
- private bool _doAsync = false;
- /// <summary>
- /// 窗体中数据是否被修改过
- /// </summary>
- private bool _isDirty = false;
- private bool _showStatusStrip = true;
- /// <summary>
- /// 窗体类型
- /// </summary>
- private FormType _formType = FormType.Select;
- private FormWindowState _formWindowState = FormWindowState.Normal;
- private string _formCode = null;
- private bool _doFocus = true;
- private int _loadCount = 0;
- #endregion
- #region 构造函数
- /// <summary>
- /// 窗体基类
- /// </summary>
- protected FormBase()
- : this(null)
- {
- }
- /// <summary>
- /// 窗体基类
- /// </summary>
- protected FormBase(string formCode)
- {
- InitializeComponent();
- this.KeyPreview = true;
- this._formCode = formCode;
- if (this._showStatusStrip)
- {
- this.Controls.Add(this.ssrAsyncStatusStrip);
- }
- else
- {
- this.Controls.Remove(this.ssrAsyncStatusStrip);
- }
- this.ssrAsyncStatusStrip.Visible = this._showStatusStrip;
- }
- #endregion
- #region 属性
- /// <summary>
- /// 获取一个值,该值指示窗体的编码(多实例窗体编码不同)。
- /// </summary>
- [Browsable(false)]
- [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
- [EditorBrowsable(EditorBrowsableState.Advanced)]
- public string FormCode
- {
- get
- {
- return this._formCode;
- }
- set
- {
- this._formCode = value;
- }
- }
- /// <summary>
- /// 获取一个值,该值指示是否正在异步处理。
- /// </summary>
- [DefaultValue(false)]
- [Browsable(false)]
- [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
- [EditorBrowsable(EditorBrowsableState.Advanced)]
- [Description("获取一个值,该值指示是否正在异步处理。"), Category("CustomerEx")]
- public bool AsyncDoing
- {
- get
- {
- return this._doAsync;
- }
- }
- /// <summary>
- /// 获取一个值,该值指示异步处理是否被取消。
- /// </summary>
- [DefaultValue(false)]
- [Browsable(false)]
- [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
- [EditorBrowsable(EditorBrowsableState.Advanced)]
- [Description("获取一个值,该值指示异步处理是否被取消。"), Category("CustomerEx")]
- public bool AsyncCanecled
- {
- get
- {
- return this._cancelAsync;
- }
- }
- /// <summary>
- /// 获取或设置一个值,该值指示窗体中数据是否被修改过。
- /// </summary>
- [DefaultValue(false)]
- [Browsable(false)]
- [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
- [EditorBrowsable(EditorBrowsableState.Advanced)]
- [Description("获取或设置一个值,该值指示窗体中数据是否被修改过。"), Category("CustomerEx")]
- public bool Dirty
- {
- get
- {
- return this._isDirty || this.CheckDirty();
- }
- set
- {
- this._isDirty = value;
- }
- }
- /// <summary>
- /// 窗体类型
- /// </summary>
- [Description("获取或设置一个值,该值指示窗体中数据是否被修改过。"), Category("CustomerEx")]
- [DefaultValue(typeof(FormType), "Select")]
- [Browsable(false)]
- [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
- [EditorBrowsable(EditorBrowsableState.Advanced)]
- public FormType FormType
- {
- get
- {
- return this._formType;
- }
- set
- {
- this._formType = value;
- }
- }
- /// <summary>
- /// 获取或设置一个值,该值指示是否显示状态条。
- /// </summary>
- [Description("获取或设置一个值,该值指示是否显示状态条。"), Category("CustomerEx")]
- [DefaultValue(true)]
- public virtual bool ShowStatusStrip
- {
- get
- {
- return this._showStatusStrip;
- }
- set
- {
- if (this._showStatusStrip != value)
- {
- this._showStatusStrip = value;
- if (this._showStatusStrip)
- {
- this.Controls.Add(this.ssrAsyncStatusStrip);
- }
- else
- {
- this.Controls.Remove(this.ssrAsyncStatusStrip);
- }
- this.ssrAsyncStatusStrip.Visible = value;
- }
- }
- }
- #endregion
- #region 重写属性
- /// <summary>
- /// 获取或设置窗体的边框样式。
- /// </summary>
- //[Browsable(false)]
- //[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
- //[EditorBrowsable(EditorBrowsableState.Advanced)]
- public virtual new FormBorderStyle FormBorderStyle
- {
- get
- {
- return base.FormBorderStyle;
- }
- set
- {
- base.FormBorderStyle = value;
- this.SetStatusSizingGrip();
- }
- }
- /// <summary>
- /// 获取或设置运行时窗体的起始位置
- /// </summary>
- [Localizable(true)]
- [DefaultValue(typeof(FormStartPosition), "CenterScreen")]
- public virtual new FormStartPosition StartPosition
- {
- get
- {
- return base.StartPosition;
- }
- set
- {
- base.StartPosition = value;
- }
- }
- #endregion
- #region 重写事件
- private bool _closeOnEsc = true;
- public bool CloseOnEsc
- {
- get
- {
- return this._closeOnEsc;
- }
- set
- {
- this._closeOnEsc = value;
- }
- }
- protected override void OnKeyDown(KeyEventArgs e)
- {
- base.OnKeyDown(e);
- if (this.CancelButton == null && e.KeyData == Keys.Escape && this._closeOnEsc)
- {
- this.Close();
- }
- }
- /// <summary>
- /// 窗体大小改变
- /// </summary>
- /// <param name="e"></param>
- protected override void OnSizeChanged(EventArgs e)
- {
- base.OnSizeChanged(e);
- if (this.WindowState != FormWindowState.Minimized)
- {
- this._formWindowState = this.WindowState;
- }
- this.SetStatusSizingGrip();
- }
- /// <summary>
- /// 窗体关闭时
- /// </summary>
- /// <param name="e"></param>
- protected override void OnClosed(EventArgs e)
- {
- base.OnClosed(e);
- FormFactory.RemoveForm(this);
- try
- {
- // datagridview控件设置保存(TODO)
- System.Collections.Generic.List<Control> items = this.GetControls(this, typeof(Dongke.IBOSS.PRD.Basics.BaseControls.C_DataGridView));
- foreach (Dongke.IBOSS.PRD.Basics.BaseControls.C_DataGridView grd in items)
- {
- if (grd.IsSaveDataGridViewSetting)
- {
- Dongke.IBOSS.PRD.Basics.Library.GridSettingManager.SaveGridSetting(grd, this.Name + grd.Name);
- }
- }
- }
- catch /*(Exception ex)*/
- {
- //Dongke.IBOSS.MBC.Basics.Library.OutputLog.TraceLog( Dongke.IBOSS.MBC.Basics.Library.LogPriority.Error,
- // "Dongke.WinForm.Controls.FormBase", "SaveGridSetting", ex.Message, logFilePath);
- }
- }
- /// <summary>
- /// 正在关闭窗体时
- /// </summary>
- /// <param name="e"></param>
- protected override void OnClosing(CancelEventArgs e)
- {
- // 画面暂不能关闭
- if(!this._canClose)
- {
- e.Cancel = true;
- return;
- }
- // 保存成功后关闭
- if (this._isSaving)
- {
- this.DialogResult = DialogResult.OK;
- base.OnClosing(e);
- return;
- }
- this._isClosing = true;
- try
- {
- // 画面数据有更改
- if (this.Dirty)
- {
- DialogResult dr = this.ShowMessageOnDirtyClose();
- // 关闭前保存
- if (dr == DialogResult.Yes)
- {
- // 保存成功
- if (this.SetData())
- {
- this._isDirty = false;
- this.DialogResult = DialogResult.OK;
- }
- // 保存失败
- else
- {
- e.Cancel = true;
- return;
- }
- }
- // 关闭不保存
- else if (dr == DialogResult.No)
- {
- //if (this.DialogResult == DialogResult.None)
- //{
- // this.DialogResult = DialogResult.Cancel;
- //}
- }
- // 取消关闭
- else //if (dr == DialogResult.Cancel)
- {
- e.Cancel = true;
- return;
- }
- }
- if (this.DialogResult == DialogResult.None)
- {
- this.DialogResult = DialogResult.Cancel;
- }
- base.OnClosing(e);
- }
- finally
- {
- this._isClosing = false;
- }
- }
- /// <summary>
- /// 窗体加载时发生。
- /// </summary>
- /// <param name="e"></param>
- protected override void OnLoad(EventArgs e)
- {
- this.DialogResult = DialogResult.None;
- this._loadCount++;
- if (this._loadCount == 1)
- {
- this.InitForm();
- }
- if (!this.DesignMode)
- {
- if (!this.LoadForm())
- {
- this._isDirty = false;
- this.Close();
- return;
- }
- }
- base.OnLoad(e);
- this._isDirty = false;
- try
- {
- // TODO 临时
- //datagridview控件设置保存
- System.Collections.Generic.List<Control> controls = this.GetControls(this, typeof(Dongke.IBOSS.PRD.Basics.BaseControls.C_DataGridView));
- foreach (Dongke.IBOSS.PRD.Basics.BaseControls.C_DataGridView dgv in controls)
- {
- if (dgv.IsSaveDataGridViewSetting)
- {
- Dongke.IBOSS.PRD.Basics.Library.GridSettingManager.InitializeGridSetting(dgv, this.Name + dgv.Name);
- }
- }
- }
- catch /*(Exception ex)*/
- {
- //Dongke.IBOSS.MBC.Basics.Library.OutputLog.TraceLog( Dongke.IBOSS.MBC.Basics.Library.LogPriority.Error,
- // "Dongke.WinForm.Controls.FormBase", "SaveGridSetting", ex.Message, logFilePath);
- }
- }
- /// <summary>
- /// TODO 临时
- /// </summary>
- /// <param name="topControl"></param>
- /// <param name="type"></param>
- /// <returns></returns>
- private System.Collections.Generic.List<Control> GetControls(Control topControl, Type type)
- {
- if (topControl == null)
- {
- return GetControls(this, type);
- }
- System.Collections.Generic.List<Control> list = new System.Collections.Generic.List<Control>();
- foreach (Control control in topControl.Controls)
- {
- if (type == null || type.Equals(control.GetType()))
- {
- list.Add(control);
- }
- list.AddRange(GetControls(control, type));
- }
- return list;
- }
- #endregion
- #region 事件处理
- #endregion
- #region 重写方法
- #endregion
- #region 公有方法
- #region Set
- /// <summary>
- /// 点击保存或确定按钮时调用。
- /// </summary>
- /// <returns>操作结果</returns>
- public virtual bool SetData()
- {
- Control ac = this.ActiveControl;
- this.txtFoucs.Focus();
- bool result = false;
- // 验证画面数据有效性
- result = this.CheckInputData();
- if (!result)
- {
- return result;
- }
- // 保存数据到服务端
- result = this.SetDataToOther();
- if (!result)
- {
- //this.ShowMessageOnSetDefeated();
- ac.Focus();
- return result;
- }
- // 关闭画面的保存
- if (this._isClosing)
- {
- if (this._formType != FormType.Select)
- {
- this.ShowMessageOnSetSucceed();
- }
- ac.Focus();
- return result;
- }
- // 新建、复制成功后
- if (this._formType == FormType.Add ||
- this._formType == FormType.Copy)
- {
- // 是否继续操作
- if (this.ShowMessageOnAddSucceed())
- {
- this.RefreshData();
- this._isDirty = false;
- ac.Focus();
- return result;
- }
- }
- else if (this._formType != FormType.Select)
- {
- this.ShowMessageOnSetSucceed();
- }
- this._isSaving = true;
- this.Close();
- this._isSaving = false;
- return result;
- }
- /// <summary>
- /// 窗体中数据保存后,需要继续操作,并初始化窗体时调用。
- /// </summary>
- public virtual void RefreshData()
- {
- this.ClearConditions();
- this.ClearQueryResults();
- this.ssrAsyncStatusStrip.ClearCommTimes();
- base.SelectNextControl(null, true, true, true, false);
- this._isDirty = false;
- }
- #endregion
- #region Query
- /// <summary>
- /// 点击查询按钮时调用。
- /// </summary>
- /// <returns>操作结果</returns>
- public virtual bool QueryData()
- {
- bool result = false;
- // 验证查询条件有效性
- result = this.CheckQueryConditions();
- if (!result)
- {
- return result;
- }
- this.ClearQueryResults();
- result = this.QueryDataFromOther();
- //if (!result)
- //{
- // this.ShowMessageOnQueryDefeated();
- //}
- return result;
- }
- /// <summary>
- /// 清除查询条件
- /// </summary>
- public virtual void ClearConditions()
- {
- }
- /// <summary>
- /// 清除查询结果
- /// </summary>
- public virtual void ClearQueryResults()
- {
- }
- #endregion
- #region 异步处理
- /// <summary>
- /// 窗体的异步处理
- /// </summary>
- /// <param name="method">异步方法</param>
- /// <param name="result">返回值</param>
- /// <returns>处理结果:true处理成功,false处理失败</returns>
- public bool DoAsync<TResult>(Func<TResult> method, out TResult result)
- {
- result = default(TResult);
- bool asyncResult = false;
- if (this._doAsync)
- {
- return asyncResult;
- }
- CancelEventArgs ce = new CancelEventArgs();
- this.OnAsyncBegin(ce);
- if (ce.Cancel)
- {
- return asyncResult;
- }
- try
- {
- this._cancelAsync = false;
- this._doAsync = true;
- this._canClose = false;
- this.StartProgress();
- IAsyncResult iAsyncResult = method.BeginInvoke(null, null);
- while (!iAsyncResult.IsCompleted)
- {
- if (this._cancelAsync)
- {
- return asyncResult;
- }
- Application.DoEvents();
- Thread.Sleep(1);
- }
- result = method.EndInvoke(iAsyncResult);
- asyncResult = true;
- }
- finally
- {
- this._doAsync = false;
- this._canClose = true;
- this.EndProgress();
- AsyncEndEventArgs e = new AsyncEndEventArgs(asyncResult, result);
- this.OnAsyncEnd(e);
- asyncResult = e.AsyncResult;
- }
- return asyncResult;
- }
- /// <summary>
- /// 取消异步处理。
- /// </summary>
- public void CancelAsync()
- {
- if (this._doAsync)
- {
- this._cancelAsync = true;
- }
- }
- #endregion
- /*
- #region 异步处理(不锁定窗体)
- /// <summary>
- /// 窗体的异步处理(不锁定窗体)
- /// </summary>
- /// <typeparam name="T">返回值类型</typeparam>
- /// <param name="method">异步方法</param>
- /// <param name="callback">回调方法</param>
- /// <param name="code">方法扩展标识</param>
- /// <returns>方法标识</returns>
- public static IAsyncInvoker DoAsync<T>(Func<T> method, Action<T> callback, string code = null)
- {
- return AsyncFactory.Invoke<T>(method, callback, code);
- }
- /// <summary>
- /// 取消异步
- /// </summary>
- /// <typeparam name="T">返回值类型</typeparam>
- /// <param name="method">异步方法</param>
- /// <param name="code">方法扩展标识</param>
- /// <returns>是否成功取消</returns>
- public static bool Cancel<T>(Func<T> method, string code = null)
- {
- return AsyncFactory.Cancel<T>(method, code);
- }
- /// <summary>
- /// 取消异步
- /// </summary>
- /// <param name="methodCode">方法标识</param>
- /// <returns>是否成功取消</returns>
- public static bool Cancel(string methodCode)
- {
- return AsyncFactory.Cancel(methodCode);
- }
- /// <summary>
- /// 获取异步是否正在处理
- /// </summary>
- /// <typeparam name="T">返回值类型</typeparam>
- /// <param name="method">异步方法</param>
- /// <param name="code">方法扩展标识</param>
- /// <returns>是否正在处理</returns>
- public static bool IsDoing<T>(Func<T> method, string code = null)
- {
- return AsyncFactory.IsDoing<T>(method, code);
- }
- /// <summary>
- /// 获取异步是否正在处理
- /// </summary>
- /// <param name="methodCode">方法标识</param>
- /// <returns>是否正在处理</returns>
- public static bool IsDoing(string methodCode)
- {
- return AsyncFactory.IsDoing(methodCode);
- }
- /// <summary>
- /// 获取方法标识
- /// </summary>
- /// <typeparam name="T">返回值类型</typeparam>
- /// <param name="method">异步方法</param>
- /// <param name="code">方法扩展标识</param>
- /// <returns>方法标识</returns>
- public static string GetMethodCode<T>(Func<T> method, string code = null)
- {
- return AsyncFactory.GetMethodCode<T>(method, code);
- }
- #endregion
- */
- /// <summary>
- /// 向用户显示具有指定所有者的窗体。
- /// </summary>
- /// <param name="owner">表示将拥有模式对话框的顶级窗口</param>
- public virtual new void Show(IWin32Window owner)
- {
- base.Show(owner);
- this.ActivateForm();
- }
- /// <summary>
- /// 向用户显示具有指定所有者的窗体。
- /// </summary>
- public virtual new void Show()
- {
- base.Show();
- this.ActivateForm();
- }
- /// <summary>
- /// 激活窗体
- /// </summary>
- public void ActivateForm()
- {
- this.Visible = true;
- if (this.WindowState == FormWindowState.Minimized)
- {
- this.WindowState = this._formWindowState;
- }
- base.Activate();
- }
- #endregion
- #region 保护方法
- /// <summary>
- /// 设置异步处理开始状态
- /// </summary>
- protected virtual void StartProgress()
- {
- this._doFocus = true;
- this.BeginAsyncControls(this);
- this.ssrAsyncStatusStrip.Communicate = true;
- }
- /// <summary>
- /// 设置异步处理结束状态
- /// </summary>
- protected virtual void EndProgress()
- {
- this.ssrAsyncStatusStrip.Communicate = false;
- this.EndAsyncControls(this);
- }
- #region NotImplemented
- #region Form
- /// <summary>
- /// 窗体加载前调用(设置Form.Text、按钮等控件Text等)。
- /// </summary>
- protected virtual void InitForm()
- {
- }
- /// <summary>
- /// 窗体加载时调用(获取窗体初始化数据等)。
- /// </summary>
- protected virtual bool LoadForm()
- {
- return true;
- }
- #endregion
- #region Close
- /// <summary>
- /// 验证窗体中数据是否改变。
- /// </summary>
- /// <returns>数据被更改true,其他false</returns>
- protected virtual bool CheckDirty()
- {
- return false;
- }
- /// <summary>
- /// 关闭数据有改变的画面时,提示消息
- /// </summary>
- protected virtual DialogResult ShowMessageOnDirtyClose()
- {
- return DialogResult.Yes;
- }
- #endregion
- #region Set
- /// <summary>
- /// 验证画面输入项目
- /// </summary>
- /// <returns>验证通过true,其他false</returns>
- protected virtual bool CheckInputData()
- {
- return true;
- }
- /// <summary>
- /// 保存或设置数据到其他位置(其他画面或DB)
- /// </summary>
- /// <returns>保存或设置成功true,其他false</returns>
- protected virtual bool SetDataToOther()
- {
- return true;
- }
- /// <summary>
- /// 保存或设置数据成功后提示消息
- /// </summary>
- protected virtual void ShowMessageOnSetSucceed()
- {
- }
- /// <summary>
- /// 保存或设置数据成功后提示消息(新建或复制时,询问是否继续操作)
- /// </summary>
- /// <returns>继续操作true,其他false</returns>
- protected virtual bool ShowMessageOnAddSucceed()
- {
- return true;
- }
- ///// <summary>
- ///// 保存或设置数据失败后提示消息
- ///// </summary>
- //protected virtual void ShowMessageOnSetDefeated()
- //{
- //}
- #endregion
- #region Query
- /// <summary>
- /// 验证查询条件。
- /// </summary>
- /// <returns>验证通过true,其他false</returns>
- protected virtual bool CheckQueryConditions()
- {
- return true;
- }
- /// <summary>
- /// 查询数据。
- /// </summary>
- /// <returns>验证通过true,其他false</returns>
- protected virtual bool QueryDataFromOther()
- {
- return true;
- }
- ///// <summary>
- ///// 查询失败后提示消息
- ///// </summary>
- //protected virtual void ShowMessageOnQueryDefeated()
- //{
- //}
- #endregion
- #endregion
- #endregion
- #region 私有方法
- // todo 控件混用补丁。
- Control _fouced = null;
- /// <summary>
- /// 异步开始设置控件状态
- /// </summary>
- /// <param name="control"></param>
- private void BeginAsyncControls(Control control)
- {
- if (control == null)
- {
- return;
- }
- if (control is IAsyncControl)
- {
- // todo 修改为把控件传入
- (control as IAsyncControl).BeginAsync(ref this._doFocus);
- if (!this._doFocus)
- {
- this.txtFoucs.Focus();
- }
- return;
- }
- else
- {
- // todo 控件混用补丁。
- if (control is DataGridView)
- {
- if (control.Focused)
- {
- this._fouced = control;
- this.txtFoucs.Focus();
- }
- control.Enabled = false;
- return;
- }
- if (control.Controls == null || control.Controls.Count == 0)
- {
- //control.Enabled = false;
- return;
- }
- foreach (Control item in control.Controls)
- {
- this.BeginAsyncControls(item);
- }
- }
- }
- /// <summary>
- /// 异步结束设置控件状态
- /// </summary>
- /// <param name="control"></param>
- private void EndAsyncControls(Control control)
- {
- if (control == null)
- {
- return;
- }
- if (control is IAsyncControl)
- {
- (control as IAsyncControl).EndAsync();
- return;
- }
- else
- {
- // todo 控件混用补丁。
- if (control is DataGridView)
- {
- control.Enabled = true;
- if (this._fouced == control)
- {
- this._fouced = null;
- control.Focus();
- }
- return;
- }
- if (control.Controls == null || control.Controls.Count == 0)
- {
- //control.Enabled = false;
- return;
- }
- foreach (Control item in control.Controls)
- {
- this.EndAsyncControls(item);
- }
- }
- }
- /// <summary>
- /// 设置是否在控件的右下角显示大小调整手柄。
- /// </summary>
- private void SetStatusSizingGrip()
- {
- switch (base.FormBorderStyle)
- {
- case FormBorderStyle.Sizable:
- case FormBorderStyle.SizableToolWindow:
- this.ssrAsyncStatusStrip.SizingGrip = true;
- break;
- default:
- this.ssrAsyncStatusStrip.SizingGrip = false;
- break;
- }
- }
- #endregion
- }
- }
|