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

📄 add.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.Text.RegularExpressions;
using System.Data.SqlClient;
using System.IO;

namespace renshiguanli
{
    public partial class Add : Form
    {
        private string pic_selected;
        private bool isdate;
        private bool issalary;
//        private DialogResult result = new DialogResult();
        public Add()
        {
            InitializeComponent();
            Information.sql.set_combobox(comboBox_department);
            pic_selected="";
        }

        private void button_cancle_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button_ok_Click(object sender, EventArgs e)
        {
            if (pic_selected=="")
            {
                MessageBox.Show("请指定员工照片");
            }
            else if (textBox_name.Text == "")
            {
                MessageBox.Show("请输入姓名");
            }
            else if (textBox_loginname.Text == "")
            {
                MessageBox.Show("请输入登录名");
            }
            else if (textBox_password.Text == "")
            {
                MessageBox.Show("请输入密码");
            }
            else if (textBox_salary.Text == "")
            {
                MessageBox.Show("请输入基本薪资");
            }
            else if (textBox_title.Text == "")
            {
                MessageBox.Show("请输入职位");
            }
            else if (textBox_phone.Text == "")
            {
                MessageBox.Show("请输入电话号码");
            }
            else if (textBox_onboard.Text == "")
            {
                MessageBox.Show("请输入出生日期");
            }
            else if (numericUpDown_level.Value == 0)
            {
                MessageBox.Show("请输入员工级别");
            }
            else
            {
                Regex mail = new Regex(@"^\w{1,20}@\w{1,20}.\w{1,20}");
                if (!mail.IsMatch(textBox_mail.Text)&&textBox_mail.Text!="")
                {
                    MessageBox.Show("Email格式错误");
                }
                else
                {
                    Regex date = new Regex(@"^(?<year>[1-9][0-9]{3})-(?<month>[0-9]{1,2})-(?<day>[0-9]{1,2})$");
                    if (!date.IsMatch(textBox_onboard.Text))
                    {
                        MessageBox.Show("出生日期格式错误");
                    }
                    else
                    {
                        try
                        {
                            isdate = true;
                            Information.employee.OnbordTime = Convert.ToDateTime(textBox_onboard.Text);
                        }
                        catch
                        {
                            isdate  = false;
                        }
                        if (!isdate)
                        {
                            MessageBox.Show("出生日期错误");
                        }
                        else
                        {
                            try
                            {
                                issalary = true;
                                Information.employee.BasicSalary = Convert.ToInt32(textBox_salary.Text);
                            }
                            catch
                            {
                                issalary = false;
                            }
                            if (!issalary)
                            {
                                MessageBox.Show("薪资错误");
                            }
                            else
                            {
                                Information.employee.Name = textBox_name.Text;
                                Information.employee.LoginName = textBox_loginname.Text;
                                Information.employee.Password = textBox_password.Text;
                                Information.employee.Email = textBox_mail.Text;
                                Information.employee.DeptID = (int)comboBox_department.SelectedValue;
                                Information.employee.Title = textBox_title.Text;
                                Information.employee.Telephone = textBox_phone.Text;
                                Information.employee.EmployeeLevel = (int)numericUpDown_level.Value;
                                this.DialogResult = DialogResult.OK;
                            }
                        }
                    }
                }
            }
        }

        private void textBox_onboard_Enter(object sender, EventArgs e)
        {
            toolTip1.Show("输入格式: 2007-01-15",textBox_onboard);
        }

        private void btn_pic_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                pic_selected = openFileDialog1.FileName;
                picBox_pic.Image = Image.FromFile(pic_selected);
                FileStream stream = new FileStream(pic_selected, FileMode.Open, FileAccess.Read);
                byte[] buffer = new byte[stream.Length];
                stream.Read(buffer, 0, (int)stream.Length);
                stream.Close();
                Information.employee.Image = buffer;
            }
        }
    }
}

⌨️ 快捷键说明

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