Exemple #1
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);
            }
        }
Exemple #2
0
 public int CompareTo(object obj)
 {
     if (obj is ChartXYValue)
     {
         ChartXYValue chartXYValue = (ChartXYValue)obj;
         return(LqtUtil.DurationToDateTime(this.XValue).CompareTo(LqtUtil.DurationToDateTime(chartXYValue.XValue)));
         //return 1;
     }
     throw new ArgumentException("This object is not of type ChartXYValue");
 }
Exemple #3
0
        // This method is inherited from the IComparer interface.
        // It compares the two objects passed using a case
        // insensitive comparison.
        //
        // x: First object to be compared
        // y: Second object to be compared
        //
        // The result of the comparison. "0" if equal,
        // negative if 'x' is less than 'y' and
        // positive if 'x' is greater than 'y'
        public int Compare(object x, object y)
        {
            int          compareResult;
            ListViewItem listviewX, listviewY;

            // Cast the objects to be compared to ListViewItem objects
            listviewX = (ListViewItem)x;
            listviewY = (ListViewItem)y;

            // Determine whether the type being compared is a date type.
            try
            {
                // Parse the two objects passed as a parameter as a DateTime.
                System.DateTime firstDate =
                    LqtUtil.DurationToDateTime(listviewX.SubItems[ColumnToSort].Text);
                // DateTime f = LqtUtil.DurationToDateTime(listviewX.SubItems[ColumnToSort].Text);
                System.DateTime secondDate =
                    LqtUtil.DurationToDateTime(listviewY.SubItems[ColumnToSort].Text);
                // DateTime.Parse(listviewY.SubItems[ColumnToSort].Text);

                // Compare the two dates.
                compareResult = DateTime.Compare(firstDate, secondDate);
            }

            // If neither compared object has a valid date format,
            // perform a Case Insensitive Sort
            catch
            {
                // Case Insensitive Compare
                compareResult = ObjectCompare.Compare(
                    listviewX.SubItems[ColumnToSort].Text,
                    listviewY.SubItems[ColumnToSort].Text
                    );
            }

            // Calculate correct return value based on object comparison
            if (OrderOfSort == SortOrder.Ascending)
            {
                // Ascending sort is selected, return normal result of compare operation
                return(compareResult);
            }
            else if (OrderOfSort == SortOrder.Descending)
            {
                // Descending sort is selected, return negative result of compare operation
                return(-compareResult);
            }
            else
            {
                // Return '0' to indicate they are equal
                return(0);
            }
        }
Exemple #4
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);
                    }
                }
            }
        }
Exemple #5
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);
            }
        }