📄 salarymodify.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.salary
{
/// <summary>
/// EmployeeManager 的摘要说明。
/// </summary>
public class SalaryModify : System.Windows.Forms.Form
{
private int style=0;
//private int thisautoid;
private int namefield=0;
private int emailfield=0;
private int bankcardfield=0;
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.Label label16;
private System.Windows.Forms.TextBox email;
private System.Windows.Forms.TextBox bankcardid;
private System.Windows.Forms.Label label9;
private System.Windows.Forms.TextBox empid;
private DataGrid dg = null;
public SalaryModify(DataGrid dg,int namefd,int emailfd,int bankcardfd)
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
this.dg = dg;
this.namefield=namefd;
this.emailfield=emailfd;
this.bankcardfield=bankcardfd;
//
// 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.email = new System.Windows.Forms.TextBox();
this.label16 = new System.Windows.Forms.Label();
this.bankcardid = new System.Windows.Forms.TextBox();
this.label9 = new System.Windows.Forms.Label();
this.empid = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// ename
//
this.ename.AutoSize = true;
this.ename.Location = new System.Drawing.Point(64, 24);
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, 24);
this.name.Name = "name";
this.name.Size = new System.Drawing.Size(160, 21);
this.name.TabIndex = 1;
this.name.Text = "";
//
// button1
//
this.button1.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
this.button1.Location = new System.Drawing.Point(88, 168);
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(216, 168);
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(112, 72);
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(40, 72);
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;
//
// bankcardid
//
this.bankcardid.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.bankcardid.Location = new System.Drawing.Point(112, 120);
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(32, 120);
this.label9.Name = "label9";
this.label9.Size = new System.Drawing.Size(66, 17);
this.label9.TabIndex = 41;
this.label9.Text = "银行卡号:";
//
// empid
//
this.empid.Location = new System.Drawing.Point(32, 168);
this.empid.Name = "empid";
this.empid.ReadOnly = true;
this.empid.Size = new System.Drawing.Size(8, 21);
this.empid.TabIndex = 34;
this.empid.Text = "";
this.empid.Visible = false;
//
// SalaryModify
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.BackColor = System.Drawing.Color.AliceBlue;
this.ClientSize = new System.Drawing.Size(368, 214);
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 = "SalaryModify";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "修改员工信息";
this.Load += new System.EventHandler(this.SalaryModify_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 count=((DataSet)this.dg.DataSource ).Tables[0].Rows.Count;
((QueryEmployeeSalary)this.Owner).dataGrid1[index,this.namefield]=this.name.Text;
((QueryEmployeeSalary)this.Owner).dataGrid1[index,this.emailfield]=this.email.Text;
((QueryEmployeeSalary)this.Owner).dataGrid1[index,this.bankcardfield]=this.bankcardid.Text;
// ((QueryEmployeeSalary)this.Owner).dataGrid1.Select(index);
//((QueryEmployeeSalary)this.Owner).dataGrid1.SelectionBackColor=System.Drawing .Color.Blue;
MessageBox.Show("关键信息修改成功\n ");
for(int i=0;i<count;i++)
{
if(((QueryEmployeeSalary)this.Owner).dataGrid1.IsSelected(i))
if(i != index) ((QueryEmployeeSalary)this.Owner).dataGrid1.UnSelect(i);
}
this.Close();
}
private void button2_Click(object sender, System.EventArgs e)
{
this.Close();
}
private void SalaryModify_Load(object sender, System.EventArgs e)
{
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,this.namefield].ToString();
this.email.Text = dg[index,this.emailfield].ToString();
this.bankcardid.Text = dg[index,this.bankcardfield].ToString();
}
catch(Exception ee)
{
MessageBox.Show(ee.ToString());
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -