protected void btnMetricSave_Click(object sender, EventArgs e) { bool success; EHS_PROFILE_MEASURE pm = null; if (hfOper.Value == "add") { pm = staticProfile.AddMeasure(Convert.ToDecimal(WebSiteCommon.ParseItemValue(ddlMetricID.SelectedValue)), Convert.ToDecimal(ddlMetricResponsible.SelectedValue)); } else { pm = staticProfile.Profile.EHS_PROFILE_MEASURE.FirstOrDefault(l => l.PRMR_ID == staticProfileMeasure.PRMR_ID); } pm.PLANT_ID = staticProfile.Profile.PLANT_ID; pm.MEASURE_ID = Convert.ToDecimal(WebSiteCommon.ParseItemValue(ddlMetricID.SelectedValue)); //pm.EHS_MEASURE = EHSModel.LookupEHSMeasure(new PSsqmEntities(), pm.MEASURE_ID, ""); pm.MEASURE_PROMPT = tbMetricPrompt.Text; pm.REG_STATUS = ddlMetricRegStatus.SelectedValue; pm.UN_CODE = ddlMetricDisposalCode.SelectedValue; pm.DEFAULT_CURRENCY_CODE = ddlMetricCurrency.SelectedValue; if (ddlMetricResponsible.SelectedIndex > 0) { pm.RESPONSIBLE_ID = Convert.ToDecimal(ddlMetricResponsible.SelectedValue); } else { pm.RESPONSIBLE_ID = Convert.ToDecimal(null); } pm.IS_REQUIRED = cbMetricRequired.Checked; pm.NEG_VALUE_ALLOWED = cbMetricNegValue.Checked; if (cbUserUOM.Checked) { staticUOM.UOM_CATEGORY = "CUST"; staticUOM.UOM_CD = tbUserUOMCode.Text; staticUOM.UOM_NAME = staticUOM.UOM_DESC = tbUserUOMName.Text; staticUOM.OWNER_ID = staticProfile.Plant.PLANT_ID; double conversionFactor = 0; double.TryParse(tbUserUOMConversionFactor.Text.Trim(), out conversionFactor); if ((staticUOM = SQMResourcesMgr.UpdateUOM(new PSsqmEntities(), staticUOM, Convert.ToDecimal(WebSiteCommon.ParseItemValue(ddlUserUOMConvertTo.SelectedValue)), conversionFactor)) != null) { SessionManager.UOMList.Add(staticUOM); ddlMetricUOM.Items.Add(new ListItem(staticUOM.UOM_NAME, WebSiteCommon.PackItemValue(staticUOM.UOM_CATEGORY, staticUOM.UOM_ID.ToString()))); pm.DEFAULT_UOM = staticUOM.UOM_ID; } cbUserUOM.Checked = false; } else { pm.DEFAULT_UOM = Convert.ToDecimal(WebSiteCommon.ParseItemValue(ddlMetricUOM.SelectedValue)); } BindProfile(staticProfile); }
protected void ddlUOMChanged(object sender, EventArgs e) { if (ddlMetricUOM.SelectedValue.Contains("CUST")) { UOM uom = null; if (!string.IsNullOrEmpty(ddlMetricUOM.SelectedValue)) { uom = SessionManager.UOMList.FirstOrDefault(l => l.UOM_ID == Convert.ToDecimal(WebSiteCommon.ParseItemValue(ddlMetricUOM.SelectedValue))); } if (uom != null) { tbUserUOMCode.Text = uom.UOM_CD; tbUserUOMName.Text = uom.UOM_DESC; } udpMetricUOM.Update(); } else { return; } }
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()); }