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

📄 employeeoperform.cs

📁 一个超市管理系统,没有错误,非常好,里面什么都有!很使用,很有用
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
//正则表达表
using System.Text.RegularExpressions;
using DaFanRongMIS.Model.Employee;
using DaFanRongMIS.Model.Common;
using DaFanRongMIS.ViewController.Employee;

namespace DaFanRongMIS.ViewController.Employee
{
    public partial class EmployeeOperForm : Form
    {
        EmployeeEntity employee;
        EmployeeDAO employeedao;

        public EmployeeOperForm()
        {
            InitializeComponent();
        }

        int flag;
        ListView LVEmployee;
        public EmployeeOperForm(int f,ListView lv)
        {
            InitializeComponent();
            flag = f;
            LVEmployee = lv;
        }

        private void EmployeeOperForm_Load(object sender, EventArgs e)
        {
            switch (flag)
            {
                case 1://增加
                    break;
                case 2://修改
                    this.Text = "员工信息更新";
                    this.txtIDCard.ReadOnly = true;
                    #region 员工信息赋值
                    this.txtIDCard.Text=LVEmployee.SelectedItems[0].SubItems[0].Text;//身份证号
                    this.txtName.Text= LVEmployee.SelectedItems[0].SubItems[1].Text;//姓名
                    if(LVEmployee.SelectedItems[0].SubItems[2].Text=="男")//性别
                        this.rbn.Checked=true;
                    else
                        this.rbw.Checked=true;
                    this.dtpBirthday.Value = Convert.ToDateTime((LVEmployee.SelectedItems[0].SubItems[3].Text));//出生日期
                    this.photo.Text = LVEmployee.SelectedItems[0].SubItems[4].Text;//照片
                    this.pbPhoto.Image = Image.FromFile(this.photo.Text);//图片显示
                    this.txtPhone.Text = LVEmployee.SelectedItems[0].SubItems[5].Text;//联系电话
                    this.txtMobile.Text = LVEmployee.SelectedItems[0].SubItems[6].Text;//手机
                    this.txtAddress.Text = LVEmployee.SelectedItems[0].SubItems[7].Text;//家庭住址
                    this.txtPostalCode.Text = LVEmployee.SelectedItems[0].SubItems[8].Text;//邮政编码
                    this.txtEmail.Text = LVEmployee.SelectedItems[0].SubItems[9].Text;//信箱
                    this.txtQQ.Text = LVEmployee.SelectedItems[0].SubItems[10].Text;//QQ
                    this.txtMemo.Text = LVEmployee.SelectedItems[0].SubItems[11].Text;//备注
#endregion
                    this.btnOK.Text = "更新";
                    break;
            }
        }

        #region 清空文本框
        public void cler()
        {
            this.txtIDCard.Text="";//身份证号
            this.txtName.Text= "";//姓名
            this.rbn.Checked=true;//性别
           
            this.dtpBirthday.Value =DateTime.Now;//出生日期
            this.photo.Text = "";//照片
            this.pbPhoto.Image=null;//图片不显示
            this.txtPhone.Text = "";//联系电话
            this.txtMobile.Text = "";//手机
            this.txtAddress.Text = "";//家庭住址
            this.txtPostalCode.Text = "";//邮政编码
            this.txtEmail.Text = "";//信箱
            this.txtQQ.Text = "";//QQ
            this.txtMemo.Text = "";//备注
        }
        #endregion

