employee_inf.cs
上传用户:zhongfine
上传日期:2022-08-01
资源大小:2860k
文件大小:12k
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using System.Data.SqlClient;
- using System.IO;
- namespace 人事管理系统
- {
- public partial class employee_inf : Form
- {
- SqlConnection sqlcn = new SqlConnection();
- Datacon mydatacon = new Datacon();
- DataSet mydataset = new DataSet();
- SqlDataAdapter myadapter;
- SqlCommandBuilder myBuilder;
- public employee_inf()
- {
- InitializeComponent();
- }
- private void SearchServe(string lie, string zi)//精确查询方式
- {
- switch (comboBox1.SelectedIndex)
- {
- case 0: lie = "ID"; break;
- case 1: lie = "NAME"; break;
- case 2: lie = "SEX"; break;
- case 3: lie = "BIRTHDAY"; break;
- case 4: lie = "TEL"; break;
- case 5: lie = "DEPARTMENT"; break;
- case 6: lie = "JOB"; break;
- case 7: lie = "EDU_LEVEL"; break;
- case 8: lie = "SPCIALTY"; break;
- case 9: lie = "ADDRESS"; break;
- case 10: lie = "EMAIL"; break;
- //将comboBox1的内容转换为与之相对应的表的字段
- }
- sqlcn = mydatacon.getcon();
- sqlcn.Open();
- string cmd = "select ID as 员工号, NAME as 姓名, SEX as 性别, BIRTHDAY as 生日, DEPARTMENT as 所在部门, JOB as 职务, EDU_LEVEL as 受教育程度, SPCIALTY as 专业技能, ADDRESS as 家庭住址, TEL as 联系电话, EMAIL as 电子邮箱, STATE as 当前状态, REMARK as 备注 from [PERSON] where " + lie + "='" + zi + "'";
- myadapter = new SqlDataAdapter(cmd, sqlcn);
- mydataset.Clear();//数据集对象清空
- myadapter.Fill(mydataset, "PERSON");
- dataGridView2.DataSource = mydataset.Tables["PERSON"];//将表PERSON内的内容输出到dataGridView2
- sqlcn.Close();
- }
- private void SearchMoHu(string lie, string zi)//模糊查询方式
- {
- switch (comboBox1.SelectedIndex)
- {
- case 0: lie = "ID"; break;
- case 1: lie = "NAME"; break;
- case 2: lie = "SEX"; break;
- case 3: lie = "BIRTHDAY"; break;
- case 4: lie = "TEL"; break;
- case 5: lie = "DEPARTMENT"; break;
- case 6: lie = "JOB"; break;
- case 7: lie = "EDU_LEVEL"; break;
- case 8: lie = "SPCIALTY"; break;
- case 9: lie = "ADDRESS"; break;
- case 10: lie = "EMAIL"; break;
- //将comboBox1的内容转换为与之相对应的表的字段
- }
- sqlcn = mydatacon.getcon();
- string cmd = "select ID as 员工号, NAME as 姓名, SEX as 性别, BIRTHDAY as 生日, DEPARTMENT as 所在部门, JOB as 职务, EDU_LEVEL as 受教育程度, SPCIALTY as 专业技能, ADDRESS as 家庭住址, TEL as 联系电话, EMAIL as 电子邮箱, STATE as 当前状态, REMARK as 备注 from [PERSON] where " + lie + " like '" + "%" + zi + "%" + "'";
- myadapter = new SqlDataAdapter(cmd, sqlcn);
- sqlcn.Open();
- mydataset.Clear();
- myadapter.Fill(mydataset, "PERSON");
- dataGridView2.DataSource = mydataset.Tables["PERSON"];//将表PERSON内的内容输出到dataGridView2
- sqlcn.Close();
- }
- private void button3_Click(object sender, EventArgs e)
- {
- if (comboBox1.Text == "")
- {
- MessageBox.Show("请选择查询类型!");
- return;
- }
- else
- if (textBox1.Text == "")
- {
- MessageBox.Show("请填写查询字段!");
- }
- try//防止出现异常情况,用try catch语句
- {
- if (radiobutton1.Checked)
- SearchServe(comboBox1.SelectedItem.ToString(), textBox1.Text);//若radiobutton1被选中,则执行精确查询方式
- else
- if (radiobutton2.Checked)
- SearchMoHu(comboBox1.SelectedItem.ToString(), textBox1.Text);//若radiobutton2被选中,则执行模糊查询方式
- //else
- // MessageBox.Show("请填写查询字段!");
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- }
- private void button2_Click(object sender, EventArgs e)
- {
- this.Close();
- major mymajor = new major();
- }
- private void employee_inf_Load(object sender, EventArgs e)
- {
- //dataGridView1.Columns[3].FillWeight = 10;
- sqlcn = mydatacon.getcon();
- string cmd = "select ID as 员工号, NAME as 姓名, SEX as 性别, BIRTHDAY as 生日, DEPARTMENT as 所在部门, JOB as 职务, EDU_LEVEL as 受教育程度, SPCIALTY as 专业技能, ADDRESS as 家庭住址, TEL as 联系电话, EMAIL as 电子邮箱, STATE as 当前状态, REMARK as 备注 from [PERSON]";
- myadapter = new SqlDataAdapter(cmd, sqlcn);
- mydataset.Clear();
-
- myadapter.Fill(mydataset, "PERSON");
- dataGridView1.DataSource = mydataset.Tables["PERSON"];
- sqlcn.Close();//在窗体加载的同时填充dataGridView1内的数据
- }
- private void button5_Click(object sender, EventArgs e)
- {
- mydataset.Clear();//清空数据集对象内的内容
- }
- private void button1_Click(object sender, EventArgs e)
- {
- if (label3.Text == "普通用户")
- {
- MessageBox.Show("您的权限不够,无法进行修改!");
- }
- else
- {
- myBuilder = new SqlCommandBuilder(myadapter);
- myadapter.Update(mydataset, "PERSON");//将对表格中进行的修改保存进数据库
- string cmd = "select ID as 员工号, NAME as 姓名, SEX as 性别, BIRTHDAY as 生日, DEPARTMENT as 所在部门, JOB as 职务, EDU_LEVEL as 受教育程度, SPCIALTY as 专业技能, ADDRESS as 家庭住址, TEL as 联系电话, EMAIL as 电子邮箱, STATE as 当前状态, REMARK as 备注 from [PERSON]";
- myadapter = new SqlDataAdapter(cmd, sqlcn);
- mydataset.Clear();
- myadapter.Fill(mydataset, "PERSON");
- dataGridView1.DataSource = mydataset.Tables["PERSON"];//刷新dataGridView1中的最新数据
- MessageBox.Show("保存修改信息成功!");
- }
- }
- private void button6_Click(object sender, EventArgs e)
- {
- sqlcn = mydatacon.getcon();
- string cmd = "select ID as 员工号, NAME as 姓名, SEX as 性别, BIRTHDAY as 生日, DEPARTMENT as 所在部门, JOB as 职务, EDU_LEVEL as 受教育程度, SPCIALTY as 专业技能, ADDRESS as 家庭住址, TEL as 联系电话, EMAIL as 电子邮箱, STATE as 当前状态, REMARK as 备注 from [PERSON]";
- myadapter = new SqlDataAdapter(cmd, sqlcn);
- mydataset.Clear();
- myadapter.Fill(mydataset, "PERSON");
- dataGridView1.DataSource = mydataset.Tables["PERSON"];//刷新dataGridView1中的最新数据
- sqlcn.Close();
- }
- private void button4_Click(object sender, EventArgs e)
- {
- if (label3.Text == "管理员")
- {
- myBuilder = new SqlCommandBuilder(myadapter);
- myadapter.Update(mydataset, "PERSON");//同理,将对表格中进行的修改保存进数据库
- MessageBox.Show("保存修改信息成功!");
- }
- else
- {
- MessageBox.Show("您的权限不够,无法进行修改!");
- }
- }
- private void dataGridView1_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
- {
- int n = dataGridView1.CurrentRow.Index;
- dataGridView1.CurrentCell = dataGridView1[0, n];
- string str = dataGridView1.CurrentCell.Value.ToString();
- sqlcn = mydatacon.getcon();
- sqlcn.Open();
- SqlDataAdapter com = new SqlDataAdapter("select * from [PERSON] where ID='" + str + "'", sqlcn);
- DataSet ds = new DataSet();
- com.Fill(ds);
- foreach (DataRow dr in ds.Tables[0].Rows)
- {
- infshow myinfshow = new infshow();
- myinfshow.label13.Text = str;
- myinfshow.label11.Text = dr["NAME"].ToString();
- myinfshow.label12.Text = dr["SEX"].ToString();
- myinfshow.dateTimePicker1.Text = dr["BIRTHDAY"].ToString();
- myinfshow.label14.Text = dr["DEPARTMENT"].ToString();
- myinfshow.label15.Text = dr["JOB"].ToString();
- myinfshow.label16.Text = dr["EDU_LEVEL"].ToString();
- myinfshow.label17.Text = dr["SPCIALTY"].ToString();
- myinfshow.textBox1.Text = dr["ADDRESS"].ToString();
- myinfshow.textBox2.Text = dr["TEL"].ToString();
- myinfshow.label20.Text = dr["STATE"].ToString();
- myinfshow.textBox3.Text = dr["REMARK"].ToString();
- myinfshow.label19.Text = label8.Text;
- myinfshow.label24.Text = label3.Text;
- SqlCommand cmd = new SqlCommand("select PHOTO from PERSON where id='" + str + "'", sqlcn);
- SqlDataReader dx = cmd.ExecuteReader();
- dx.Read();
- if (dx["PHOTO"] != Convert.DBNull)
- {
- MemoryStream ms = new MemoryStream((byte[])dx["PHOTO"]);
- Image myimage = Image.FromStream(ms, true);
- myinfshow.pictureBox1.Image = myimage;
- }
- myinfshow.ShowDialog();
- }
- }
- private void dataGridView2_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
- {
- int n = dataGridView1.CurrentRow.Index;
- dataGridView1.CurrentCell = dataGridView1[0, n];
- string str = dataGridView1.CurrentCell.Value.ToString();
- sqlcn = mydatacon.getcon();
- sqlcn.Open();
- SqlDataAdapter com = new SqlDataAdapter("select * from [PERSON] where ID='" + str + "'", sqlcn);
- DataSet ds = new DataSet();
- com.Fill(ds);
- foreach (DataRow dr in ds.Tables[0].Rows)
- {
- infshow myinfshow = new infshow();
- myinfshow.label13.Text = str;
- myinfshow.label11.Text = dr["NAME"].ToString();
- myinfshow.label12.Text = dr["SEX"].ToString();
- myinfshow.dateTimePicker1.Text = dr["BIRTHDAY"].ToString();
- myinfshow.label14.Text = dr["DEPARTMENT"].ToString();
- myinfshow.label15.Text = dr["JOB"].ToString();
- myinfshow.label16.Text = dr["EDU_LEVEL"].ToString();
- myinfshow.label17.Text = dr["SPCIALTY"].ToString();
- myinfshow.textBox1.Text = dr["ADDRESS"].ToString();
- myinfshow.textBox2.Text = dr["TEL"].ToString();
- myinfshow.label20.Text = dr["STATE"].ToString();
- myinfshow.textBox3.Text = dr["REMARK"].ToString();
- myinfshow.label19.Text = label8.Text;
- myinfshow.label24.Text = label3.Text;
- SqlCommand cmd = new SqlCommand("select PHOTO from PERSON where id='" + str + "'", sqlcn);
- SqlDataReader dx = cmd.ExecuteReader();
- dx.Read();
- if (dx["PHOTO"] != Convert.DBNull)
- {
- MemoryStream ms = new MemoryStream((byte[])dx["PHOTO"]);
- Image myimage = Image.FromStream(ms, true);
- myinfshow.pictureBox1.Image = myimage;
- ms.Close();
- dx.Close();
- }
- myinfshow.ShowDialog();
- }
- }
- }
- }