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

📄 configure.cs

📁 人事,工资,考勤系统,C#实现 1、查看建模图 本文件夹中的Model目录下包含了系统的数据库模型图和系统建模图
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.OleDb;

namespace ManPowerManage.UILevel
{
	/// <summary>
	/// Configure 的摘要说明。
	/// </summary>
	public class Configure : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Button btnDelete;
		private System.Windows.Forms.Button btnAdd;
		private System.Windows.Forms.Button btnApply;
		private System.Windows.Forms.Button btnExit;
		private System.Windows.Forms.Button btnCancel;
		private OleDbConnection Connection1=null;
		private OleDbCommand  Command1=null;
		private OleDbDataReader DataReader1=null;
		private string commandStr;
		private string connectionStr;
		private string dataTable;
		private bool add;
		private System.Windows.Forms.ListBox listBox1;
		private System.Windows.Forms.TextBox textBox1;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.ComboBox comboBox1;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.GroupBox groupBox1;
		private System.Windows.Forms.GroupBox groupBox2;

			
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;

		public Configure()
		{
			//
			// Windows 窗体设计器支持所必需的
			//
			InitializeComponent();
			this.connectionStr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" +Application.StartupPath + "\\ManPowerManage.mdb"; 
			this.Connection1=new OleDbConnection(this.connectionStr);
			this.Command1=new OleDbCommand();
			this.Command1.Connection=this.Connection1;
			this.dataTable="Department";
			this.add=false;
			//
			// 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()
		{
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Configure));
			this.btnDelete = new System.Windows.Forms.Button();
			this.btnAdd = new System.Windows.Forms.Button();
			this.btnApply = new System.Windows.Forms.Button();
			this.btnExit = new System.Windows.Forms.Button();
			this.btnCancel = new System.Windows.Forms.Button();
			this.listBox1 = new System.Windows.Forms.ListBox();
			this.textBox1 = new System.Windows.Forms.TextBox();
			this.label1 = new System.Windows.Forms.Label();
			this.comboBox1 = new System.Windows.Forms.ComboBox();
			this.label2 = new System.Windows.Forms.Label();
			this.groupBox1 = new System.Windows.Forms.GroupBox();
			this.groupBox2 = new System.Windows.Forms.GroupBox();
			this.groupBox1.SuspendLayout();
			this.groupBox2.SuspendLayout();
			this.SuspendLayout();
			// 
			// btnDelete
			// 
			this.btnDelete.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
			this.btnDelete.Image = ((System.Drawing.Image)(resources.GetObject("btnDelete.Image")));
			this.btnDelete.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
			this.btnDelete.Location = new System.Drawing.Point(16, 96);
			this.btnDelete.Name = "btnDelete";
			this.btnDelete.Size = new System.Drawing.Size(56, 24);
			this.btnDelete.TabIndex = 61;
			this.btnDelete.Text = "删除";
			this.btnDelete.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			this.btnDelete.Click += new System.EventHandler(this.btnDelete_Click);
			// 
			// btnAdd
			// 
			this.btnAdd.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
			this.btnAdd.Image = ((System.Drawing.Image)(resources.GetObject("btnAdd.Image")));
			this.btnAdd.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
			this.btnAdd.Location = new System.Drawing.Point(16, 56);
			this.btnAdd.Name = "btnAdd";
			this.btnAdd.Size = new System.Drawing.Size(56, 24);
			this.btnAdd.TabIndex = 59;
			this.btnAdd.Text = "添加";
			this.btnAdd.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			this.btnAdd.Click += new System.EventHandler(this.btnAdd_Click);
			// 
			// btnApply
			// 
			this.btnApply.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
			this.btnApply.Image = ((System.Drawing.Image)(resources.GetObject("btnApply.Image")));
			this.btnApply.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
			this.btnApply.Location = new System.Drawing.Point(16, 224);
			this.btnApply.Name = "btnApply";
			this.btnApply.Size = new System.Drawing.Size(56, 24);
			this.btnApply.TabIndex = 58;
			this.btnApply.Text = "确定";
			this.btnApply.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			this.btnApply.Click += new System.EventHandler(this.btnApply_Click);
			// 
			// btnExit
			// 
			this.btnExit.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
			this.btnExit.Image = ((System.Drawing.Image)(resources.GetObject("btnExit.Image")));
			this.btnExit.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
			this.btnExit.Location = new System.Drawing.Point(16, 312);
			this.btnExit.Name = "btnExit";
			this.btnExit.Size = new System.Drawing.Size(56, 24);
			this.btnExit.TabIndex = 56;
			this.btnExit.Text = "退出";
			this.btnExit.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			this.btnExit.Click += new System.EventHandler(this.btnExit_Click);
			// 
			// btnCancel
			// 
			this.btnCancel.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
			this.btnCancel.Image = ((System.Drawing.Image)(resources.GetObject("btnCancel.Image")));
			this.btnCancel.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
			this.btnCancel.Location = new System.Drawing.Point(16, 184);
			this.btnCancel.Name = "btnCancel";
			this.btnCancel.Size = new System.Drawing.Size(56, 24);
			this.btnCancel.TabIndex = 57;
			this.btnCancel.Text = "取消";
			this.btnCancel.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
			// 
			// listBox1
			// 
			this.listBox1.BackColor = System.Drawing.SystemColors.Window;
			this.listBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
			this.listBox1.Font = new System.Drawing.Font("楷体_GB2312", 15.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.listBox1.ForeColor = System.Drawing.SystemColors.HotTrack;
			this.listBox1.ItemHeight = 21;
			this.listBox1.Location = new System.Drawing.Point(56, 160);
			this.listBox1.Name = "listBox1";
			this.listBox1.ScrollAlwaysVisible = true;
			this.listBox1.Size = new System.Drawing.Size(200, 191);
			this.listBox1.TabIndex = 62;
			// 
			// textBox1
			// 
			this.textBox1.BackColor = System.Drawing.Color.LightYellow;
			this.textBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
			this.textBox1.Enabled = false;
			this.textBox1.Location = new System.Drawing.Point(112, 96);
			this.textBox1.Name = "textBox1";
			this.textBox1.TabIndex = 64;
			this.textBox1.Text = "";
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(48, 96);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(56, 23);
			this.label1.TabIndex = 65;
			this.label1.Text = "新记录";
			// 
			// comboBox1
			// 
			this.comboBox1.Items.AddRange(new object[] {
														   "部门",
														   "职称",
														   "职务",
														   "民族",
														   "工种"});
			this.comboBox1.Location = new System.Drawing.Point(112, 40);
			this.comboBox1.Name = "comboBox1";
			this.comboBox1.Size = new System.Drawing.Size(104, 20);
			this.comboBox1.TabIndex = 66;
			this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged);
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(48, 40);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(56, 23);
			this.label2.TabIndex = 67;
			this.label2.Text = "选择表";
			// 
			// groupBox1
			// 
			this.groupBox1.Controls.Add(this.btnApply);
			this.groupBox1.Controls.Add(this.btnExit);
			this.groupBox1.Controls.Add(this.btnCancel);
			this.groupBox1.Controls.Add(this.btnDelete);
			this.groupBox1.Controls.Add(this.btnAdd);
			this.groupBox1.Location = new System.Drawing.Point(440, 32);
			this.groupBox1.Name = "groupBox1";
			this.groupBox1.Size = new System.Drawing.Size(88, 376);
			this.groupBox1.TabIndex = 68;
			this.groupBox1.TabStop = false;
			// 
			// groupBox2
			// 
			this.groupBox2.Controls.Add(this.listBox1);
			this.groupBox2.Controls.Add(this.label1);
			this.groupBox2.Controls.Add(this.textBox1);
			this.groupBox2.Controls.Add(this.label2);
			this.groupBox2.Controls.Add(this.comboBox1);
			this.groupBox2.Location = new System.Drawing.Point(16, 32);
			this.groupBox2.Name = "groupBox2";
			this.groupBox2.Size = new System.Drawing.Size(312, 376);
			this.groupBox2.TabIndex = 69;
			this.groupBox2.TabStop = false;
			// 
			// Configure
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.BackColor = System.Drawing.SystemColors.Control;
			this.ClientSize = new System.Drawing.Size(528, 437);
			this.Controls.Add(this.groupBox2);
			this.Controls.Add(this.groupBox1);
			this.ForeColor = System.Drawing.SystemColors.Desktop;
			this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
			this.Name = "Configure";
			this.Text = "基础资料配置";
			this.Load += new System.EventHandler(this.Configure_Load);
			this.groupBox1.ResumeLayout(false);
			this.groupBox2.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

