| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383 |
- /*******************************************************************************
- * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
- * 类的信息:
- * 1.程序名称:DockPanelBase.cs
- * 2.功能描述:类文件
- * 编辑履历:
- * 作者 日期 版本 修改内容
- * 陈晓野 2014/09/01 1.00 新建
- *******************************************************************************/
- using System;
- using System.Collections;
- using System.ComponentModel;
- using System.Data;
- using System.Windows.Forms;
- using Dongke.IBOSS.PRD.Basics.BaseControls;
- using Dongke.IBOSS.PRD.Basics.Library;
- namespace Dongke.IBOSS.PRD.Basics.DockPanel
- {
- #region 异步处理的委托
- /// <summary>
- /// 异步处理
- /// </summary>
- /// <returns></returns>
- public delegate object AsyncMethod();
- #endregion
- public partial class DockPanelBase : DockContent
- {
- #region 成员变量
- private bool _canClosing = true;
- private DataSet _dataSource = null;
- private ContextMenuStrip cmsMenu;
- private ToolStripMenuItem tsmiClose;
- private ToolStripMenuItem tsmiCloseAll;
- private ToolStripMenuItem tsmiCloseAllExcept;
- private IContainer components = null;
- #endregion
- #region 属性
- /// <summary>
- /// 窗体的数据源的取得和设定
- /// </summary>
- [Browsable(true)]
- [DefaultValue(null)]
- [Description("窗体的数据源的取得和设定。")]
- public DataSet DataSource
- {
- get
- {
- return _dataSource;
- }
- set
- {
- _dataSource = value;
- }
- }
- #endregion
- #region 构造函数
- /// <summary>
- /// 构造函数
- /// </summary>
- public DockPanelBase()
- {
- InitializeComponent();
- this.Font = ControlsConst.FONT_SYSTEM_DEFAULT;
- this.TabPageContextMenuStrip = cmsMenu;
- this.BackgroundImage = ResourceBackGroundImage.bg;
- }
- #endregion
- #region 事件
- /// <summary>
- /// 关闭事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void DockPanelBase_FormClosing(object sender, FormClosingEventArgs e)
- {
- if (!this._canClosing)
- {
- e.Cancel = true;
- }
- }
-
- #region 重写方法或者函数
- /// <summary>
- /// 重写Form的OnLoad事件
- /// </summary>
- /// <param name="e"></param>
- protected override void OnLoad(EventArgs e)
- {
- base.OnLoad(e);
- //datagridview控件设置保存
- Control[] controls = this.GetControls(this, typeof(C_DataGridView));
- foreach (C_DataGridView dgv in controls)
- {
- if (dgv.IsSaveDataGridViewSetting)
- {
- GridSettingManager.InitializeGridSetting(dgv, this.Name + dgv.Name);
- }
- }
- }
- /// <summary>
- /// 重写Form的OnFormClosing事件
- /// </summary>
- /// <param name="e"></param>
- protected override void OnFormClosing(FormClosingEventArgs e)
- {
- if (!this._canClosing)
- {
- e.Cancel = true;
- return;
- }
- base.OnFormClosing(e);
- }
- /// <summary>
- /// 重写Form的OnFormClosed事件
- /// </summary>
- /// <param name="e"></param>
- protected override void OnFormClosed(FormClosedEventArgs e)
- {
- // datagridview控件设置保存(TODO)
- Control[] items = this.GetControls(this, typeof(C_DataGridView));
- foreach (C_DataGridView grd in items)
- {
- if (grd.IsSaveDataGridViewSetting)
- {
- GridSettingManager.SaveGridSetting(grd, this.Name + grd.Name);
- }
- }
- base.OnFormClosed(e);
- // 内存回收 241224
- GC.Collect();
- GC.WaitForPendingFinalizers();
- }
- /// <summary>
- /// 取得所有控件
- /// </summary>
- /// <param name="topControl">控件类型</param>
- /// <param name="type">控件类型</param>
- /// <returns>所有控件</returns>
- public Control[] GetControls(Control topControl, Type type)
- {
- if (topControl == null)
- {
- return GetControls(this, type);
- }
- ArrayList list = new ArrayList();
- foreach (Control control in topControl.Controls)
- {
- if (type == null || type.Equals(control.GetType()))
- {
- list.Add(control);
- }
- list.AddRange(GetControls(control, type));
- }
- return (Control[])list.ToArray(typeof(Control));
- }
- #endregion
- #endregion
- #region 程序异步处理
- /// <summary>
- /// 窗体的异步处理
- /// </summary>
- /// <param name="method">异步方法</param>
- /// <returns></returns>
- public object DoAsync(AsyncMethod method)
- {
- object result = null;
- try
- {
- StartProgress();
- IAsyncResult asyncResult = method.BeginInvoke(null, null);
- while (!asyncResult.IsCompleted)
- {
- Application.DoEvents();
- System.Threading.Thread.Sleep(1);
- }
- result = method.EndInvoke(asyncResult);
- }
- finally
- {
- EndProgress();
- }
- return result;
- }
- /// <summary>
- /// 开始异步处理
- /// </summary>
- public virtual void StartProgress()
- {
- this._canClosing = false;
- BeginAsyncControls(this);
- }
- public virtual void BeginAsyncControls(Control control)
- {
- if (control == null)
- {
- return;
- }
- if (control is IDKControl)
- {
- (control as IDKControl).BeginAsync();
- return;
- }
- else
- {
- if (control is ToolStrip)
- {
- control.Enabled = false;
- return;
- }
- if (control.Controls == null || control.Controls.Count == 0)
- {
- //control.Enabled = false;
- return;
- }
- foreach (Control item in control.Controls)
- {
- BeginAsyncControls(item);
- }
- }
- }
- /// <summary>
- /// 结束异步处理
- /// </summary>
- public virtual void EndProgress()
- {
- this._canClosing = true;
- EndAsyncControls(this);
- }
- public virtual void EndAsyncControls(Control control)
- {
- if (control == null)
- {
- return;
- }
- if (control is IDKControl)
- {
- (control as IDKControl).EndAsync();
- return;
- }
- else
- {
- if (control is ToolStrip)
- {
- control.Enabled = true;
- return;
- }
- if (control.Controls == null || control.Controls.Count == 0)
- {
- //control.Enabled = false;
- return;
- }
- foreach (Control item in control.Controls)
- {
- EndAsyncControls(item);
- }
- }
- }
- #endregion
- #region 私有方法/函数
- private void InitializeComponent()
- {
- this.components = new System.ComponentModel.Container();
- System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(DockPanelBase));
- this.cmsMenu = new System.Windows.Forms.ContextMenuStrip(this.components);
- this.tsmiClose = new System.Windows.Forms.ToolStripMenuItem();
- this.tsmiCloseAllExcept = new System.Windows.Forms.ToolStripMenuItem();
- this.tsmiCloseAll = new System.Windows.Forms.ToolStripMenuItem();
- this.cmsMenu.SuspendLayout();
- this.SuspendLayout();
- //
- // cmsMenu
- //
- this.cmsMenu.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
- this.tsmiClose,
- this.tsmiCloseAllExcept,
- this.tsmiCloseAll});
- this.cmsMenu.Name = "cmsMenu";
- this.cmsMenu.ShowImageMargin = false;
- this.cmsMenu.Size = new System.Drawing.Size(163, 70);
- //
- // tsmiClose
- //
- this.tsmiClose.Name = "tsmiClose";
- this.tsmiClose.Size = new System.Drawing.Size(162, 22);
- this.tsmiClose.Text = "关闭(&X)";
- this.tsmiClose.Click += new System.EventHandler(this.tsmiClose_Click);
- //
- // tsmiCloseAllExcept
- //
- this.tsmiCloseAllExcept.Name = "tsmiCloseAllExcept";
- this.tsmiCloseAllExcept.Size = new System.Drawing.Size(162, 22);
- this.tsmiCloseAllExcept.Text = "除此之外全部关闭(&E)";
- this.tsmiCloseAllExcept.Click += new System.EventHandler(this.tsmiCloseAllExcept_Click);
- //
- // tsmiCloseAll
- //
- this.tsmiCloseAll.Name = "tsmiCloseAll";
- this.tsmiCloseAll.Size = new System.Drawing.Size(162, 22);
- this.tsmiCloseAll.Text = "全部关闭(&A)";
- this.tsmiCloseAll.Click += new System.EventHandler(this.tsmiCloseAll_Click);
- //
- // DockPanelBase
- //
- this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
- this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.AutoScroll = true;
- this.ClientSize = new System.Drawing.Size(284, 262);
- this.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
- this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
- this.Name = "DockPanelBase";
- this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.DockPanelBase_FormClosing);
- this.cmsMenu.ResumeLayout(false);
- this.ResumeLayout(false);
- }
- private void tsmiClose_Click(object sender, EventArgs e)
- {
- this.Close();
- }
- private void tsmiCloseAllExcept_Click(object sender, EventArgs e)
- {
- IDockContent[] documents = DockPanel.DocumentsToArray();
- foreach (IDockContent content in documents)
- {
- if (!content.Equals(this))
- {
- content.DockHandler.Close();
- }
- }
- }
- private void tsmiCloseAll_Click(object sender, EventArgs e)
- {
- IDockContent[] documents = DockPanel.DocumentsToArray();
- foreach (IDockContent content in documents)
- {
- content.DockHandler.Close();
- }
- }
- /// <summary>
- /// 显示对应的页面中主窗体中
- /// </summary>
- /// <param name="dockPanelBaseForm">需要停靠的DockPanelBase</param>
- public void ShowInDockPanel(DockPanel dockPanel)
- {
- try
- {
- this.Show(dockPanel, DockState.Document);
- this.Activate();
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- #endregion
- }
- }
|