예제 #1
0
        public void BuildMeapResultView(IList <MAPEResult> maperesult, ForecastInfo finfo)
        {
            DataTable Maper = new DataTable();


            IEnumerable <MAPEResult> sortedMAPE     = maperesult.OrderBy(meap => meap.DurationDateTime);
            IList <MAPEResult>       sortedMAPEList = sortedMAPE.ToList();

            Maper = LqtUtil.ToDataTable <MAPEResult>(CorrectMapeResultDates(sortedMAPEList, finfo));
            string x = "";
            string y = "";
            string z = "";

            if (finfo.FMethodologeyEnum == MethodologyEnum.CONSUMPTION)
            {
                y = Maper.Columns[4].ColumnName;//product
            }
            else
            {
                y = Maper.Columns[3].ColumnName; //test
            }
            x = Maper.Columns[11].ColumnName;    //duration

            z = Maper.Columns[8].ColumnName;     //mape percentage value

            DataTable newDt = new DataTable();

            newDt = PivotTable.GetInversedDataTable(Maper, x, y, z, "-", false);

            gdvmeapresult.DataSource = newDt;
        }
예제 #2
0
        public void GenerateHelp()
        {
            try
            {

                using (FileStream fs = new FileStream(LqtUtil.GetFolderPath(AppSettings.ExportPath) + "\\ForLAB.chm", FileMode.Create))
                {
                    Stream xstream = Assembly.GetExecutingAssembly().GetManifestResourceStream("LQT.GUI.Resources.ForLAB.chm");

                    byte[] b = new byte[xstream.Length + 1];
                    xstream.Read(b, 0, Convert.ToInt32(xstream.Length));

                    fs.Write(b, 0, Convert.ToInt32(b.Length - 1));
                    fs.Flush();
                    fs.Close();


                }

            }
            catch
            {
                MessageBox.Show("Access Denied. ", "Generate Help File", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
예제 #3
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);
            }
        }
예제 #4
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");
 }
예제 #5
0
        //public void ExcelHeaderFormatt(Excel.Range unicell)
        //{
        //    unicell.Font.Color = System.Drawing.ColorTranslator.ToOle(Color.White);
        //    unicell.Interior.Color = System.Drawing.ColorTranslator.ToOle(Color.Gray);
        //    unicell.Font.Bold = true;
        //    unicell.BorderAround(Excel.XlLineStyle.xlContinuous, Excel.XlBorderWeight.xlThin, Excel.XlColorIndex.xlColorIndexAutomatic, 1);
        //}

        private void showHelp()
        {
            string path = LqtUtil.GetFolderPath(AppSettings.ExportPath);
            if (!File.Exists(path + "\\ForLAB.chm"))
            {
                GenerateHelp();
            }
            path = "file://" + Path.Combine(path, "ForLAB.chm");

            Help.ShowHelp(this, path);
        }
예제 #6
0
 private static void CreateChemistryTestQM(MorbidityTest _morbidityTest)
 {
     ChemistryTestNameEnum[] chem = LqtUtil.EnumToArray <ChemistryTestNameEnum>();
     for (int i = 0; i < chem.Length; i++)
     {
         QuantifyMenu qmenuTest = CreateNewQMenu(_morbidityTest);
         qmenuTest.ChemTestName = chem[i].ToString();
         qmenuTest.Title        = String.Format("{0} Tests - {1}", chem[i], _morbidityTest.Instrument.InstrumentName);
         qmenuTest.TestType     = TestTypeEnum.Test.ToString();
         _morbidityTest.QuantifyMenus.Add(qmenuTest);
     }
 }
예제 #7
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);
            }
        }
예제 #8
0
 private void UpdateAdjustment()
 {
     if (_forecastInfo.DatausageEnum == DataUsageEnum.DATA_USAGE1 || _forecastInfo.DatausageEnum == DataUsageEnum.DATA_USAGE2)
     {
         foreach (ForecastSite fs in _forecastInfo.ForecastSites)
         {
             foreach (ForecastSiteTest ft in fs.SiteTests)
             {
                 ft.Adjusted = ft.AmountUsed;
                 if (ft.AmountUsed == 0)
                 {
                     try
                     {
                         Consumption cs = GetConsumption(ft.Test.Id, ft);
                         ft.Adjusted = Math.Round(cs.TotalConsumption / cs.NoConsumption, 2, MidpointRounding.ToEven);
                     }
                     catch
                     {
                         ft.Adjusted = ft.AmountUsed;
                     }
                 }
                 if ((ft.InstrumentDowntime > 0 || ft.StockOut > 0) && ft.AmountUsed > 0)
                 {
                     ft.Adjusted = LqtUtil.GetAdjustedVolume(ft.AmountUsed, ft.StockOut + ft.InstrumentDowntime, _forecastInfo.PeriodEnum, GetActiveSiteWorkingDays(ft));    //b
                 }
             }
         }
     }
     else
     {
         foreach (ForecastCategory fc in _forecastInfo.ForecastCategories)
         {
             foreach (ForecastCategoryTest ft in fc.CategoryTests)
             {
                 ft.Adjusted = ft.AmountUsed;
                 if (ft.AmountUsed == 0)
                 {
                     try
                     {
                         Consumption cs = GetConsumption(ft.Product.Id, ft);
                         ft.Adjusted = Math.Round(cs.TotalConsumption / cs.NoConsumption, 2, MidpointRounding.ToEven);
                     }
                     catch { ft.Adjusted = ft.AmountUsed; }
                 }
                 if ((ft.InstrumentDowntime > 0 || ft.StockOut > 0) && ft.AmountUsed > 0)
                 {
                     ft.Adjusted = LqtUtil.GetAdjustedVolume(ft.AmountUsed, ft.StockOut + ft.InstrumentDowntime, _forecastInfo.PeriodEnum, 22);//b
                 }
             }
         }
     }
 }
예제 #9
0
        public void SetDefaultDate()
        {
            if (_popQuarter)
            {
                comMonth.SelectedText = _quarter[LqtUtil.GetQuarter(DateTime.Now) - 1].ToString();
                comMonth.Text         = _quarter[LqtUtil.GetQuarter(DateTime.Now) - 1].ToString();
            }
            else
            {
                comMonth.SelectedText = GetMonths(DateTime.Now.Month);
                comMonth.Text         = GetMonths(DateTime.Now.Month);
            }

            comYear.SelectedText = DateTime.Now.Year.ToString();
            comYear.Text         = DateTime.Now.Year.ToString();

            if (_disableMonthcom)
            {
                comMonth.Items.Clear();
            }
        }
예제 #10
0
        public IList <MAPEResult> CorrectMapeResultDates(IList <MAPEResult> maperesults, ForecastInfo finfo)
        {
            foreach (MAPEResult maperesult in maperesults)
            {
                DateTime date = new DateTime();
                if (maperesult.DurationDateTime.Day > 28)
                {
                    if (maperesult.DurationDateTime.Month == 12)
                    {
                        date = new DateTime(maperesult.DurationDateTime.Year + 1, 1, 01);
                    }
                    else
                    {
                        date = new DateTime(maperesult.DurationDateTime.Year, maperesult.DurationDateTime.Month + 1, 01);
                    }
                }
                else
                {
                    date = maperesult.DurationDateTime;
                }
                string duration = date.ToShortDateString();

                if (finfo.PeriodEnum == ForecastPeriodEnum.Bimonthly || finfo.PeriodEnum == ForecastPeriodEnum.Monthly)
                {
                    duration = date.ToString("MMMM-yyyy");
                }
                if (finfo.PeriodEnum == ForecastPeriodEnum.Quarterly)
                {
                    duration = "Qua" + LqtUtil.GetQuarter(date).ToString() + "-" + date.Year.ToString();
                }
                if (finfo.PeriodEnum == ForecastPeriodEnum.Yearly)
                {
                    duration = date.Year.ToString();
                }

                maperesult.Duration = duration;
            }
            return(maperesults);
        }
예제 #11
0
        private void lnkexporttoexcel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            Excel.Application xlApp;
            Excel.Workbook    xlWorkBook;
            Excel.Worksheet   xlWorkSheet;
            object            misValue = System.Reflection.Missing.Value;

            xlApp       = new Excel.ApplicationClass();
            xlWorkBook  = xlApp.Workbooks.Add(misValue);
            xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
            int i = 0;
            int j = 0;

            Excel.Range cells = xlWorkSheet.Cells;

            for (i = 1; i <= gdvmeapresult.ColumnCount; i++)
            {
                string column = gdvmeapresult.Columns[i - 1].Name;
                xlWorkSheet.Cells[2, i + 1] = column;
                cells                = (Excel.Range)xlWorkSheet.Cells[2, i + 1];
                cells.Font.Bold      = true;
                cells.Borders.Weight = Excel.XlBorderWeight.xlMedium;
                cells.ColumnWidth    = 15;
            }

            for (i = 2; i <= gdvmeapresult.RowCount + 1; i++)
            {
                for (j = 2; j <= gdvmeapresult.ColumnCount + 1; j++)
                {
                    DataGridViewCell cell = gdvmeapresult[j - 2, i - 2];
                    xlWorkSheet.Cells[i + 1, j] = Convert.ToString(cell.Value);

                    ////format cells
                    if (j > 2)
                    {
                        Color bgc = Color.Pink;
                        Color fgc = Color.Black;
                        if (cell.Value.ToString() == "-")//data not available
                        {
                            bgc = Color.Gray;
                        }
                        else
                        {
                            decimal mapevalue = decimal.Parse(cell.Value.ToString());
                            if (mapevalue > 25)
                            {
                                bgc = Color.Red; //Color.Black;//(204, 51, 51);
                            }
                            if (mapevalue < -25)
                            {
                                bgc = Color.Blue;//(114, 154, 210);
                            }
                            if (mapevalue <= 25 && mapevalue >= -25)
                            {
                                bgc = Color.White;
                            }
                        }

                        ((Excel.Range)xlWorkSheet.Cells[i + 1, j]).Interior.Color = System.Drawing.ColorTranslator.ToOle(bgc);
                        ((Excel.Range)xlWorkSheet.Cells[i + 1, j]).Font.Color     = System.Drawing.ColorTranslator.ToOle(fgc);
                    }
                    ((Excel.Range)xlWorkSheet.Cells[i + 1, j]).Borders.Weight = Excel.XlBorderWeight.xlThin;
                    //end cell format
                }
            }


            //last row range
            Excel.Range range = xlWorkSheet.get_Range(xlWorkSheet.Cells[i + 1, 2], xlWorkSheet.Cells[i + 1, gdvmeapresult.ColumnCount + 1]);
            range.Merge(true);
            range.RowHeight             = 40;
            range.WrapText              = true;
            xlWorkSheet.Cells[i + 1, 2] = "Note: Red represents underforecasts (>25%), Blue represents overforecasts (<-25%)," +
                                          "Gray represents insufficient data to complete the forecast, and no field color represents an accurate forecast, within 25%.";

            //header
            Excel.Range header = xlWorkSheet.get_Range(xlWorkSheet.Cells[1, 1], xlWorkSheet.Cells[1, 1]);
            header = header.EntireRow;
            for (int no = 0; no < 5; no++)
            {
                header.Insert(Excel.XlInsertShiftDirection.xlShiftDown, misValue);
            }

            header       = xlWorkSheet.get_Range(xlWorkSheet.Cells[2, 2], xlWorkSheet.Cells[2, gdvmeapresult.ColumnCount + 1]);
            header.Value = "Forecast MAPE Result";
            header.Merge(true);
            header.Font.Underline      = true;
            header.Font.Bold           = true;
            header.HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;
            header.RowHeight           = 40;
            header.VerticalAlignment   = Excel.XlVAlign.xlVAlignCenter;


            xlWorkSheet.Cells[3, 2] = "Forecast Id : ";
            xlWorkSheet.Cells[3, 3] = forecastInfo.ForecastNo;
            xlWorkSheet.Cells[3, 4] = "Methodology : ";
            xlWorkSheet.Cells[3, 5] = forecastInfo.Methodology;
            xlWorkSheet.Cells[3, 6] = "Wastage % : ";
            xlWorkSheet.Cells[3, 7] = forecastInfo.Westage.ToString();

            xlWorkSheet.Cells[4, 2] = "Start Date : ";
            xlWorkSheet.Cells[4, 3] = forecastInfo.StartDate.ToShortDateString();
            xlWorkSheet.Cells[4, 4] = "Data Usage : ";
            xlWorkSheet.Cells[4, 5] = forecastInfo.DataUsage;
            xlWorkSheet.Cells[4, 6] = "Add By % : ";
            xlWorkSheet.Cells[4, 7] = forecastInfo.Scaleup.ToString();

            xlWorkSheet.Cells[5, 2] = "Period : ";
            xlWorkSheet.Cells[5, 3] = forecastInfo.Period;
            xlWorkSheet.Cells[5, 4] = "Regression Type : ";
            xlWorkSheet.Cells[5, 5] = forecastInfo.Method;
            xlWorkSheet.Cells[5, 6] = "Extension Period : ";
            xlWorkSheet.Cells[5, 7] = forecastInfo.Extension.ToString();

            //header end

            saveFileDialog1.FileName = forecastInfo.ForecastNo + ".xls";
            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                xlWorkBook.SaveAs(saveFileDialog1.FileName, Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);
                xlWorkBook.Close(true, misValue, misValue);
                xlApp.Quit();

                LqtUtil.releaseObject(xlWorkSheet);
                LqtUtil.releaseObject(xlWorkBook);
                LqtUtil.releaseObject(xlApp);
                MessageBox.Show("Exported Successfully!");
            }
        }
예제 #12
0
        private void BuildTestMenu(TreeNode parentNode)
        {
            IList <TestingArea> list = DataRepository.GetAllTestingArea();

            //added just for this build will be optimized later on
            IList <TestingGroup> listtg = DataRepository.GetAllTestingGroup();
            IList <Test>         listtc = DataRepository.GetAllTests();

            TreeNode rootNode = new TreeNode("Test Profile");

            rootNode.Tag                = MainMenuTag.TEST.ToString();
            rootNode.ImageIndex         = 2;
            rootNode.SelectedImageIndex = 2;

            TreeNode tareaNode = new TreeNode("Testing Areas [" + list.Count + "]");

            tareaNode.Tag                = MainMenuTag.TEST.ToString() + "|" + -1;
            tareaNode.ImageIndex         = 3;
            tareaNode.SelectedImageIndex = 3;
            rootNode.Nodes.Add(tareaNode);

            TreeNode tgroupNode = new TreeNode("Testing Groups [" + listtg.Count + "]");

            tgroupNode.Tag                = MainMenuTag.TEST.ToString() + "|" + -2;
            tgroupNode.ImageIndex         = 4;
            tgroupNode.SelectedImageIndex = 4;
            rootNode.Nodes.Add(tgroupNode);

            TreeNode testNode = new TreeNode("Tests [" + listtc.Count + "]");

            testNode.Tag                = MainMenuTag.TEST.ToString() + "|" + -3;
            testNode.ImageIndex         = 5;
            testNode.SelectedImageIndex = 5;



            foreach (TestingArea ta in list)
            {
                if (!ta.UseInDemography)
                {
                    TreeNode node = new TreeNode(ta.AreaName);
                    node.Tag                = MainMenuTag.TEST.ToString() + "|-4|" + ta.Id;
                    node.ImageIndex         = 3;
                    node.SelectedImageIndex = 3;
                    AddTestingGroupToMenu(node, ta.TestingGroups);
                    testNode.Nodes.Add(node);
                }
            }
            rootNode.Nodes.Add(testNode);

            ClassOfMorbidityTestEnum[] mtestEnums = LqtUtil.EnumToArray <ClassOfMorbidityTestEnum>();
            TreeNode artNode = new TreeNode("ART Tests");

            artNode.Tag                = MainMenuTag.TEST.ToString() + "|" + -6;
            artNode.ImageIndex         = 5;
            artNode.SelectedImageIndex = 5;


            for (int i = 0; i < mtestEnums.Length; i++)
            {
                ClassOfMorbidityTestEnum cm = mtestEnums[i];
                TreeNode node = new TreeNode(cm.ToString());
                node.Tag                = MainMenuTag.TEST.ToString() + "|-6|" + (int)cm;
                node.ImageIndex         = 4;
                node.SelectedImageIndex = 4;
                //AddTestingGroupToMenu(node, ta.TestingGroups);
                artNode.Nodes.Add(node);
            }

            rootNode.Nodes.Add(artNode);
            //rootNode.Expand();
            parentNode.Nodes.Add(rootNode);
            //treeViewNav.Nodes.Add(rootNode);
        }
예제 #13
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);
                    }
                }
            }
        }
예제 #14
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);
            }
        }
예제 #15
0
        private void ProcessByCategory()
        {
            foreach (ListViewItem li in lsvSites.CheckedItems)
            {
                ForecastCategory fcat = (ForecastCategory)li.Tag;
                _selectedProductids = fcat.GetSelectedProductId();

                int month = _forecastInfo.StartDate.Month;

                foreach (ListViewItem l in lvProductAll.SelectedItems)
                {
                    MasterProduct pro = (MasterProduct)l.Tag;
                    if (!IsTestSelected(pro.Id))
                    {
                        int      year  = _forecastInfo.StartDate.Year;
                        int      quar  = LqtUtil.GetQuarter(_forecastInfo.StartDate);
                        DateTime lastd = _forecastInfo.StartDate;

                        int quartermonth = 1;
                        for (int x = 1; x <= NoRPeriod(); x++)
                        {
                            ForecastCategoryProduct sp = new ForecastCategoryProduct();
                            sp.Product    = pro;
                            sp.Category   = fcat;
                            sp.AmountUsed = 1;
                            sp.Adjusted   = 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;
                            }
                            fcat.CategoryProducts.Add(sp);
                        }
                    }
                }
                // _forecastInfo.ForecastSites.Add(fsite);
            }
        }
예제 #16
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);
            }
        }