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

📄 staffmodify.cs

📁 工资结算系统 拥有权限控制 临时工资表 自动导入导出Excel 以及邮件群发功能
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.OleDb;

namespace HrSalary.employee
{
	/// <summary>
	/// EmployeeManager 的摘要说明。
	/// </summary>
	public class StaffModify : System.Windows.Forms.Form
	{
		int style=0;
		private  int thisautoid; 
		private System.Windows.Forms.Label ename;
		private System.Windows.Forms.TextBox name;
		private System.Windows.Forms.Button button1;
		private System.Windows.Forms.Button button2;
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;
		private OleDbConnection dbCon = null;
		private System.Windows.Forms.TextBox empid;
		private System.Windows.Forms.Label label16;
		private System.Windows.Forms.TextBox email;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.TextBox bankcardid;
		private System.Windows.Forms.Label label9;
		private DataGrid dg = null;

		public StaffModify(DataGrid dg)
		{
			//
			// Windows 窗体设计器支持所必需的
			//
			InitializeComponent();
			this.dg = dg;
		
			//
			// 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.ename = new System.Windows.Forms.Label();
			this.name = new System.Windows.Forms.TextBox();
			this.button1 = new System.Windows.Forms.Button();
			this.button2 = new System.Windows.Forms.Button();
			this.empid = new System.Windows.Forms.TextBox();
			this.email = new System.Windows.Forms.TextBox();
			this.label16 = new System.Windows.Forms.Label();
			this.label2 = new System.Windows.Forms.Label();
			this.bankcardid = new System.Windows.Forms.TextBox();
			this.label9 = new System.Windows.Forms.Label();
			this.SuspendLayout();
			// 
			// ename
			// 
			this.ename.AutoSize = true;
			this.ename.Location = new System.Drawing.Point(64, 64);
			this.ename.Name = "ename";
			this.ename.Size = new System.Drawing.Size(42, 17);
			this.ename.TabIndex = 0;
			this.ename.Text = "姓名:";
			// 
			// name
			// 
			this.name.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
			this.name.Location = new System.Drawing.Point(112, 64);
			this.name.Name = "name";
			this.name.Size = new System.Drawing.Size(160, 21);
			this.name.TabIndex = 1;
			this.name.Text = "";
			// 
			// button1
			// 
			this.button1.Location = new System.Drawing.Point(80, 176);
			this.button1.Name = "button1";
			this.button1.TabIndex = 25;
			this.button1.Text = "修改";
			this.button1.Click += new System.EventHandler(this.button1_Click);
			// 
			// button2
			// 
			this.button2.Location = new System.Drawing.Point(208, 176);
			this.button2.Name = "button2";
			this.button2.TabIndex = 26;
			this.button2.Text = "取消";
			this.button2.Click += new System.EventHandler(this.button2_Click);
			// 
			// empid
			// 
			this.empid.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
			this.empid.Location = new System.Drawing.Point(112, 24);
			this.empid.Name = "empid";
			this.empid.ReadOnly = true;
			this.empid.Size = new System.Drawing.Size(160, 21);
			this.empid.TabIndex = 34;
			this.empid.Text = "";
			// 
			// email
			// 
			this.email.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
			this.email.Location = new System.Drawing.Point(112, 104);
			this.email.Name = "email";
			this.email.Size = new System.Drawing.Size(160, 21);
			this.email.TabIndex = 38;
			this.email.Text = "";
			// 
			// label16
			// 
			this.label16.AutoSize = true;
			this.label16.Location = new System.Drawing.Point(48, 104);
			this.label16.Name = "label16";
			this.label16.Size = new System.Drawing.Size(48, 17);
			this.label16.TabIndex = 37;
			this.label16.Text = "Email:";
			this.label16.TextAlign = System.Drawing.ContentAlignment.TopRight;
			// 
			// label2
			// 
			this.label2.AutoSize = true;
			this.label2.Location = new System.Drawing.Point(64, 24);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(42, 17);
			this.label2.TabIndex = 45;
			this.label2.Text = "编号:";
			// 
			// bankcardid
			// 
			this.bankcardid.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
			this.bankcardid.Location = new System.Drawing.Point(112, 144);
			this.bankcardid.Name = "bankcardid";
			this.bankcardid.Size = new System.Drawing.Size(160, 21);
			this.bankcardid.TabIndex = 42;
			this.bankcardid.Text = "";
			// 
			// label9
			// 
			this.label9.AutoSize = true;
			this.label9.Location = new System.Drawing.Point(40, 144);
			this.label9.Name = "label9";
			this.label9.Size = new System.Drawing.Size(66, 17);
			this.label9.TabIndex = 41;
			this.label9.Text = "银行卡号:";
			// 
			// StaffModify
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.BackColor = System.Drawing.Color.AliceBlue;
			this.ClientSize = new System.Drawing.Size(328, 213);
			this.Controls.Add(this.label2);
			this.Controls.Add(this.bankcardid);
			this.Controls.Add(this.label9);
			this.Controls.Add(this.email);
			this.Controls.Add(this.label16);
			this.Controls.Add(this.empid);
			this.Controls.Add(this.name);
			this.Controls.Add(this.ename);
			this.Controls.Add(this.button2);
			this.Controls.Add(this.button1);
			this.MaximumSize = new System.Drawing.Size(544, 465);
			this.Name = "StaffModify";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "修改员工信息";
			this.Load += new System.EventHandler(this.StaffModify_Load);
			this.ResumeLayout(false);

		}
		#endregion

			
		private  string   number_Input_Check(string caption,string  text)//,long maxvalue
		{
			string error="";
			text=text.Trim();
			if(text=="" )
			{
				error=caption+"不能为空!!!\n";
				return(error);
			}
			
			int i=0;
			for(i=0;i<text.Length;i++)
			{

				if(text[i]>'9' || text[i]<'0')            
					break;
			}
			if(i<text.Length)
			{
				error=caption+"输入格式不正确,请修正!!!\n";
				return(error);
			}

			return(error);
		}
	
