Exemple #1
0
        public virtual void RemoveFSiteProduct(int fsproid)
        {
            ForecastSiteProduct fp = GetSiteProduct(fsproid);

            if (fp != null)
            {
                SiteProducts.Remove(fp);
            }
        }
Exemple #2
0
        public decimal GetActiveSiteWorkingDays(ForecastSiteProduct fp)
        {
            decimal workingday = 22;

            switch (_forecastInfo.DatausageEnum)
            {
                case DataUsageEnum.DATA_USAGE1:
                case DataUsageEnum.DATA_USAGE2:
                    workingday = fp.ForecastSite.Site.WorkingDays;
                    break;
            }
            return workingday;
        }
Exemple #3
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);
            }
        }
        private IBaseDataUsage GetNewDataUsage()
        {
            IBaseDataUsage dusage = null;
            if (_forecastInfo.FMethodologeyEnum == MethodologyEnum.CONSUMPTION)
            {
                switch (_forecastInfo.DatausageEnum)
                {
                    case DataUsageEnum.DATA_USAGE1:
                    case DataUsageEnum.DATA_USAGE2:
                        dusage = new ForecastSiteProduct() { ForecastSite = _activeFSite };

                        break;
                    case DataUsageEnum.DATA_USAGE3:
                        dusage = new ForecastCategoryProduct() { Category = _activeCategory };
                        break;
                }
            }
            else
            {
                switch (_forecastInfo.DatausageEnum)
                {
                    case DataUsageEnum.DATA_USAGE1:
                    case DataUsageEnum.DATA_USAGE2:
                        dusage = new ForecastSiteTest() { ForecastSite = _activeFSite };
                        break;
                    case DataUsageEnum.DATA_USAGE3:
                        dusage = new ForecastCategoryTest() { Category = _activeCategory };
                        break;
                }
            }
            return dusage;
        }
        private IBaseDataUsage GetCloneForecastSiteProduct(IBaseDataUsage fsp)
        {
            IBaseDataUsage dusage;
            if (_forecastInfo.FMethodologeyEnum == MethodologyEnum.CONSUMPTION)
                dusage = new ForecastSiteProduct();
            else
                dusage = new ForecastSiteTest();

            dusage.Product = fsp.Product;
            dusage.AmountUsed = fsp.AmountUsed;
            dusage.Adjusted = fsp.Adjusted;
            dusage.CDuration = fsp.CDuration;
            dusage.DurationDateTime = fsp.DurationDateTime;
            dusage.Test = fsp.Test; //Feb 19 2015
            return dusage;
        }
