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;
        }
        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;
        }
Beispiel #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);
                }
                _selectedTestids = fsite.GetSelectedTestId();

                int month = _forecastInfo.StartDate.Month;

                foreach (ListViewItem l in lvTests.SelectedItems)
                {
                    int noperiod = NoRPeriod();
                    Test test = (Test)l.Tag;
                    if (!IsTestSelected(test.Id))
                    {
                        int year = _forecastInfo.StartDate.Year;
                        DateTime lastd = _forecastInfo.StartDate;
                        int quar = LqtUtil.GetQuarter(_forecastInfo.StartDate);
                        IList<ForecastSiteTest> historicalSiteProduct =
                 DataRepository.GetHistoricalTest(_forecastInfo.Period,_forecastInfo.Methodology, _forecastInfo.DataUsage, test.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.Monthly)
                            {
                                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)
                        {

                            AddForecastSiteHistory(test.Id, fsite.Site.Id, _forecastInfo.StartDate);
                        }

                        for (int x = 1; x <= noperiod; x++)
                        {
                            ForecastSiteTest sp = new ForecastSiteTest();
                            sp.Test = test;
                            sp.ForecastSite = fsite;
                            sp.AmountUsed = 1;
                            sp.Adjusted = 1;
                            int quartermonth = 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;
                            }
                            fsite.SiteTests.Add(sp);
                        }

                    }
                }

            }
        }
Beispiel #4
0
        public decimal GetActiveSiteWorkingDays(ForecastSiteTest fp)
        {
            decimal workingday = 22;

            switch (_forecastInfo.DatausageEnum)
            {
                case DataUsageEnum.DATA_USAGE1:
                case DataUsageEnum.DATA_USAGE2:
                    workingday = fp.ForecastSite.Site.WorkingDays;
                    break;
            }
            return workingday;
        }
Beispiel #5
0
        private void SaveAsSite()
        {
            bool isduplicate = false;
            ForecastSite fs =new ForecastSite();
            IList<ForecastSiteTest> exsistingFst = new List<ForecastSiteTest>();
            foreach (ForecastSite efs in _forecastInfo.ForecastSites)
            {
                foreach (ForecastSiteTest efst in efs.SiteTests)
                    exsistingFst.Add(efst);
            }
            foreach (ReportedData rd in _rdata)
            {
                if (!rd.HasError)
                {
                    ForecastSiteTest ft = new ForecastSiteTest();
                    fs = _forecastInfo.GetForecastSiteBySiteId(rd.Site.Id);

                    if (fs == null)
                    {
                        fs = new ForecastSite();
                        fs.Site = rd.Site;
                        fs.ForecastInfo = _forecastInfo;
                        _forecastInfo.ForecastSites.Add(fs);
                    }

                    ft.ForecastSite = fs;
                    ft.Test = rd.Test;
                    ft.CDuration = rd.Duration;
                    ft.AmountUsed = rd.Amount;
                    ft.StockOut = rd.StockOut;
                    ft.InstrumentDowntime = rd.InstrumentDownTime;//b
                    ft.Adjusted = rd.Amount;//b rd.Adjusted;
                    ft.DurationDateTime = LqtUtil.DurationToDateTime(ft.CDuration);
                    fs.SiteTests.Add(ft);
                    if (ft.AmountUsed == 0)
                    {
                        Consumption cs = GetConsumption(ft.Test.Id, ft);
                        if(cs.NoConsumption!=0)
                        ft.Adjusted = Math.Round(cs.TotalConsumption / cs.NoConsumption, 2, MidpointRounding.ToEven);
                    }
                    if (ft.StockOut > 0)
                    {
                        int days = ft.StockOut;
                        decimal workingday = GetActiveSiteWorkingDays(ft);

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

                    if ((ft.InstrumentDowntime > 0 || ft.StockOut > 0) && ft.AmountUsed > 0)
                        ft.Adjusted = LqtUtil.GetAdjustedVolume(ft.AmountUsed, ft.StockOut + ft.InstrumentDowntime, _forecastInfo.PeriodEnum, GetActiveSiteWorkingDays(ft));
                    foreach (ForecastSiteTest efst in exsistingFst)
                    {
                        isduplicate = false;
                        if (ft.ForecastSite.Site.Region == efst.ForecastSite.Site.Region)
                            if (ft.ForecastSite.Site == efst.ForecastSite.Site)
                                if (ft.Test == efst.Test && ft.DurationDateTime == efst.DurationDateTime)
                                { isduplicate = true; break; }
                    }
                    foreach (ForecastSiteTest fst in fs.SiteTests)
                    {
                        isduplicate = false;
                        if (ft.ForecastSite.Site.Region == fst.ForecastSite.Site.Region)
                            if (ft.ForecastSite.Site == fst.ForecastSite.Site)
                                if (ft.Test == fst.Test && ft.DurationDateTime == fst.DurationDateTime)
                                { isduplicate = true; break; }
                    }
                    if (!isduplicate)
                        fs.SiteTests.Add(ft);
                }
            }
        }
Beispiel #6
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);
                bool haserror = false;

                lvImport.BeginUpdate();
                lvImport.Items.Clear();

                ForecastSite fs = new ForecastSite();
                ForecastCategorySite fcatsite = new ForecastCategorySite();

                bool isduplicate = false;
                ForecastSite efs = new ForecastSite();//existing
                IList<ForecastSiteTest> existingFst = new List<ForecastSiteTest>();
                foreach (ForecastSite efss in _forecastInfo.ForecastSites)
                {
                    foreach (ForecastSiteTest efst in efss.SiteTests)
                        existingFst.Add(efst);
                }

                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.TestName);

                    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
                        {
                            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 = " Test Performed 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 test
                    if (!rd.HasError && _forecastInfo.DatausageEnum != DataUsageEnum.DATA_USAGE3)
                    {

                        ForecastSiteTest ft = new ForecastSiteTest();
                        fs = _forecastInfo.GetForecastSiteBySiteId(rd.Site.Id);

                        if (fs == null)
                        {
                            fs = new ForecastSite();
                            fs.Site = rd.Site;
                            fs.ForecastInfo = _forecastInfo;
                            _forecastInfo.ForecastSites.Add(fs);
                        }
                        ft.ForecastSite = fs;
                        ft.Test = rd.Test;
                        if (!LqtUtil.IsDateTime(rd.Duration))
                        {
                            ft.CDuration = rd.Duration;
                            ft.DurationDateTime = LqtUtil.DurationToDateTime(rd.Duration);
                        }
                        else
                        {
                            ft.CDuration = LqtUtil.DatetimeToDurationStr(_forecastInfo.PeriodEnum, DateTime.Parse(rd.Duration));
                            ft.DurationDateTime = DateTime.Parse(rd.Duration);
                        }
                        ft.AmountUsed = rd.Amount;
                        ft.StockOut = rd.StockOut;
                        ft.InstrumentDowntime = rd.InstrumentDownTime;//b
                        ft.Adjusted = rd.Amount;

                        if (ft.StockOut > 0)
                        {
                            int days = ft.StockOut;
                            decimal workingday = GetActiveSiteWorkingDays(ft);

                            if (days >= workingday)
                            {
                                days = 0;
                                ft.StockOut = 0;
                            }
                            if (days >= 0)
                                ft.StockOut = days;
                        }
                        foreach (ForecastSiteTest efst in existingFst)
                        {
                            isduplicate = false;
                            if (ft.ForecastSite.Site.Region == efst.ForecastSite.Site.Region)
                                if (ft.ForecastSite.Site == efst.ForecastSite.Site)
                                    if (ft.Test == efst.Test && ft.DurationDateTime == efst.DurationDateTime)
                                    { isduplicate = true; break; }
                        }
                        foreach (ForecastSiteTest fst in fs.SiteTests)
                        {
                            isduplicate = false;
                            if (ft.ForecastSite.Site.Region == fst.ForecastSite.Site.Region)
                                if (ft.ForecastSite.Site == fst.ForecastSite.Site)
                                    if (ft.Test == fst.Test && ft.DurationDateTime == fst.DurationDateTime)
                                    { isduplicate = true; break; }
                        }
                        if (!isduplicate)
                            fs.SiteTests.Add(ft);
                    }
                    //end adding

                    //add by category
                    if (!rd.HasError && _forecastInfo.DatausageEnum == DataUsageEnum.DATA_USAGE3)
                    {
                        ForecastCategory fcat = new ForecastCategory();
                        ForecastCategoryTest ft = new ForecastCategoryTest();
                       // fcat = DataRepository.GetForecastCategoryByName(_forecastInfo.Id, rd.CategoryName);
                        fcat = _forecastInfo.GetForecastCategorybyname(rd.CategoryName);
                        if (fcat == null)
                        {
                            fcat = new ForecastCategory();
                            fcat.CategoryName = rd.CategoryName;
                            fcat.ForecastInfo = _forecastInfo;
                            _forecastInfo.ForecastCategories.Add(fcat);
                        }

                         ft = fcat.GetFCatTest(rd.Test.Id, rd.Duration);
                        isduplicate = false;

                        if (ft == null)
                            ft = new ForecastCategoryTest();
                        else
                            isduplicate = true;

                        ft.Category = fcat;
                        ft.Test = rd.Test;
                    //    ft.CDuration = rd.Duration;
                        ft.AmountUsed = rd.Amount;
                        ft.StockOut = rd.StockOut;
                        ft.InstrumentDowntime = rd.InstrumentDownTime;//b
                       // ft.Adjusted = rd.Adjusted;
                    //    ft.DurationDateTime = LqtUtil.DurationToDateTime(ft.CDuration);
                        if (!LqtUtil.IsDateTime(rd.Duration))
                        {
                            ft.CDuration = rd.Duration;
                            ft.DurationDateTime = LqtUtil.DurationToDateTime(rd.Duration);
                        }
                        else
                        {
                            ft.CDuration = LqtUtil.DatetimeToDurationStr(_forecastInfo.PeriodEnum, DateTime.Parse(rd.Duration));
                            ft.DurationDateTime = DateTime.Parse(rd.Duration);
                        }

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

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

                        if (!isduplicate)
                            fcat.CategoryTests.Add(ft);

                    }
                    //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);
            }
        }
Beispiel #7
0
 public Consumption GetConsumption(int id, ForecastSiteTest fp)
 {
     Consumption con = null;
     switch (_forecastInfo.DatausageEnum)
     {
         case DataUsageEnum.DATA_USAGE1:
         case DataUsageEnum.DATA_USAGE2:
             con = fp.ForecastSite.ConsumptionByTest(id);
             break;
         case DataUsageEnum.DATA_USAGE3:
             con = fp.ForecastSite.ConsumptionByTest(id);
             break;
     }
     return con;
 }