private void button_OnOK_Click(object sender, EventArgs e) { this.CheckData_DataTable(); if (this.myDataTable.Select("Len(ErrMessage)>0").Length > 0) { this.DialogResult = DialogResult.None; this.label_ErrMessage.Text = "有数据不合法,请查看 ErrMessage 字段返回信息! "; return; } else { if (MessageBox.Show("确认导入吗?", "确认窗口", MessageBoxButtons.OKCancel) != DialogResult.OK) { this.DialogResult = DialogResult.None; return; } } //删除数据库中该单位下多余的焊工名单(不在Excel文件中的焊工) if (this.checkBox_DeleteWelderBelongAll.Checked) { //Class_WelderBelong.DeleteBatch(this.str_EmployerHPID, this.str_DepartmentHPID, this.str_WorkPlaceHPID); DataTable myDataTable_Temp = Class_WelderBelong.GetWelderBelong("", this.str_EmployerHPID, this.str_DepartmentHPID, this.str_WorkPlaceHPID); foreach (DataRow myDataRow_Temp in myDataTable_Temp.Rows) { if (this.myDataTable.Rows.Find(myDataRow_Temp["IdentificationCard"].ToString()) == null) { Class_WelderBelong.ExistAndCanDeleteAndDelete((long)myDataRow_Temp["WelderBelongID"], Enum_zwjKindofUpdate.Delete); } } } Class_Welder myClass_Welder; Class_WelderBelong myClass_WelderBelong; bool bool_WelderFilled; //string str_ErrMessage; foreach (DataRow myDataRow in this.myDataTable.Rows) { //myDataRow["ErrMessage"] = ""; //str_ErrMessage = ""; myClass_Welder = new Class_Welder(); myClass_Welder.IdentificationCard = myDataRow["IdentificationCard"].ToString().Trim(); bool_WelderFilled = myClass_Welder.FillData(); myClass_Welder.WelderName = myDataRow["WelderName"].ToString().Trim(); myClass_Welder.Schooling = myDataRow["Schooling"].ToString().Trim(); myClass_Welder.Sex = myDataRow["Sex"].ToString().Trim(); DateTime.TryParse(myDataRow["WeldingBeginning"].ToString().Trim(), out myClass_Welder.WeldingBeginning); myClass_Welder.myClass_BelongUnit.WorkerID = myDataRow["WelderBelongWorkerID"].ToString().Trim(); myClass_Welder.myClass_BelongUnit.EmployerHPID = myDataRow["WelderBelongEmployerHPID"].ToString(); myClass_Welder.myClass_BelongUnit.DepartmentHPID = myDataRow["WelderBelongDepartmentHPID"].ToString(); myClass_Welder.myClass_BelongUnit.WorkPlaceHPID = myDataRow["WelderBelongWorkPlaceHPID"].ToString(); myClass_Welder.myClass_BelongUnit.LaborServiceTeamHPID = myDataRow["WelderBelongLaborServiceTeamHPID"].ToString(); if (bool_WelderFilled) { myClass_Welder.AddAndModify(Enum_zwjKindofUpdate.Modify); } else { myClass_Welder.AddAndModify(Enum_zwjKindofUpdate.Add); } //如果该单位下已存在该焊工,则修改相应信息 DataTable myDataTable_Temp = Class_WelderBelong.GetWelderBelong(myClass_Welder.IdentificationCard, this.str_EmployerHPID, this.str_DepartmentHPID, this.str_WorkPlaceHPID); myClass_WelderBelong = new Class_WelderBelong(); if (myDataTable_Temp.Rows.Count > 0) { foreach (DataRow myDataRow_Temp in myDataTable_Temp.Rows) { myClass_WelderBelong.WelderBelongID = (long)myDataRow_Temp["WelderBelongID"]; myClass_WelderBelong.IdentificationCard = myClass_Welder.IdentificationCard; myClass_WelderBelong.myClass_BelongUnit = myClass_Welder.myClass_BelongUnit; myClass_WelderBelong.AddAndModify(Enum_zwjKindofUpdate.Modify); } } else { myClass_WelderBelong.IdentificationCard = myClass_Welder.IdentificationCard; myClass_WelderBelong.myClass_BelongUnit = myClass_Welder.myClass_BelongUnit; myClass_WelderBelong.AddAndModify(Enum_zwjKindofUpdate.Add); } } }
/// <summary> /// 初始化数据 /// </summary> /// <param name="myClass_WelderBelong"></param> /// <param name="bool_Add"></param> public void InitControl(Class_WelderBelong myClass_WelderBelong, bool bool_Add) { Class_Data myClass_Data = (Class_Data)Class_Public.myHashtable[Enum_DataTable.LaborServiceTeam.ToString()]; this.myDataView_LaborServiceTeam = new DataView(myClass_Data.myDataTable); this.myDataView_LaborServiceTeam.Sort = myClass_Data.myDataView.Sort; Class_DataControlBind.InitializeComboBox(this.ComboBox_LaborServiceTeam, this.myDataView_LaborServiceTeam, "LaborServiceTeamHPID", "LaborServiceTeam"); this.CheckBox_Sex.Enabled = false; this.DateTimePicker_WeldingBeinning.Enabled = false; this.myClass_WelderBelong = myClass_WelderBelong; if (string.IsNullOrEmpty(myClass_WelderBelong.myClass_BelongUnit.WorkPlaceHPID)) { if (string.IsNullOrEmpty(myClass_WelderBelong.myClass_BelongUnit.DepartmentHPID)) { Class_Employer myClass_Employer = new Class_Employer(myClass_WelderBelong.myClass_BelongUnit.EmployerHPID); this.TextBox_Employer.Text = myClass_Employer.Employer; } else { Class_Department myClass_Department = new Class_Department(myClass_WelderBelong.myClass_BelongUnit.DepartmentHPID); this.TextBox_Department.Text = myClass_Department.Department; Class_Employer myClass_Employer = new Class_Employer(myClass_Department.EmployerHPID); this.TextBox_Employer.Text = myClass_Employer.Employer; this.myClass_WelderBelong.myClass_BelongUnit.EmployerHPID = myClass_Employer.EmployerHPID; } } else { Class_WorkPlace myClass_WorkPlace = new Class_WorkPlace(myClass_WelderBelong.myClass_BelongUnit.WorkPlaceHPID); this.TextBox_WorkPlace.Text = myClass_WorkPlace.WorkPlace; Class_Department myClass_Department = new Class_Department(myClass_WorkPlace.DepartmentHPID); this.TextBox_Department.Text = myClass_Department.Department; Class_Employer myClass_Employer = new Class_Employer(myClass_Department.EmployerHPID); this.TextBox_Employer.Text = myClass_Employer.Employer; this.myClass_WelderBelong.myClass_BelongUnit.DepartmentHPID = myClass_Department.DepartmentHPID; this.myClass_WelderBelong.myClass_BelongUnit.EmployerHPID = myClass_Employer.EmployerHPID; } this.myDataView_LaborServiceTeam.RowFilter = string.Format("EmployerHPID='{0}'", this.myClass_WelderBelong.myClass_BelongUnit.EmployerHPID); if (bool_Add) { if (myClass_WelderBelongDefault != null) { } } else { myDataView_LaborServiceTeam.RowFilter = string.Format("EmployerHPID='{0}'", this.myClass_WelderBelong.myClass_BelongUnit.EmployerHPID); this.textBox_WelderBelongID.Text = this.myClass_WelderBelong.WelderBelongID.ToString(); this.textBox_WelderBelongRemark.Text = myClass_WelderBelong.WelderBelongRemark; this.InitControlWelder(new Class_Welder(this.myClass_WelderBelong.IdentificationCard)); if (string.IsNullOrEmpty(myClass_WelderBelong.myClass_BelongUnit.LaborServiceTeamHPID)) { this.CheckBox_LaborServiceTeam.Checked = false; } else { this.CheckBox_LaborServiceTeam.Checked = true; this.ComboBox_LaborServiceTeam.SelectedValue = myClass_WelderBelong.myClass_BelongUnit.LaborServiceTeamHPID; } this.TextBox_WorkerID.Text = myClass_WelderBelong.myClass_BelongUnit.WorkerID; } }