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

📄 formadddepartment.cs

📁 人事管理系统
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace HumanResourceManagement
{
    public partial class FormAddDepartment : Form
    {
        SqlConnection cnn;
        public FormAddDepartment()
        {
            InitializeComponent();
        }

        private const int CP_NOCLOSE_BUTTON = 0x200;
        protected override CreateParams CreateParams
        {
            get
            {
                CreateParams myCp = base.CreateParams;
                myCp.ClassStyle = myCp.ClassStyle | CP_NOCLOSE_BUTTON;
                return myCp;
            }
        } 
        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Hide();
            FormDepartmentManagement FDeptM = new FormDepartmentManagement();
            FDeptM.Show();
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            if (txtDeptName.Text == "")
            {
                DialogResult = MessageBox.Show("请输入要添加的部门名!", "提示");
            }
            else
            {
                if (txtDeptDescription.Text == "")
                {
                    DialogResult = MessageBox.Show("请填写对该部门的描述!", "提示");
                }
                else
                {
                    if (txtManagerID.Text == "")
                    {
                        DialogResult = MessageBox.Show("请指派该部门的经理!", "提示");
                    }
                    else
                    {
                        SqlConnection con = DB.connection();
                        con.Open();
                        try
                        {
                            SqlCommand cmd = new SqlCommand("insert into tblDepartment(DeptID,DeptName,Desciption,ManagerID) values ('" + texDeptID.Text.ToString().Trim() + "','" + txtDeptName.Text.ToString().Trim()
                                + "','" + txtDeptDescription.Text.ToString().Trim() + "','" + txtManagerID.Text.ToString().Trim() + "')", con);
                            int count = Convert.ToInt32(cmd.ExecuteNonQuery());
                            if (count > 0)
                            {
                                con.Close();
                                DialogResult = MessageBox.Show("添加成功!", "提示");
                                this.Close();
                                FormDepartmentManagement FDM = new FormDepartmentManagement();
                                FDM.Show();
                            }
                            else
                            {
                                con.Close();
                                DialogResult = MessageBox.Show("操作失败!", "提示");
                            }
                        }
                        catch (Exception ev)
                        {
                            MessageBox.Show(ev.ToString());
                        }
                    }
                }
            }
        }

        private void FormAddDepartment_Load(object sender, EventArgs e)
        {
            cnn = new SqlConnection("data source=.;initial catalog=BlueHill_HRM;integrated security=true;");
            cnn.Open();
            SqlCommand cmd1 = new SqlCommand("select * from tblEmployee", cnn);
            SqlDataReader bm1 = cmd1.ExecuteReader();
            while (bm1.Read())
            {
                cbDepartment.Items.Add(bm1["name"].ToString());
            }
            cnn.Close();
        }

        private void cbDepartment_SelectedIndexChanged(object sender, EventArgs e)
        {
            cnn = new SqlConnection("data source=.;initial catalog=BlueHill_HRM;integrated security=true;");
            cnn.Open();
            SqlCommand cmd = new SqlCommand("select EmployeeID from tblEmployee where  Name =('" + cbDepartment.Text + "')", cnn);
            SqlDataReader bm = cmd.ExecuteReader();
            while (bm.Read())
            {
                txtManagerID.Text = (bm["EmployeeID"].ToString());

            }
            cnn.Close();
        }
    }                           

}

⌨️ 快捷键说明

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