Beispiel #1
0
        public static List <CarriageCost> GetAllCarriageCost(List <EmCarriageCostDetail> all)
        {
            List <CarriageCost>         costs       = new List <CarriageCost>();
            List <EmCarriageCostDetail> temp        = new List <EmCarriageCostDetail>();
            List <EmCarriageCostDetail> sameDetails = new List <EmCarriageCostDetail>();

            foreach (var item in all)
            {
                temp.Add(item);
            }
            while (temp.Count > 0)
            {
                foreach (var item in temp)
                {
                    //相同运费的信息构建在一起
                    sameDetails = temp.FindAll(t => item.CarriageCost == t.CarriageCost);
                    CarriageCost cost = GetCarriageCost(sameDetails);
                    costs.Add(cost);
                    break;
                }

                foreach (var item in sameDetails)
                {
                    temp.Remove(item);
                }
            }

            return(costs);
        }
Beispiel #2
0
        /// <summary>
        /// 只返回被选中的项
        /// </summary>
        /// <param name="zones"></param>
        /// <returns></returns>
        public static CarriageCost ZoneToCarriageCost(List <Zone> zones)
        {
            CarriageCost cost = new CarriageCost();

            //
            if (zones != null)
            {
                cost.Zones   = new List <Zone>();
                cost.Cost    = 0;
                cost.AreaStr = string.Empty;
                foreach (Zone item in zones)
                {
                    Zone newZone = GetSelectedZone(item);
                    cost.Zones.Add(newZone);

                    if (item.Province != null)
                    {
                        foreach (Province p in item.Province)
                        {
                            if (p.SelectAll)
                            {
                                cost.AreaStr += p.Name + "、";
                            }
                            else
                            {
                                if (p.Selected)
                                {
                                    if (cost.AreaStr.Length > 0)
                                    {
                                        cost.AreaStr = cost.AreaStr.Substring(0, cost.AreaStr.Length - 1) + ";";
                                    }
                                    cost.AreaStr += p.Name + ":";
                                    if (p.Sub != null)
                                    {
                                        foreach (City c in p.Sub)
                                        {
                                            if (c.Selected)
                                            {
                                                cost.AreaStr += c.Name + "、";
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            if (cost.AreaStr.Length > 0)
            {
                cost.AreaStr = cost.AreaStr.Substring(0, cost.AreaStr.Length - 1) + ";";
            }
            return(cost);
        }
Beispiel #3
0
        //获取相同运费的详情,构造一起成为一个CarriageCost
        public static CarriageCost GetCarriageCost(List <EmCarriageCostDetail> source)
        {
            CarriageCost cost  = new CarriageCost();
            List <Zone>  zones = new List <Zone>();

            if (source != null)
            {
                List <EmCarriageCostDetail> temp = new List <EmCarriageCostDetail>();
                foreach (EmCarriageCostDetail item in source)
                {
                    temp.Add(item);
                }



                if (temp != null)
                {
                    //将相同的省份拼起来,再拼全部。
                    cost.Cost = temp[0].CarriageCost;

                    //zones
                    Zone zone = new Zone();
                    zone.Province = new List <Province>();
                    List <EmCarriageCostDetail> allSameList = null;

                    while (temp.Count > 0)
                    {
                        foreach (EmCarriageCostDetail item in temp)
                        {
                            Province province = new Province();
                            province.Name     = item.Province;
                            province.Selected = true;
                            //找到所有相同的省份,
                            allSameList = temp.FindAll(t => t.Province == item.Province);
                            CommonGlobalUtil.Debug("找到省份:" + item.Province + " " + allSameList.Count);
                            if (!String.IsNullOrEmpty(item.City))
                            {
                                cost.AreaStr += item.Province + ":";
                                //找出所有相同省份的城市信息
                                foreach (EmCarriageCostDetail cityData in allSameList)
                                {
                                    if (province.Sub == null)
                                    {
                                        province.Sub = new List <City>();
                                    }
                                    City city = new City();
                                    city.Name     = cityData.City;
                                    city.Selected = true;
                                    province.Sub.Add(city);
                                    cost.AreaStr += cityData.City + "、";
                                }
                                if (cost.AreaStr.Length > 0)
                                {
                                    cost.AreaStr = cost.AreaStr.Substring(0, cost.AreaStr.Length - 1) + ";";
                                }
                            }
                            else
                            {
                                cost.AreaStr += item.Province + ";";
                            }
                            CommonGlobalUtil.Debug("添加:" + province);
                            zone.Province.Add(province);
                            break;
                        }

                        foreach (var removed in allSameList)
                        {
                            temp.Remove(removed);
                        }
                    }

                    zones.Add(zone);

                    if (cost.AreaStr.Length > 0)
                    {
                        cost.AreaStr = cost.AreaStr.Substring(0, cost.AreaStr.Length - 1) + ";";
                    }
                }
            }


            cost.Zones = zones;

            return(cost);
        }