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

📄 formnewemployee.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 FormNewEmployee : Form
    {
        SqlConnection cnn;
        public FormNewEmployee()
        {
            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();
            FormListEmployee FE = new FormListEmployee();
            FE.Show();
        }

        private void btnNewEmployee_Click(object sender, EventArgs e)
        {
            byte[] images = FormPhotoPath.image;
            dateTimePicker1.CustomFormat = "yyyy-mm-dd  hh-mi";
            dateTimePicker1.Format = DateTimePickerFormat.Custom;
            //DateTime DT = Convert.ToDateTime(dateTimePicker1.Text.ToString());
            if (textBox1.Text.Trim() == "")
            {
                DialogResult = MessageBox.Show("请输入姓名!", "提示");
                textBox1.Focus();
            }
            else
            {
                if (textBox2.Text.Trim() == "")
                {
                    DialogResult = MessageBox.Show("请输入登陆名!", "提示");
                    textBox2.Focus();
                }
                else
                {
                    if (textBox5.Text.Trim() == "")
                    {
                        DialogResult = MessageBox.Show("请输入电子邮件!", "提示");
                        textBox5.Focus();
                    }
                    else
                    {
                        SqlConnection con = DB.connection();
                        con.Open();
                        if (textBox3.Text.Trim() == "")
                        {
                            cnn = new SqlConnection("data source=.;initial catalog=BlueHill_HRM;integrated security=true;");
                            cnn.Open();
                            DialogResult = MessageBox.Show("你没有给此员工设置初始密码,系统将默认设置为“000000?” ", "南山人事管理系统提示你", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
                            if (DialogResult == DialogResult.OK)
                            {
                                SqlCommand cmd = new SqlCommand("insert into tblEmployee(Name,LoginName,Password,Email,DeptID,BasicSalary,Title,Telephone,OnboardDate,PhotoImage,EmployeeLevel) values('"
                                    + textBox1.Text.ToString().Trim() + "','" + textBox2.Text.ToString().Trim() + "','" + 123456 + "','" + textBox5.Text.ToString().Trim() + "','" + txtManagerID.Text.ToString().Trim()
                                    + "','" + textBox6.Text.ToString().Trim() + "','" + textBox7.Text.ToString().Trim() + "','" + textBox8.Text.ToString().Trim() + "','" + dateTimePicker1.Value.ToShortDateString() + "','" + images + "','" + numLevel.Value.ToString()
                                    + "')", con);
                                int count = Convert.ToInt32(cmd.ExecuteNonQuery());
                                if (count > 0)
                                {
                                    DialogResult = MessageBox.Show("添加成功!", "提示");
                                }
                                else
                                {
                                    DialogResult = MessageBox.Show("操作失败!", "提示");
                                }
                            }
                        }
                        else
                        {
                            if (textBox3.Text.Length < 6)
                            {
                                DialogResult = MessageBox.Show("密码至少为6位!", "提示");
                            }
                            else
                            {
                                SqlCommand cmd = new SqlCommand("insert into tblEmployee(Name,LoginName,Password,Email,DeptID,BasicSalary,Title,Telephone,OnboardDate,PhotoImage,EmployeeLevel) values('"
                                        + textBox1.Text.ToString().Trim() + "','" + textBox2.Text.ToString().Trim() + "','" + textBox3.Text.ToString().Trim() + "','" + textBox5.Text.ToString().Trim() + "','" + txtManagerID.Text.ToString().Trim()
                                        + "','" + textBox5.Text.ToString().Trim() + "','" + textBox6.Text.ToString().Trim() + "','" + textBox7.Text.ToString().Trim() + "','" + dateTimePicker1.Value.ToShortDateString() + "','" + images + "','" + numLevel.Value.ToString()
                                        + "')", con);
                                char count = Convert.ToChar(cmd.ExecuteNonQuery());// Convert.ToInt32(cmd.ExecuteNonQuery());
                                //int count = Convert.ToInt32(cmd.ExecuteNonQuery());
                                if (count > 0)
                                {
                                    DialogResult = MessageBox.Show("添加成功!", "提示");
                                }
                                else
                                {
                                    DialogResult = MessageBox.Show("操作失败!", "提示");
                                }
                            }
                        }
                    }
                }
            }


            DialogResult = MessageBox.Show(dateTimePicker1.Value.ToShortTimeString(), "提示");

        }

        private void buttonUploadPhoto_Click(object sender, EventArgs e)
        {
            FormPhotoPath FP = new FormPhotoPath();
            FP.Show();
        }

        private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
        {
            string imageU = FormPhotoPath.txt;
            picPhoto.ImageLocation = imageU;
        }

        private void FormNewEmployee_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 tblDepartment", cnn);
            SqlDataReader bm1 = cmd1.ExecuteReader();
            while (bm1.Read())
            {
                cbDepartmenta.Items.Add(bm1["DeptName"].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 DeptID from tblDepartment where  DeptName =('" + cbDepartmenta.Text + "')", cnn);
            SqlDataReader bm = cmd.ExecuteReader();
            while (bm.Read())
            {
                txtManagerID.Text = (bm["DeptID"].ToString());

            }
            cnn.Close();
        }
    }
}

⌨️ 快捷键说明

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