Exemple #6
0
        private void butSave_Click(object sender, EventArgs e)
        {
            foreach (ReportedData rd in _rdata)
            {
                ForecastSiteProduct fp = new ForecastSiteProduct();
                ForecastSite fs = _forecastInfo.GetForecastSiteBySiteId(rd.Site.Id);
                if (fs == null)
                {
                    fs = new ForecastSite();
                    fs.Site = rd.Site;
                    fs.ForecastInfo = _forecastInfo;
                    _forecastInfo.ForecastSites.Add(fs);
                }
                fp.ForecastSite = fs;
                fp.Product = rd.Product;
                fp.CDuration = rd.Duration;
                fp.AmountUsed = rd.Amount;
                fp.StockOut = rd.StockOut;
                fp.InstrumentDowntime = rd.InstrumentDownTime;//b
                fp.Adjusted = rd.Amount; //b

                fs.SiteProducts.Add(fp);
            }
            try
            {
                DataRepository.SaveOrUpdateForecastInfo(_forecastInfo);
                MessageBox.Show("Consumption data imported and saved successfully.", "Importing", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.DialogResult = System.Windows.Forms.DialogResult.OK;
                this.Close();
            }
            catch
            {
                MessageBox.Show("Error: Unable to imported and saved consumption data.", "Importing", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemple #7
0
 public Consumption GetConsumption(int id,ForecastSiteProduct fp)
 {
     Consumption con = null;
     switch (_forecastInfo.DatausageEnum)
         {
             case DataUsageEnum.DATA_USAGE1:
             case DataUsageEnum.DATA_USAGE2:
                 con = fp.ForecastSite.ConsumptionByProduct(id);
                 break;
             case DataUsageEnum.DATA_USAGE3:
                 con = fp.ForecastSite.ConsumptionByProduct(id);
                 break;
         }
     return con;
 }
Exemple #8
0
        private void butImport_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtFilename.Text.Trim()))
                return;
            try
            {
                DataSet ds = LqtUtil.ReadExcelFileforecast(txtFilename.Text, _noColumn);

                _rdata = GetDataRow(ds);
                lvImport.BeginUpdate();
                lvImport.Items.Clear();
                ForecastSite fs = new ForecastSite();
                ForecastCategorySite fcatsite = new ForecastCategorySite();

                bool isduplicate = false;
                ForecastSite efs = new ForecastSite();//existing
                IList<ForecastSiteProduct> existingFsp = new List<ForecastSiteProduct>();
                foreach (ForecastSite efss in _forecastInfo.ForecastSites)
                {
                    foreach (ForecastSiteProduct efsp in efss.SiteProducts)
                        existingFsp.Add(efsp);
                }

                foreach (ReportedData rd in _rdata)
                {
                    ListViewItem li = new ListViewItem(rd.RowNo.ToString());

                    if (_forecastInfo.DatausageEnum == DataUsageEnum.DATA_USAGE3)
                    {
                        li.SubItems.Add(rd.CategoryName);
                    }
                    else
                    {
                        li.SubItems.Add(rd.RegionName);
                        li.SubItems.Add(rd.SiteName);
                    }

                    li.SubItems.Add(rd.ProductName);
                    if (!LqtUtil.IsDateTime(rd.Duration))
                    {

                        try
                        {
                            DateTime dd = LqtUtil.DurationToDateTime(rd.Duration);
                            if (rd.Duration.StartsWith("Q") && (_forecastInfo.PeriodEnum == ForecastPeriodEnum.Yearly))
                            {

                                rd.Duration = dd.Year.ToString();
                                li.SubItems.Add(LqtUtil.DatetimeToDurationStr(_forecastInfo.PeriodEnum, dd));
                            }
                            else
                            li.SubItems.Add(rd.Duration);
                        }
                        catch (Exception ex)
                        {
                            li.SubItems.Add(rd.Duration);
                            rd.HasError = true;
                        }

                    }
                    else
                    {

                        string datestr = LqtUtil.DatetimeToDurationStr(_forecastInfo.PeriodEnum, DateTime.Parse(rd.Duration));
                        if (!rd.Duration.StartsWith("Q"))
                        {
                            rd.Duration = LqtUtil.DatetimeToDurationStr(_forecastInfo.PeriodEnum, DateTime.Parse(rd.Duration));
                            if (_forecastInfo.PeriodEnum == ForecastPeriodEnum.Yearly)
                            {
                                li.SubItems.Add(datestr);

                            }
                            else
                            {
                                li.SubItems.Add(rd.Duration);

                            }
                        }
                        else
                        {
                            {
                                li.SubItems.Add(datestr);

                            }

                        }

                    }
                    li.SubItems.Add(rd.Amount.ToString());
                    li.SubItems.Add(rd.StockOut.ToString());
                    li.SubItems.Add(rd.InstrumentDownTime.ToString());//
                    if (rd.HasError == true && rd.ErrorDescription == "")
                        rd.ErrorDescription = " Product Consumed Required ";

                    if (LqtUtil.validDate(rd.Duration, _forecastInfo.PeriodEnum))
                        rd.HasError = true;

                    //check if stockout and instrument downtime is less than site working days
                    try
                    {
                        if (rd.Site != null)
                            if (!LqtUtil.ValidDownTime(rd.StockOut + rd.InstrumentDownTime, _forecastInfo.PeriodEnum, rd.Site.WorkingDays))
                            {
                                rd.HasError = true;
                                rd.ErrorDescription += " Sum of Stockout and Instrument Downtime can not be greater than site working days";
                            }
                    }
                    catch
                    {
                    }
                    li.SubItems.Add(rd.ErrorDescription.ToString());
                    //add to forecast site product
                    if (!rd.HasError && _forecastInfo.DatausageEnum != DataUsageEnum.DATA_USAGE3)
                    {

                        ForecastSiteProduct fp = new ForecastSiteProduct();
                        fs = _forecastInfo.GetForecastSiteBySiteId(rd.Site.Id);

                        if (fs == null)
                        {
                            fs = new ForecastSite();
                            fs.Site = rd.Site;
                            fs.ForecastInfo = _forecastInfo;
                            _forecastInfo.ForecastSites.Add(fs);
                        }
                        fp.ForecastSite = fs;
                        fp.Product = rd.Product;
                        if (!LqtUtil.IsDateTime(rd.Duration))
                        {
                            fp.CDuration = rd.Duration;
                            fp.DurationDateTime = LqtUtil.DurationToDateTime(rd.Duration);

                        }
                        else
                        {
                            fp.DurationDateTime = DateTime.Parse(rd.Duration);
                            fp.CDuration = LqtUtil.DatetimeToDurationStr(_forecastInfo.PeriodEnum, DateTime.Parse(rd.Duration));
                        }
                        fp.AmountUsed = rd.Amount;
                        fp.StockOut = rd.StockOut;
                        fp.InstrumentDowntime = rd.InstrumentDownTime;//b
                        if (fp.StockOut > 0)
                        {
                            int days = fp.StockOut;
                            decimal workingday = GetActiveSiteWorkingDays(fp);

                            if (days >= workingday)
                            {
                                days = 0;
                                fp.StockOut = 0;
                            }
                            if (days >= 0)
                                fp.StockOut = days;
                        }

                        foreach (ForecastSiteProduct efsp in existingFsp)
                        {
                            isduplicate = false;
                            if (fp.ForecastSite.Site.Region == efsp.ForecastSite.Site.Region)
                                if (fp.ForecastSite.Site == efsp.ForecastSite.Site)
                                    if (fp.Product == efsp.Product && fp.DurationDateTime == efsp.DurationDateTime)
                                    { isduplicate = true; break; }
                        }
                        foreach (ForecastSiteProduct fsp in fs.SiteProducts)
                        {
                            isduplicate = false;
                            if (fp.ForecastSite.Site.Region == fsp.ForecastSite.Site.Region)
                                if (fp.ForecastSite.Site == fsp.ForecastSite.Site)
                                    if (fp.Product == fsp.Product && fp.DurationDateTime == fsp.DurationDateTime)
                                    { isduplicate = true; break; }
                        }
                        if (!isduplicate)
                            fs.SiteProducts.Add(fp);
                    }

                    //end adding

                    //add by category
                    if (!rd.HasError && _forecastInfo.DatausageEnum == DataUsageEnum.DATA_USAGE3)
                    {
                            ForecastCategory fcat = new ForecastCategory();
                         ForecastCategoryProduct fp = new ForecastCategoryProduct();
                         fcat = _forecastInfo.GetForecastCategorybyname(rd.CategoryName);
                         if (fcat== null)
                         {
                             fcat = new ForecastCategory();
                             fcat.CategoryName = rd.CategoryName;
                             fcat.ForecastInfo = _forecastInfo;
                             _forecastInfo.ForecastCategories.Add(fcat);
                         }

                        fp = fcat.GetFCatProduct(rd.Product.Id, rd.Duration);
                        isduplicate = false;

                        if (fp == null)
                            fp = new ForecastCategoryProduct();
                        else
                            isduplicate = true;

                        fp.Category = fcat;
                        fp.Product = rd.Product;

                        fp.AmountUsed = rd.Amount;
                        fp.StockOut = rd.StockOut;
                        fp.InstrumentDowntime = rd.InstrumentDownTime;//b

                        if (!LqtUtil.IsDateTime(rd.Duration))
                        {
                            fp.DurationDateTime = LqtUtil.DurationToDateTime(rd.Duration);
                            fp.CDuration = rd.Duration;
                        }
                        else
                        {
                            fp.DurationDateTime = DateTime.Parse(rd.Duration);
                            fp.CDuration = LqtUtil.DatetimeToDurationStr(_forecastInfo.PeriodEnum, DateTime.Parse(rd.Duration));
                        }

                        if (fp.StockOut > 0)
                        {
                            int days = fp.StockOut;
                            decimal workingday = 22;

                            if (days >= workingday)
                            {
                                days = 0;
                                fp.StockOut = 0;
                            }
                            if (days >= 0)
                                fp.StockOut = days;
                        }
                        if (!isduplicate)
                            fcat.CategoryProducts.Add(fp);
                    }
                    //end category adding
                    if (rd.HasError)
                    {
                        li.BackColor = Color.Red;
                        _error++;
                    }
                    else if (isduplicate)
                    {
                        li.BackColor = Color.Yellow;
                        _error++;
                    }
                    else
                    {
                        _count++;
                    }

                    lvImport.Items.Add(li);
                }
                sort();
                lvImport.EndUpdate();

                butClear.Enabled = true;
                butSave.Enabled = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: " + ex.Message, "Importing", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }