Example #1
0
 public static void SaveOrUpdateForecastCategory(ForecastCategory fcategory)
 {
     DaoFactory.GetDaoFactory().CreateForecastCategoryDao().SaveOrUpdate(fcategory);
 }
Example #2
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);
            }
        }
Example #3
0
        private void butAddnew_Click(object sender, EventArgs e)
        {
            ForecastCategory cat = new ForecastCategory();
            cat.ForecastInfo = _forecastInfo;
            cat.CategoryName = txtCatname.Text.Trim();
            if (cat.CategoryName != "")//b
            {
                ForecastCategory catagory = DataRepository.GetForecastCategoryByName(_forecastInfo.Id, cat.CategoryName);//b
                if (catagory != null)//b
                {
                    MessageBox.Show("Duplicate Category.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                else
                {
                    for(int i=0;i<lvCategory.Items.Count;)
                    {
                        if (lvCategory.Items[i].Text.Trim() == txtCatname.Text.Trim())
                        {
                            MessageBox.Show("Duplicate Category.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }
                        else i++;
                    }

                    _forecastInfo.ForecastCategories.Add(cat);

                    _activeCategory = cat;
                    _newCatIndex = lvCategory.Items.Count;
                    BindCategorys();
                    BindForecastCategory();
                    BindForecastSite();
                    BindForecastProduct();
                    ShowSummary();//b

                  }
            }
            else
            {
                MessageBox.Show("Category Name Can not be Empty.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
        }
Example #4
0
        private void SaveAsCategory()
        {
            foreach (ReportedData rd in _rdata)
            {
                ForecastCategory fcat = rd.Category;

                if (fcat == null)
                {
                    fcat = new ForecastCategory();
                    fcat.CategoryName = rd.CategoryName;
                    fcat.ForecastInfo = _forecastInfo;
                    _forecastInfo.ForecastCategories.Add(fcat);
                }

                ForecastCategoryTest fp = fcat.GetFCatTest(rd.Test.Id, rd.Duration);

                if (fp == null)
                    fp = new ForecastCategoryTest();

                fp.Category = fcat;
                fp.Test = rd.Test;
                fp.CDuration = rd.Duration;
                fp.AmountUsed = rd.Amount;
                fp.StockOut = rd.StockOut;
                fp.InstrumentDowntime = rd.InstrumentDownTime;//b
                fp.Adjusted = rd.Amount;//b rd.Adjusted;
                fp.DurationDateTime = LqtUtil.DurationToDateTime(fp.CDuration);

                fcat.CategoryTests.Add(fp);
            }
        }