📄 employeemanageform.cs
字号:
this.m_AddButton.Click += new System.EventHandler(this.m_AddButton_Click);
//
// m_ModifyButton
//
this.m_ModifyButton.Location = new System.Drawing.Point(200, 296);
this.m_ModifyButton.Name = "m_ModifyButton";
this.m_ModifyButton.Size = new System.Drawing.Size(80, 24);
this.m_ModifyButton.TabIndex = 2;
this.m_ModifyButton.Text = "修改";
this.m_ModifyButton.Click += new System.EventHandler(this.m_ModifyButton_Click);
//
// m_DeleteButton
//
this.m_DeleteButton.Location = new System.Drawing.Point(312, 296);
this.m_DeleteButton.Name = "m_DeleteButton";
this.m_DeleteButton.Size = new System.Drawing.Size(80, 24);
this.m_DeleteButton.TabIndex = 3;
this.m_DeleteButton.Text = "删除";
this.m_DeleteButton.Click += new System.EventHandler(this.m_DeleteButton_Click);
//
// groupBox1
//
this.groupBox1.Controls.Add(this.m_UserText);
this.groupBox1.Controls.Add(this.label9);
this.groupBox1.Controls.Add(this.m_StartWorkDateTime);
this.groupBox1.Controls.Add(this.m_BirthdayDateTime);
this.groupBox1.Controls.Add(this.m_IDText);
this.groupBox1.Controls.Add(this.m_PasswordText);
this.groupBox1.Controls.Add(this.label8);
this.groupBox1.Controls.Add(this.m_PriorityCombo);
this.groupBox1.Controls.Add(this.label4);
this.groupBox1.Controls.Add(this.label3);
this.groupBox1.Controls.Add(this.m_NameText);
this.groupBox1.Controls.Add(this.label2);
this.groupBox1.Controls.Add(this.m_SexCombo);
this.groupBox1.Controls.Add(this.label7);
this.groupBox1.Controls.Add(this.m_PostText);
this.groupBox1.Controls.Add(this.label5);
this.groupBox1.Controls.Add(this.label6);
this.groupBox1.Location = new System.Drawing.Point(0, 200);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(816, 88);
this.groupBox1.TabIndex = 1;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "员工信息";
//
// m_UserText
//
this.m_UserText.Location = new System.Drawing.Point(96, 56);
this.m_UserText.Name = "m_UserText";
this.m_UserText.ReadOnly = true;
this.m_UserText.Size = new System.Drawing.Size(88, 21);
this.m_UserText.TabIndex = 4;
this.m_UserText.Text = "";
//
// label9
//
this.label9.Location = new System.Drawing.Point(32, 56);
this.label9.Name = "label9";
this.label9.Size = new System.Drawing.Size(56, 24);
this.label9.TabIndex = 19;
this.label9.Text = "用户名:";
this.label9.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// m_StartWorkDateTime
//
this.m_StartWorkDateTime.Enabled = false;
this.m_StartWorkDateTime.Location = new System.Drawing.Point(672, 24);
this.m_StartWorkDateTime.MaxDate = new System.DateTime(2005, 12, 8, 22, 58, 16, 843);
this.m_StartWorkDateTime.MinDate = new System.DateTime(1965, 1, 1, 0, 0, 0, 0);
this.m_StartWorkDateTime.Name = "m_StartWorkDateTime";
this.m_StartWorkDateTime.Size = new System.Drawing.Size(112, 21);
this.m_StartWorkDateTime.TabIndex = 3;
this.m_StartWorkDateTime.Value = new System.DateTime(2005, 12, 8, 22, 58, 16, 843);
//
// m_BirthdayDateTime
//
this.m_BirthdayDateTime.Enabled = false;
this.m_BirthdayDateTime.Location = new System.Drawing.Point(440, 24);
this.m_BirthdayDateTime.MaxDate = new System.DateTime(2005, 12, 8, 22, 58, 16, 843);
this.m_BirthdayDateTime.MinDate = new System.DateTime(1950, 1, 1, 0, 0, 0, 0);
this.m_BirthdayDateTime.Name = "m_BirthdayDateTime";
this.m_BirthdayDateTime.Size = new System.Drawing.Size(112, 21);
this.m_BirthdayDateTime.TabIndex = 2;
this.m_BirthdayDateTime.Value = new System.DateTime(2005, 12, 8, 22, 58, 16, 843);
//
// m_IDText
//
this.m_IDText.Location = new System.Drawing.Point(736, 56);
this.m_IDText.Name = "m_IDText";
this.m_IDText.TabIndex = 16;
this.m_IDText.TabStop = false;
this.m_IDText.Text = "";
this.m_IDText.Visible = false;
//
// m_PasswordText
//
this.m_PasswordText.Location = new System.Drawing.Point(632, 56);
this.m_PasswordText.Name = "m_PasswordText";
this.m_PasswordText.ReadOnly = true;
this.m_PasswordText.Size = new System.Drawing.Size(144, 21);
this.m_PasswordText.TabIndex = 7;
this.m_PasswordText.Text = "";
//
// label8
//
this.label8.Location = new System.Drawing.Point(568, 56);
this.label8.Name = "label8";
this.label8.Size = new System.Drawing.Size(48, 24);
this.label8.TabIndex = 14;
this.label8.Text = "密码:";
this.label8.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// m_PriorityCombo
//
this.m_PriorityCombo.AllowDrop = true;
this.m_PriorityCombo.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.m_PriorityCombo.Enabled = false;
this.m_PriorityCombo.Items.AddRange(new object[] {
"销售员",
"财务管理员",
"超级管理员"});
this.m_PriorityCombo.Location = new System.Drawing.Point(440, 56);
this.m_PriorityCombo.Name = "m_PriorityCombo";
this.m_PriorityCombo.Size = new System.Drawing.Size(112, 20);
this.m_PriorityCombo.TabIndex = 6;
//
// m_CancelButton
//
this.m_CancelButton.Enabled = false;
this.m_CancelButton.Location = new System.Drawing.Point(536, 296);
this.m_CancelButton.Name = "m_CancelButton";
this.m_CancelButton.Size = new System.Drawing.Size(80, 24);
this.m_CancelButton.TabIndex = 5;
this.m_CancelButton.Text = "放弃";
this.m_CancelButton.Click += new System.EventHandler(this.m_CancelButton_Click);
//
// m_OKButton
//
this.m_OKButton.Enabled = false;
this.m_OKButton.Location = new System.Drawing.Point(424, 296);
this.m_OKButton.Name = "m_OKButton";
this.m_OKButton.Size = new System.Drawing.Size(80, 24);
this.m_OKButton.TabIndex = 4;
this.m_OKButton.Text = "提交";
this.m_OKButton.Click += new System.EventHandler(this.m_OKButton_Click);
//
// EmployeeManageForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(816, 326);
this.Controls.Add(this.m_OKButton);
this.Controls.Add(this.m_CancelButton);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.m_DeleteButton);
this.Controls.Add(this.m_ModifyButton);
this.Controls.Add(this.m_AddButton);
this.Controls.Add(this.label1);
this.Controls.Add(this.m_EmployeeDataGrid);
this.Name = "EmployeeManageForm";
this.Text = "员工管理";
this.Load += new System.EventHandler(this.EmployeeManageForm_Load);
((System.ComponentModel.ISupportInitialize)(this.m_EmployeeDataGrid)).EndInit();
this.groupBox1.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private void EmployeeManageForm_Load(object sender, System.EventArgs e)
{
System.Data.DataTable dt = new System.Data.DataTable();
System.Data.DataRow dr;
dt.Columns.Add(new System.Data.DataColumn("name"));
dt.Columns.Add(new System.Data.DataColumn("sex"));
dt.Columns.Add(new System.Data.DataColumn("age"));
dt.Columns.Add(new System.Data.DataColumn("workyear"));
dt.Columns.Add(new System.Data.DataColumn("username"));
dt.Columns.Add(new System.Data.DataColumn("post"));
dt.Columns.Add(new System.Data.DataColumn("priority"));
dt.Columns.Add(new System.Data.DataColumn("password"));
getEmployeeList();
for (int i=0;i<employeeList.Count;i++)
//for (int i = 0; i<3; i++)
{
Employee m_employee;
m_employee=(Employee)employeeList[i];
dr = dt.NewRow();
dr[0] = m_employee.Employeename;
dr[1] = m_employee.Employeesex;
dr[2] = m_employee.Birthday;
dr[3] = m_employee.StartWorkTime;
dr[4] = m_employee.UserName;
dr[5] = m_employee.Employeepost;
dr[6] = m_employee.Priority;
dr[7] = m_employee.Employeepassword;
dt.Rows.Add(dr);
}
System.Data.DataView dv = new System.Data.DataView(dt);
m_EmployeeDataGrid.DataSource=dv;
previousRowNumber=m_EmployeeDataGrid.CurrentCell.RowNumber;
if (!(employeeList==null||employeeList.Count==0))
{
string sex=(string)dt.Rows[0][1];
string priority=(string)dt.Rows[0][6];
m_NameText.Text=(string)dt.Rows[0][0];
if (sex.Equals("男"))
m_SexCombo.SelectedIndex=0;
else if (sex.Equals("女"))
m_SexCombo.SelectedIndex=1;
else
{}
m_BirthdayDateTime.Value=DateTime.Parse((string)dt.Rows[0][2]);
m_StartWorkDateTime.Value=DateTime.Parse((string)dt.Rows[0][3]);
m_PostText.Text=(string)dt.Rows[0][5];
if (priority.Equals("0"))
m_PriorityCombo.SelectedIndex=0;
else if (priority.Equals("1"))
m_PriorityCombo.SelectedIndex=1;
else if (priority.Equals("2"))
m_PriorityCombo.SelectedIndex=2;
else
{}
m_PasswordText.Text=(string)dt.Rows[0][7];
m_UserText.Text=(string)dt.Rows[0][4];
m_IDText.Text=""+((Employee)employeeList[0]).Employeeid;
}
else
{
m_IDText.Text="";
m_ModifyButton.Enabled=false;
m_DeleteButton.Enabled=false;
}
}
private void getEmployeeList()
{
employeeList=new ArrayList();
int rowCount;
//从数据库读取员工数据
System.Data.DataSet m_DataSet=new DataSet();
SqlCommand m_sqlSelectCommand=new SqlCommand();
m_sqlDataAdapter.SelectCommand=m_sqlSelectCommand;
m_sqlSelectCommand.CommandText="select * from Employee";
m_sqlSelectCommand.Connection=m_Connection;
try
{
m_Connection.Open();
}
catch (SqlException e1)
{
MessageBox.Show(this,e1.Message,"数据库连接错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
m_sqlSelectCommand.ExecuteNonQuery();
m_DataSet=new System.Data.DataSet();
//填充m_DataSet
m_sqlDataAdapter.Fill(m_DataSet);
DataTable m_DataTable=m_DataSet.Tables[0];
rowCount=m_DataTable.Rows.Count;
//将数据放入ArrayList中
for (int i=0;i<rowCount;i++)
{
Employee m_employee=new Employee();
try
{
m_employee.Employeeid=Int32.Parse(((Int32)m_DataTable.Rows[i]["EmployeeID"]).ToString());
m_employee.UserName=(string)m_DataTable.Rows[i]["UserName"];
m_employee.Employeename=(string)m_DataTable.Rows[i]["EmployeeName"];
m_employee.Birthday=((DateTime)m_DataTable.Rows[i]["Birthday"]).ToString("d");
m_employee.StartWorkTime=((DateTime)m_DataTable.Rows[i]["StartWorkingTime"]).ToString("d");
m_employee.Employeesex=(string)m_DataTable.Rows[i]["Sex"];
m_employee.Employeepost=(string)m_DataTable.Rows[i]["Title"];
m_employee.Employeepassword=(string)m_DataTable.Rows[i]["Password"];
m_employee.Priority=(string)m_DataTable.Rows[i]["Priority"];
employeeList.Add(m_employee);
}
catch(Exception e2)
{
MessageBox.Show(this,e2.Message,"类型转换错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
m_Connection.Close();
}
private void m_EmployeeDataGrid_CurrentCellChanged(object sender, EventArgs e)
{
int currentRowNumber=m_EmployeeDataGrid.CurrentCell.RowNumber;
string sex;
string priority;
if (previousRowNumber!=currentRowNumber && employeeList.Count>currentRowNumber)
{
sex=(string)m_EmployeeDataGrid[m_EmployeeDataGrid.CurrentCell.RowNumber,1];
priority=(string)m_EmployeeDataGrid[m_EmployeeDataGrid.CurrentCell.RowNumber,6];
m_NameText.Text=(string)m_EmployeeDataGrid[m_EmployeeDataGrid.CurrentCell.RowNumber,0];
if (sex.Equals("男"))
m_SexCombo.SelectedIndex=0;
else if (sex.Equals("女"))
m_SexCombo.SelectedIndex=1;
else
{}
m_BirthdayDateTime.Value=DateTime.Parse((string)m_EmployeeDataGrid[m_EmployeeDataGrid.CurrentCell.RowNumber,2]);
m_StartWorkDateTime.Value=DateTime.Parse((string)m_EmployeeDataGrid[m_EmployeeDataGrid.CurrentCell.RowNumber,3]);
m_PostText.Text=(string)m_EmployeeDataGrid[m_EmployeeDataGrid.CurrentCell.RowNumber,5];
if (priority.Equals("0"))
m_PriorityCombo.SelectedIndex=0;
else if (priority.Equals("1"))
m_PriorityCombo.SelectedIndex=1;
else if (priority.Equals("2"))
m_PriorityCombo.SelectedIndex=2;
else
{}
m_PasswordText.Text=(string)m_EmployeeDataGrid[m_EmployeeDataGrid.CurrentCell.RowNumber,7];
m_UserText.Text=(string)m_EmployeeDataGrid[m_EmployeeDataGrid.CurrentCell.RowNumber,4];
if (employeeList!=null&&employeeList.Count>0)
m_IDText.Text=""+((Employee)employeeList[m_EmployeeDataGrid.CurrentCell.RowNumber]).Employeeid;
else
m_IDText.Text="";
previousRowNumber=currentRowNumber;
}
}
private void m_AddButton_Click(object sender, System.EventArgs e)
{
m_ModifyButton.Enabled=false;
m_DeleteButton.Enabled=false;
m_AddButton.Enabled=false;
m_CancelButton.Enabled=true;
m_OKButton.Enabled=true;
m_NameText.ReadOnly=false;
m_NameText.Text="";
m_SexCombo.SelectedIndex=0;
m_SexCombo.Enabled=true;
m_BirthdayDateTime.Value=DateTime.Parse("1980-1-1");
m_BirthdayDateTime.Enabled=true;
m_StartWorkDateTime.Value=DateTime.Parse("1988-1-1");
m_StartWorkDateTime.Enabled=true;
m_PostText.Text="";
m_PostText.ReadOnly=false;
m_UserText.Text="";
m_UserText.ReadOnly=false;
m_PriorityCombo.SelectedIndex=0;
m_PriorityCombo.Enabled=true;
m_PasswordText.Text="";
m_PasswordText.ReadOnly=false;
m_IDText.Text="";
}
private void m_CancelButton_Click(object sender, System.EventArgs e)
{
System.Data.DataTable dt = new System.Data.DataTable();
System.Data.DataRow dr;
dt.Columns.Add(new System.Data.DataColumn("name"));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -