人事管理系统实现(八)

时间:2023-01-05 16:33:34

   按照(七)中的介绍我们需要此章节需要设计职工简历这一选项卡,然而选项卡之间的切换需要转换不同的功能,所以在这里首先设计选项卡的切换的Click事件:

        private void tabControl1_Click(object sender, EventArgs e)
        {
            groupBox5.Enabled = true;
            Sut_Delete.Enabled = true;
            MyMC.Ena_Button(Sut_Add, Sut_Amend, Sut_Cancel, Sut_Save, 1, 1, 0, 0);
            if (tabControl1.SelectedTab.Name == "tabPage1") //如果选择的是“职工基本信息”选项卡
            {
                hold_n = 0;  //恢复原始标识
                MyMC.Ena_Button(Sut_Add, Sut_Amend, Sut_Cancel, Sut_Save, 1, 1, 0, 0);  //
                groupBox5.Text = "";
                Ima_n = 0;//标识是否选择了职工照片
                Img_Clear.Enabled = false;  //使按钮为不可用状态
                Img_Save.Enabled = false;
                Sub_Table.Enabled = true;
            }
            //如果选择的是“工作简历”、“家庭关系”、“培训记录”和“奖惩记录”选项卡
            if (tabControl1.SelectedTab.Name == "tabPage2" | tabControl1.SelectedTab.Name == "tabPage3" | tabControl1.SelectedTab.Name == "tabPage4" | tab            Control1.SelectedTab.Name == "tabPage5")
            {
                groupBox5.Enabled = false;  //使窗体中的操作按钮为不可用状态
                Sub_Table.Enabled = false;
                if (tabControl1.SelectedTab.Name == "tabPage2") //“工作简历”选项卡
                {
                    groupBox6.Parent = (TabPage)tabPage2;
                    MyMC.MaskTextBox_Format(Word_2);  //指定MaskedTextBox控件的格式
                    MyMC.MaskTextBox_Format(Word_3);
                }
                if (tabControl1.SelectedTab.Name == "tabPage3") //“家庭关系”选项卡
                {
                    groupBox6.Parent = (TabPage)tabPage3;
                    MyMC.MaskTextBox_Format(Famity_4);

                }
                if (tabControl1.SelectedTab.Name == "tabPage4") //“培训记录”选项卡
                {
                    groupBox6.Parent = (TabPage)tabPage4;
                    MyMC.MaskTextBox_Format(TrainNote_3);
                    MyMC.MaskTextBox_Format(TrainNote_4);
                }
                if (tabControl1.SelectedTab.Name == "tabPage5") //“奖惩记录”选项卡
                {
                    groupBox6.Parent = (TabPage)tabPage5;
                    MyMC.MaskTextBox_Format(RANDP_3);
                    MyMC.MaskTextBox_Format(RANDP_5);
                    MyMC.CoPassData(RANDP_2, "tb_RPKind");  //向“奖惩类别”列表框中添加信息
                }
                MyMC.Ena_Button(Part_Add, Part_Amend, Part_Cancel, Part_Save, 1, 1, 0, 0);
            }
            if (tabControl1.SelectedTab.Name == "tabPage6") //“个人简历”选项卡
            {
                MyMC.Ena_Button(Sut_Add, Sut_Amend, Sut_Cancel, Sut_Delete, 0, 0, 0, 0);    //使窗体中的操作按钮为不可用
                Sut_Save.Enabled = true;    //将窗体中的“保存”按钮设为可用状态
            }
        }
     当点击职工简历这个选项卡时就会选择这个界面,其界面的最下面的按钮栏没有改变,故不在叙述其事件的实现过程。此界面的设计如下:

人事管理系统实现(八)


      简历信息GroupBox框中包含了职工的简单的信息,同时,下面的数据表显示得到的结果,其中,还有对记录的添加,修改,删除等操作。

      当填写完数据并点击添加后会在下面的数据框中显示,故设计其Cell_Enter事件:

        private void dataGridView2_CellEnter(object sender, DataGridViewCellEventArgs e)
        {
            MyMC.Show_DGrid(dataGridView2, groupBox7.Controls, "Word_");
        }
   注:show_DGrid方法见MyMoudle类中方法的实现。

当文本框添加完毕,点击添加时,会触发事件的响应程序如下:

        private void button2_Click(object sender, EventArgs e)
        {
            hold_n = 1;
            if (tabControl1.SelectedTab.Name == "tabPage2")
            {
                MyMC.Clear_Control(this.groupBox7.Controls);
                Part_ID = MyMC.GetAutoCoding("tb_WordResume", "ID");  //自动添加编号;(此方法见MyModule类)
            }
            if (tabControl1.SelectedTab.Name == "tabPage3")
            {
                MyMC.Clear_Control(this.groupBox10.Controls);
                Part_ID = MyMC.GetAutoCoding("tb_Family", "ID");  //自动添加编号;
            }
            if (tabControl1.SelectedTab.Name == "tabPage4")
            {
                MyMC.Clear_Control(this.groupBox12.Controls);
                Part_ID = MyMC.GetAutoCoding("tb_TrainNote", "ID");  //自动添加编号;
            }
            if (tabControl1.SelectedTab.Name == "tabPage5")
            {
                MyMC.Clear_Control(this.groupBox14.Controls);
                Part_ID = MyMC.GetAutoCoding("tb_RANDP", "ID");  //自动添加编号;
            }
            MyMC.Ena_Button(Part_Add, Part_Amend, Part_Cancel, Part_Save, 1, 0, 1, 1);(此方法见MyModule类)
        }
     当点击修改时,实现此事件的代码如下:

        private void Part_Amend_Click(object sender, EventArgs e)
        {
            hold_n = 2;
            MyMC.Ena_Button(Part_Add, Part_Amend, Part_Cancel, Part_Save, 0, 1, 1, 1);
        }
    当点击删除时,事件的响应代码如下:

        private void Part_Delete_Click(object sender, EventArgs e)
        {
            string Delete_Table = "";
            string Delete_ID = "";
            if (tabControl1.SelectedTab.Name == "tabPage2")
            {
                if (dataGridView2.RowCount < 2)
                {
                    MessageBox.Show("数据表为空,不可以删除。");
                    return;
                }
                MyMC.Clear_Control(this.groupBox7.Controls);
                Delete_ID = dataGridView2[1, dataGridView2.CurrentCell.RowIndex].Value.ToString();
                Delete_Table = "tb_WordResume";
            }
            if (tabControl1.SelectedTab.Name == "tabPage3")
            {
                if (dataGridView3.RowCount < 2)
                {
                    MessageBox.Show("数据表为空,不可以删除。");
                    return;
                }
                MyMC.Clear_Control(this.groupBox10.Controls);
                Delete_ID = dataGridView3[1, dataGridView3.CurrentCell.RowIndex].Value.ToString();
                Delete_Table = "tb_Family";
            }
            if (tabControl1.SelectedTab.Name == "tabPage4")
            {
                if (dataGridView4.RowCount < 2)
                {
                    MessageBox.Show("数据表为空,不可以删除。");
                    return;
                }
                MyMC.Clear_Control(this.groupBox12.Controls);
                Delete_ID = dataGridView4[1, dataGridView4.CurrentCell.RowIndex].Value.ToString();
                Delete_Table = "tb_TrainNote";
            }
            if (tabControl1.SelectedTab.Name == "tabPage5")
            {
                if (dataGridView5.RowCount < 2)
                {
                    MessageBox.Show("数据表为空,不可以删除。");
                    return;
                }
                MyMC.Clear_Control(this.groupBox14.Controls);
                Delete_ID = dataGridView5[1, dataGridView5.CurrentCell.RowIndex].Value.ToString();
                Delete_Table = "tb_RANDP";
            }
            if ((Delete_ID.Trim()).Length > 0)
            {
                MyDataClass.GetA_M_D_command("Delete " + Delete_Table + " where ID='" + Delete_ID + "'");
                Part_Cancel_Click(sender, e);
            }
        }
     
        当点击取消按钮时,其事件的响应代码如下:

        private void Part_Cancel_Click(object sender, EventArgs e)
        {
            if (tabControl1.SelectedTab.Name == "tabPage2")
            {
                DataSet WDset = MyDataClass.GetDataSet("select Sut_ID,ID,BeginDate as 开始时间,EndDate as 结束时间, Branch as 部门, Business as 职务, Word                Unit as 工作单位 from tb_WordResume where Sut_ID='" + tem_ID + "'", "tb_WordResume");
                MyMC.Correlation_Table(WDset, dataGridView2);
            }
            if (tabControl1.SelectedTab.Name == "tabPage3")
            {
                DataSet FDset = MyDataClass.GetDataSet("select Sut_ID,ID,LeaguerName as 家庭成员名称,Nexus as 与本人的关系, BirthDate as 出生日期, WordUni                t as 工作单位, Business as 职务, Visage as 政治面貌, Phone as 电话 from tb_Family where Sut_ID='" + tem_ID + "'", "tb_Family");
                MyMC.Correlation_Table(FDset, dataGridView3);
            }
            if (tabControl1.SelectedTab.Name == "tabPage4")
            {
                DataSet TDset = MyDataClass.GetDataSet("select Sut_ID,ID,TrainFashion as 培训方式,BeginDate as 培训开始时间, EndDate as 培训结束时间, Spec                iality as 培训专业, TrainUnit as 培训单位, KulturMemo as 培训内容, Charge as 费用, Effect as 效果 from tb_TrainNote where Sut_ID='" + tem_                ID + "'", "tb_TrainNote");
                MyMC.Correlation_Table(TDset, dataGridView4);
            }
            if (tabControl1.SelectedTab.Name == "tabPage5")
            {
                DataSet RDset = MyDataClass.GetDataSet("select Sut_ID,ID,RPKind as 奖惩种类,RPDate as 奖惩时间, SealMan as 批准人, QuashDate as 撤消时间,                 QuashWhys as 撤消原因 from tb_RANDP where Sut_ID='" + tem_ID + "'", "tb_RANDP");
                MyMC.Correlation_Table(RDset, dataGridView5);
            }
            hold_n = 0;  //恢复原始标识
            MyMC.Ena_Button(Part_Add, Part_Amend, Part_Cancel, Part_Save, 1, 1, 0, 0);
        }
     当点击保存时,实现的代码如下:

        private void Part_Save_Click(object sender, EventArgs e)
        {
            string s = "";
            if (tabControl1.SelectedTab.Name == "tabPage2")
            {
                s = "ID,Sut_ID,BeginDate,EndDate,Branch,Business,WordUnit";
                //"select Sut_ID,ID,BeginDate as 开始时间,EndDate as 结束时间, Branch as 部门, Business as 职务, WordUnit as 工作单位 from tb_WordResume
                ModuleClass.MyModule.ADDs = "";
                if (hold_n == 2)
                {
                    if (dataGridView2.RowCount < 2)
                    {
                        MessageBox.Show("数据表为空,不可以修改");
                    }
                    else
                        Part_ID = dataGridView2[1, dataGridView2.CurrentCell.RowIndex].Value.ToString();
                }
                MyMC.Part_SaveClass(s, tem_ID, Part_ID, this.groupBox7.Controls, "Word_", "tb_WordResume", 7, hold_n);
            }
            if (tabControl1.SelectedTab.Name == "tabPage3")
            {
                s = "ID,Sut_ID,LeaguerName,Nexus,BirthDate,WordUnit,Business,Visage,Phone";
                ModuleClass.MyModule.ADDs = "";
                if (hold_n == 2)
                {
                    if (dataGridView3.RowCount < 2)
                    {
                        MessageBox.Show("数据表为空,不可以修改");
                    }
                    else
                        Part_ID = dataGridView3[1, dataGridView3.CurrentCell.RowIndex].Value.ToString();
                }
                MyMC.Part_SaveClass(s, tem_ID, Part_ID, this.groupBox10.Controls, "Famity_", "tb_Family", 9, hold_n);
            }
            if (tabControl1.SelectedTab.Name == "tabPage4")
            {
                s = "ID,Sut_ID,TrainFashion,BeginDate,EndDate,Speciality,TrainUnit,KulturMemo,Charge,Effect";
                ModuleClass.MyModule.ADDs = "";
                if (hold_n == 2)
                {
                    if (dataGridView4.RowCount < 2)
                    {
                        MessageBox.Show("数据表为空,不可以修改");
                    }
                    else
                        Part_ID = dataGridView4[1, dataGridView4.CurrentCell.RowIndex].Value.ToString();
                }
                MyMC.Part_SaveClass(s, tem_ID, Part_ID, this.groupBox12.Controls, "TrainNote_", "tb_TrainNote", 10, hold_n);
            }
            if (tabControl1.SelectedTab.Name == "tabPage5")
            {
                s = "ID,Sut_ID,RPKind,RPDate,SealMan,QuashDate,QuashWhys";
                ModuleClass.MyModule.ADDs = "";
                if (hold_n == 2)
                {
                    if (dataGridView5.RowCount < 2)
                    {
                        MessageBox.Show("数据表为空,不可以修改");
                    }
                    else
                        Part_ID = dataGridView5[1, dataGridView5.CurrentCell.RowIndex].Value.ToString();
                }
                MyMC.Part_SaveClass(s, tem_ID, Part_ID, this.groupBox14.Controls, "RANDP_", "tb_RANDP", 7, hold_n);
            }
            if (ModuleClass.MyModule.ADDs != "")
                MyDataClass.GetA_M_D_command(ModuleClass.MyModule.ADDs);
            Part_Cancel_Click(sender, e);
        }

    补充上一节中的某些方法:

    首先对于时间输入的格式的问题,我们需要设计接收窗口的KeyPress事件来实现对窗口中实现输入指定的内容,从而拒绝非法输入,保证系统的安全性问题。

