public void LoadProfileInput()
        {
            divProfilePeriodScrollRepeater.Visible = true;
            SetLocalProfileList(new List <EHSProfile>());

            foreach (RadComboBoxItem item in SQMBasePage.GetComboBoxCheckedItems(ddlExportPlantSelect))
            {
                if (radExportDateSelect1.SelectedDate != null)
                {
                    EHSProfile profile = new EHSProfile().Load(Convert.ToDecimal(item.Value), false, true);
                    if (profile.Profile != null)
                    {
                        profile.LoadPeriod((DateTime)radExportDateSelect1.SelectedDate);
                        profile.MapPlantAccountingInputs(true, true);
                        LocalProfileList().Add(profile);
                    }
                }
            }
            rptProfile.DataSource = LocalProfileList();
            rptProfile.DataBind();

            if (UserContext.GetMaxScopePrivilege(SysScope.envdata) <= SysPriv.config)
            {
                btnRollupAll.Visible = true;
            }
        }
        protected void btnRollup_Click(object sender, EventArgs e)
        {
            Button btn = (Button)sender;

            uclProgress.BindProgressDisplay(100, "Finalizing: ");
            int progressValue = 10;

            uclProgress.UpdateDisplay(1, progressValue, "Calculating...");

            if (LocalProfileList() != null && LocalProfileList().Count > 0)
            {
                try
                {
                    EHSProfile profile    = LocalProfileList().Where(l => l.Plant.PLANT_ID == Convert.ToDecimal(btn.CommandArgument)).FirstOrDefault();
                    DateTime   endDate    = profile.InputPeriod.PeriodDate;
                    DateTime   periodDate = profile.InputPeriod.PeriodDate;

                    if (btn.ClientID.Contains("YTD"))
                    {
                        periodDate = new DateTime(profile.InputPeriod.PeriodDate.Year, 1, 1);
                    }

                    int progressDelta = 70 / Math.Max(1, ((endDate.Year - periodDate.Year) * 12 + endDate.Month - periodDate.Month));

                    while (periodDate <= endDate)
                    {
                        progressValue += progressDelta;
                        uclProgress.UpdateDisplay(1, progressValue, periodDate.ToShortDateString());

                        if (profile.InputPeriod.PeriodDate != periodDate)
                        {
                            profile.LoadPeriod(periodDate);
                        }

                        if (profile.ValidPeriod())
                        {
                            if (!profile.InputPeriod.PlantAccounting.APPROVAL_DT.HasValue)
                            {
                                profile.InputPeriod.PlantAccounting.APPROVAL_DT = DateTime.UtcNow;
                                profile.InputPeriod.PlantAccounting.APPROVER_ID = SessionManager.UserContext.Person.PERSON_ID;
                            }
                            //profile.UpdateMetricHistory();
                            profile.UpdateMetricHistory(periodDate);  // new roll-up logic
                            periodDate = periodDate.AddMonths(1);
                        }
                    }
                    uclProgress.ProgressComplete();
                    ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alertResult('hfAlertSaveSuccess');", true);
                    LoadProfileInput();
                }
                catch { }
            }
        }
Exemple #3
0
        public List <EHSProfilePeriod> SelectProfilePeriodList(EHSProfile profile, DateTime fromDate, DateTime toDate)
        {
            List <EHSProfilePeriod> periodList = new List <EHSProfilePeriod>();

            foreach (WebSiteCommon.DatePeriod pd in WebSiteCommon.CalcDatePeriods(fromDate, toDate, DateIntervalType.month, DateSpanOption.SelectRange, ""))
            {
                profile.LoadPeriod(pd.FromDate);
                // profile.MapPlantAccountingInputs(true, true);
                periodList.Add(profile.InputPeriod);
            }

            return(periodList);
        }