⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dlgbase.cs

📁 报刊广告管理系统。CSharp编写
💻 CS
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
using System.IO;

namespace WWAM.Forms.Dlg
{
	/// <summary>
	/// FHDialogFormBase 的摘要说明。
	/// </summary>
	public class DlgBase : System.Windows.Forms.Form
	{
		
		#region DlgBase
		private System.ComponentModel.IContainer components = null;
		protected DevExpress.XtraEditors.SimpleButton btnAccept;
		private DevExpress.LookAndFeel.DefaultLookAndFeel defaultLookAndFeel1;
		protected DevExpress.Utils.ToolTipController baseToolTip;
		protected DevExpress.XtraEditors.SimpleButton btnCancel;

		public DlgBase()
		{
			// 该调用是 Windows.Forms 窗体设计器所必需的。
			InitializeComponent();
			this.Visible = false;
		}

		public DlgBase(Form form)
		{
			InitializeComponent();
			this.Owner = form;
			this.Visible = false;
		}

		/// <summary> 
		/// 清理所有正在使用的资源。
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region 组件设计器生成的代码
		/// <summary> 
		/// 设计器支持所需的方法 - 不要使用代码编辑器 
		/// 修改此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{
			this.components = new System.ComponentModel.Container();
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(DlgBase));
			this.btnAccept = new DevExpress.XtraEditors.SimpleButton();
			this.btnCancel = new DevExpress.XtraEditors.SimpleButton();
			this.defaultLookAndFeel1 = new DevExpress.LookAndFeel.DefaultLookAndFeel(this.components);
			this.baseToolTip = new DevExpress.Utils.ToolTipController(this.components);
			this.SuspendLayout();
			// 
			// btnAccept
			// 
			this.btnAccept.DialogResult = System.Windows.Forms.DialogResult.OK;
			this.btnAccept.Location = new System.Drawing.Point(128, 112);
			this.btnAccept.LookAndFeel.Style = DevExpress.LookAndFeel.LookAndFeelStyle.Skin;
			this.btnAccept.LookAndFeel.UseWindowsXPTheme = false;
			this.btnAccept.Name = "btnAccept";
			this.btnAccept.TabIndex = 0;
			this.btnAccept.Text = "确 认";
			this.btnAccept.Click += new System.EventHandler(this.btnAccept_Click);
			// 
			// btnCancel
			// 
			this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
			this.btnCancel.Location = new System.Drawing.Point(224, 112);
			this.btnCancel.LookAndFeel.Style = DevExpress.LookAndFeel.LookAndFeelStyle.Skin;
			this.btnCancel.LookAndFeel.UseWindowsXPTheme = false;
			this.btnCancel.Name = "btnCancel";
			this.btnCancel.TabIndex = 1;
			this.btnCancel.Text = "取 消";
			this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
			// 
			// defaultLookAndFeel1
			// 
			this.defaultLookAndFeel1.LookAndFeel.Style = DevExpress.LookAndFeel.LookAndFeelStyle.Skin;
			this.defaultLookAndFeel1.LookAndFeel.UseWindowsXPTheme = false;
			// 
			// baseToolTip
			// 
			this.baseToolTip.Rounded = true;
			// 
			// DlgBase
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.CancelButton = this.btnCancel;
			this.ClientSize = new System.Drawing.Size(314, 152);
			this.Controls.Add(this.btnAccept);
			this.Controls.Add(this.btnCancel);
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
			this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
			this.MaximizeBox = false;
			this.MinimizeBox = false;
			this.Name = "DlgBase";
			this.ShowInTaskbar = false;
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.ResumeLayout(false);

		}
		#endregion
		#endregion

		#region Variable
		private bool clickOk = false;
		private bool firstShow = true;
		protected bool gridViewLayoutChanged = false;
		string layoutFileName = "";
		string layoutPath;
		protected bool edited = false;
		#endregion

		#region Control Event
		private void btnAccept_Click(object sender, System.EventArgs e)
		{
			clickOk = true;
			//this.Close();
		}

		private void btnCancel_Click(object sender, System.EventArgs e)
		{
			clickOk = false;
			//this.Close();
		}
		#endregion

		#region Virtaul Method
		protected virtual void OnFormLoad()
		{}
		protected virtual void OnFormClose()
		{}
		protected virtual bool CanClose()
		{
			return true;
		}

		protected virtual void OnResultOK()
		{
		}

		protected virtual void OnResultCancel()
		{
		}

		protected virtual void OnFormShow()
		{
		}
		#endregion

		#region protected Method
		protected void SetToolTip(Control control, string toolTip)
		{
			baseToolTip.ShowHint(toolTip,control,DevExpress.Utils.ToolTipLocation.BottomCenter);
		}
		protected void HideToolTip()
		{
			baseToolTip.HideHint();
		}
		protected void ComboDataBind(DevExpress.XtraEditors.ComboBoxEdit cmb, DataTable _dt, string fieldName)		{			cmb.Properties.Items.Clear();			foreach(DataRow _dr in _dt.Rows)			{				cmb.Properties.Items.Add(_dr[fieldName]);			}		}
		protected void ComboDataBind(DevExpress.XtraEditors.ComboBoxEdit cmb, DataTable _dt, string fieldName,string rowFilter)		{			_dt.DefaultView.RowFilter = rowFilter;			IEnumerator ie = _dt.DefaultView.GetEnumerator();			ie.Reset();			cmb.Properties.Items.Clear();			while(ie.MoveNext())			{				DataRow _dr = ((DataRowView)ie.Current).Row;				cmb.Properties.Items.Add(_dr[fieldName]);			}		}		protected bool ControlEmpty(DevExpress.XtraEditors.BaseControl ctrl, string errortext)		{			bool rv = ctrl.Text.Trim() == string.Empty;			if(rv)			{				SetToolTip(ctrl,errortext);
				ctrl.Focus();			}			return rv;		}		protected void BaseEditor_EditValueChanged(object sender, System.EventArgs e)		{			HideToolTip();			this.edited = true;		}		protected void setCheckEditColor(DevExpress.XtraEditors.CheckEdit chk)		{			chk.ForeColor = chk.Checked?Color.FromArgb(192,0,0):Color.Black;		}		#region GridViewLayoutSave		protected void setLayoutFileName(string fileName)
		{
			this.layoutFileName = layoutPath+"\\"+fileName+".gvl";
		}
		protected void ViewLoadLayout(DevExpress.XtraGrid.Views.Base.BaseView view)
		{
			if(File.Exists(layoutFileName))
			{
				view.RestoreLayoutFromXml(layoutFileName);
			}
		}
		protected void ViewSaveLayout(DevExpress.XtraGrid.Views.Base.BaseView view)
		{
			if(gridViewLayoutChanged && layoutFileName!="")
			{
				if(!Directory.Exists(layoutPath))
					Directory.CreateDirectory(layoutPath);
				view.SaveLayoutToXml(layoutFileName);
			}
		}
		protected void View_Layout(object sender, System.EventArgs e)
		{
			this.gridViewLayoutChanged = true;
		}		#endregion		#endregion

		#region FromEvent
		protected override void OnLoad(EventArgs e)
		{
			base.OnLoad (e);
			layoutPath = Application.StartupPath+@"\\gvLayout";
			OnFormLoad();
		}

		protected override void OnVisibleChanged(EventArgs e)
		{
			base.OnVisibleChanged(e);

			if(this.DesignMode)
			{
				return;
			}

			if(this.Visible)
			{
				if(this.Owner != null && this.Owner.Visible)
				{
					Point OwnerPos = this.Owner.PointToScreen(new Point(0,0));
					this.Left = OwnerPos.X + (this.Owner.Width - this.Width)/2;
					this.Top = OwnerPos.Y + (this.Owner.Height - this.Height)/2;
				}
				else
				{
					this.Left = (Screen.PrimaryScreen.WorkingArea.Width - this.Width)/2;
					this.Top = (Screen.PrimaryScreen.WorkingArea.Height - this.Height)/2;
				}
			}
		}


		protected override void OnClosing(CancelEventArgs e)
		{
			base.OnClosing (e);

			e.Cancel = clickOk &&!CanClose();
		}


		protected override void OnActivated(EventArgs e)
		{
			base.OnActivated (e);
			if(firstShow)
			{
				OnFormShow();
				firstShow = false;
				edited = false;
			}
		}


		protected override void OnClosed(EventArgs e)
		{
			if(clickOk)
			{
				OnResultOK();
				clickOk = false;
			}
			else
			{
				OnResultCancel();
			}
			OnFormClose();
			this.firstShow = true;
			base.OnClosed (e);

		}
		

		#endregion
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -