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

📄 staffmanager.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;
using HrSalary.salary;

namespace HrSalary.employee
{
	/// <summary>
	/// EmployeeManager 的摘要说明。
	/// </summary>
	public class StaffManager : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Label ename;
		private System.Windows.Forms.Label label3;
		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 System.Windows.Forms.TextBox email;
		private System.Windows.Forms.Label label15;
		private System.Windows.Forms.TextBox empid;
		private System.Windows.Forms.Label label14;
		private System.Windows.Forms.TextBox bankcardid;
		private OleDbConnection dbCon = null;

		public StaffManager()
		{
			//
			// 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.ename = new System.Windows.Forms.Label();
			this.name = new System.Windows.Forms.TextBox();
			this.label3 = new System.Windows.Forms.Label();
			this.bankcardid = new System.Windows.Forms.TextBox();
			this.button1 = new System.Windows.Forms.Button();
			this.button2 = new System.Windows.Forms.Button();
			this.email = new System.Windows.Forms.TextBox();
			this.label15 = new System.Windows.Forms.Label();
			this.empid = new System.Windows.Forms.TextBox();
			this.label14 = new System.Windows.Forms.Label();
			this.SuspendLayout();
			// 
			// ename
			// 
			this.ename.AutoSize = true;
			this.ename.Location = new System.Drawing.Point(80, 56);
			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(128, 56);
			this.name.Name = "name";
			this.name.Size = new System.Drawing.Size(176, 21);
			this.name.TabIndex = 1;
			this.name.Text = "";
			// 
			// label3
			// 
			this.label3.AutoSize = true;
			this.label3.Location = new System.Drawing.Point(56, 96);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(66, 17);
			this.label3.TabIndex = 7;
			this.label3.Text = "银行卡号:";
			// 
			// bankcardid
			// 
			this.bankcardid.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
			this.bankcardid.Location = new System.Drawing.Point(128, 96);
			this.bankcardid.Name = "bankcardid";
			this.bankcardid.Size = new System.Drawing.Size(176, 21);
			this.bankcardid.TabIndex = 8;
			this.bankcardid.Text = "";
			// 
			// button1
			// 
			this.button1.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
			this.button1.Location = new System.Drawing.Point(112, 184);
			this.button1.Name = "button1";
			this.button1.TabIndex = 25;
			this.button1.Text = "增加";
			this.button1.Click += new System.EventHandler(this.button1_Click);
			// 
			// button2
			// 
			this.button2.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
			this.button2.Location = new System.Drawing.Point(256, 184);
			this.button2.Name = "button2";
			this.button2.TabIndex = 26;
			this.button2.Text = "取消";
			this.button2.Click += new System.EventHandler(this.button2_Click);
			// 
			// email
			// 
			this.email.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
			this.email.Location = new System.Drawing.Point(128, 136);
			this.email.Name = "email";
			this.email.Size = new System.Drawing.Size(176, 21);
			this.email.TabIndex = 36;
			this.email.Text = "";
			// 
			// label15
			// 
			this.label15.AutoSize = true;
			this.label15.Location = new System.Drawing.Point(72, 136);
			this.label15.Name = "label15";
			this.label15.Size = new System.Drawing.Size(48, 17);
			this.label15.TabIndex = 35;
			this.label15.Text = "Email:";
			// 
			// empid
			// 
			this.empid.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
			this.empid.Location = new System.Drawing.Point(128, 16);
			this.empid.Name = "empid";
			this.empid.ReadOnly = true;
			this.empid.Size = new System.Drawing.Size(176, 21);
			this.empid.TabIndex = 38;
			this.empid.Text = "";
			// 
			// label14
			// 
			this.label14.AutoSize = true;
			this.label14.Location = new System.Drawing.Point(80, 16);
			this.label14.Name = "label14";
			this.label14.Size = new System.Drawing.Size(42, 17);
			this.label14.TabIndex = 37;
			this.label14.Text = "编号:";
			// 
			// StaffManager
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.BackColor = System.Drawing.Color.AliceBlue;
			this.ClientSize = new System.Drawing.Size(392, 213);
			this.Controls.Add(this.empid);
			this.Controls.Add(this.label14);
			this.Controls.Add(this.email);
			this.Controls.Add(this.label15);
			this.Controls.Add(this.bankcardid);
			this.Controls.Add(this.label3);
			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(536, 443);
			this.Name = "StaffManager";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "添加员工信息";
			this.Load += new System.EventHandler(this.StaffManager_Load);
			this.ResumeLayout(false);

		}
		#endregion


		/// <summary>
		/// 数字验证
		/// </summary>
		/// <param name="caption">用户填写的项 例如用户名</param>
		/// <param name="text">用户填写的值</param>
		/// <returns></returns>
		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);
		}
	    /// <summary>
	    /// 检验用户输入犯人Email地址是否合法
	    /// </summary>
	    /// <returns></returns>
		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();//判断Email是否合法
			error+=number_Input_Check("银行卡号",this.bankcardid.Text);
			//判断银行卡号是否都为数字
			if(!error.Trim().Equals(""))
			{
				MessageBox.Show("      错误!\n\n"+error+"\n 请重新输入!!!\n ");
				return;
			}	
				string sql = "insert into employee(姓名,Email,银行卡号,状态) values(";
				sql+="'"+this.name.Text+"',";
				sql+="'"+this.email.Text+"',";
				sql+="'"+this.bankcardid.Text+"',";
				sql+="'0"+"')";	
				if(dbCon==null) dbCon = MainForm.getConnection();
				try
				{
					OleDbCommand cmd = dbCon.CreateCommand();
					try
					{
						cmd.CommandText =  sql;
						int result = cmd.ExecuteNonQuery();
						if(result==1)
						{ 
							
							 MessageBox.Show(this,"添加员工信息成功!","提示信息");
							//添加成功后 初始化各个选项 为连续输入下个员工信息准备
							//取得下个员工的编号
							this.empid.Text=Find_Autoid().ToString();  
								this.name.Text = "";
								this.email.Text = "";
								this.bankcardid.Text = "";
						}
						else
						{
							MessageBox.Show("增加员工信息失败");
						}
					}
					catch(Exception eee)
					{
						MessageBox.Show(eee.ToString());
					}
					cmd.Dispose();
				}
				catch(Exception ee)
				{
					MessageBox.Show(ee.ToString());
				}
			
		}
		//取得下个员工的编号
		private long  Find_Autoid()
		{
			long num = 1;
			if(dbCon==null) dbCon = MainForm.getConnection();
			OleDbCommand cmd = dbCon.CreateCommand();
			cmd.CommandText = "select max(编号) from employee ";
			OleDbDataReader reader = cmd.ExecuteReader();			
			if(reader.Read())
			{
				num=long.Parse(reader.GetInt32(0).ToString());
			}
			reader.Close();
			cmd.Dispose();
			return(num);
		}
	
		private void button2_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}

		private void StaffManager_Load(object sender, System.EventArgs e)
		{
		    this.empid.Text=Find_Autoid().ToString ();  
		}
	}
}

⌨️ 快捷键说明

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