事件实现如下:

        private void S_Pact_B_Leave(object sender, EventArgs e)
        {
            MyMC.Estimate_Date((MaskedTextBox)sender);
        }

        private void S_Pact_B_KeyPress(object sender, KeyPressEventArgs e)
        {
            MyMC.Estimate_Key(e, "", 0);
        }

        private void S_Pact_E_KeyPress(object sender, KeyPressEventArgs e)
        {
            MyMC.Estimate_Key(e, "", 0);
        }

  其 中Estimate_Key方法和Estimate_Date方法已经在MyModule类中进行了实现,前者控制输入,后者控制日期的检查等,所以在这里不再去详细介绍此方法的实现过程。其分别控制毕业时间,以及输入格式的控制,以及输入内容的控制。


        private void S_GraduateDate_KeyPress(object sender, KeyPressEventArgs e)
        {
            MyMC.Estimate_Key(e, "", 0);
        }

        private void S_GraduateDate_Leave(object sender, EventArgs e)
        {
            MyMC.Estimate_Date((MaskedTextBox)sender);
        }

        private void S_Workdate_Leave(object sender, EventArgs e)
        {
            MyMC.Estimate_Date((MaskedTextBox)sender);
        }

        private void S_Workdate_KeyPress(object sender, KeyPressEventArgs e)
        {
            MyMC.Estimate_Key(e, "", 0);
        }

        private void S_M_Pay_KeyPress(object sender, KeyPressEventArgs e)
        {
            MyMC.Estimate_Key(e, ((TextBox)sender).Text, 1);
        }

        private void S_Pact_Y_KeyPress(object sender, KeyPressEventArgs e)
        {
            MyMC.Estimate_Key(e, "", 0);
        }

        private void S_Age_KeyPress(object sender, KeyPressEventArgs e)
        {
            MyMC.Estimate_Key(e, "", 0);
        }

        private void S_WorkLength_KeyPress(object sender, KeyPressEventArgs e)
        {
            MyMC.Estimate_Key(e, "", 0);
        }

    至此,职工简历部分的设计已经基本完成,接下来设计家庭关系这一选项卡。