示例#1
0
        public static List<ForeCastObject> generateTemplate(DataTable dt)
        {
            List<ForeCastObject> res = new List<ForeCastObject>();
            Boolean bIsData = false;
            DataRow prevResult = null;
            int tempMonth = 0;
            ForeCastObject ftemp = new ForeCastObject();

            //get start table index
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                if ((dt.Rows[i][0] != null) && (dt.Rows[i][0].ToString() == "Customer"))
                {
                    bIsData = true;
                    i++;
                    continue;
                }
                else if (bIsData)
                {
                    if ((prevResult == null) || (!string.IsNullOrEmpty(dt.Rows[i][0].ToString())))
                    {
                        prevResult = dt.Rows[i];
                        ftemp.Customer = dt.Rows[i][ForeCastObjectTemplate.indexCustomer].ToString();
                        ftemp.StartDate = dt.Rows[i][ForeCastObjectTemplate.indexStartDate].ToString();
                        ftemp.Model = dt.Rows[i][ForeCastObjectTemplate.indexModel].ToString();
                    }
                    else if (!string.IsNullOrEmpty(dt.Rows[i][ForeCastObjectTemplate.indexStartDate].ToString()))
                    {
                        ftemp.StartDate = dt.Rows[i][ForeCastObjectTemplate.indexStartDate].ToString();
                        ftemp.Model = dt.Rows[i][ForeCastObjectTemplate.indexModel].ToString();
                    }
                    else if (!string.IsNullOrEmpty(dt.Rows[i][ForeCastObjectTemplate.indexModel].ToString()))
                    {
                        ftemp.Model = dt.Rows[i][ForeCastObjectTemplate.indexModel].ToString();
                    }
                    else
                    {
                        ftemp.Customer = prevResult[ForeCastObjectTemplate.indexCustomer].ToString();
                        ftemp.StartDate = prevResult[ForeCastObjectTemplate.indexStartDate].ToString();
                        ftemp.Model = prevResult[ForeCastObjectTemplate.indexModel].ToString();
                    }
                    ftemp.PartName = dt.Rows[i][ForeCastObjectTemplate.indexPartName].ToString();
                    ftemp.Type = dt.Rows[i][ForeCastObjectTemplate.indexType].ToString();
                    ftemp.UnitQty = dt.Rows[i][ForeCastObjectTemplate.indexUnitQty].ToString();
                    ftemp.forecastDtl = new List<ForeCastObjectDetail>();
                    tempMonth = 0;
                    for (int j = 6; j < dt.Rows[i].ItemArray.Length - 1; j++)
                    {
                        if (!String.IsNullOrEmpty(dt.Rows[i][j + 1].ToString()))
                        {
                            ForeCastObjectDetail fcDetail = new ForeCastObjectDetail();
                            fcDetail.Month = tempMonth++;
                            fcDetail.PlanQty = dt.Rows[i][j].ToString();
                            fcDetail.ForecastQty = dt.Rows[i][j + 1].ToString();
                            ftemp.forecastDtl.Add(fcDetail);
                            j++;
                        }
                    }
                    res.Add(ftemp);
                }
            }
            return res;
        }
示例#2
0
        public static List <ForeCastObject> generateTemplate(DataTable dt)
        {
            List <ForeCastObject> res = new List <ForeCastObject>();
            Boolean        bIsData    = false;
            DataRow        prevResult = null;
            int            tempMonth  = 0;
            ForeCastObject ftemp      = new ForeCastObject();

            //get start table index
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                if ((dt.Rows[i][0] != null) && (dt.Rows[i][0].ToString() == "Customer"))
                {
                    bIsData = true;
                    i++;
                    continue;
                }
                else if (bIsData)
                {
                    if ((prevResult == null) || (!string.IsNullOrEmpty(dt.Rows[i][0].ToString())))
                    {
                        prevResult      = dt.Rows[i];
                        ftemp.Customer  = dt.Rows[i][ForeCastObjectTemplate.indexCustomer].ToString();
                        ftemp.StartDate = dt.Rows[i][ForeCastObjectTemplate.indexStartDate].ToString();
                        ftemp.Model     = dt.Rows[i][ForeCastObjectTemplate.indexModel].ToString();
                    }
                    else if (!string.IsNullOrEmpty(dt.Rows[i][ForeCastObjectTemplate.indexStartDate].ToString()))
                    {
                        ftemp.StartDate = dt.Rows[i][ForeCastObjectTemplate.indexStartDate].ToString();
                        ftemp.Model     = dt.Rows[i][ForeCastObjectTemplate.indexModel].ToString();
                    }
                    else if (!string.IsNullOrEmpty(dt.Rows[i][ForeCastObjectTemplate.indexModel].ToString()))
                    {
                        ftemp.Model = dt.Rows[i][ForeCastObjectTemplate.indexModel].ToString();
                    }
                    else
                    {
                        ftemp.Customer  = prevResult[ForeCastObjectTemplate.indexCustomer].ToString();
                        ftemp.StartDate = prevResult[ForeCastObjectTemplate.indexStartDate].ToString();
                        ftemp.Model     = prevResult[ForeCastObjectTemplate.indexModel].ToString();
                    }
                    ftemp.PartName    = dt.Rows[i][ForeCastObjectTemplate.indexPartName].ToString();
                    ftemp.Type        = dt.Rows[i][ForeCastObjectTemplate.indexType].ToString();
                    ftemp.UnitQty     = dt.Rows[i][ForeCastObjectTemplate.indexUnitQty].ToString();
                    ftemp.forecastDtl = new List <ForeCastObjectDetail>();
                    tempMonth         = 0;
                    for (int j = 6; j < dt.Rows[i].ItemArray.Length - 1; j++)
                    {
                        if (!String.IsNullOrEmpty(dt.Rows[i][j + 1].ToString()))
                        {
                            ForeCastObjectDetail fcDetail = new ForeCastObjectDetail();
                            fcDetail.Month       = tempMonth++;
                            fcDetail.PlanQty     = dt.Rows[i][j].ToString();
                            fcDetail.ForecastQty = dt.Rows[i][j + 1].ToString();
                            ftemp.forecastDtl.Add(fcDetail);
                            j++;
                        }
                    }
                    res.Add(ftemp);
                }
            }
            return(res);
        }