Esempio n. 1
0
 //public static IList<ForecastSite> GetAllForecasSite()
 //{
 //    return DaoFactory.GetDaoFactory()().GetAll();
 //}
 //public static  GetById(int id)
 //{
 //    return DaoFactory.GetDaoFactory()().GetById(id);
 //}
 public static void SaveOrUpdateForecastSite(ForecastSite fsite)
 {
     DaoFactory.GetDaoFactory().CreateForecastSiteDao().SaveOrUpdate(fsite);
 }
Esempio n. 2
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);
            }
        }
Esempio n. 3
0
 public static void DeleteForecastSite(ForecastSite t)
 {
     DaoFactory.GetDaoFactory().CreateForecastSiteDao().Delete(t);
 }
Esempio n. 4
0
        public bool AddNoneReportedSite()
        {
            // FrmSelectSite frm = new FrmSelectSite(_activeFSite.GetSelectedNRSiteId(), _sites);
            FrmSelectSite frm = new FrmSelectSite(_forecastInfo.GetSelectedSiteId(), _sites);//b it Filters N.R site and Reported Site
            if (frm.ShowDialog() == DialogResult.OK)
            {
                foreach (int siteid in frm.SelectedSiteIds)
                {
                    ForecastNRSite fc = new ForecastNRSite();
                    fc.NReportedSite = DataRepository.GetSiteById(siteid);
                    fc.ForecastSite = _activeFSite;

                    _activeFSite.NoneReportedSites.Add(fc);

                    ForecastSite fs = new ForecastSite();
                    fs.Site = fc.NReportedSite;
                    fs.ForecastInfo = _forecastInfo;
                    fs.ReportedSiteId = _activeFSite.Id;

                    CopySiteProduct(_activeFSite, fs);

                    _forecastInfo.ForecastSites.Add(fs);
                }

                OnForecastInfoDataChanged();
                return true;
            }
            return false;
        }
Esempio n. 5
0
        public bool AddSiteToForecast()
        {
            FrmSelectSite frm = new FrmSelectSite(_forecastInfo.GetSelectedSiteId(), _sites);
            if (frm.ShowDialog() == DialogResult.OK)
            {
                foreach (int siteid in frm.SelectedSiteIds)
                {
                    ForecastSite fc = new ForecastSite();
                    fc.Site = DataRepository.GetSiteById(siteid);
                    fc.ForecastInfo = _forecastInfo;

                    _forecastInfo.ForecastSites.Add(fc);
                }
                OnForecastInfoDataChanged();
                return true;
            }
            return false;
        }
Esempio n. 6
0
 private void CopySiteProduct(ForecastSite source, ForecastSite destination)
 {
     if (_forecastInfo.FMethodologeyEnum == MethodologyEnum.CONSUMPTION)
     {
         foreach (IBaseDataUsage fp in source.SiteProducts)
         {
             ForecastSiteProduct fc = (ForecastSiteProduct)GetCloneForecastSiteProduct(fp);
             fc.ForecastSite = destination;
             destination.SiteProducts.Add(fc);
         }
     }
     else
     {
         foreach (IBaseDataUsage fp in source.SiteTests)
         {
             ForecastSiteTest ft = (ForecastSiteTest)GetCloneForecastSiteProduct(fp);
             ft.ForecastSite = destination;
             destination.SiteTests.Add(ft);
         }
     }
 }
Esempio n. 7
0
        private void lbtAddsite_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            int len = lvSiteAll.SelectedItems.Count;

            for (int i = 0; i < len; i++)
            {
                int siteid = (int)lvSiteAll.SelectedItems[i].Tag;
                ForecastSite fs = new ForecastSite();
                fs.Site = DataRepository.GetSiteById(siteid);
                fs.ForecastInfo = _forecastInfo;

                _forecastInfo.ForecastSites.Add(fs);
            }

            BindSites();
            BindForecastSite();
        }
Esempio n. 8
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);
            }
        }
Esempio n. 9
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);
            }
        }
Esempio n. 10
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);
                }
            }
        }