Ejemplo n.º 1
0
        private IList <ReportedData> GetDataRow(DataSet ds)
        {
            //ArrayList errorList = new ArrayList();
            //int count = 0;

            //try
            //{
            string        regionName;
            string        siteName;
            string        productName;
            string        duration;
            decimal       amount;
            int           stockout;
            int           instrumentDownTime;//b
            decimal       adjusited;
            int           rowno = 0;
            bool          haserror;
            string        rName   = "";
            string        sName   = "";
            string        pName   = "";
            ForlabRegion  region  = null;
            ForlabSite    site    = null;
            MasterProduct product = null;

            IList <ReportedData> rdlist = new List <ReportedData>();

            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                rowno++;
                haserror    = false;
                regionName  = Convert.ToString(dr[0]);  //region name
                siteName    = Convert.ToString(dr[1]);  //site name
                productName = Convert.ToString(dr[2]);  //product name
                duration    = Convert.ToString(dr[3]);  // reporting period(duration)

                try
                {
                    amount = Convert.ToDecimal(dr[4]);      //amount
                }
                catch
                {
                    haserror = true;
                    amount   = 0;
                }
                try
                {
                    stockout = Convert.ToInt32(dr[5]);         //stock out
                }
                catch
                {
                    haserror = true;
                    stockout = 0;
                }
                try
                {
                    instrumentDownTime = Convert.ToInt32(dr[6]);         //instrumentDownTime
                }
                catch
                {
                    haserror           = true;
                    instrumentDownTime = 0;
                }
                try
                {
                    adjusited = Convert.ToDecimal(dr[7]);         //adjusted
                }
                catch
                {
                    haserror  = true;
                    adjusited = 0;
                }

                ReportedData rd = new ReportedData(rowno, regionName, siteName, productName, 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;
                    }
                }
                else
                {
                    haserror = true;
                }

                if (pName != productName)
                {
                    if (!string.IsNullOrEmpty(productName))
                    {
                        product = DataRepository.GetProductByName(productName);
                    }
                    else
                    {
                        product = null;
                    }
                    pName = productName;
                }

                if (product != null)
                {
                    rd.Product = product;
                }
                else
                {
                    haserror = true;
                }
                rd.HasError = haserror;
                rdlist.Add(rd);
            }

            //}
            //catch (Exception ex)
            //{
            //    //ShowError(ex.Message);
            //}
            return(rdlist);
        }
Ejemplo n.º 2
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);
        }