		private string email_Input_Check()
		{
			string error="";
			if(this.email.Text=="" || this.email.Text.Trim().Equals(""))
			{
				error="Email不能为空!!!\n      ";
				return error;
			}
			if((this.email.Text.IndexOf("@")==-1) || (this.email.Text.IndexOf(".")==-1))
			{
				error+="Email格式不正确!!!\n    ";
				return error;
			}
			return error;			
		}


		private void button1_Click(object sender, System.EventArgs e)
		{
			string error="";
			if(this.name.Text.Trim().Equals("") || this.name.Text=="")
			{
				error+="姓名不能为空!!!\n";
				
			}
			error+=email_Input_Check();
			error+=number_Input_Check("银行卡号",this.bankcardid.Text);
			if(!error.Trim().Equals(""))
			{
				MessageBox.Show("      错误!\n\n"+error+"\n 请重新输入!!!\n ");
				return;
			}
			int index = dg.CurrentRowIndex;
			int num=0;
			string sql = "update employee set ";		
			if(!this.name.Text.Equals(dg[index,1].ToString()))
			{
				num++;
				sql+="姓名='"+this.name.Text+"'";
				
			}
			if(!this.email.Text.Equals(dg[index,2].ToString()))
			{
				if(num>0) sql+=",";
				sql+="Email='"+this.email.Text+"'";
				num++;
			}
			
			if(!this.bankcardid.Text.Equals(dg[index,3].ToString()))
			{
					if(num>0) sql+=",";
				sql+="银行卡号='"+this.bankcardid.Text+"'";
				num++;
			}

			sql+=" where 编号="+this.empid.Text;
			if(num==0)
			{
				this.Close();
				return;
			}
			//			MessageBox.Show(num.ToString(),sql);//
			try
			{
				if(dbCon==null) dbCon = MainForm.getConnection();
				OleDbCommand cmd = dbCon.CreateCommand();
				cmd.CommandText = sql;
				try
				{
					int result = cmd.ExecuteNonQuery();
					if(result==1)
					{
					 MessageBox.Show("员工信息修改成功");
						 cmd.Dispose();
						this.Close();
					}
					else
					{  cmd.Dispose();
						MessageBox.Show("员工信息修改失败");
					}					
				}
				catch(Exception ee)
				{
					MessageBox.Show("workstatus"+ee.ToString());
				}				
			}
			catch(Exception eee)
			{
				MessageBox.Show(eee.ToString());
			}
		}
		

		private void button2_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}

		private void StaffModify_Load(object sender, System.EventArgs e)
		{
		
		  initStaffModify();
		}
		private void initStaffModify()
		{
			try
			{
				int index = dg.CurrentRowIndex;
				this.thisautoid=Int32.Parse(dg[index,0].ToString());
				this.empid.Text = dg[index,0].ToString();
				this.name.Text = dg[index,1].ToString();
				this.email.Text = dg[index,2].ToString();
				this.bankcardid.Text = dg[index,3].ToString();
			}
			catch(Exception ee)
			{
				MessageBox.Show(ee.ToString());
			}

		}
	}
}

⌨️ 快捷键说明

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