工资管理系统c#与SQL Server

表的建立:

Create table Usemen

(

用户 nchar(10)primary key,

密码 nchar(10)not null,

性别 nchar(3)not null,

年龄 int notnull,

员工号 nchar(10)not null,

职位 nchar(10)not null
);

Create table Salary

{

基本工资 int notnull,

津贴 int,

总工资 int notnull,

员工号 nchar(10)not null

};

Create teable Work

{

职位 nchar(10)not null,

基本工资 int notnull
};

Create table 价值表

{

职位 nchar(10)not null,

加班费/小时 int not null,

误工费/小时 int not null
};

Create table 津贴

{

员工号 nchar(10)primary key;

加班时间 int,

误工时间 int,

加班费 int,

误工费 int,

奖金 int,

津贴 int
};

当然我并不是通过SQL语句建立表的,而是直接建立的,但是不知道怎么的发不了截图了,就不把我的每个表里的数据上传了

登陆

功能选择界面


查询任意一人的工资

添加员工

删除员工


修改员工信息

数据导出

将所有人的工资信息导出到excel表,这里运用的是excel2016版


附录

//工资查询

namespace 工资管理系统{

    public partial class Form3 : Form{

        SqlConnection conn = newSqlConnection("server=.;uid=sa;pwd=981210;database=工资数据库");

        public Form3(){

            InitializeComponent();

        }

        private void Form3_Load(object sender,EventArgs e){

            this.salaryTableAdapter2.Fill(this.工资数据库DataSet6.Salary);

        }

        private voidtextBox1_TextChanged(object sender, EventArgs e){

            try{

                String strsql = "select *from Salary where 员工号='" + textBox1.Text + "'";

                SqlCommand cmd = newSqlCommand(strsql, conn);

                SqlDataAdapter da = newSqlDataAdapter(cmd);

                DataSet ds = new DataSet();

                da.Fill(ds);

                dataGridView1.DataSource =ds.Tables[0];

            }

            catch (Exception ce){

                MessageBox.Show(ce.Message);

            }

            finally{ }

        }

    }

}

//添加员工

namespace 工资管理系统{

    public partial class Form5 : Form{

        SqlConnection conn =new SqlConnection("server=.;uid=sa;pwd=981210;database=工资数据库");

        public Form5(){

            InitializeComponent();

        }

        private void button1_Click(objectsender, EventArgs e){

            try{

                if ((textBox1.Text == "") || (textBox2.Text == " ") || (textBox3.Text == " ")|| (textBox4.Text == " ") || (textBox5.Text == "")||(textBox6.Text == " ")) {

                    MessageBox.Show("界面中的所有属性值不能为空!");

                }

                else {

                     string number = textBox1.Text.Trim();

                     string name = textBox2.Text.Trim();

                     string age = textBox3.Text.Trim();

                                stringsex = textBox4.Text.Trim();

                     string work = textBox5.Text.Trim();

                     string id = textBox6.Text.Trim();

                     string password = number;

                     String strsql = "select * from Work where 职位='" + work + "'";

                     SqlCommand cmd = new SqlCommand(strsql, conn);

                     SqlDataAdapter da = new SqlDataAdapter(cmd);

                     DataSet ds = new DataSet();

                     da.Fill(ds);

                     string basedsalary = ds.Tables[0].Rows[0][1].ToString();

                     strsql = "insert into Usemen(用户,密码,员工号,年龄,性别,职位,系统身份)values('" + name + "','"+password+"','"  + number +"','"+age+"','"+sex+"','"+work+"','"+id+"')"

                    +"insert into 津贴(员工号) values('" + number + "')"

  + "insert into Salary(基本工资,总工资,员工号)values('" + basedsalary + "','" + basedsalary + "','"+ number + "')";

                     cmd= new SqlCommand(strsql, conn);

                     conn.Open();

                     cmd.ExecuteNonQuery();

                     MessageBox.Show("添加成功!");

                     conn.Close();

                }

            }

            catch (Exception e2){

                MessageBox.Show(e2.Message);

            }

        }

    }

}

//修改员工信息

namespace 工资管理系统{

    public partial class Form11 : Form{

        SqlConnection conn = newSqlConnection("server=.;uid=sa;pwd=981210;database=工资数据库");

        string sex, age, work,name11;

        String strsql;

        SqlCommand cmd;

        SqlDataAdapter da;

        DataSet ds;

        public Form11(){

            InitializeComponent();

        }

