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

📄 frmeinfomanage.cs

📁 客户关系管理系统
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace CRM.PInfoManage
{
    public partial class frmEInfoManage : Form
    {
        CRM.BaseClass.BaseOperate boperate = new CRM.BaseClass.BaseOperate();
        CRM.BaseClass.OperateAndValidate opAndvalidate = new CRM.BaseClass.OperateAndValidate();
        protected string M_str_sql = "select EID as 员工编号,EName as 员工姓名,ESex as 员工性别,"
            + "EBirthday as 员工生日,EWDate as 工作日期,EDiploma as 学历,EDepartment as 所在部门,"
            + "EPosition as 当前职务,EType as 员工类别 from tb_Employee";
        protected string M_str_table = "tb_Employee";
        protected int M_int_judge;
        public frmEInfoManage()
        {
            InitializeComponent();
        }

        private void frmEInfoManage_Load(object sender, EventArgs e)
        {
            DataSet myds = boperate.getds(M_str_sql, M_str_table);
            dgvEInfo.DataSource = myds.Tables[0];
            if (myds.Tables[0].Rows.Count > 0)
                tsbtnDel.Enabled = true;
            else
                tsbtnDel.Enabled = false;
        }

        private void tsbtnAdd_Click(object sender, EventArgs e)
        {
            opAndvalidate.autoNum("select EID from tb_Employee", "tb_Employee", "EID", "YG", "1000001", txtEID);
            tsbtnSave.Enabled = true;
            M_int_judge = 0;
            txtEName.Text = "";
        }

        private void tsbtnEdit_Click(object sender, EventArgs e)
        {
            tsbtnSave.Enabled = true;
            M_int_judge = 1;
        }

        private void tsbtnSave_Click(object sender, EventArgs e)
        {
            if (M_int_judge == 0)
            {
                if (txtEName.Text == "")
                {
                    MessageBox.Show("员工姓名不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    boperate.getcom("insert into tb_Employee(EID,EName,ESex,EBirthday,EWDate,EDiploma,EDepartment,"
                        + "EPosition,EType) values('" + txtEID.Text.Trim() + "','" + txtEName.Text.Trim() + "','"
                        + cboxSex.Text.Trim() + "','" + dtpEBirthday.Text.Trim() + "','" + dtpWDate.Text.Trim() + "','"
                        + cboxEDiploma.Text.Trim() + "','" + cboxEDepartment.Text.Trim() + "','"
                        + cboxEPositon.Text.Trim() + "','" + cboxEType.Text.Trim() + "')");
                    frmEInfoManage_Load(sender, e);
                    MessageBox.Show("员工信息添加成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    tsbtnSave.Enabled = false;
                }
            }
            if (M_int_judge == 1)
            {
                if (txtEName.Text == "")
                {
                    MessageBox.Show("员工姓名不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    boperate.getcom("update tb_Employee set EName='" + txtEName.Text.Trim()
                        + "',ESex='" + cboxSex.Text.Trim() + "',EBirthday='" + dtpEBirthday.Text.Trim() + "',EWDate='"
                        + dtpWDate.Text.Trim() + "',EDiploma='" + cboxEDiploma.Text.Trim() + "',EDepartment='"
                        + cboxEDepartment.Text.Trim() + "',EPosition='" + cboxEPositon.Text.Trim() + "',EType='"
                        + cboxEType.Text.Trim() + "' where EID='" + txtEID.Text.Trim() + "'");
                    frmEInfoManage_Load(sender, e);
                    MessageBox.Show("员工信息修改成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    tsbtnSave.Enabled = false;
                }
            }
        }

        private void tsbtnDel_Click(object sender, EventArgs e)
        {
            try
            {
                if (MessageBox.Show("确定要删除该员工吗?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
                {
                    boperate.getcom("delete from tb_Employee where EID='" + Convert.ToString(dgvEInfo[0, dgvEInfo.CurrentCell.RowIndex].Value).Trim() + "'");
                    frmEInfoManage_Load(sender, e);
                    MessageBox.Show("删除数据成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
            }
        }

        private void tsbtnLook_Click(object sender, EventArgs e)
        {
            try
            {
                if (tstxtKeyWord.Text == "")
                {
                    frmEInfoManage_Load(sender, e);
                }
                if (tscboxCondition.Text.Trim() == "员工编号")
                {
                    DataSet myds = boperate.getds(M_str_sql + " where EID like '%" + tstxtKeyWord.Text.Trim() + "%'", M_str_table);
                    if (myds.Tables[0].Rows.Count > 0)
                        dgvEInfo.DataSource = myds.Tables[0];
                    else
                        MessageBox.Show("没有要查找的相关记录!");
                }
                if (tscboxCondition.Text.Trim() == "员工姓名")
                {
                    DataSet myds = boperate.getds(M_str_sql + " where EName like '%" + tstxtKeyWord.Text.Trim() + "%'", M_str_table);
                    if (myds.Tables[0].Rows.Count > 0)
                        dgvEInfo.DataSource = myds.Tables[0];
                    else
                        MessageBox.Show("没有要查找的相关记录!");
                }
                if (tscboxCondition.Text.Trim() == "学历")
                {
                    DataSet myds = boperate.getds(M_str_sql + " where EDiploma like '%" + tstxtKeyWord.Text.Trim() + "%'", M_str_table);
                    if (myds.Tables[0].Rows.Count > 0)
                        dgvEInfo.DataSource = myds.Tables[0];
                    else
                        MessageBox.Show("没有要查找的相关记录!");
                }
                if (tscboxCondition.Text.Trim() == "部门")
                {
                    DataSet myds = boperate.getds(M_str_sql + " where EDepartment like '%" + tstxtKeyWord.Text.Trim() + "%'", M_str_table);
                    if (myds.Tables[0].Rows.Count > 0)
                        dgvEInfo.DataSource = myds.Tables[0];
                    else
                        MessageBox.Show("没有要查找的相关记录!");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }

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

        private void dgvEInfo_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            txtEID.Text = Convert.ToString(dgvEInfo[0, dgvEInfo.CurrentCell.RowIndex].Value).Trim();
            txtEName.Text = Convert.ToString(dgvEInfo[1, dgvEInfo.CurrentCell.RowIndex].Value).Trim();
            cboxSex.Text = Convert.ToString(dgvEInfo[2, dgvEInfo.CurrentCell.RowIndex].Value).Trim();
            dtpEBirthday.Text = Convert.ToString(dgvEInfo[3, dgvEInfo.CurrentCell.RowIndex].Value).Trim();
            dtpWDate.Text = Convert.ToString(dgvEInfo[4, dgvEInfo.CurrentCell.RowIndex].Value).Trim();
            cboxEDiploma.Text = Convert.ToString(dgvEInfo[5, dgvEInfo.CurrentCell.RowIndex].Value).Trim();
            cboxEDepartment.Text = Convert.ToString(dgvEInfo[6, dgvEInfo.CurrentCell.RowIndex].Value).Trim();
            cboxEPositon.Text = Convert.ToString(dgvEInfo[7, dgvEInfo.CurrentCell.RowIndex].Value).Trim();
            cboxEType.Text = Convert.ToString(dgvEInfo[8, dgvEInfo.CurrentCell.RowIndex].Value).Trim();
        }
    }
}

⌨️ 快捷键说明

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