Пример #1
0
        public void SetDefaultDate()
        {
            if (_popQuarter)
            {
                comMonth.SelectedText = _quarter[LqtUtil.GetQuarter(DateTime.Now) - 1].ToString();
                comMonth.Text         = _quarter[LqtUtil.GetQuarter(DateTime.Now) - 1].ToString();
            }
            else
            {
                comMonth.SelectedText = GetMonths(DateTime.Now.Month);
                comMonth.Text         = GetMonths(DateTime.Now.Month);
            }

            comYear.SelectedText = DateTime.Now.Year.ToString();
            comYear.Text         = DateTime.Now.Year.ToString();

            if (_disableMonthcom)
            {
                comMonth.Items.Clear();
            }
        }
Пример #2
0
        public IList <MAPEResult> CorrectMapeResultDates(IList <MAPEResult> maperesults, ForecastInfo finfo)
        {
            foreach (MAPEResult maperesult in maperesults)
            {
                DateTime date = new DateTime();
                if (maperesult.DurationDateTime.Day > 28)
                {
                    if (maperesult.DurationDateTime.Month == 12)
                    {
                        date = new DateTime(maperesult.DurationDateTime.Year + 1, 1, 01);
                    }
                    else
                    {
                        date = new DateTime(maperesult.DurationDateTime.Year, maperesult.DurationDateTime.Month + 1, 01);
                    }
                }
                else
                {
                    date = maperesult.DurationDateTime;
                }
                string duration = date.ToShortDateString();

                if (finfo.PeriodEnum == ForecastPeriodEnum.Bimonthly || finfo.PeriodEnum == ForecastPeriodEnum.Monthly)
                {
                    duration = date.ToString("MMMM-yyyy");
                }
                if (finfo.PeriodEnum == ForecastPeriodEnum.Quarterly)
                {
                    duration = "Qua" + LqtUtil.GetQuarter(date).ToString() + "-" + date.Year.ToString();
                }
                if (finfo.PeriodEnum == ForecastPeriodEnum.Yearly)
                {
                    duration = date.Year.ToString();
                }

                maperesult.Duration = duration;
            }
            return(maperesults);
        }
Пример #3
0
        private void ProcessByCategory()
        {
            foreach (ListViewItem li in lsvSites.CheckedItems)
            {
                ForecastCategory fcat = (ForecastCategory)li.Tag;
                _selectedProductids = fcat.GetSelectedProductId();

                int month = _forecastInfo.StartDate.Month;

                foreach (ListViewItem l in lvProductAll.SelectedItems)
                {
                    MasterProduct pro = (MasterProduct)l.Tag;
                    if (!IsTestSelected(pro.Id))
                    {
                        int      year  = _forecastInfo.StartDate.Year;
                        int      quar  = LqtUtil.GetQuarter(_forecastInfo.StartDate);
                        DateTime lastd = _forecastInfo.StartDate;

                        int quartermonth = 1;
                        for (int x = 1; x <= NoRPeriod(); x++)
                        {
                            ForecastCategoryProduct sp = new ForecastCategoryProduct();
                            sp.Product    = pro;
                            sp.Category   = fcat;
                            sp.AmountUsed = 1;
                            sp.Adjusted   = 1;
                            if (_forecastInfo.PeriodEnum == ForecastPeriodEnum.Bimonthly)
                            {
                                lastd        = lastd.AddMonths(-2);
                                sp.CDuration = LqtUtil.Months[lastd.Month - 1] + "-" + lastd.Year.ToString();
                                DateTime Duration = new DateTime(lastd.Year, lastd.Month, 1);
                                sp.DurationDateTime = Duration;
                            }
                            else if (_forecastInfo.PeriodEnum == ForecastPeriodEnum.Monthly)
                            {
                                lastd        = lastd.AddMonths(-1);
                                sp.CDuration = LqtUtil.Months[lastd.Month - 1] + "-" + lastd.Year.ToString();
                                DateTime Duration = new DateTime(lastd.Year, lastd.Month, 1);
                                sp.DurationDateTime = Duration;
                            }
                            else if (_forecastInfo.PeriodEnum == ForecastPeriodEnum.Quarterly)
                            {
                                if (quar == 1)
                                {
                                    quar = 4;
                                    year--;
                                }
                                else
                                {
                                    quar--;
                                }
                                sp.CDuration = String.Format("{0}-Qua{1}", year, quar);

                                if (quar == 1)
                                {
                                    quartermonth = 1;
                                }
                                else if (quar == 2)
                                {
                                    quartermonth = 4;
                                }
                                else if (quar == 3)
                                {
                                    quartermonth = 7;
                                }
                                else
                                {
                                    quartermonth = 10;
                                }

                                DateTime Duration = new DateTime(year, quartermonth, 1);
                                sp.DurationDateTime = Duration;
                            }
                            else
                            {
                                year--;
                                sp.CDuration = year.ToString();
                                DateTime Duration = new DateTime(year, 1, 1);
                                sp.DurationDateTime = Duration;
                            }
                            fcat.CategoryProducts.Add(sp);
                        }
                    }
                }
                // _forecastInfo.ForecastSites.Add(fsite);
            }
        }
