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

📄 frmbase.cs

📁 采用C#和SQL Server 2000开发 功能比较全面的酒店管理系统
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;

namespace 酒店管理系统
{
	/// <summary>
	/// frmBase 的摘要说明。
	/// </summary>
	public class frmBase : System.Windows.Forms.Form
	{
		internal System.Windows.Forms.ToolBarButton tbbModify;
		internal System.Windows.Forms.ToolBarButton tbbDel;
		internal System.Windows.Forms.ToolBarButton tbbNew;
		internal System.Windows.Forms.ToolBarButton tbbForward;
		internal System.Windows.Forms.ToolBarButton tbbLast;
		internal System.Windows.Forms.ToolBarButton tbbSave;
		public System.Windows.Forms.DataGrid dgdList;
		internal System.Windows.Forms.ImageList ImageList1;
		internal System.Windows.Forms.ToolBarButton tbbUndo;
		internal System.Windows.Forms.ToolBarButton tbbExit;
		internal System.Windows.Forms.GroupBox grbSearch;
		internal System.Windows.Forms.Label Label3;
		internal System.Windows.Forms.TextBox txbThree;
		internal System.Windows.Forms.TextBox txbTwo;
		internal System.Windows.Forms.Label Label2;
		internal System.Windows.Forms.Label Label1;
		internal System.Windows.Forms.TextBox txbOne;
		internal System.Windows.Forms.Button btnSearch;
		internal System.Windows.Forms.Label lblCount;
		internal System.Windows.Forms.ToolBarButton tbbFirst;
		internal System.Windows.Forms.ToolBarButton tbbBack;
		internal System.Windows.Forms.ToolBar ToolBar1;
		private System.ComponentModel.IContainer components;

		// added member
		protected BindingManagerBase bmData;
		protected DataTable dtData;
		protected bool bAdd;

		public frmBase()
		{
			//
			// Windows 窗体设计器支持所必需的
			//
			InitializeComponent();

			//
			// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
			//
		}

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

