protected void btnSave_Click(object sender, EventArgs e) { TRNDepartureCheckList objDepartureCheckList = new TRNDepartureCheckList(); int CurrentEmploymentId = 0; int employmentId = 0; int updateEmp = 0; int updateCurrentEmployment = 0; #region Current Abroad Information TRNCurrentEmployment objCurrentEmployment = new TRNCurrentEmployment(); objCurrentEmployment.TraineeID = TraineeID; DataView dvCurrentEmployment = TRNCurrentEmploymentBO.GetCurrentEmploymentIdByTraineeID(TraineeID); if (rbCurrentCountryYes.Checked) { objCurrentEmployment.CountryID = Convert.ToInt32(ddlWhichCountry.SelectedValue); objCurrentEmployment.WorkingYear = txtWorkingYears.Text; objCurrentEmployment.WorkingMonth = txtWorkingMonths.Text; objCurrentEmployment.Occupation = txtOccupation.Text; objCurrentEmployment.MonthlySalary = txtPreviousMonthlySalary.Text; objCurrentEmployment.ReturnDate = txtPreviousReturnDate.Text; } else { objCurrentEmployment.CountryID = 0; objCurrentEmployment.WorkingYear = ""; objCurrentEmployment.WorkingMonth = ""; objCurrentEmployment.Occupation = ""; objCurrentEmployment.MonthlySalary = ""; objCurrentEmployment.ReturnDate = ""; } objCurrentEmployment.Status = 1; if (rbCurrentCountryYes.Checked) { if (dvCurrentEmployment.Count == 0) { objCurrentEmployment.CreatedBy = UserAuthentication.GetUserId(this.Page); CurrentEmploymentId = new TRNTraineeBO().InsertCurrentEmployment(objCurrentEmployment); } else { objCurrentEmployment.ModifiedBy = UserAuthentication.GetUserId(this.Page); CurrentEmploymentId = Convert.ToInt32(dvCurrentEmployment.Table.Rows[0]["ID"]); objCurrentEmployment.EmploymentID = CurrentEmploymentId; objCurrentEmployment.ModifiedBy = UserAuthentication.GetUserId(this.Page); new TRNTraineeBO().UpdateCurrentEmployment(objCurrentEmployment); } } else { if (dvCurrentEmployment.Count > 0) { CurrentEmploymentId = Convert.ToInt32(dvCurrentEmployment.Table.Rows[0]["ID"]); objCurrentEmployment.EmploymentID = CurrentEmploymentId; //objEmployment.Status = 0; updateCurrentEmployment = TRNCurrentEmploymentBO.Delete(CurrentEmploymentId); DisableCurrentAbroadInfo(); } else { } } #endregion #region Past Abroad Information TRNEmployment objEmployment = new TRNEmployment(); objEmployment.TraineeID = TraineeID; DataView dvEmployment = TRNEmploymentBO.GetEmploymentIdByTraineeID(TraineeID); if (rdoAbroadYes.Checked) { if (!String.IsNullOrEmpty(ddlCountry.SelectedValue.ToString())) objEmployment.CountryID = Convert.ToInt32(ddlCountry.SelectedValue); objEmployment.Organization = txtCompany.Text; objEmployment.RecruitmentAgency = txtPastRecruitmentAgency.Text; //if (!String.IsNullOrEmpty(ddlOrganization.SelectedValue.ToString())) // objEmployment.OrganizationID = Convert.ToInt32(ddlOrganization.SelectedValue); if (!String.IsNullOrEmpty(ddlEmploymentType.SelectedValue.ToString())) objEmployment.EmploymentTypeID = Convert.ToInt32(ddlEmploymentType.SelectedValue); if (!String.IsNullOrEmpty(ddlEmploymentStatus.SelectedValue.ToString())) objEmployment.EmploymentStatusID = Convert.ToInt32(ddlEmploymentStatus.SelectedValue); //if (!String.IsNullOrEmpty(ddlRecruitmentAgency.SelectedValue.ToString())) // objEmployment.RecruitmentAgencyID = Convert.ToInt32(ddlRecruitmentAgency.SelectedValue); //objEmployment.WorkDoneMonth = txtJobDoneMonth.Text; //objEmployment.WorkDoneYear = txtJobDoneYear.Text; objEmployment.EmploymentPeriod = txtEmploymentPeriod.Text; if (!String.IsNullOrEmpty(txtMonthlySalary.Text)) objEmployment.Salary = txtMonthlySalary.Text.ToString(); if (!String.IsNullOrEmpty(txtForeignCurrency.Text)) objEmployment.Currency = txtForeignCurrency.Text; if (!String.IsNullOrEmpty(txtDepartureDate.Text)) objEmployment.DepartureDate = Convert.ToDateTime(txtDepartureDate.Text); if (!String.IsNullOrEmpty(txtReturnDate.Text)) objEmployment.ReturnDate = Convert.ToDateTime(txtReturnDate.Text); } else { objEmployment.CountryID = 0; objEmployment.Organization = ""; objEmployment.EmploymentTypeID = 0; objEmployment.EmploymentStatusID = 0; objEmployment.RecruitmentAgency = ""; objEmployment.WorkDoneMonth = ""; objEmployment.WorkDoneYear = ""; objEmployment.Salary = ""; objEmployment.Currency = ""; objEmployment.DepartureDate = null; objEmployment.ReturnDate = null; } objEmployment.Status = 1; if (rdoAbroadYes.Checked) { if (dvEmployment.Count == 0) { objEmployment.CreatedBy = UserAuthentication.GetUserId(this.Page); employmentId = new TRNTraineeBO().InsertEmployment(objEmployment); } else { objEmployment.ModifiedBy = UserAuthentication.GetUserId(this.Page); employmentId = Convert.ToInt32(dvEmployment.Table.Rows[0]["ID"]); objEmployment.EmploymentID = employmentId; new TRNTraineeBO().UpdateEmployment(objEmployment); } } else { if (dvEmployment.Count > 0) { employmentId = Convert.ToInt32(dvEmployment.Table.Rows[0]["ID"]); List<int> count = TRNDepartureChecklistBO.GetDepartureCheckListByEmploymentID(employmentId); for (int b = 0; b < count.Count; b++) { DataView dvDepartureCheckList = TRNEmploymentBO.GetDepartureIDByEmploymentID(employmentId); objDepartureCheckList.DepartureChecklistID = Convert.ToInt32(dvDepartureCheckList.Table.Rows[0]["ID"]); TRNDepartureChecklistBO.Delete(Convert.ToInt32(dvDepartureCheckList.Table.Rows[0]["ID"])); } objEmployment.EmploymentID = employmentId; //objEmployment.Status = 0; updateEmp = TRNEmploymentBO.Delete(employmentId); DisableAbroadInfo(); } else { } } #endregion #region DepartureCheckList List<TRNDepartureCheckList> lstDeparture = new List<TRNDepartureCheckList>(); List<int> checkList = new List<int>(); string departureList = hfTraineeCheckList.Value; string[] list = departureList.Split(','); foreach (string item in list) { if (item != string.Empty) { checkList.Add(Convert.ToInt32(item)); } } //int EmploymentID = 0; //DataView dv = TRNEmploymentBO.GetEmploymentIdByTraineeID(TraineeID); //int EmploymentID = Convert.ToInt32(dv.Table.Rows[0]["ID"]); if (employmentId > 0) { String a = hfTraineeCheckList.Value; List<int> lstCheckList = TRNDepartureChecklistBO.GetDepartureCheckListByEmploymentID(employmentId); //if (lstCheckList.Count > 0) //{ for (int j = 0; j < ddlTraineeCheckList.Items.Count; j++) { if (lstCheckList.Exists(delegate(int region) { return region == Convert.ToInt32(ddlTraineeCheckList.Items[j].Value); })) { if (checkList.Exists(delegate(int region) { return region == Convert.ToInt32(ddlTraineeCheckList.Items[j].Value); })) { } else { new TRNDepartureChecklistBO().DeleteDepartureList(employmentId, Convert.ToInt32(ddlTraineeCheckList.Items[j].Value)); } } else { if (checkList.Exists(delegate(int region) { return region == Convert.ToInt32(ddlTraineeCheckList.Items[j].Value); })) { objDepartureCheckList.EmploymentID = employmentId; objDepartureCheckList.CheckListID = Convert.ToInt32(ddlTraineeCheckList.Items[j].Value); objDepartureCheckList.Availability = 1; objDepartureCheckList.DepartureChecklistID = new TRNTraineeBO().InsertDepartureList(objDepartureCheckList); } else { } } //list.Add(j); } //} } //if (updateEmp > 0) //{ // employmentId = Convert.ToInt32(dvEmployment.Table.Rows[0]["ID"]); // DataView dvDepartureCheckList = TRNEmploymentBO.GetDepartureIDByEmploymentID(employmentId); // objDepartureCheckList.DepartureChecklistID = Convert.ToInt32(dvDepartureCheckList.Table.Rows[0]["ID"]); // int a = TRNDepartureChecklistBO.Delete(Convert.ToInt32(dvDepartureCheckList.Table.Rows[0]["ID"])); // //new TRNDepartureChecklistBO().DeleteDepartureList(employmentId, Convert.ToInt32(ddlTraineeCheckList.Items[j].Value)); //} #endregion #region PreviousTraining int previousTrainingId = 0; TRNPreviousTraining objPreviousTraining = new TRNPreviousTraining(); DataView dvPreviousTraining = TRNPreviousTrainingBO.GetPreviousTrainingIDByTraineeID(TraineeID); objPreviousTraining.TraineeID = Convert.ToInt32(Request.QueryString.Get("ID")); if (rbHavePreviousTrainingYes.Checked) { objPreviousTraining.Name = txtTrainingName.Text; objPreviousTraining.Year = txtTrainingYear.Text; objPreviousTraining.Institute = txtTrainingInstituteName.Text; objPreviousTraining.Duration = txtTrainingDuration.Text; } else { objPreviousTraining.Name = ""; objPreviousTraining.Year = ""; objPreviousTraining.Institute = ""; objPreviousTraining.Duration = ""; } if (rbHavePreviousTrainingYes.Checked) { if (dvPreviousTraining.Count == 0) { previousTrainingId = new TRNTraineeBO().InsertPreviousTraining(objPreviousTraining); } else { objPreviousTraining.PreviousTrainingID = Convert.ToInt32(dvPreviousTraining.Table.Rows[0]["ID"]); previousTrainingId = new TRNTraineeBO().UpdatePreviousTraining(objPreviousTraining); } } else { if (dvPreviousTraining.Count > 0) { objPreviousTraining.PreviousTrainingID = Convert.ToInt32(dvPreviousTraining.Table.Rows[0]["ID"]); previousTrainingId = new TRNTraineeBO().UpdatePreviousTraining(objPreviousTraining); } else { } } #endregion int result = new TRNTraineeBO().UpdateTrainee(MapTrainee()); if (employmentId > 0 || objDepartureCheckList.DepartureChecklistID > 0 || previousTrainingId > 0) { Response.Redirect("Default.aspx"); } else { Response.Redirect("Default.aspx"); } //Update TRNTrainee, TRNEmployment, TRNPreviousTraining, TRNDepartureCheckList //if (dvPreviousTraining.Count > 0 && dvEmployment.Count > 0) //{ // int result = new TRNTraineeBO().UpdateTrainee(MapTrainee(), objEmployment, objPreviousTraining); //} //if (result > 0) //{ // Response.Redirect("Default.aspx"); //} //else //{ //} }
TRNPreviousTraining MapPreviousTraining() { TRNPreviousTraining objPreviousTraining = new TRNPreviousTraining(); if (rbHavePreviousTrainingYes.Checked) { objPreviousTraining.Name = txtTrainingName.Text; objPreviousTraining.Year = txtTrainingYear.Text; objPreviousTraining.Institute = txtTrainingInstituteName.Text; objPreviousTraining.Duration = txtTrainingDuration.Text; } else { objPreviousTraining.Name = ""; objPreviousTraining.Year = ""; objPreviousTraining.Institute = ""; objPreviousTraining.Duration = ""; } return objPreviousTraining; }