        private void button1_Click(objectsender, EventArgs e){

            try{

                age = textBox3.Text.Trim();

                work = textBox4.Text.Trim();

                String strsql = "select *from Work where 职位='" + work + "'";

                SqlCommand cmd = newSqlCommand(strsql, conn);

                SqlDataAdapter da = newSqlDataAdapter(cmd);

                DataSet ds = new DataSet();

                da.Fill(ds);

                int basedsalary =int.Parse(ds.Tables[0].Rows[0][1].ToString());

       strsql = "select * from 津贴 where 员工号=(select 员工号 fromUsemen where 用户='" + name11 + "')";

                cmd = new SqlCommand(strsql,conn);

                da = new SqlDataAdapter(cmd);

                ds = new DataSet();

                da.Fill(ds);

                int 津贴 = int.Parse(ds.Tables[0].Rows[0][5].ToString());

                int 工资 = basedsalary + 津贴;

              strsql = "update Usemen set 年龄='" + age + "',职位='" +work + "' where 用户='" + name11 + "'"+"update Salary set 基本工资='" + basedsalary + "',总工资='" + 工资 + "'where 员工号=(select 员工号 fromUsemen where 用户='" + name11 + "')";

                cmd = new SqlCommand(strsql,conn);

                conn.Open();

                cmd.ExecuteNonQuery();

                MessageBox.Show("修改成功!");

                conn.Close();

            }

            catch (Exception ce){

                MessageBox.Show(ce.Message);

            }

        }

        private void button3_Click(objectsender, EventArgs e){

            strsql = "select * from Usemenwhere 用户='" + textBox1.Text + "'";

            try{

            conn.Open();

            SqlCommand com = newSqlCommand(strsql, conn);

                name11 = textBox1.Text.Trim();

                cmd = new SqlCommand(strsql,conn);

                da = new SqlDataAdapter(cmd);

                ds = new DataSet();

                da.Fill(ds);

                sex =ds.Tables[0].Rows[0][2].ToString();

                age =ds.Tables[0].Rows[0][3].ToString();

                work =ds.Tables[0].Rows[0][5].ToString();

                this.textBox2.Text = sex;

                this.textBox3.Text = age;

                this.textBox4.Text = work;

            }

            catch (Exception ce){

               MessageBox.Show(ce.Message);

            }

            conn.Close();

        }

    }

}

//删除员工记录

namespace 工资管理系统{

    public partial class Form6 : Form{

        SqlConnection conn = newSqlConnection("server=.;uid=sa;pwd=981210;database=工资数据库");

        public Form6(){

            InitializeComponent();

        }

        private void button1_Click(objectsender, EventArgs e){

            try{

                String strsql = "deletefrom Salary where 员工号='" + this.textBox1.Text +"'"

                                + "deletefrom 津贴 where 员工号='"+ this.textBox1.Text + "'"

                                +"deletefrom Usemen where 员工号='" + this.textBox1.Text +"'";

                SqlCommand cmd = newSqlCommand(strsql, conn);

                conn.Open();

                cmd.ExecuteNonQuery();

                MessageBox.Show("删除成功!");

                conn.Close();

            }

            catch (Exception ce){

                MessageBox.Show(ce.Message);

            }

            finally{}

        }

    }

}

//数据导出

namespace 工资管理系统{

    public partial class Form13 : Form{

        SqlConnection conn = newSqlConnection("server=.;uid=sa;pwd=981210;database=工资数据库");

        public Form13(){

            InitializeComponent();

            try{

                String strsql = "select 用户,基本工资,总工资,津贴.* from Usemen,Salary,津贴 where Usemen.员工号=Salary.员工号 and Salary.员工号=津贴.员工号";

                SqlCommand cmd = newSqlCommand(strsql, conn);

                SqlDataAdapter da = newSqlDataAdapter(cmd);

                DataSet ds = new DataSet();

                da.Fill(ds);

                dataGridView1.DataSource = ds.Tables[0];

            }

            catch (Exception ce){

                MessageBox.Show(ce.Message);

            }

            finally{ }

        }

        private void button1_Click(objectsender, EventArgs e){

            if (ExportDataGridview(dataGridView1,true)==true)

                MessageBox.Show("导出成功,请记得保存!");

            else

                MessageBox.Show("导出不成功,请检查是否有错!");

        }

        public boolExportDataGridview(DataGridView gridview, bool isshowExcle){

            if (gridview.Rows.Count == 0)

                return false;

            Excel.Application excel = newExcel.Application();

           excel.Application.Workbooks.Add(true);

            excel.Visible = isshowExcle;

            for (int i = 0; i <gridview.ColumnCount; i++){

                excel.Cells[1, i + 1] =gridview.Columns[i].HeaderText;

            }

            for (int i = 0; i <gridview.RowCount-1; i++){

                for (int j = 0; j <gridview.ColumnCount; j++){

                    if (gridview[j, i].ValueType== typeof(string)){

                        excel.Cells[i + 2, j +1] = "'" + gridview[j, i].Value.ToString();

                    }

                    else{

                        excel.Cells[i + 2, j +1] = gridview[j, i].Value.ToString();

                    }

                }

            }

            return true;

        }

    }

}

猜你喜欢

转载自blog.csdn.net/qq_41093493/article/details/81048802
今日推荐