Ejemplo n.º 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);
            }
        }
Ejemplo n.º 2
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();
                    BindForecastTest();
                    ShowSummary();//b
                }
            }
            else
            {
                MessageBox.Show("Category Name Can not be Empty.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
        }
Ejemplo n.º 3
0
 public static void SaveOrUpdateForecastCategory(ForecastCategory fcategory)
 {
     DaoFactory.GetDaoFactory().CreateForecastCategoryDao().SaveOrUpdate(fcategory);
 }
Ejemplo n.º 4
0
        public static void GetPipeline(long?layoutId, long?pipelineId)
        {
            //Get instance of PipelineOperations Class
            PipelineOperations pipelineOperations = new PipelineOperations(layoutId);

            //Call GetPipeline method
            APIResponse <ResponseHandler> response = pipelineOperations.GetPipeline(pipelineId);

            if (response != null)
            {
                //Get the status code from response
                Console.WriteLine("Status Code: " + response.StatusCode);

                if (new List <int>()
                {
                    204, 304
                }.Contains(response.StatusCode))
                {
                    Console.WriteLine(response.StatusCode == 204 ? "No Content" : "Not Modified");

                    return;
                }

                //Check if expected response is received
                if (response.IsExpected)
                {
                    //Get object from response
                    ResponseHandler responseHandler = response.Object;

                    if (responseHandler is ResponseWrapper)
                    {
                        //Get the received ResponseWrapper instance
                        ResponseWrapper responseWrapper = (ResponseWrapper)responseHandler;

                        //Get the list of obtained Pipeline instances
                        List <Pipeline> pipelineList = responseWrapper.Pipeline;

                        foreach (Pipeline pipeline in pipelineList)
                        {
                            //Get the Id of each Pipeline
                            Console.WriteLine("Pipeline ID: " + pipeline.Id);

                            //Get the DisplayValue of each Pipeline
                            Console.WriteLine("Pipeline DisplayValue: " + pipeline.DisplayValue);

                            //Get the ActualValue of each Pipeline
                            Console.WriteLine("Pipeline Maps ActualValue: " + pipeline.ActualValue);

                            //Get the Default of each Pipeline
                            Console.WriteLine("Pipeline Default: " + pipeline.Default);

                            //Get the child available of each Pipeline
                            Console.WriteLine("Pipeline Child Available  : " + pipeline.ChildAvailable);

                            API.Pipeline.Pipeline parent = pipeline.Parent;

                            if (parent != null)
                            {
                                //Get the ID of  parent
                                Console.WriteLine("Pipeline parent ID: " + parent.Id);
                            }

                            List <PickListValue> maps = pipeline.Maps;

                            if (maps != null)
                            {
                                foreach (PickListValue map in maps)
                                {
                                    //Get the Maps ActualValue of each Pipeline
                                    Console.WriteLine("Pipeline Maps ActualValue: " + map.ActualValue);

                                    //Get PickListValue delete
                                    Console.WriteLine("PickListValue Delete" + map.Delete);

                                    //Get the Maps DisplayValue of each Pipeline
                                    Console.WriteLine("Pipeline Maps DisplayValue: " + map.DisplayValue);

                                    ForecastCategory forecastCategory = map.ForecastCategory;

                                    if (forecastCategory != null)
                                    {
                                        //Get the Maps ForecastCategory Name of each Pipeline
                                        Console.WriteLine("Pipeline Maps ForecastCategory Name: " + forecastCategory.Name);

                                        //Get the Maps ForecastCategory Id of each Pipeline
                                        Console.WriteLine("Pipeline Maps ForecastCategory Id: " + forecastCategory.Id);
                                    }

                                    //Get the Maps ForecastType of each Pipeline
                                    Console.WriteLine("Pipeline Maps ForecastType: " + map.ForecastType);

                                    //Get the Maps Id of each Pipeline
                                    Console.WriteLine("Pipeline Maps Id: " + map.Id);

                                    //Get the Maps SequenceNumber of each Pipeline
                                    Console.WriteLine("Pipeline Maps SequenceNumber: " + map.SequenceNumber);
                                }
                            }
                        }
                    }
                    //Check if the request returned an exception
                    else if (responseHandler is APIException)
                    {
                        //Get the received APIException instance
                        APIException exception = (APIException)responseHandler;

                        //Get the Status
                        Console.WriteLine("Status: " + exception.Status.Value);

                        //Get the Code
                        Console.WriteLine("Code: " + exception.Code.Value);

                        Console.WriteLine("Details: ");

                        //Get the details map
                        foreach (KeyValuePair <string, object> entry in exception.Details)
                        {
                            //Get each value in the map
                            Console.WriteLine(entry.Key + ": " + JsonConvert.SerializeObject(entry.Value));
                        }

                        //Get the Message
                        Console.WriteLine("Message: " + exception.Message.Value);
                    }
                }
                else
                { //If response is not as expected
                    //Get model object from response
                    Model responseObject = response.Model;

                    //Get the response object's class
                    Type type = responseObject.GetType();

                    //Get all declared fields of the response class
                    Console.WriteLine("Type is: {0}", type.Name);

                    PropertyInfo[] props = type.GetProperties();

                    Console.WriteLine("Properties (N = {0}):", props.Length);

                    foreach (var prop in props)
                    {
                        if (prop.GetIndexParameters().Length == 0)
                        {
                            Console.WriteLine("{0} ({1}) in {2}", prop.Name, prop.PropertyType.Name, prop.GetValue(responseObject));
                        }
                        else
                        {
                            Console.WriteLine("{0} ({1}) in <Indexed>", prop.Name, prop.PropertyType.Name);
                        }
                    }
                }
            }
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 6
0
        private IList <ReportedData> GetDataRow(DataSet ds)
        {
            string  categoryName = null;
            string  regionName;
            string  siteName;
            string  testName;
            string  duration;
            decimal amount;
            int     stockout;
            int     instrumentDownTime;
            decimal adjusited;
            int     rowno = 0;
            bool    haserror;
            string  cName = "";
            string  rName = "";
            string  sName = "";
            string  tName = "";

            ForecastCategory fcategory = null;
            ForlabRegion     region    = null;
            ForlabSite       site      = null;
            //MasterProduct product = null;
            Test   test                 = null;
            string errorDescription     = "";
            IList <ReportedData> rdlist = new List <ReportedData>();
            DataRow dr = ds.Tables[0].Rows[0];

            //foreach (DataRow dr in ds.Tables[0].Rows)
            //{
            for (int i = 1; i < ds.Tables[0].Rows.Count; i = i + 4)
            {
                rowno++;
                haserror = false;
                DataRow dr1 = ds.Tables[0].Rows[i];
                DataRow dr2 = ds.Tables[0].Rows[i + 1];
                DataRow dr3 = ds.Tables[0].Rows[i + 2];
                DataRow dr4 = ds.Tables[0].Rows[i + 3];
                DataRow g   = ds.Tables[0].Rows[0];
                // int colid = 0;
                int f = 3;
                int colid;  //0
                if (_forecastInfo.DatausageEnum == DataUsageEnum.DATA_USAGE3)
                {
                    colid = 3;
                }
                else
                {
                    colid = 4;
                }
                do
                {
                    regionName = "";
                    siteName   = "";

                    if (_forecastInfo.DatausageEnum == DataUsageEnum.DATA_USAGE3)
                    {
                        categoryName = Convert.ToString(dr1[0]).Trim(); //(dr[colid++])
                        testName     = Convert.ToString(dr1[1]).Trim(); //(dr[colid++])testName
                    }
                    else
                    {
                        regionName = Convert.ToString(dr1[0]).Trim(); //(dr[colid++]) region name
                        siteName   = Convert.ToString(dr1[1]).Trim(); //(dr[colid++]) site name
                        testName   = Convert.ToString(dr1[2]).Trim(); //(dr[colid++])testName
                    }


                    if (_forecastInfo.PeriodEnum != ForecastPeriodEnum.Monthly || _forecastInfo.PeriodEnum != ForecastPeriodEnum.Bimonthly)
                    {
                        duration = Convert.ToString(DateTime.FromOADate(Convert.ToDouble(dr[colid])));//(g[f]) Convert.ToString(dr[colid++]); //  reporting period(duration)
                    }
                    // f = f + 3;
                    else
                    {
                        duration = Convert.ToString(dr[colid]);
                    }

                    //duration = Convert.ToString(dr[colid++]); // reporting period(duration)

                    try
                    {
                        if (dr1[colid].ToString() == string.Empty)
                        {
                            amount = 0;
                        }
                        else
                        {
                            amount = Convert.ToDecimal(dr1[colid]); //amount
                        }
                        ///if (amount == 0)
                        //  haserror = true;
                    }
                    catch
                    {
                        haserror = true;
                        amount   = 0;
                    }
                    try
                    {
                        if (dr2[colid].ToString() == string.Empty)
                        {
                            stockout = 0;
                        }
                        else
                        {
                            stockout = Convert.ToInt32(dr2[colid]); //stock out
                        }
                    }
                    catch
                    {
                        haserror = true;
                        stockout = 0;
                    }
                    try
                    {
                        if (dr3[colid].ToString() == string.Empty)
                        {
                            instrumentDownTime = 0;
                        }
                        else
                        {
                            instrumentDownTime = Convert.ToInt32(dr3[colid]); //instrumentDownTime
                        }
                    }
                    catch
                    {
                        haserror           = true;
                        instrumentDownTime = 0;
                    }
                    //try
                    //{
                    //    adjusited = Convert.ToDecimal(dr[colid++]);     //adjusted
                    //}
                    //catch
                    //{
                    //    haserror = true;
                    adjusited = 0;
                    // }

                    ReportedData rd = null;

                    if (_forecastInfo.DatausageEnum == DataUsageEnum.DATA_USAGE3)
                    {
                        rd = new ReportedData(categoryName, rowno, testName, duration, amount, stockout, instrumentDownTime);
                        if (cName != categoryName)
                        {
                            if (!string.IsNullOrEmpty(categoryName))
                            {
                                fcategory = DataRepository.GetForecastCategoryByName(_forecastInfo.Id, categoryName);
                            }
                            else
                            {
                                fcategory = null;
                            }
                            cName = categoryName;
                        }

                        if (fcategory != null)
                        {
                            rd.Category = fcategory;
                        }
                        else
                        {
                            rd.HasError      = true;
                            errorDescription = errorDescription + " Category Doesn't Exist";
                        }
                    }
                    else
                    {
                        rd = new ReportedData(regionName, rowno, siteName, testName, duration, amount, stockout, instrumentDownTime);

                        if (rName != regionName)
                        {
                            if (!string.IsNullOrEmpty(regionName))
                            {
                                region = DataRepository.GetRegionByName(regionName);
                            }
                            else
                            {
                                region = null;
                            }
                            rName = regionName;
                        }

                        if (region != null)
                        {
                            rd.Region = region;
                            if (sName != siteName)
                            {
                                if (!string.IsNullOrEmpty(siteName))
                                {
                                    site = DataRepository.GetSiteByName(siteName, region.Id);
                                }
                                else
                                {
                                    site = null;
                                }
                                sName = siteName;
                            }
                            if (site != null)
                            {
                                rd.Site = site;
                            }
                            else
                            {
                                haserror         = true;
                                errorDescription = errorDescription + " Site Doesn't Exist";
                            }
                        }
                        else
                        {
                            haserror         = true;
                            errorDescription = errorDescription + " Region Doesn't Exist";
                        }
                    }



                    if (tName != testName)
                    {
                        if (!string.IsNullOrEmpty(testName))
                        {
                            test = DataRepository.GetTestByName(testName);
                        }
                        else
                        {
                            test = null;
                        }
                        tName = testName;
                    }

                    if (test != null)
                    {
                        rd.Test = test;
                    }
                    else
                    {
                        haserror         = true;
                        errorDescription = errorDescription + " Test Doesn't Exist";
                    }


                    rd.HasError         = haserror;
                    rd.ErrorDescription = errorDescription;
                    rdlist.Add(rd);
                    colid++;
                    errorDescription = "";
                }while (colid < g.ItemArray.Length && g[colid].ToString() != "");// dr.ItemArray.Length / ds.Tables[0].Rows.Count);
            }

            return(rdlist);
        }
Ejemplo n.º 7
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);
            }
        }