protected void btnMetricSave_Click(object sender, EventArgs e) { bool success; bool measureChanged = false; bool reqdError = false; EHS_PROFILE_MEASURE pm = null; if (hfOper.Value == "add") { pm = new EHS_PROFILE_MEASURE(); pm.EHS_PROFILE_MEASURE_EXT = new EHS_PROFILE_MEASURE_EXT(); } else { pm = LocalProfile().Profile.EHS_PROFILE_MEASURE.FirstOrDefault(l => l.PRMR_ID == LocalProfile().CurrentProfileMeasure.PRMR_ID); if (pm.EHS_PROFILE_MEASURE_EXT == null) { pm.EHS_PROFILE_MEASURE_EXT = new EHS_PROFILE_MEASURE_EXT(); pm.EHS_PROFILE_MEASURE_EXT.PRMR_ID = pm.PRMR_ID; } } pm.PLANT_ID = LocalProfile().Profile.PLANT_ID; decimal measureID = 0; if (!string.IsNullOrEmpty(ddlMetricID.SelectedValue)) { measureID = Convert.ToDecimal(WebSiteCommon.ParseItemValue(ddlMetricID.SelectedValue)); if (pm.MEASURE_ID != measureID) { measureChanged = true; } } pm.MEASURE_ID = measureID; pm.MEASURE_PROMPT = tbMetricPrompt.Text; pm.REG_STATUS = ddlMetricRegStatus.SelectedValue; pm.UN_CODE = ddlMetricDisposalCode.SelectedValue; pm.WASTE_CODE = tbWasteCode.Text; pm.DEFAULT_CURRENCY_CODE = ddlMetricCurrency.SelectedValue; if (ddlMetricResponsible.SelectedIndex > 0) { decimal personID = Convert.ToDecimal(ddlMetricResponsible.SelectedValue); if (personID != pm.RESPONSIBLE_ID) { pm = LocalProfile().UpdateMeasureResponsible(pm, personID); } pm.RESPONSIBLE_ID = personID; } else { pm.RESPONSIBLE_ID = Convert.ToDecimal(null); } if (ddlMetricCost.SelectedValue == "CREDIT") { pm.NEG_VALUE_ALLOWED = true; } else { pm.NEG_VALUE_ALLOWED = false; } pm.STATUS = ddlMetricStatus.SelectedValue; pm.IS_REQUIRED = cbMetricRequired.Checked; decimal uomID = 0; if (ddlMetricCategory.SelectedValue == "FACT") { pm.DEFAULT_UOM = EHSModel.LookupEHSMeasure(new PSsqmEntities(), pm.MEASURE_ID, "").STD_UOM; } else { if (SQMBasePage.ParseToDecimal(WebSiteCommon.ParseItemValue(ddlMetricUOM.SelectedValue), out uomID)) { pm.DEFAULT_UOM = uomID; } decimal UOMFactor = 0; if (decimal.TryParse(tbUOMFactor.Text, out UOMFactor)) { pm.UOM_FACTOR = UOMFactor; } else { pm.UOM_FACTOR = null; } } if (phMetricExt.Visible) { decimal decimalValue; if (SQMBasePage.ParseToDecimal(tbValueDflt.Text, out decimalValue)) { pm.EHS_PROFILE_MEASURE_EXT.VALUE_DEFAULT = decimalValue; } else { pm.EHS_PROFILE_MEASURE_EXT.VALUE_DEFAULT = null; } if (SQMBasePage.ParseToDecimal(tbCostDflt.Text, out decimalValue)) { pm.EHS_PROFILE_MEASURE_EXT.COST_DEFAULT = decimalValue; } else { pm.EHS_PROFILE_MEASURE_EXT.COST_DEFAULT = null; } if ((pm.EHS_PROFILE_MEASURE_EXT.VALUE_DEFAULT.HasValue || pm.EHS_PROFILE_MEASURE_EXT.COST_DEFAULT.HasValue)) { pm.EHS_PROFILE_MEASURE_EXT.OVERRIDE_ALLOWED = cbEnableOverride.Checked; } else { pm.EHS_PROFILE_MEASURE_EXT.OVERRIDE_ALLOWED = false; } /* * if ((pm.EHS_PROFILE_MEASURE_EXT.VALUE_DEFAULT.HasValue || pm.EHS_PROFILE_MEASURE_EXT.COST_DEFAULT.HasValue) && radEffEndDate.SelectedDate != null) * pm.EHS_PROFILE_MEASURE_EXT.EFF_END_DT = (DateTime)radEffEndDate.SelectedDate; * else * pm.EHS_PROFILE_MEASURE_EXT.EFF_END_DT = null; */ } // validate switch (ddlMetricCategory.SelectedValue) { case "ENGY": case "EUTL": if (string.IsNullOrEmpty(ddlMetricCategory.SelectedValue) || string.IsNullOrEmpty(ddlMetricID.SelectedValue) || string.IsNullOrEmpty(ddlMetricUOM.SelectedValue) || string.IsNullOrEmpty(ddlMetricResponsible.SelectedValue)) { reqdError = true; } break; case "PROD": case "FACT": if (string.IsNullOrEmpty(ddlMetricCategory.SelectedValue) || string.IsNullOrEmpty(ddlMetricID.SelectedValue) || string.IsNullOrEmpty(ddlMetricResponsible.SelectedValue)) { reqdError = true; } break; case "SAFE": if (string.IsNullOrEmpty(ddlMetricCategory.SelectedValue) || string.IsNullOrEmpty(ddlMetricID.SelectedValue) || string.IsNullOrEmpty(ddlMetricResponsible.SelectedValue)) { reqdError = true; } break; default: if (string.IsNullOrEmpty(ddlMetricCategory.SelectedValue) || string.IsNullOrEmpty(ddlMetricID.SelectedValue) || string.IsNullOrEmpty(ddlMetricUOM.SelectedValue) || string.IsNullOrEmpty(ddlMetricResponsible.SelectedValue) || string.IsNullOrEmpty(ddlMetricDisposalCode.SelectedValue) || string.IsNullOrEmpty(ddlMetricRegStatus.SelectedValue)) { reqdError = true; } if (tbUOMFactor.Visible && string.IsNullOrEmpty(tbUOMFactor.Text)) { reqdError = true; } break; } if (reqdError) { BindProfileMeasure(pm); DisplayErrorMessage(hfErrRequiredInputs); return; } if (hfOper.Value == "add") // add measure to list { pm = LocalProfile().AddMeasure(pm, Convert.ToDecimal(WebSiteCommon.ParseItemValue(ddlMetricID.SelectedValue))); } EHSProfile.UpdateProfile(LocalProfile()); if (pm.STATUS == "D") { EHSProfile.DeleteProfileMeasure(LocalProfile(), pm.MEASURE_ID, true, true); measureChanged = true; } if (measureChanged) { SetLocalProfile(new EHSProfile().Load(LocalProfile().Plant.PLANT_ID, true, false)); } btnMetricClear_Click(null, null); BindProfile(LocalProfile()); }
protected void btnMeasureSave_Click(object sender, EventArgs e) { bool success; EHS_MEASURE subCategory = null; if (hfOper.Value == "add") { staticMeasure = new EHS_MEASURE(); staticMeasure.COMPANY_ID = SessionManager.UserContext.HRLocation.Company.COMPANY_ID; staticMeasure.MEASURE_CATEGORY = ddlMeasureCategory.SelectedValue; } else { staticMeasure = EHSModel.LookupEHSMeasure(entities, staticMeasure.MEASURE_ID, ""); } staticMeasure.MEASURE_SUBCATEGORY = ddlMeasureSubcategory.SelectedValue; staticMeasure.STATUS = ddlMeasureStatus.SelectedValue; staticMeasure.MEASURE_CD = tbMeasureCode.Text; staticMeasure.MEASURE_NAME = tbMeasureName.Text; staticMeasure.MEASURE_DESC = tbMeasureDesc.Text; // validate if (hfOper.Value == "add" && measureList.FirstOrDefault(l => l.MEASURE_CD == tbMeasureCode.Text) != null) { BindMeasure(staticMeasure); DisplayErrorMessage(hfDuplicateMeasure); return; } if (string.IsNullOrEmpty(staticMeasure.MEASURE_CD) || string.IsNullOrEmpty(staticMeasure.MEASURE_NAME)) { BindMeasure(staticMeasure); DisplayErrorMessage(hfErrRequiredInputs); return; } btnMeasureSave.Enabled = false; staticMeasure.PLANT_ACCT_FIELD = ""; if (staticMeasure.MEASURE_CATEGORY == "PROD") { staticMeasure.PLANT_ACCT_FIELD = ddlProdTableField.SelectedValue; } else if (staticMeasure.MEASURE_CATEGORY == "SAFE") { staticMeasure.PLANT_ACCT_FIELD = ddlSafeTableField.SelectedValue; } else if (staticMeasure.MEASURE_CATEGORY == "FACT") { if (ddlOutputUOM.SelectedIndex > 0) { staticMeasure.STD_UOM = Convert.ToDecimal(ddlOutputUOM.SelectedValue); } else { staticMeasure.STD_UOM = null; } } if (ddlMeasureEFMType.SelectedIndex == 0) { staticMeasure.EFM_TYPE = null; } else { staticMeasure.EFM_TYPE = ddlMeasureEFMType.SelectedValue; } hfOper.Value = ""; if ((staticMeasure = EHSModel.UpdateEHSMeasure(entities, staticMeasure, SessionManager.UserContext.UserName())) != null) { EHS_MEASURE measure; if ((measure = measureList.FirstOrDefault(l => l.MEASURE_ID == staticMeasure.MEASURE_ID)) == null) { measureList.Add(staticMeasure); } else { if (staticMeasure.EntityState == System.Data.EntityState.Detached || staticMeasure.EntityState == System.Data.EntityState.Deleted) { measureList.Remove(measure); } else { measure = (EHS_MEASURE)SQMModelMgr.CopyObjectValues(measure, staticMeasure, false); } } ClearMeasure(null, null); BindMeasureList(measureList); } }