Пример #4
0
        private void ProcessBySite()
        {
            foreach (ListViewItem li in lsvSites.CheckedItems)
            {
                ForlabSite site = (ForlabSite)li.Tag;
                fsite = _forecastInfo.GetForecastSiteBySiteId(site.Id);

                if (fsite == null)
                {
                    fsite              = new ForecastSite();
                    fsite.Site         = site;
                    fsite.ForecastInfo = _forecastInfo;
                    _forecastInfo.ForecastSites.Add(fsite);
                }
                _selectedProductids = fsite.GetSelectedTestId();

                int month = _forecastInfo.StartDate.Month;

                foreach (ListViewItem l in lvProductAll.SelectedItems)
                {
                    int           noperiod = NoRPeriod();
                    MasterProduct pro      = (MasterProduct)l.Tag;
                    if (!IsTestSelected(pro.Id))
                    {
                        int      year         = _forecastInfo.StartDate.Year;
                        DateTime lastd        = _forecastInfo.StartDate;
                        int      quar         = LqtUtil.GetQuarter(_forecastInfo.StartDate);
                        int      quartermonth = 1;
                        IList <ForecastSiteProduct> historicalSiteProduct =
                            DataRepository.GetHistoricalProduct(_forecastInfo.Period, _forecastInfo.Methodology, _forecastInfo.DataUsage, pro.Id, fsite.Site.Id, _forecastInfo.StartDate, 0);
                        TimeSpan diff = new TimeSpan();;
                        if (historicalSiteProduct.Count > 0)
                        {
                            DateTime lasthistorydate = historicalSiteProduct[0].DurationDateTime.Value;//sd
                            DateTime startdate       = _forecastInfo.StartDate;
                            diff = startdate.Subtract(lasthistorydate);
                            if (_forecastInfo.PeriodEnum == ForecastPeriodEnum.Bimonthly)
                            {
                                int noofemptyM = (((int)diff.TotalDays / 30) * 2) - 1;
                                if (noofemptyM >= 1)
                                {
                                    if (noperiod > noofemptyM)
                                    {
                                        noHistoryRecord = noperiod - noofemptyM;
                                        noperiod        = noofemptyM;
                                        getHistory      = true;
                                    }
                                    else
                                    {
                                        getHistory = false;
                                    }
                                }
                                else
                                {
                                    noHistoryRecord = noperiod;
                                    getHistory      = true;
                                    noperiod        = 0;
                                }
                            }
                            else if (_forecastInfo.PeriodEnum == ForecastPeriodEnum.Monthly)
                            {
                                int noofemptyM = ((int)diff.TotalDays / 30) - 1;
                                if (noofemptyM >= 1)
                                {
                                    if (noperiod > noofemptyM)
                                    {
                                        noHistoryRecord = noperiod - noofemptyM;
                                        noperiod        = noofemptyM;
                                        getHistory      = true;
                                    }
                                    else
                                    {
                                        getHistory = false;
                                    }
                                }
                                else
                                {
                                    noHistoryRecord = noperiod;
                                    getHistory      = true;
                                    noperiod        = 0;
                                }
                            }
                            else if (_forecastInfo.PeriodEnum == ForecastPeriodEnum.Quarterly)
                            {
                                int noofemptyQ = ((int)diff.TotalDays / (30 * 3)) - 1;
                                if (noofemptyQ >= 1)
                                {
                                    if (noperiod > noofemptyQ)
                                    {
                                        noHistoryRecord = noperiod - noofemptyQ;
                                        noperiod        = noofemptyQ;
                                        getHistory      = true;
                                    }
                                    else
                                    {
                                        getHistory = false;
                                    }
                                }
                                else
                                {
                                    noofemptyQ      = noperiod;
                                    noHistoryRecord = noperiod;
                                    getHistory      = true;
                                    noperiod        = 0;
                                }
                            }
                            else
                            {
                                int noofemptyY = ((int)diff.TotalDays / 365) - 1;
                                if (noofemptyY >= 1)
                                {
                                    if (noperiod > noofemptyY)
                                    {
                                        noHistoryRecord = noperiod - noofemptyY;
                                        noperiod        = noofemptyY;
                                        getHistory      = true;
                                    }
                                    else
                                    {
                                        getHistory = false;
                                    }
                                }
                                else
                                {
                                    noHistoryRecord = noperiod;
                                    getHistory      = true;
                                    noperiod        = 0;
                                }
                            }
                        }
                        else
                        {
                            getHistory = false;
                        }


                        if (getHistory)
                        {
                            AddForecastProductHistory(pro.Id, fsite.Site.Id, _forecastInfo.StartDate);
                        }

                        for (int x = 1; x <= noperiod; x++)
                        {
                            ForecastSiteProduct sp = new ForecastSiteProduct();
                            sp.Product      = pro;
                            sp.ForecastSite = fsite;
                            sp.AmountUsed   = 1;
                            sp.Adjusted     = 1;
                            if (_forecastInfo.PeriodEnum == ForecastPeriodEnum.Bimonthly)
                            {
                                //int y = month - x;
                                //if (y <= 0)
                                //    y = 12 + y;
                                lastd        = lastd.AddMonths(-2);
                                sp.CDuration = LqtUtil.Months[lastd.Month - 1] + "-" + lastd.Year.ToString();
                                DateTime Duration = new DateTime(lastd.Year, lastd.Month, 1);
                                sp.DurationDateTime = Duration;
                            }
                            else if (_forecastInfo.PeriodEnum == ForecastPeriodEnum.Monthly)
                            {
                                //int y = month - x;
                                //if (y <= 0)
                                //    y = 12 + y;
                                lastd        = lastd.AddMonths(-1);
                                sp.CDuration = LqtUtil.Months[lastd.Month - 1] + "-" + lastd.Year.ToString();
                                DateTime Duration = new DateTime(lastd.Year, lastd.Month, 1);
                                sp.DurationDateTime = Duration;
                            }
                            else if (_forecastInfo.PeriodEnum == ForecastPeriodEnum.Quarterly)
                            {
                                if (quar == 1)
                                {
                                    quar = 4;
                                    year--;
                                }
                                else
                                {
                                    quar--;
                                }

                                sp.CDuration = String.Format("{0}-Qua{1}", year, quar);
                                if (quar == 1)
                                {
                                    quartermonth = 1;
                                }
                                else if (quar == 2)
                                {
                                    quartermonth = 4;
                                }
                                else if (quar == 3)
                                {
                                    quartermonth = 7;
                                }
                                else
                                {
                                    quartermonth = 10;
                                }

                                DateTime Duration = new DateTime(year, quartermonth, 1);
                                sp.DurationDateTime = Duration;
                            }
                            else
                            {
                                year--;
                                sp.CDuration = year.ToString();
                                DateTime Duration = new DateTime(year, 1, 1);
                                sp.DurationDateTime = Duration;
                            }
                            fsite.SiteProducts.Add(sp);
                        }
                    }
                }
                // _forecastInfo.ForecastSites.Add(fsite);
            }
        }