protected void lnkMeasureList_Click(object sender, EventArgs e) { LinkButton lnk = (LinkButton)sender; decimal measureID = Convert.ToDecimal(lnk.CommandArgument.ToString().Trim()); BindMeasure((staticMeasure = measureList.FirstOrDefault(l => l.MEASURE_ID == measureID))); }
protected void UpdateListTitles() { string title = ""; EHS_MEASURE measure = null; foreach (ListItem item in ddlMetricID.Items) { if (item.Enabled && !string.IsNullOrEmpty(item.Text)) { measure = measureList.FirstOrDefault(l => l.MEASURE_NAME == item.Text); if (measure != null) { item.Attributes.Add("title", measure.MEASURE_CD); } } } foreach (ListItem item in ddlMetricDisposalCode.Items) { if (item.Enabled && !string.IsNullOrEmpty(item.Text)) { item.Attributes.Add("title", SessionManager.DisposalCodeList.FirstOrDefault(l => l.UN_CODE == item.Value).DESCRIPTION); } } }
public int BindMeasure(EHS_MEASURE measure) { int status = 0; if (measure != null) { tbMeasureCode.Text = measure.MEASURE_CD; tbMeasureName.Text = measure.MEASURE_NAME; tbMeasureDesc.Text = measure.MEASURE_DESC; ddlMeasureSubcategory.SelectedValue = measure.MEASURE_SUBCATEGORY; SQMBasePage.SetStatusList(ddlMeasureStatus, measure.STATUS); UOM uom = SessionManager.UOMList.FirstOrDefault(l => l.UOM_ID == measure.STD_UOM); if (uom != null) { SetFindControlValue("hfUOMCategory_out", hfBase, uom.UOM_CATEGORY); SetFindControlValue("hfMeasureUOM_out", hfBase, (uom.UOM_CATEGORY + "|" + measure.STD_UOM.ToString())); ScriptManager.RegisterStartupScript(this, GetType(), "filterlist", "filterDependentList('ddlUOMCategory', 'ddlMeasureUOM', 'hfUOMCategory_out', 'hfMeasureUOM_out');", true); ddlUOMCategory.SelectedValue = uom.UOM_CATEGORY; ddlMeasureUOM.SelectedValue = measure.STD_UOM.ToString(); } pnlMeasureEdit.Enabled = btnMeasureCancel.Enabled = btnMeasureSave.Enabled = true; } return(status); }
protected void btnMeasureSave_Click(object sender, EventArgs e) { bool success; if (hfOper.Value == "add") { staticMeasure = new EHS_MEASURE(); staticMeasure.COMPANY_ID = SessionManager.SessionContext.ActiveCompany().COMPANY_ID; staticMeasure.STATUS = "A"; } else { staticMeasure = SQMResourcesMgr.LookupEHSMeasure(entities, staticMeasure.MEASURE_ID, ""); } btnMeasureSave.Enabled = false; hfOper.Value = ""; staticMeasure.MEASURE_CATEGORY = ddlMeasureCategory.SelectedValue; staticMeasure.STD_CURRENCY_CODE = ddlMeasureCurrency.SelectedValue; staticMeasure.MEASURE_SUBCATEGORY = ddlMeasureSubcategory.SelectedValue; staticMeasure.STATUS = ddlMeasureStatus.SelectedValue; staticMeasure.STD_UOM = Convert.ToDecimal(null); string sel = GetFindControlValue("hfMeasureUOM_out", hfBase, out success); if (!string.IsNullOrEmpty(sel)) { string[] parms = sel.Split('|'); if (parms.Length > 1) { staticMeasure.STD_UOM = Convert.ToDecimal(parms[1]); } } staticMeasure.MEASURE_CD = tbMeasureCode.Text; staticMeasure.MEASURE_NAME = tbMeasureName.Text; staticMeasure.MEASURE_DESC = tbMeasureDesc.Text; if ((staticMeasure = SQMResourcesMgr.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); } } BindMeasureList(measureList); } }
protected void ClearMeasure(object sender, EventArgs e) { hfOper.Value = ""; staticMeasure = null; tbMeasureCode.Text = tbMeasureDesc.Text = tbMeasureName.Text = ""; ddlMeasureSubcategory.SelectedIndex = ddlMeasureEFMType.SelectedIndex = ddlMeasureStatus.SelectedIndex = 0; btnMeasureCancel.Enabled = btnMeasureSave.Enabled = false; pnlMeasureEdit.Visible = false; }
public void gvList_OnMeasureSubcatRowDataBound(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e) { if ((!e.Row.RowType.ToString().Trim().Equals(System.Web.UI.WebControls.ListItemType.Header.ToString())) & (!e.Row.RowType.ToString().Trim().Equals(System.Web.UI.WebControls.ListItemType.Footer.ToString()))) { try { Label lbl = (Label)e.Row.Cells[0].FindControl("lblMeasureSubcat"); HiddenField hf = (HiddenField)e.Row.Cells[0].FindControl("hfMeasureSubcat"); EHS_MEASURE subcat = subList.FirstOrDefault(l => l.MEASURE_CD == hf.Value); if (subcat != null) { lbl.Text = subcat.MEASURE_NAME; } GridView gv = (GridView)e.Row.Cells[0].FindControl("gvMeasureList"); gv.DataSource = measureList.Where(l => l.MEASURE_SUBCATEGORY == hf.Value).ToList(); gv.DataBind(); } catch (Exception ex) { ; } } }
public int BindProfileMeasure(EHS_PROFILE_MEASURE pm) { int status = 0; divMetricUOM.Visible = true; divUserUOM.Visible = false; if (pm == null) { ddlMetricCategory.SelectedIndex = ddlMetricID.SelectedIndex = ddlMetricDisposalCode.SelectedIndex = ddlMetricUOM.SelectedIndex = ddlMetricResponsible.SelectedIndex = 0; ddlMetricCurrency.SelectedValue = staticProfile.Plant.CURRENCY_CODE; lblMetricName.Text = lblDisposalDesc.Text = ""; tbMetricPrompt.Text = ""; } else { staticProfileMeasure = pm; staticMeasure = pm.EHS_MEASURE; // ScriptManager.RegisterStartupScript(this, GetType(), "enablelist", "enableListItems('ddlMetricCategory','ddlMetricID'); enableListItems('ddlMetricUOMCategory','ddlMetricUOM');", true); ddlMetricCategory.SelectedValue = pm.EHS_MEASURE.MEASURE_CATEGORY; ddlMetricID.SelectedValue = pm.EHS_MEASURE.MEASURE_CATEGORY + "|" + pm.EHS_MEASURE.MEASURE_ID.ToString(); lblMetricName.Text = pm.EHS_MEASURE.MEASURE_CD; tbMetricPrompt.Text = pm.MEASURE_PROMPT; ddlMetricRegStatus.SelectedValue = pm.REG_STATUS; ddlMetricDisposalCode.SelectedValue = pm.UN_CODE; if (!string.IsNullOrEmpty(pm.UN_CODE)) { lblDisposalDesc.Text = disposalList.FirstOrDefault(l => l.UN_CODE == pm.UN_CODE).DESCRIPTION; } else { lblDisposalDesc.Text = ""; } if (pm.EHS_MEASURE.MEASURE_CATEGORY == "EUTL" || pm.EHS_MEASURE.MEASURE_CATEGORY == "PROD") { tbWasteCode.Enabled = false; tbWasteCode.Text = ""; } else { tbWasteCode.Enabled = true; tbWasteCode.Text = pm.WASTE_CODE; } ddlMetricCurrency.SelectedValue = pm.DEFAULT_CURRENCY_CODE; if (pm.RESPONSIBLE_ID > 0) { ddlMetricResponsible.SelectedValue = pm.RESPONSIBLE_ID.ToString(); } if (pm.DEFAULT_UOM > 0) { UOM uom = staticUOM = SessionManager.UOMList.FirstOrDefault(l => l.UOM_ID == pm.DEFAULT_UOM); if (uom != null) { ddlMetricUOM.SelectedValue = WebSiteCommon.PackItemValue(uom.UOM_CATEGORY, uom.UOM_ID.ToString()); if (uom.UOM_CATEGORY == "CUST") { divUserUOM.Visible = true; tbUserUOMName.Text = uom.UOM_NAME; tbUserUOMCode.Text = uom.UOM_CD; UOM_XREF xref = uom.UOM_XREF.FirstOrDefault(); if (xref != null) { UOM refUOM = SessionManager.UOMList.FirstOrDefault(l => l.UOM_ID == xref.UOM_TO); if (refUOM != null) { ddlUserUOMConvertTo.SelectedValue = WebSiteCommon.PackItemValue(refUOM.UOM_CATEGORY, refUOM.UOM_ID.ToString()); tbUserUOMConversionFactor.Text = SQMBasePage.FormatValue(xref.CONVERSION, 4); } } } } } ddlMetricStatus.SelectedValue = pm.STATUS; cbMetricNegValue.Checked = (bool)pm.NEG_VALUE_ALLOWED; cbMetricRequired.Checked = (bool)pm.IS_REQUIRED; } UpdateListTitles(); pnlMetricEdit.Enabled = btnMetricCancel.Enabled = btnMetricSave.Enabled = true; return(status); }
protected void Page_Load(object sender, EventArgs e) { PSsqmEntities ctx = new PSsqmEntities(); string delimStr = "~"; char[] delimiter = delimStr.ToCharArray(); string[] exportParms = null; string[] plants = null; int loop1; exportParms = SessionManager.ExportCriteria.Split(delimiter); delimStr = ","; delimiter = null; delimiter = delimStr.ToCharArray(); plants = exportParms[1].Split(delimiter); decimal[] plantIDs = new decimal[plants.Length]; for (loop1 = 0; loop1 < plants.Length; loop1++) { plantIDs[loop1] = Convert.ToDecimal(plants[loop1]); } DateTime dtFrom = Convert.ToDateTime(exportParms[2]); DateTime dtTo = Convert.ToDateTime(exportParms[3]); EHSCalcsCtl esMgr = new EHSCalcsCtl().CreateNew(SessionManager.FYStartDate().Month, DateSpanOption.SelectRange, "E"); esMgr.LoadMetricHistory(plantIDs, dtFrom, dtTo, DateIntervalType.month, false); List <MetricData> metric_history = esMgr.MetricHst.OrderBy(l => l.MetricRec.PLANT_ID).ThenBy(l => l.MetricRec.PERIOD_YEAR).ThenBy(l => l.MetricRec.PERIOD_MONTH).ThenBy(l => l.Measure.MEASURE_CATEGORY).ThenBy(l => l.Measure.MEASURE_CD).ToList(); string uom_cd; string uom_input_cd; decimal uom_id = 0; // need to cycle thru and populate the UOM and other formatting try { string filename = exportParms[0].Trim() + ".xls"; Response.ContentType = "application/vnd.ms-excel"; Response.AddHeader("Content-Disposition", string.Format("attachment;filename={0}", filename)); Response.Clear(); InitializeWorkbook(); ISheet sheet1 = hssfworkbook.CreateSheet("Metric History"); //// create the header - Plant Name, DUNS Code, Measure, Measure Name, Period Year, Period Month, Period from Date, Period To Date, Value, UOM, UOM Name, Input Value, Cost, Currency, Input Cost, Input Currency IRow row = sheet1.CreateRow(0); row.CreateCell(0).SetCellValue("Plant Name"); row.CreateCell(1).SetCellValue("DUNS Code"); row.CreateCell(2).SetCellValue("Measure"); row.CreateCell(3).SetCellValue("Measure Name"); row.CreateCell(4).SetCellValue("Period Year"); row.CreateCell(5).SetCellValue("Period Month"); row.CreateCell(6).SetCellValue(Resources.LocalizedText.Value); row.CreateCell(7).SetCellValue("UOM"); row.CreateCell(8).SetCellValue("Input Value"); row.CreateCell(9).SetCellValue("Input UOM"); row.CreateCell(10).SetCellValue(Resources.LocalizedText.Cost); row.CreateCell(11).SetCellValue("Currency"); row.CreateCell(12).SetCellValue("Input Cost"); row.CreateCell(13).SetCellValue("Input Currency"); ICell cellNumeric; ICellStyle cellStyleNumeric = hssfworkbook.CreateCellStyle(); cellStyleNumeric.DataFormat = HSSFDataFormat.GetBuiltinFormat("0.00"); for (int irows = 0; irows < metric_history.Count; irows++) { int rownum = irows + 1; UOM uom = null; uom_id = metric_history[irows].MetricRec.UOM_ID; uom = SessionManager.UOMList.FirstOrDefault(l => l.UOM_ID == uom_id); if (uom != null) { uom_cd = uom.UOM_CD; } else { uom_cd = ""; } try { uom_id = Convert.ToDecimal(metric_history[irows].MetricRec.INPUT_UOM_ID.ToString()); uom = SessionManager.UOMList.FirstOrDefault(l => l.UOM_ID == uom_id); if (uom != null) { uom_input_cd = uom.UOM_CD; } else { uom_input_cd = ""; } } catch { uom_input_cd = ""; } // create a column for each field we want PLANT plant = SQMModelMgr.LookupPlant(ctx, metric_history[irows].MetricRec.PLANT_ID, ""); //metric_history[irows].Plant; EHS_MEASURE measure = metric_history[irows].Measure as EHS_MEASURE; row = sheet1.CreateRow(rownum); try { row.CreateCell(0).SetCellValue(plant.PLANT_NAME); } catch { row.CreateCell(0).SetCellValue(""); } try { row.CreateCell(1).SetCellValue(plant.DUNS_CODE); } catch { row.CreateCell(1).SetCellValue(""); } try { row.CreateCell(2).SetCellValue(measure.MEASURE_CD); } catch { row.CreateCell(2).SetCellValue(""); } try { row.CreateCell(3).SetCellValue(measure.MEASURE_NAME); } catch { row.CreateCell(3).SetCellValue(""); } try { row.CreateCell(4).SetCellValue(metric_history[irows].MetricRec.PERIOD_YEAR); } catch { row.CreateCell(4).SetCellValue(""); } try { row.CreateCell(5).SetCellValue(metric_history[irows].MetricRec.PERIOD_MONTH); } catch { row.CreateCell(5).SetCellValue(""); } try { cellNumeric = row.CreateCell(6); cellNumeric.CellStyle = cellStyleNumeric; cellNumeric.SetCellValue(Convert.ToDouble(metric_history[irows].MetricRec.MEASURE_VALUE)); } catch { row.CreateCell(6).SetCellValue(""); } try { row.CreateCell(7).SetCellValue(uom_cd); } catch { row.CreateCell(7).SetCellValue(""); } try { cellNumeric = row.CreateCell(8); cellNumeric.CellStyle = cellStyleNumeric; cellNumeric.SetCellValue(Convert.ToDouble(metric_history[irows].MetricRec.INPUT_VALUE)); } catch { row.CreateCell(8).SetCellValue(""); } try { row.CreateCell(9).SetCellValue(uom_input_cd); } catch { row.CreateCell(9).SetCellValue(""); } try { cellNumeric = row.CreateCell(10); cellNumeric.CellStyle = cellStyleNumeric; cellNumeric.SetCellValue(Convert.ToDouble(metric_history[irows].MetricRec.MEASURE_COST)); } catch { row.CreateCell(10).SetCellValue(""); } try { row.CreateCell(11).SetCellValue(metric_history[irows].MetricRec.CURRENCY_CODE); } catch { row.CreateCell(11).SetCellValue(""); } try { cellNumeric = row.CreateCell(12); cellNumeric.CellStyle = cellStyleNumeric; cellNumeric.SetCellValue(Convert.ToDouble(metric_history[irows].MetricRec.INPUT_COST)); } catch { row.CreateCell(12).SetCellValue(""); } try { row.CreateCell(13).SetCellValue(metric_history[irows].MetricRec.INPUT_CURRENCY_CODE); } catch { row.CreateCell(13).SetCellValue(""); } } sheet1.AutoSizeColumn(0); sheet1.AutoSizeColumn(1); sheet1.AutoSizeColumn(2); sheet1.AutoSizeColumn(3); sheet1.AutoSizeColumn(4); sheet1.AutoSizeColumn(5); sheet1.AutoSizeColumn(6); sheet1.AutoSizeColumn(7); sheet1.AutoSizeColumn(8); sheet1.AutoSizeColumn(9); sheet1.AutoSizeColumn(10); sheet1.AutoSizeColumn(11); sheet1.AutoSizeColumn(12); sheet1.AutoSizeColumn(13); GetExcelStream().WriteTo(Response.OutputStream); Response.End(); } catch (Exception ex) { //Response.Write("Error processing the file:" + ex.Message.ToString()); Response.End(); } }
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); } }
public int BindMeasure(EHS_MEASURE measure) { int status = 0; pnlMeasureEdit.Visible = true; DisplayErrorMessage(null); BindSubcategoryList(measure != null ? measure.MEASURE_CATEGORY : ""); trMeasureEFMType.Visible = false; phProdTableField.Visible = phSafeTableField.Visible = phOutputUOM.Visible = false; ddlMeasureEFMType.SelectedIndex = ddlProdTableField.SelectedIndex = ddlSafeTableField.SelectedIndex = ddlOutputUOM.SelectedIndex = 0; if ((measure != null && measure.MEASURE_CATEGORY == "PROD") || ddlMeasureCategory.SelectedValue == "PROD") { phProdTableField.Visible = true; } else if ((measure != null && measure.MEASURE_CATEGORY == "SAFE") || ddlMeasureCategory.SelectedValue == "SAFE") { phSafeTableField.Visible = true; } else if ((measure != null && measure.MEASURE_CATEGORY == "FACT") || ddlMeasureCategory.SelectedValue == "FACT") { phOutputUOM.Visible = true; } else if ((measure != null && measure.MEASURE_CATEGORY == "ENGY") || ddlMeasureCategory.SelectedValue == "ENGY") { trMeasureEFMType.Visible = true; } winMeasureEdit.Title = hfAddMeasure.Value; if (measure != null) { winMeasureEdit.Title = hfUpdateMeasure.Value; tbMeasureCode.Text = measure.MEASURE_CD; tbMeasureName.Text = measure.MEASURE_NAME.Trim(); tbMeasureDesc.Text = measure.MEASURE_DESC.Trim(); ddlMeasureSubcategory.SelectedValue = measure.MEASURE_SUBCATEGORY; SQMBasePage.SetStatusList(ddlMeasureStatus, measure.STATUS); ddlProdTableField.SelectedIndex = ddlSafeTableField.SelectedIndex = ddlOutputUOM.SelectedIndex = 0; if (!string.IsNullOrEmpty(measure.PLANT_ACCT_FIELD) && ddlProdTableField.Items.FindByValue(measure.PLANT_ACCT_FIELD) != null) { ddlProdTableField.SelectedValue = measure.PLANT_ACCT_FIELD; } if (!string.IsNullOrEmpty(measure.PLANT_ACCT_FIELD) && ddlSafeTableField.Items.FindByValue(measure.PLANT_ACCT_FIELD) != null) { ddlSafeTableField.SelectedValue = measure.PLANT_ACCT_FIELD; } if (measure.STD_UOM.HasValue && ddlOutputUOM.Items.FindByValue(measure.STD_UOM.ToString()) != null) { ddlOutputUOM.SelectedValue = measure.STD_UOM.ToString(); } if (ddlMeasureEFMType.Items.FindByValue(measure.EFM_TYPE) != null) { ddlMeasureEFMType.SelectedValue = measure.EFM_TYPE; } } btnMeasureCancel.Enabled = btnMeasureSave.Enabled = true; string script = "function f(){OpenMeasureEditWindow(); Sys.Application.remove_load(f);}Sys.Application.add_load(f);"; ScriptManager.RegisterStartupScript(Page, Page.GetType(), "key", script, true); return(status); }