/// <summary> /// Description: Method to add/update PI settings including worklist settings /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnsave_Click(object sender, EventArgs e) { try { bool Activate_Scheduler = false; int WorklistPIId = 0; string interval = ddlInterval.SelectedItem.Value; string UOM = ddlUOM.SelectedValue; int result = 0; int Company_Id = Convert.ToInt32(Session["USERCOMPANYID"]); string Minor_Ids = ""; if (ddlListSource.SelectedValue != "0") { DataSource = ddlListSource.SelectedValue; } int PI_status = Convert.ToInt32(ddlStatus.SelectedValue); if (chkIsWorklist.Checked) { Activate_Scheduler = chkActivate_Scheduler.Checked; Job_Type = string.Join(",", lstJOB.Items.Cast <ListItem>() .Where(li => li.Selected).Select(x => x.Value).ToArray()); Assignor_Ids = string.Join(",", ddlAssignor.Items.Cast <ListItem>() .Where(li => li.Selected).Select(x => x.Value).ToArray()); Nature_Ids = string.Join(",", ddlNature.Items.Cast <ListItem>() .Where(li => li.Selected).Select(x => x.Value).ToArray()); Primary_IDs = string.Join(",", ddlPrimary.Items.Cast <ListItem>() .Where(li => li.Selected).Select(x => x.Value).ToArray()); Secondary_IDs = string.Join(",", ddlSecondary.Items.Cast <ListItem>() .Where(li => li.Selected).Select(x => x.Value).ToArray()); Minor_Ids = string.Join(",", ddlMinor.Items.Cast <ListItem>() .Where(li => li.Selected).Select(x => x.Value).ToArray()); } if (chkInspection.Checked) { Activate_Scheduler = chkActivateInspectionScheduler.Checked; InspectionType_IDs = string.Join(",", ddlInspectionType.Items.Cast <ListItem>() .Where(li => li.Selected).Select(x => x.Value).ToArray()); } if (chkVetting.Checked) { Activate_Scheduler = chkActivateVettingScheduler.Checked; VettingType_IDs = string.Join(",", ddlVettingType.Items.Cast <ListItem>() .Where(li => li.Selected).Select(x => x.Value).ToArray()); } if (chkObservation.Checked) { Activate_Scheduler = chkActivateObservationScheduler.Checked; VettingType_IDs = string.Join(",", lstObservationVettingType.Items.Cast <ListItem>() .Where(li => li.Selected).Select(x => x.Value).ToArray()); Observation_Category = string.Join(",", lstObservationCategory.Items.Cast <ListItem>() .Where(li => li.Selected).Select(x => x.Value).ToArray()); Observation_Type = string.Join(",", lstObservationType.Items.Cast <ListItem>() .Where(li => li.Selected).Select(x => x.Value).ToArray()); Observation_Risk_Level = string.Join(",", lstRiskLevel.Items.Cast <ListItem>() .Where(li => li.Selected).Select(x => x.Value).ToArray()); } WorklistPIId = UDFLib.ConvertToInteger(ViewState["Worklist_PIID"]); if (Request.QueryString[0] != null) { PI_Id = Convert.ToInt32(Request.QueryString[0]); if (chkMeasuredForSBU.Checked) { MeasuredForSBU = 1; } if (chkBallastLaden.Checked) { IncludeBL = 1; } if (chkIsWorklist.Checked) { IsWorkList = 1; } if (chkInspection.Checked) { IsInspection = 1; } if (chkVetting.Checked) { IsVetting = 1; } if (chkObservation.Checked) { IsVetting = 2; } //To insert new PI if (Convert.ToInt32(Request.QueryString[0]) == 0) { result = BLL_TMSA_PI.INS_PI_Details(txtName.Text, txtPICode.Text, interval, txtDescription.Text, null, txtContext.Text, UOM, DataSource, MeasuredForSBU, IncludeBL, PI_status, IsWorkList, IsInspection, IsVetting, GetSessionUserID()); PI_Id = result; } //To update PI setting else { result = BLL_TMSA_PI.Update_PI(PI_Id, txtName.Text, txtPICode.Text, interval, txtDescription.Text, null, txtContext.Text, UOM, DataSource, MeasuredForSBU, IncludeBL, PI_status, IsWorkList, IsInspection, IsVetting, GetSessionUserID()); } //To insert worklist PI setting if (chkIsWorklist.Checked) { DateTime?dtEffective = UDFLib.ConvertDateToNull(txtEffectivedate.Text); if (WorklistPIId != null && WorklistPIId != 0) { result = BLL_TMSA_PI.Update_Worklist_PI(WorklistPIId, PI_Id, Company_Id, Job_Type, Assignor_Ids, Nature_Ids, Primary_IDs, Secondary_IDs, Minor_Ids, Activate_Scheduler, dtEffective, GetSessionUserID()); } else { result = BLL_TMSA_PI.INS_Worklist_PI_Details(PI_Id, Company_Id, Job_Type, Assignor_Ids, Nature_Ids, Primary_IDs, Secondary_IDs, Minor_Ids, Activate_Scheduler, dtEffective, GetSessionUserID()); } } else if (chkInspection.Checked)//For inspection type { Assignor_Ids = ""; DateTime?dtEffective = UDFLib.ConvertDateToNull(txtMigrateFormInspection.Text); if (WorklistPIId != null && WorklistPIId != 0) { result = BLL_TMSA_PI.Update_Inspection_PI(WorklistPIId, PI_Id, Company_Id, InspectionType_IDs, Assignor_Ids, Activate_Scheduler, dtEffective, GetSessionUserID()); } else { result = BLL_TMSA_PI.INS_Inspection_PI_Details(PI_Id, Company_Id, InspectionType_IDs, Assignor_Ids, Activate_Scheduler, dtEffective, GetSessionUserID()); } } else if (chkVetting.Checked)//For vetting type { Assignor_Ids = ""; DateTime?dtEffective = UDFLib.ConvertDateToNull(txtMigrateFormVetting.Text); if (WorklistPIId != null && WorklistPIId != 0) { result = BLL_TMSA_PI.Update_Vetting_PI(WorklistPIId, PI_Id, Company_Id, VettingType_IDs, Observation_Type, Observation_Category, Observation_Risk_Level, Assignor_Ids, Activate_Scheduler, dtEffective, GetSessionUserID()); } else { result = BLL_TMSA_PI.INS_Vetting_PI_Details(PI_Id, Company_Id, VettingType_IDs, Observation_Type, Observation_Category, Observation_Risk_Level, Assignor_Ids, Activate_Scheduler, dtEffective, GetSessionUserID()); } } else if (chkObservation.Checked)//For observation setting { Assignor_Ids = ""; DateTime?dtEffective = UDFLib.ConvertDateToNull(txtMigrateFormObservation.Text); if (WorklistPIId != null && WorklistPIId != 0) { result = BLL_TMSA_PI.Update_Vetting_PI(WorklistPIId, PI_Id, Company_Id, VettingType_IDs, Observation_Type, Observation_Category, Observation_Risk_Level, Assignor_Ids, Activate_Scheduler, dtEffective, GetSessionUserID()); } else { result = BLL_TMSA_PI.INS_Vetting_PI_Details(PI_Id, Company_Id, VettingType_IDs, Observation_Type, Observation_Category, Observation_Risk_Level, Assignor_Ids, Activate_Scheduler, dtEffective, GetSessionUserID()); } } } } catch (Exception ex) { UDFLib.WriteExceptionLog(ex); } string msgDraft = String.Format("parent.ReloadParent_ByButtonID();"); ScriptManager.RegisterStartupScript(Page, Page.GetType(), "msgDraft", msgDraft, true); }