        private void btnOK_Click(object sender, EventArgs e)
        {
            employee = new EmployeeEntity();
            switch (flag)
            { 
                case 1://增加
                    #region 对输入数据进行验证
                    #region 身份证验证
                    if (this.txtIDCard.Text.Length == 15 && Regex.IsMatch(this.txtIDCard.Text, "^([0-9_-]+)[0-9]$")) 
                    {}//return;
                    else if (this.txtIDCard.Text.Length == 18 && Regex.IsMatch(this.txtIDCard.Text, "^([0-9_-]+)[0-9?x]$"))
                    { }  //return;
                    else
                    {
                        MessageBox.Show("身份证号不能为空或输入有误!");
                        this.txtIDCard.Focus();
                        this.txtIDCard.SelectAll();
                        return;
                    }
                    #endregion
                    #region 联系电话验证
                    string aa = @"(\(\d{3}\)|\d{3}-)?\d{8}";
                    Regex zz = new Regex(aa);
                    if (!zz.IsMatch(this.txtPhone.Text))
                    {
                        MessageBox.Show("没有填写信息或或联系电话格式不正确!");
                        txtPhone.Focus();
                        txtPhone.SelectAll();
                        return;
                    }
                    #endregion

                    #region 手机号码验证
                    if (this.txtMobile.Text != "")
                    {
                        string bb = @"^\d{11}$";
                        Regex ww = new Regex(bb);
                        if (!ww.IsMatch(this.txtMobile.Text))
                        {
                            MessageBox.Show("没有填写信息或手机号码格式不正确,只能是11位数字!");
                            this.txtMobile.Focus();
                            this.txtMobile.SelectAll();
                            return;
                        }
                    }
                    #endregion

                    #region 邮政编码验证
                    if (this.txtPostalCode.Text != "")
                    {
                        string cc = @"\d{6}";
                        Regex yy = new Regex(cc);
                        if (!yy.IsMatch(this.txtPostalCode.Text))
                        {
                            MessageBox.Show("没有填写信息或邮政编码格式不正确,只能是6位数字!");
                            this.txtPostalCode.Focus();
                            this.txtPostalCode.SelectAll();
                            return;
                        }
                    }
                    #endregion

                    #region 传真验证
                    /*if (this.txtFax.Text != "")
                    {
                        string dd = @"(\(\d{3}\)|\d{3}-)?\d{8}";
                        Regex xx = new Regex(dd);
                        if (!xx.IsMatch(this.txtFax.Text))
                        {
                            MessageBox.Show("传真号码格式不正确!");
                            this.txtFax.Focus();
                            this.txtPostalCode.SelectAll();
                            return;
                        }
                    }*/
                    #endregion

                    #region E-Mail验证
                    if (this.txtEmail.Text != "")
                    {
                        string ee = @"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*";
                        Regex vv = new Regex(ee);
                        if (!vv.IsMatch(this.txtEmail.Text))
                        {
                            MessageBox.Show("没有填写信息或E-mail格式不正确!");
                            this.txtEmail.Focus();
                            this.txtEmail.SelectAll();
                            return;
                        }
                    }
                    #endregion
                    #endregion
                    if (this.txtIDCard.Text != "" && this.txtName.Text != "")
                    {
                        #region 为属性字段赋值
                        employee.EmIDCard = this.txtIDCard.Text;//身份证号
                        employee.EmName = this.txtName.Text;//姓名
                        if (this.rbn.Checked == true)//性别
                            employee.EmSex = "男";
                        else
                            employee.EmSex = "女";
                        employee.EmBirthday = this.dtpBirthday.Text;//出生日期
                        employee.EmPhoto = this.photo.Text;//照片
                        employee.EmPhone = this.txtPhone.Text;//联系电话
                        employee.EmMobile = this.txtMobile.Text;//手机
                        employee.EmAddress = this.txtAddress.Text;//家庭住址
                        employee.EmPostalCode = this.txtPostalCode.Text;//邮政编码
                        employee.EmEmail = this.txtEmail.Text;//信箱
                        employee.EmQQ = this.txtQQ.Text;//QQ
                        employee.EmMemo = this.txtMemo.Text;//备注
                        #endregion
                        employeedao = new EmployeeDAOImpl();
                        string str = employeedao.AddEmployee(employee);
                        if (str == "OK")
                        {
                            #region 填加成功回填ListView
                            ListViewItem item = new ListViewItem(this.txtIDCard.Text);
                            //item.SubItems.Add((LVEmployee.Items.Count + 1).ToString());
                            item.SubItems.Add(txtName.Text);
                            if (this.rbn.Checked == true)//性别
                                item.SubItems.Add("男");
                            else
                                item.SubItems.Add("女");
                            item.SubItems.Add(Convert.ToString(this.dtpBirthday.Value));
                            item.SubItems.Add(photo.Text);
                            item.SubItems.Add(txtPhone.Text);
                            item.SubItems.Add(txtMobile.Text);
                            item.SubItems.Add(txtAddress.Text);
                            item.SubItems.Add(txtPostalCode.Text);
                            item.SubItems.Add(txtEmail.Text);
                            item.SubItems.Add(txtQQ.Text);
                            item.SubItems.Add(txtMemo.Text);

                            LVEmployee.Items.Add(item);
                            #endregion
                            MessageBox.Show("新员工信息登记成功!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            cler();
                        }
                        else
                            MessageBox.Show("信息有误!未登记成功!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                    }
                    else
                    {
                        MessageBox.Show("身份证号,姓名,性别,出生日期为必填项!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                        break;//end case 1 Add 
                case 2://修改
                    #region 为属性字段赋值

                    employee.EmIDCard = this.txtIDCard.Text;//身份证号
                    employee.EmName = this.txtName.Text;//姓名
                    if (this.rbn.Checked == true)//性别
                        employee.EmSex = "男";
                    else
                        employee.EmSex = "女";
                    employee.EmBirthday = Convert.ToString(this.dtpBirthday.Value);//出生日期
                    employee.EmPhoto = this.photo.Text;//照片
                    employee.EmPhone = this.txtPhone.Text;//联系电话
                    employee.EmMobile = this.txtMobile.Text;//手机
                    employee.EmAddress = this.txtAddress.Text;//家庭住址
                    employee.EmPostalCode = this.txtPostalCode.Text;//邮政编码
                    employee.EmEmail = this.txtEmail.Text;//信箱
                    employee.EmQQ = this.txtQQ.Text;//QQ
                    employee.EmMemo = this.txtMemo.Text;//备注
#endregion
                    employeedao = new EmployeeDAOImpl();
                    if (employeedao.UpdateEmployee(employee) == "OK")
                    {
                        #region 修改成功回填ListView
                        LVEmployee.SelectedItems[0].Text = this.txtIDCard.Text;//身份证号
                        LVEmployee.SelectedItems[0].SubItems[1].Text = this.txtName.Text;//姓名
                        if (this.rbn.Checked == true)//性别
                            LVEmployee.SelectedItems[0].SubItems[2].Text = "男";
                        else
                            LVEmployee.SelectedItems[0].SubItems[2].Text = "女";
                        LVEmployee.SelectedItems[0].SubItems[3].Text = Convert.ToString(this.dtpBirthday.Value);//出生日期
                        LVEmployee.SelectedItems[0].SubItems[4].Text = this.photo.Text;//照片
                        LVEmployee.SelectedItems[0].SubItems[5].Text = this.txtPhone.Text;//联系电话
                        LVEmployee.SelectedItems[0].SubItems[6].Text = this.txtMobile.Text;//手机
                        LVEmployee.SelectedItems[0].SubItems[7].Text = this.txtAddress.Text;//家庭住址
                        LVEmployee.SelectedItems[0].SubItems[8].Text = this.txtPostalCode.Text;//邮政编码
                        LVEmployee.SelectedItems[0].SubItems[9].Text = this.txtEmail.Text;//信箱
                        LVEmployee.SelectedItems[0].SubItems[10].Text = this.txtQQ.Text;//QQ
                        LVEmployee.SelectedItems[0].SubItems[11].Text = this.txtMemo.Text;//备注
                        #endregion
                        MessageBox.Show("员工信息修改成功!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        this.Close();
                    }
                    else
                        MessageBox.Show("信息有误!未登记成功!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                    break;//end case 2 Update
            }
        }

        #region 图片上传按钮中现实图片上传存储
        public void FileUp_Click(object sender, EventArgs e)
        {
            //图片上传
            this.openFileDialog1.ShowDialog();//打开文件窗体
            //将选定文件的路径存储到数组中
            string[] file = openFileDialog1.FileName.Split('\\');
            //获得选定文件的名
            string filename = "Image\\" + file[file.Length - 1];
            //得到本项目路径
            string path = Application.StartupPath;
            //指定最终文件存储路径
            string pathnew= path.Replace("bin\\Debug", "")+filename;
            //将最终图片路径放入文本框,用以写入数据库应用
            this.photo.Text = pathnew;
            //将选定图片复制到项目中指定路径
            File.Copy(openFileDialog1.FileName, pathnew,true);
            //让图片显示
            this.pbPhoto.Image = Image.FromFile(pathnew);
        }
        #endregion

        private void button1_Click(object sender, EventArgs e)
        {
            this.cler();//清空文本框
        }
    }
}

⌨️ 快捷键说明

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