private void MessageDisplay(EHSProfileStatus status)
        {
            lblInputError.Visible = lblPeriodLimit.Visible = lblProfileNotExist.Visible = lblNoMetrics.Visible = lblNoInputs.Visible = lblRangeWarning.Visible = lblIncompleteInputs.Visible = false;
            uclExport.Visible     = phApproval.Visible = true;

            // suppress local approval input when auto-rollup settings are active
            SETTINGS sets = SQMSettings.GetSetting("EHS", "INPUTFINALIZE");

            if (sets != null && !string.IsNullOrEmpty(sets.VALUE))
            {
                phApproval.Visible = false;
            }

            if (LocalProfile() != null)
            {
                LocalProfile().CurrentStatus = status;
                BindSharedCalendars();
            }
            switch (status)
            {
            case EHSProfileStatus.NonExist:
                lblProfileNotExist.Visible = true;
                uclExport.Visible          = phApproval.Visible = false;
                break;

            case EHSProfileStatus.PeriodLimit:
                lblPeriodLimit.Visible = true;
                break;

            case EHSProfileStatus.InputError:
                lblInputError.Visible = true;
                break;

            case EHSProfileStatus.NoMeasures:
                lblNoMetrics.Visible = true;
                uclExport.Visible    = phApproval.Visible = false;
                break;

            case EHSProfileStatus.NoInputs:
                lblNoInputs.Visible = true;
                break;

            case EHSProfileStatus.OutOFRange:
                lblRangeWarning.Visible = true;
                break;

            case EHSProfileStatus.Incomplete:
                lblIncompleteInputs.Visible = true;
                break;

            default:
                break;
            }
        }
        protected void OnInputPeriodSelect(DateTime periodDate)
        {
            EHSProfileStatus selectStatus = EHSProfileStatus.Normal;

            if (new DateTime(periodDate.Year, periodDate.Month, 1) == new DateTime(LocalProfile().MinPeriodDate.Year, LocalProfile().MinPeriodDate.Month, 1))
            {
                selectStatus = EHSProfileStatus.PeriodLimit;
            }

            if (LocalProfile() != null && LocalProfile().Status == EHSProfileStatus.Normal)
            {
                LoadProfileInput(periodDate, selectStatus);
            }
            else
            {
                uclInputHdr.TriggerPlantInputSelected();
            }
        }
        public void LoadProfileInput(DateTime targetDate, EHSProfileStatus selectStatus)
        {
            AccessMode accessMode = UserContext.CheckAccess("EHS", "311");

            LocalProfile().LoadPeriod(targetDate);
            if (LocalProfile().InputPeriod != null)
            {
                LocalProfile().MapPlantAccountingInputs(true, false);

                uclInputHdr.BindProfileInputHdr(LocalProfile());
                EHSProfileStatus status = BindProfileInputList(LocalProfile().MeasureList(true, accessMode).ToList(), LocalProfile().Profile);
                if (status == EHSProfileStatus.Normal)
                {
                    if (LocalProfile().Profile.APPROVER_ID == SessionManager.UserContext.Person.PERSON_ID || accessMode >= AccessMode.Admin)
                    {
                        cbFinalApproval.Enabled = true;
                    }
                    if (LocalProfile().InputPeriod.PlantAccounting.APPROVER_ID.HasValue&& LocalProfile().InputPeriod.PlantAccounting.APPROVAL_DT.HasValue)
                    {
                        cbFinalApproval.Checked  = true;
                        cbFinalApproval.Enabled  = false;
                        hfWasApproved.Value      = lblFinalApprovalBy.Text = SQMModelMgr.FormatPersonListItem(SQMModelMgr.LookupPerson((decimal)LocalProfile().InputPeriod.PlantAccounting.APPROVER_ID, ""));
                        lblFinalApprovalBy.Text += ("  " + SQMBasePage.FormatDate((DateTime)LocalProfile().InputPeriod.PlantAccounting.APPROVAL_DT, "", false));
                    }
                    else
                    {
                        cbFinalApproval.Checked = false;
                        hfWasApproved.Value     = lblFinalApprovalBy.Text = "";
                    }
                }
                MessageDisplay(selectStatus == EHSProfileStatus.Normal ? status : selectStatus);
                btnSave1.Enabled = btnSave2.Enabled = btnCancel1.Enabled = btnCancel2.Enabled = UserContext.CheckAccess("EHS", "311") >= AccessMode.Update ? true : false;
            }
            else
            {
                MessageDisplay(EHSProfileStatus.NoInputs);
            }
        }
Exemplo n.º 4
0
        public void LoadProfileInput(DateTime targetDate, EHSProfileStatus selectStatus)
        {
            UserContext.CheckUserPrivilege(SysPriv.originate, SysScope.envdata);
            LocalProfile().LoadPeriod(targetDate);
            if (LocalProfile().InputPeriod != null)
            {
                LocalProfile().MapPlantAccountingInputs(true, false);

                uclInputHdr.BindProfileInputHdr(LocalProfile());
                EHSProfileStatus status = BindProfileInputList(LocalProfile().MeasureList(true, UserContext.GetScopePrivileges(SysScope.envdata)).ToList(), LocalProfile().Profile);
                if (status == EHSProfileStatus.Normal)
                {
                    if (LocalProfile().Profile.APPROVER_ID == SessionManager.UserContext.Person.PERSON_ID || UserContext.CheckUserPrivilege(SysPriv.approve, SysScope.envdata))
                    {
                        cbFinalApproval.Enabled = true;
                    }
                    if (LocalProfile().InputPeriod.PlantAccounting.APPROVER_ID.HasValue&& LocalProfile().InputPeriod.PlantAccounting.APPROVAL_DT.HasValue)
                    {
                        cbFinalApproval.Checked  = true;
                        cbFinalApproval.Enabled  = false;
                        hfWasApproved.Value      = lblFinalApprovalBy.Text = SQMModelMgr.FormatPersonListItem(SQMModelMgr.LookupPerson((decimal)LocalProfile().InputPeriod.PlantAccounting.APPROVER_ID, ""));
                        lblFinalApprovalBy.Text += ("  " + SQMBasePage.FormatDate((DateTime)LocalProfile().InputPeriod.PlantAccounting.APPROVAL_DT, "", false));
                    }
                    else
                    {
                        cbFinalApproval.Checked = false;
                        hfWasApproved.Value     = lblFinalApprovalBy.Text = "";
                    }
                }
                MessageDisplay(selectStatus == EHSProfileStatus.Normal ? status : selectStatus);
                btnSave1.Enabled = btnSave2.Enabled = btnCancel1.Enabled = btnCancel2.Enabled = UserContext.GetMaxScopePrivilege(SysScope.envdata) < SysPriv.notify ? true : false;
            }
            else
            {
                MessageDisplay(EHSProfileStatus.NoInputs);
            }
        }
        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);
        }
Exemplo n.º 6
0
 private void MessageDisplay(EHSProfileStatus status)
 {
 }