public void BindProfileInputHdr(EHSProfile profile) { ToggleVisible(pnlProfileInputHdr); lblPlantName_out.Text = profile.Plant.PLANT_NAME; lblPeriodFrom_out.Text = SQMBasePage.FormatDate(profile.InputPeriod.PeriodDate, "MM/yyyy", false); lblDueDate_out.Text = SQMBasePage.FormatDate(profile.InputPeriod.DueDate.AddMonths(1), "d", false); DateTime lastUpdateDate; TaskStatus status = profile.PeriodStatus(new string[0] { }, true, out lastUpdateDate); lblInputStatus1_out.Text = profile.InputPeriod.NumRequiredComplete.ToString(); lblInputStatus2_out.Text = profile.InputPeriod.NumRequired.ToString(); lblLastUpdateBy_out.Text = lblLastUpdate_out.Text = ""; EHS_PROFILE_INPUT lastinput = profile.InputPeriod.GetLastInput(); if (lastinput == null || lastinput.LAST_UPD_DT.HasValue == false) { if (profile.InputPeriod.PlantAccounting != null && !string.IsNullOrEmpty(profile.InputPeriod.PlantAccounting.LAST_UPD_BY)) { lblLastUpdateBy_out.Text = profile.InputPeriod.PlantAccounting.LAST_UPD_BY; if (profile.InputPeriod.PlantAccounting.LAST_UPD_DT.HasValue) { lblLastUpdate_out.Text = SQMBasePage.FormatDate((DateTime)profile.InputPeriod.PlantAccounting.LAST_UPD_DT, "", false); } } } else { lblLastUpdateBy_out.Text = lastinput.LAST_UPD_BY; lblLastUpdate_out.Text = SQMBasePage.FormatDate((DateTime)lastinput.LAST_UPD_DT, "", false); } CURRENCY_XREF exchangeRate = profile.InputPeriod.PeriodExchangeRate(profile.Plant); if (exchangeRate != null && exchangeRate.EFF_MONTH > 0) { phRateStatus.Visible = true; lblCurrency.Text = profile.Plant.CURRENCY_CODE; lblRateStatus.Text = (System.Environment.NewLine + SQMBasePage.FormatDate(new DateTime(exchangeRate.EFF_YEAR, exchangeRate.EFF_MONTH, DateTime.DaysInMonth(exchangeRate.EFF_YEAR, exchangeRate.EFF_MONTH)), "d", false)); } }
protected void lnkMetricInput_Click(object sender, EventArgs e) { string cmdID = ""; LinkButton lnk; if (sender.GetType().ToString().ToUpper().Contains("LINK")) { lnk = (LinkButton)sender; cmdID = lnk.CommandArgument; } else { ImageButton btn = (ImageButton)sender; cmdID = btn.CommandArgument; } EHS_PROFILE_INPUT input = LocalProfile().InputPeriod.InputsList[0]; input.LAST_UPD_DT = DateTime.UtcNow; EHSProfile.UpdateProfile(LocalProfile()); foreach (RepeaterItem item in rptProfilePeriod.Items) { lnk = (LinkButton)item.FindControl("lnkMetricCD"); if (lnk.CommandArgument == cmdID) { SaveInputs(Convert.ToDecimal(cmdID), false); Repeater rpt = (Repeater)item.FindControl("rptProfileInput"); EHS_PROFILE_MEASURE metric = LocalProfile().GetMeasure(Convert.ToDecimal(lnk.CommandArgument)); LocalProfile().CreatePeriodInput(LocalProfile().InputPeriod, metric, true); rpt.DataSource = LocalProfile().InputPeriod.GetPeriodInputList(metric.PRMR_ID); rpt.DataBind(); } } BindSharedCalendars(); }
public void rptProfileInput_OnItemDataBound(object sender, RepeaterItemEventArgs e) { if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item) { try { EHS_PROFILE_INPUT input = (EHS_PROFILE_INPUT)e.Item.DataItem; EHS_PROFILE_MEASURE metric = LocalProfile().GetMeasure((decimal)input.PRMR_ID); Label lbl; LinkButton lnk; //TextBox tb; DropDownList ddl; // bool enabled = input.STATUS == "C" ? false : true; bool enabled = true; sharedCalendar.Visible = true; RadDatePicker dtp1 = (RadDatePicker)e.Item.FindControl("radDateFrom"); dtp1.SharedCalendar = sharedCalendar; dtp1.Enabled = enabled; dtp1.ShowPopupOnFocus = true; RadDatePicker dtp2 = (RadDatePicker)e.Item.FindControl("radDateTo"); dtp2.SharedCalendar = sharedCalendar; dtp2.Enabled = enabled; dtp2.ShowPopupOnFocus = true; SETTINGS sets = SQMSettings.GetSetting("EHS", "INPUTSPAN"); int inputspan = 0; int monthSpan1 = Convert.ToInt32(WebSiteCommon.GetXlatValue("invoiceSpan", "MINDATE")); int monthSpan2 = monthSpan1; if (sets != null && int.TryParse(sets.VALUE, out inputspan)) { monthSpan2 = monthSpan1 = inputspan; } dtp1.MinDate = LocalProfile().InputPeriod.PeriodDate.AddMonths(monthSpan1 * -1); dtp2.MinDate = LocalProfile().InputPeriod.PeriodDate.AddMonths(monthSpan2 * -1); if (inputspan > 0) { dtp1.MaxDate = dtp2.MaxDate = LocalProfile().InputPeriod.PeriodDate.AddMonths(inputspan); } else { dtp1.MaxDate = dtp2.MaxDate = LocalProfile().InputPeriod.PeriodDate.AddMonths(Convert.ToInt32(WebSiteCommon.GetXlatValue("invoiceSpan", "MAXDATE"))); } dtp1.Culture = System.Threading.Thread.CurrentThread.CurrentUICulture; if (input != null) { if (input.STATUS == "N") { dtp1.Focus(); } if (input.EFF_FROM_DT > DateTime.MinValue) { dtp1.SelectedDate = input.EFF_FROM_DT; } else { dtp1.FocusedDate = new DateTime(LocalProfile().InputPeriod.PeriodYear, LocalProfile().InputPeriod.PeriodMonth, 1); } } dtp2.Culture = System.Threading.Thread.CurrentThread.CurrentUICulture; if (input != null && input.EFF_TO_DT > DateTime.MinValue) { dtp2.SelectedDate = input.EFF_TO_DT; } else { dtp2.FocusedDate = new DateTime(LocalProfile().InputPeriod.PeriodYear, LocalProfile().InputPeriod.PeriodMonth, 1); } UOM uom = SessionManager.UOMList.FirstOrDefault(l => l.UOM_ID == input.UOM); if (uom != null) { lbl = (Label)e.Item.FindControl("lblMetricUOM"); lbl.Text = uom.UOM_CD; } lbl = (Label)e.Item.FindControl("lblMetricCurrency"); lbl.Text = metric.DEFAULT_CURRENCY_CODE; if (input != null) { lbl.Text = input.CURRENCY_CODE; } TextBox tbValue = (TextBox)e.Item.FindControl("tbMetricValue"); tbValue.Enabled = enabled; if (input != null && (dtp1.SelectedDate != null && dtp2.SelectedDate != null)) { //if (input != null && input.MEASURE_VALUE != null) tbValue.Text = SQMBasePage.FormatValue((decimal)input.MEASURE_VALUE, 2); } TextBox tbCost = (TextBox)e.Item.FindControl("tbMetricCost"); TextBox tbCredit = (TextBox)e.Item.FindControl("tbMetricCredit"); if ((bool)metric.NEG_VALUE_ALLOWED) { tbCredit.Visible = tbCredit.Enabled = enabled; tbCost.Enabled = false; } else { tbCredit.Visible = false; tbCost.Enabled = true; } if (input != null && input.MEASURE_COST.HasValue && input.MEASURE_COST < 0) { tbCredit.Text = SQMBasePage.FormatValue((decimal)input.MEASURE_COST * -1, 2); } if (input != null && input.MEASURE_COST.HasValue && input.MEASURE_COST >= 0) { tbCost.Text = SQMBasePage.FormatValue((decimal)input.MEASURE_COST, 2); } if (metric.EHS_MEASURE.MEASURE_CATEGORY == "PROD" || metric.EHS_MEASURE.MEASURE_CATEGORY == "SAFE" || metric.EHS_MEASURE.MEASURE_CATEGORY == "FACT") { dtp1.SelectedDate = new DateTime(LocalProfile().InputPeriod.PeriodYear, LocalProfile().InputPeriod.PeriodMonth, 1); dtp1.Enabled = false; dtp2.SelectedDate = new DateTime(LocalProfile().InputPeriod.PeriodYear, LocalProfile().InputPeriod.PeriodMonth, DateTime.DaysInMonth(LocalProfile().InputPeriod.PeriodYear, LocalProfile().InputPeriod.PeriodMonth)); dtp2.Enabled = false; tbCost.Visible = false; tbCredit.Visible = false; lbl = (Label)e.Item.FindControl("lblMetricCurrency"); lbl.Visible = false; } if (LocalProfile().GetMeasureExt(metric, DateTime.Now) != null && metric.EHS_PROFILE_MEASURE_EXT.VALUE_DEFAULT.HasValue) { tbValue.CssClass = "defaultText"; tbValue.ToolTip = hfDefaultValue.Value + metric.EHS_PROFILE_MEASURE_EXT.NOTE; tbValue.ReadOnly = metric.EHS_PROFILE_MEASURE_EXT.OVERRIDE_ALLOWED == true ? false : true; if (string.IsNullOrEmpty(tbValue.Text)) { tbValue.Text = SQMBasePage.FormatValue((decimal)metric.EHS_PROFILE_MEASURE_EXT.VALUE_DEFAULT, 2); } } if (LocalProfile().GetMeasureExt(metric, DateTime.Now) != null && metric.EHS_PROFILE_MEASURE_EXT.COST_DEFAULT.HasValue) { tbCost.CssClass = "defaultText"; tbCost.ToolTip = hfDefaultValue.Value + metric.EHS_PROFILE_MEASURE_EXT.NOTE; tbCost.ReadOnly = metric.EHS_PROFILE_MEASURE_EXT.OVERRIDE_ALLOWED == true ? false : true; if (string.IsNullOrEmpty(tbCost.Text)) { tbCost.Text = SQMBasePage.FormatValue((decimal)metric.EHS_PROFILE_MEASURE_EXT.COST_DEFAULT, 2); } } CheckBox cbDelete = (CheckBox)e.Item.FindControl("cbDelete"); //string cbId = "ctl00_ContentPlaceHolder_Body_rptProfilePeriod_ctl06_rptProfileInput_ctl01_cbDelete"; cbDelete.Attributes.Add("onClick", "CheckInputDelete('" + cbDelete.ClientID + "');"); if (input.STATUS == "A" || input.STATUS == "D") { cbDelete.Enabled = true; } if (input.STATUS == "D") { cbDelete.Checked = true; cbDelete.ToolTip = hfDeleteText.Value; hfNumDelete.Value = (Convert.ToInt32(hfNumDelete.Value) + 1).ToString(); } } catch (Exception ex) { ; } } }
private int SaveInputs(decimal targetPrmrID, bool commitChanges) { int status = 0; LinkButton lnk; HiddenField hf; TextBox tbValue, tbCost, tbCredit; CheckBox cbDelete; decimal decimalValue; DateTime dateValue; decimal prmrID; bool hasReqdInputs = true; bool hasSaveWarning = false; bool hasSaveError = false; EHSProfileStatus saveStatus = EHSProfileStatus.Normal; try { foreach (RepeaterItem item in rptProfilePeriod.Items) { lnk = (LinkButton)item.FindControl("lnkMetricCD"); prmrID = Convert.ToDecimal(lnk.CommandArgument); EHS_PROFILE_MEASURE metric = LocalProfile().GetMeasure((decimal)prmrID); if (prmrID == targetPrmrID || commitChanges) { Repeater rpt = (Repeater)item.FindControl("rptProfileInput"); int numInput = 0; foreach (RepeaterItem inputItem in rpt.Items) { hf = (HiddenField)inputItem.FindControl("hfInputDate"); EHS_PROFILE_INPUT input = LocalProfile().InputPeriod.GetPeriodInput(prmrID, Convert.ToDateTime(hf.Value)); if (input != null) { RadDatePicker dtpFrom = (RadDatePicker)inputItem.FindControl("radDateFrom"); RadDatePicker dtpTo = (RadDatePicker)inputItem.FindControl("radDateTo"); tbValue = (TextBox)inputItem.FindControl("tbMetricValue"); tbCost = (TextBox)inputItem.FindControl("tbMetricCost"); tbCredit = (TextBox)inputItem.FindControl("tbMetricCredit"); cbDelete = (CheckBox)inputItem.FindControl("cbDelete"); hf = (HiddenField)inputItem.FindControl("hfStatus"); Control tr = new Control(); EHSProfileStatus inputStatus = EHSProfileStatus.Normal; switch (metric.EHS_MEASURE.MEASURE_CATEGORY) { case "PROD": case "SAFE": case "FACT": if (dtpFrom.SelectedDate == null || dtpTo.SelectedDate == null) { inputStatus = EHSProfileStatus.Incomplete; } else if (string.IsNullOrEmpty(tbValue.Text.Trim())) { inputStatus = EHSProfileStatus.NoInputs; } break; default: if (string.IsNullOrEmpty(tbValue.Text.Trim())) { if (string.IsNullOrEmpty(tbCost.Text.Trim() + tbCredit.Text.Trim())) { inputStatus = EHSProfileStatus.NoInputs; } else { inputStatus = EHSProfileStatus.Incomplete; } } else if (string.IsNullOrEmpty(tbCost.Text.Trim() + tbCredit.Text.Trim())) { inputStatus = EHSProfileStatus.Incomplete; } else if (dtpFrom.SelectedDate == null || dtpTo.SelectedDate == null) { inputStatus = EHSProfileStatus.Incomplete; } if (metric.EHS_PROFILE_MEASURE_EXT != null && (metric.EHS_PROFILE_MEASURE_EXT.VALUE_DEFAULT.HasValue || metric.EHS_PROFILE_MEASURE_EXT.COST_DEFAULT.HasValue)) { if (inputStatus == EHSProfileStatus.Incomplete && (dtpFrom.SelectedDate == null || dtpTo.SelectedDate == null)) { inputStatus = EHSProfileStatus.NoInputs; } } break; } if (inputStatus == EHSProfileStatus.NoInputs) { LocalProfile().InputPeriod.DeletePeriodInput(input); } else if (inputStatus == EHSProfileStatus.Incomplete) { hasSaveError = true; saveStatus = EHSProfileStatus.Incomplete; dtpFrom.DateInput.Style.Add("BACKGROUND-COLOR", "LIGHTCORAL"); dtpTo.DateInput.Style.Add("BACKGROUND-COLOR", "LIGHTCORAL"); tbValue.Style.Add("BACKGROUND-COLOR", "LIGHTCORAL"); if (tbCost.Enabled) { tbCost.Style.Add("BACKGROUND-COLOR", "LIGHTCORAL"); } if (tbCredit.Enabled) { tbCredit.Style.Add("BACKGROUND-COLOR", "LIGHTCORAL"); } } //if ((string.IsNullOrEmpty(tbValue.Text) || dtpFrom.SelectedDate == null || dtpTo.SelectedDate == null) || (string.IsNullOrEmpty(tbCost.Text + tbCredit.Text) && metric.EHS_MEASURE.MEASURE_CATEGORY != "PROD" && metric.EHS_MEASURE.MEASURE_CATEGORY != "SAFE" && metric.EHS_MEASURE.MEASURE_CATEGORY != "FACT")) //{ // LocalProfile().InputPeriod.DeletePeriodInput(input); //} else { ++numInput; if (cbDelete.Checked) { input.STATUS = "D"; } else if (input.STATUS == "D") { input.STATUS = "A"; } if (input.EFF_FROM_DT > DateTime.MinValue || input.EFF_FROM_DT != dtpFrom.SelectedDate) { input.EFF_FROM_DT = (DateTime)dtpFrom.SelectedDate; } if (input.EFF_TO_DT > DateTime.MinValue || input.EFF_TO_DT != dtpTo.SelectedDate) { input.EFF_TO_DT = (DateTime)dtpTo.SelectedDate; } if (SQMBasePage.ParseToDecimal(tbValue.Text, out decimalValue)) { if (input.MEASURE_VALUE != decimalValue) { input.MEASURE_VALUE = decimalValue; } } if (!string.IsNullOrEmpty(tbCredit.Text)) { SQMBasePage.ParseToDecimal(tbCredit.Text, out decimalValue); decimalValue = Math.Abs(decimalValue) * -1; if (!input.MEASURE_COST.HasValue || input.MEASURE_COST != decimalValue) { input.MEASURE_COST = decimalValue; } } else { SQMBasePage.ParseToDecimal(tbCost.Text, out decimalValue); decimalValue = Math.Abs(decimalValue); if (!input.MEASURE_COST.HasValue || input.MEASURE_COST != decimalValue) { input.MEASURE_COST = decimalValue; } } if (commitChanges && metric.EHS_MEASURE.MEASURE_CATEGORY != "PROD" && metric.EHS_MEASURE.MEASURE_CATEGORY != "SAFE" && metric.EHS_MEASURE.MEASURE_CATEGORY != "FACT" && LocalProfile().CurrentStatus != EHSProfileStatus.OutOFRange) { if (!EHSModel.IsMeasureValueInRange(metric, (double)input.MEASURE_VALUE, 1.0)) { hasSaveWarning = true; saveStatus = EHSProfileStatus.OutOFRange; tbValue.Style.Add("BACKGROUND-COLOR", "CORNSILK"); } } } } if (metric != null && (bool)metric.IS_REQUIRED && numInput == 0) { hasReqdInputs = false; } } } } if (commitChanges) { if (hasSaveError) { MessageDisplay(saveStatus); return(0); } if (hasSaveWarning) { MessageDisplay(saveStatus); return(0); } // deleted inputs after approval if ((!string.IsNullOrEmpty(hfNumDelete.Value) && hfNumDelete.Value != "0") && LocalProfile().InputPeriod.PlantAccounting.APPROVAL_DT.HasValue) { cbFinalApproval.Checked = false; } // changed inputs after approval if ((!string.IsNullOrEmpty(hfNumChanged.Value) && hfNumChanged.Value != "0") && LocalProfile().InputPeriod.PlantAccounting.APPROVAL_DT.HasValue) { cbFinalApproval.Checked = false; } status = LocalProfile().UpdatePeriod(true, "", cbFinalApproval.Checked, SessionManager.UserContext.UserName()); if (status >= 0) { // option to finalize metrics SETTINGS sets = SQMSettings.GetSetting("EHS", "INPUTFINALIZE"); if (sets != null) { bool doRollup = false; DateTime lastUpdateDate; LocalProfile().PeriodStatus(new string[0] { }, false, out lastUpdateDate); switch (sets.VALUE.ToUpper()) { case "ANY": // finalize any inputs doRollup = true; break; case "ANY_CURRENCY": // finalize any inputs and if the exchange rate for the period exists if (LocalProfile().InputPeriod.PeriodExchangeRate(LocalProfile().Plant) != null) { doRollup = true; } break; case "REQD": // finalize only when all required inputs have been entered if (LocalProfile().InputPeriod.IsRequiredComplete()) { doRollup = true; } break; case "REQD_CURRENCY": // finalize only when all required inputs are entered and exchange rate for the period exists if (LocalProfile().InputPeriod.IsRequiredComplete() && LocalProfile().InputPeriod.PeriodExchangeRate(LocalProfile().Plant) != null) { doRollup = true; } break; default: break; } if (doRollup && LocalProfile().ValidPeriod()) { status = LocalProfile().UpdateMetricHistory(LocalProfile().InputPeriod.PeriodDate); // new roll-up logic } } } if (status >= 0) { ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alertResult('hfAlertSaveSuccess');", true); hasSaveWarning = false; // cancel warning to allow re-save MessageDisplay(0); LoadProfileInput(LocalProfile().InputPeriod.PeriodDate, EHSProfileStatus.Normal); } else { ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alertResult('hfAlertSaveError');", true); MessageDisplay(0); ClearInput(); } } } catch (Exception ex) { // SQMLogger.LogException(ex); status = -1; } BindSharedCalendars(); return(status); }