C#switch循环实现代码共用

void save()
        {
            if (!is数据正确()) { return; }
            List<SQLStruct> col = new List<SQLStruct>();
            col.Add(new SQLStruct("EmployeeInfo_JobNumber", this.txtNO.Text));
            col.Add(new SQLStruct("EmployeeInfo_Name", this.txtName.Text));
            col.Add(new SQLStruct("EmployeeInfo_NameJP",ClassFunction.ChineseCap(this.txtName.Text)));
            col.Add(new SQLStruct("EmployeeInfo_Use", this.txt启用员工.Checked));
            col.Add(new SQLStruct("EmployeeInfo_Sex", this.txtsex1.Checked?"先生":"女士"));


            col.Add(new SQLStruct("EmployeeInfo_EDepartmentNO", this.txt部门.SelectedValue.ToString()));
            col.Add(new SQLStruct("EmployeeInfo_PowerNO", this.txt权限.SelectedValue.ToString()));

            col.Add(new SQLStruct("EmployeeInfo_BirthIs", this.txt出生日期启用.Checked));
            col.Add(new SQLStruct("EmployeeInfo_Birth", this.txt出生年月.Value));
            col.Add(new SQLStruct("EmployeeInfo_Address", this.txtaddress.Text));
            col.Add(new SQLStruct("EmployeeInfo_Phone", this.txtTel.Text));
            col.Add(new SQLStruct("EmployeeInfo_CheckNO", this.txt考勤编号.Text));

            col.Add(new SQLStruct("EmployeeInfo_EntryDate", this.txt入职时间.Value));
            col.Add(new SQLStruct("EmployeeInfo_DepartureIs", this.txt是否离职.Checked));
            col.Add(new SQLStruct("EmployeeInfo_DepartureDate", this.txt离职时间.Value));
            col.Add(new SQLStruct("EmployeeInfo_PlayMoney", this.txtn员工计划.Value));

            string sql = "";
            switch (this.cft)
            {
                case ClassFormType.添加:
                    this.eNO=ClassFunction.SCNO("ENO");
                    col.Add(new SQLStruct("EmployeeInfo_NO", this.eNO));
                    col.Add(new SQLStruct("EmployeeInfo_PassWord",  ClassUser.MD5员工(this.txtPass.Text, eNO)));
                    sql += SQLGet.Add(col, "EmployeeInfo");
                    break;
                case ClassFormType.修改:
                    sql += SQLGet.Update(col, "EmployeeInfo") + " where EmployeeInfo_NO='" + this.eNO+"'";
                    txt考勤编号.Text = sql;
                    break;
                default:
                    this.Close();
                    break;
            }
            //MessageBox.Show(sql);
            if (ClassData.UpDate(sql) > 0)
            {
                MessageBox.Show(this.cft.ToString() + "成功!");
                ClassData.SysLog(this.cft.ToString() + "员工【" + this.eNO + "】【" + this.txtName.Text + "】");
                IsOK = true;
                this.Close();
            }
            else
            {
                MessageBox.Show(this.cft.ToString() + "失败!");
            }
        }
------------------------------YXToolSystem-------------------------
using System;

namespace YXToolSystem
{
    public enum ClassFormType
    {
        添加 = 0,
        删除 = 1,
        修改 = 2,
        查看 = 3,
        审核 = 4,
        反审核 = 5,
    }
}
------------------------------cft---eNO-------------------------------------------
public Form员工管理添加(ClassFormType cft, string eNO)
        {
            InitializeComponent();

            //
          InterfaceSystem.ClassFormStyle.FromStyleFixedToolWindow(this);
          InterfaceSystem.ClassFormStyle.BUTB_STYE(this.butExit);
          InterfaceSystem.ClassFormStyle.BUTB_STYE(this.butOK);

            this.cft = cft;
            this.eNO = eNO;
            this.Text = "员工设置" + cft.ToString();
            this.butOK.Text = cft.ToString();
        }

原文地址:https://www.cnblogs.com/qq1206583608/p/5165516.html