		#region Windows 窗体设计器生成的代码
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{
			this.components = new System.ComponentModel.Container();
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(frmBase));
			this.tbbModify = new System.Windows.Forms.ToolBarButton();
			this.tbbDel = new System.Windows.Forms.ToolBarButton();
			this.tbbNew = new System.Windows.Forms.ToolBarButton();
			this.tbbForward = new System.Windows.Forms.ToolBarButton();
			this.tbbLast = new System.Windows.Forms.ToolBarButton();
			this.tbbSave = new System.Windows.Forms.ToolBarButton();
			this.dgdList = new System.Windows.Forms.DataGrid();
			this.ImageList1 = new System.Windows.Forms.ImageList(this.components);
			this.tbbUndo = new System.Windows.Forms.ToolBarButton();
			this.tbbExit = new System.Windows.Forms.ToolBarButton();
			this.grbSearch = new System.Windows.Forms.GroupBox();
			this.Label3 = new System.Windows.Forms.Label();
			this.txbThree = new System.Windows.Forms.TextBox();
			this.txbTwo = new System.Windows.Forms.TextBox();
			this.Label2 = new System.Windows.Forms.Label();
			this.Label1 = new System.Windows.Forms.Label();
			this.txbOne = new System.Windows.Forms.TextBox();
			this.btnSearch = new System.Windows.Forms.Button();
			this.lblCount = new System.Windows.Forms.Label();
			this.tbbFirst = new System.Windows.Forms.ToolBarButton();
			this.tbbBack = new System.Windows.Forms.ToolBarButton();
			this.ToolBar1 = new System.Windows.Forms.ToolBar();
			((System.ComponentModel.ISupportInitialize)(this.dgdList)).BeginInit();
			this.grbSearch.SuspendLayout();
			this.SuspendLayout();
			// 
			// tbbModify
			// 
			this.tbbModify.ImageIndex = 5;
			this.tbbModify.Text = "修改";
			this.tbbModify.ToolTipText = "修改";
			// 
			// tbbDel
			// 
			this.tbbDel.ImageIndex = 6;
			this.tbbDel.Text = "删除";
			this.tbbDel.ToolTipText = "删除";
			// 
			// tbbNew
			// 
			this.tbbNew.ImageIndex = 4;
			this.tbbNew.Text = "新增";
			this.tbbNew.ToolTipText = "新增";
			// 
			// tbbForward
			// 
			this.tbbForward.ImageIndex = 2;
			this.tbbForward.Text = "下记录";
			this.tbbForward.ToolTipText = "下一条记录";
			// 
			// tbbLast
			// 
			this.tbbLast.ImageIndex = 3;
			this.tbbLast.Text = "尾记录";
			this.tbbLast.ToolTipText = "尾记录";
			// 
			// tbbSave
			// 
			this.tbbSave.Enabled = false;
			this.tbbSave.ImageIndex = 7;
			this.tbbSave.Text = "保存";
			this.tbbSave.ToolTipText = "保存";
			// 
			// dgdList
			// 
			this.dgdList.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
				| System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.dgdList.CaptionVisible = false;
			this.dgdList.DataMember = "";
			this.dgdList.HeaderForeColor = System.Drawing.SystemColors.ControlText;
			this.dgdList.Location = new System.Drawing.Point(0, 96);
			this.dgdList.Name = "dgdList";
			this.dgdList.Size = new System.Drawing.Size(603, 88);
			this.dgdList.TabIndex = 6;
			this.dgdList.CurrentCellChanged += new System.EventHandler(this.dgdList_CurrentCellChanged);
			// 
			// ImageList1
			// 
			this.ImageList1.ImageSize = new System.Drawing.Size(16, 16);
			this.ImageList1.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("ImageList1.ImageStream")));
			this.ImageList1.TransparentColor = System.Drawing.Color.Transparent;
			// 
			// tbbUndo
			// 
			this.tbbUndo.Enabled = false;
			this.tbbUndo.ImageIndex = 8;
			this.tbbUndo.Text = "取消";
			this.tbbUndo.ToolTipText = "取消";
			// 
			// tbbExit
			// 
			this.tbbExit.ImageIndex = 9;
			this.tbbExit.Text = "退出";
			this.tbbExit.ToolTipText = "退出";
			// 
			// grbSearch
			// 
			this.grbSearch.Controls.Add(this.Label3);
			this.grbSearch.Controls.Add(this.txbThree);
			this.grbSearch.Controls.Add(this.txbTwo);
			this.grbSearch.Controls.Add(this.Label2);
			this.grbSearch.Controls.Add(this.Label1);
			this.grbSearch.Controls.Add(this.txbOne);
			this.grbSearch.Controls.Add(this.btnSearch);
			this.grbSearch.Controls.Add(this.lblCount);
			this.grbSearch.Dock = System.Windows.Forms.DockStyle.Top;
			this.grbSearch.Location = new System.Drawing.Point(0, 41);
			this.grbSearch.Name = "grbSearch";
			this.grbSearch.Size = new System.Drawing.Size(608, 39);
			this.grbSearch.TabIndex = 5;
			this.grbSearch.TabStop = false;
			// 
			// Label3
			// 
			this.Label3.Location = new System.Drawing.Point(328, 16);
			this.Label3.Name = "Label3";
			this.Label3.Size = new System.Drawing.Size(56, 15);
			this.Label3.TabIndex = 6;
			this.Label3.Text = "楼层编号";
			// 
			// txbThree
			// 
			this.txbThree.Location = new System.Drawing.Point(384, 11);
			this.txbThree.Name = "txbThree";
			this.txbThree.Size = new System.Drawing.Size(56, 21);
			this.txbThree.TabIndex = 5;
			this.txbThree.Text = "";
			// 
			// txbTwo
			// 
			this.txbTwo.Location = new System.Drawing.Point(264, 11);
			this.txbTwo.Name = "txbTwo";
			this.txbTwo.Size = new System.Drawing.Size(56, 21);
			this.txbTwo.TabIndex = 4;
			this.txbTwo.Text = "";
			// 
			// Label2
			// 
			this.Label2.Location = new System.Drawing.Point(208, 16);
			this.Label2.Name = "Label2";
			this.Label2.Size = new System.Drawing.Size(56, 15);
			this.Label2.TabIndex = 3;
			this.Label2.Text = "类型编号";
			// 
			// Label1
			// 
			this.Label1.Location = new System.Drawing.Point(88, 16);
			this.Label1.Name = "Label1";
			this.Label1.Size = new System.Drawing.Size(56, 15);
			this.Label1.TabIndex = 2;
			this.Label1.Text = "客房编号";
			// 
			// txbOne
			// 
			this.txbOne.Location = new System.Drawing.Point(144, 11);
			this.txbOne.Name = "txbOne";
			this.txbOne.Size = new System.Drawing.Size(56, 21);
			this.txbOne.TabIndex = 1;
			this.txbOne.Text = "";
			// 
			// btnSearch
			// 
			this.btnSearch.Image = ((System.Drawing.Image)(resources.GetObject("btnSearch.Image")));
			this.btnSearch.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
			this.btnSearch.Location = new System.Drawing.Point(16, 12);
			this.btnSearch.Name = "btnSearch";
			this.btnSearch.Size = new System.Drawing.Size(64, 22);
			this.btnSearch.TabIndex = 0;
			this.btnSearch.Text = "   搜索";
			this.btnSearch.Click += new System.EventHandler(this.btnSearch_Click);
			// 
			// lblCount
			// 
			this.lblCount.Location = new System.Drawing.Point(472, 15);
			this.lblCount.Name = "lblCount";
			this.lblCount.Size = new System.Drawing.Size(104, 12);
			this.lblCount.TabIndex = 4;
			// 
			// tbbFirst
			// 
			this.tbbFirst.ImageIndex = 0;
			this.tbbFirst.Text = "首记录";
			this.tbbFirst.ToolTipText = "首记录";
			// 
			// tbbBack
			// 
			this.tbbBack.ImageIndex = 1;
			this.tbbBack.Text = "上记录";
			this.tbbBack.ToolTipText = "上一条记录";
			// 
			// ToolBar1
			// 
			this.ToolBar1.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] {
																						this.tbbFirst,
																						this.tbbBack,
																						this.tbbForward,
																						this.tbbLast,
																						this.tbbNew,
																						this.tbbModify,
																						this.tbbDel,
																						this.tbbSave,
																						this.tbbUndo,
																						this.tbbExit});
			this.ToolBar1.DropDownArrows = true;
			this.ToolBar1.ImageList = this.ImageList1;
			this.ToolBar1.Location = new System.Drawing.Point(0, 0);
			this.ToolBar1.Name = "ToolBar1";
			this.ToolBar1.ShowToolTips = true;
			this.ToolBar1.Size = new System.Drawing.Size(608, 41);
			this.ToolBar1.TabIndex = 4;
			this.ToolBar1.ButtonClick += new System.Windows.Forms.ToolBarButtonClickEventHandler(this.ToolBar1_ButtonClick);
			// 
			// frmBase
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(608, 284);
			this.Controls.Add(this.grbSearch);
			this.Controls.Add(this.ToolBar1);
			this.Controls.Add(this.dgdList);
			this.Name = "frmBase";
			this.Text = "frmBase";
			this.Load += new System.EventHandler(this.frmBase_Load);
			((System.ComponentModel.ISupportInitialize)(this.dgdList)).EndInit();
			this.grbSearch.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

		private void btnSearch_Click(object sender, System.EventArgs e)
		{
			SearchResult();
		}

		private void frmBase_Load(object sender, System.EventArgs e)
		{
			Prepare();
			SetDataGrid();
			SetTextBoxState( true );
		}

		private void SetToolBarState( bool bState )
		{
			ToolBar1.Buttons[ 0 ].Enabled = bState;
			ToolBar1.Buttons[ 1 ].Enabled = bState;
			ToolBar1.Buttons[ 2 ].Enabled = bState;
			ToolBar1.Buttons[ 3 ].Enabled = bState;
			ToolBar1.Buttons[ 4 ].Enabled = bState;
			ToolBar1.Buttons[ 5 ].Enabled = bState;
			ToolBar1.Buttons[ 6 ].Enabled = bState;
			ToolBar1.Buttons[ 7 ].Enabled = !bState;
			ToolBar1.Buttons[ 8 ].Enabled = !bState;
		}

		public virtual void Prepare()
		{	}

		public virtual void LoadData()
		{	}

		public virtual void SetDataGrid()
		{	}

		public virtual void SearchResult()
		{
			SetDataGrid();
			dgdList.DataSource = dtData.DefaultView;
		}

		public virtual void SaveForAdd()
		{	}

		public virtual void SaveForUpdate()
		{	}

		public virtual void DeleteData()
		{	}

		public virtual void Clear()
		{	}

		public virtual void SetTextBoxState( bool bState )
		{	}

		public virtual void SetData()
		{	}

		private void dgdList_CurrentCellChanged(object sender, System.EventArgs e)
		{
			try
			{
				// 判断bmData是否为null
				if ( bmData == null )
				{
					return;
				}
				if ( bmData.Position != dgdList.CurrentCell.RowNumber )
				{
					bmData.Position = dgdList.CurrentCell.RowNumber;
					SetData();
				}
			}
			catch( Exception ex )
			{
				MessageBox.Show( ex.ToString() );
			}
				
			}

		private void ToolBar1_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
		{
			switch ( e.Button.Text )
			{
				case "首记录" :
					// 返回首记录
					bmData.Position = 0;
					break;
				case "上记录" :
					if ( bmData.Position != 0 )
					{
						bmData.Position -= 1;
					}
					break;
				case "下记录" :
					if ( bmData.Position != bmData.Count )
						bmData.Position += 1;
					break;
				case "尾记录" :
					bmData.Position = bmData.Count;
					break;
				case "新增" :
					dgdList.Enabled = false;
					SetTextBoxState( false );
					SetToolBarState( false );
					bAdd = true;
					Clear();
					break;
				case "修改" :
					dgdList.Enabled = false;
					SetTextBoxState( false );
					SetToolBarState( false );
					bAdd = false;
					break;
				case "删除" :
					// 弹出询问对话框
					DialogResult dlgResult = MessageBox.Show( "你确认删除此数据?", "删除", MessageBoxButtons.OKCancel );
					if ( dlgResult == DialogResult.OK )
						DeleteData();
					break;
				case "保存" :
					SetToolBarState( true );
					SetTextBoxState( true );
					if ( bAdd )
					{
						// 为新增数据保存
						SaveForAdd();
					}
					else
					{
						// 为更新数据保存
						SaveForUpdate();
					}
					dgdList.Enabled = true;
					break;
				case "取消" :
					SetTextBoxState( true );
					SetToolBarState( true );
					dgdList.Enabled = true;
					SearchResult();
					break;
				case "退出" :
					// 关闭本窗体
					this.Close();
					break;
			}
			try
			{
				dgdList.CurrentRowIndex = bmData.Position;
				SetData();
			}
			catch( Exception ex )
			{
				ex.ToString();
			}
		}
	}
}

⌨️ 快捷键说明

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