		private void btnExit_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}
		private void ErrorHandle(string e)
		{
			MessageBox.Show(e);
		}

		private void Configure_Load(object sender, System.EventArgs e)
		{
			this.ButtonsControl(false);
			this.ListBox_Fill();
		}
		private void ListBox_Fill()
		{
			this.commandStr="select * from "+this.dataTable;
			this.Command1.CommandText=this.commandStr;
			this.listBox1.Items.Clear();
			try
			{
				if(this.Connection1.State==ConnectionState.Closed)
					this.Connection1.Open();
				this.DataReader1=this.Command1.ExecuteReader();
				while(DataReader1.Read())
				{
					this.listBox1.Items.Add(this.DataReader1[1].ToString());					
				}
				this.listBox1.SelectedIndex=0;
			}				
			catch (System.Exception E)
			{
				this.ErrorHandle(E.ToString());

			}		
			finally
			{
				this.Connection1.Close();
			}

		}
		private void Command_Excute()
		{
			this.Command1.CommandText=this.commandStr;
			try
			{
				if(this.Connection1.State==ConnectionState.Closed)
					this.Connection1.Open();
				this.Command1.ExecuteNonQuery();
				this.ListBox_Fill();
			
			}				
			catch (System.Exception E)
			{
				this.ErrorHandle(E.ToString());

			}		
			finally
			{
				this.Connection1.Close();
			}

		}
		private void ButtonsControl(bool IsEnable)
		{
			if(IsEnable)
			{
				this.textBox1.Enabled=true;
				this.btnCancel.Enabled=true;
				this.btnApply.Enabled=true;
			}
			else
			{
				this.textBox1.Enabled=false;
				this.btnCancel.Enabled=false;
				this.btnApply.Enabled=false;
			}
		}		

		private void comboBox1_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			int selectIndex=this.comboBox1.SelectedIndex;			
			switch(selectIndex)
			{
				case 0:					
					this.dataTable="Department";
					break;
				case 1:					
					this.dataTable="Title";
					break;
				case 2:					
					this.dataTable="Duty";
					break;
				case 3:					
					this.dataTable="Nation";
					break;
				case 4:					
					this.dataTable="WorkType";
					break;
				default:
					break;
			}
			
			this.ListBox_Fill();
		
		}

		private void btnAdd_Click(object sender, System.EventArgs e)
		{
			this.ButtonsControl(true);
			this.textBox1.Focus();
			this.add=true;
			
		}

		private void btnCancel_Click(object sender, System.EventArgs e)
		{
			this.textBox1.Clear();
			this.ButtonsControl(false);
		}

		private void btnApply_Click(object sender, System.EventArgs e)
		{		
			this.ButtonsControl(false);
			if(add)
			{
				this.commandStr="insert into "+this.dataTable+"("+this.dataTable+") values("+"'"+this.textBox1.Text+"'"+")";
				
			}
			else
			{
				this.commandStr="delete from "+this.dataTable+" where "+this.dataTable+"='"+this.listBox1.SelectedItem.ToString()+"'";				
			}
			this.Command_Excute();
			this.ListBox_Fill();
			this.add=false;
			this.textBox1.Clear();
		}

		private void btnDelete_Click(object sender, System.EventArgs e)
		{
			this.ButtonsControl(true);
		}
	}
}

⌨️ 快捷键说明

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