Ejemplo n.º 1
0
        public List<ChangeCusCarWithOMViewModel> GetChangeCusCarOfPlat(string tenantCode, string iconSkin)
        {
            List<ChangeCusCarWithOMViewModel> list = new List<ChangeCusCarWithOMViewModel>();
            try
            {
                IList<EMTenant> ltTenantAll = new EMTenantService().GetGrandChildren(tenantCode);
                if (ltTenantAll.IsNullOrEmpty())
                    return list;

                var ltAllCus = ltTenantAll.Where(s => s.TenantType == EnumTenantType.EndCustomer && !string.IsNullOrEmpty(s.TenantName));
                if (ltAllCus.Count() == 0) return list;

                List<string> ltCusTenantCode = ltAllCus.Select(o => o.TenantCode).ToList();
                EMVehicleService vehicleServ = new EMVehicleService();
                //客户和客户的车辆总数
                Dictionary<string, int> dicVehicleCount = vehicleServ.SelectVehicleCount(ltCusTenantCode);
               
                EMTenant lastCreateTenant = ltAllCus.OrderByDescending(s => s.CreateTime).ElementAt(0);

                IList<ChangeCusCarWithOMViewModel> ltChildren = GetCarChildren(tenantCode, lastCreateTenant.TenantCode, ltTenantAll, dicVehicleCount);
                if (!ltChildren.IsNullOrEmpty())
                    list.AddRange(ltChildren);

                List<ChangeCusCarWithOMViewModel> vechileList = null;
                for (int j = 0; j < list.Count; j++)
                {
                    if (list[j].Children.Count == 0)
                    {
                        string stenantCode = list[j].TenantCode;

                        List<EMVehicle> veList = new VehicleDAL().GetVehicleListByTenantCode(stenantCode);
                        if (veList != null&&veList.Count>0)
                        {
                            vechileList = new List<ChangeCusCarWithOMViewModel>();
                            for (int a = 0; a < veList.Count; a++)
                            {
                                ChangeCusCarWithOMViewModel ve = new ChangeCusCarWithOMViewModel();
                                ve.TenantCode = veList[a].VehicleCode.ToString();
                                ve.TenantName = veList[a].LicenceNumber;
                                ve.iconSkin = "CarDeviceNo";
                                 
                                vechileList.Add(ve);
                            }
                            list[j].iconSkin = iconSkin;// 值为CarDeviceNo表示是车辆的上一级可以选中,为空表示车辆的上一级不可以选中
                            list[j].Children.AddRange(vechileList);
                        }
                    }
                    else
                    {
                        for (int k = 0; k < list[j].Children.Count; k++)
                        {
                            string stenantCode = list[j].Children[k].TenantCode;
                            vechileList = new List<ChangeCusCarWithOMViewModel>();
                            List<EMVehicle> veList = new VehicleDAL().GetVehicleListByTenantCode(stenantCode);
                            if (veList != null&&veList.Count>0)
                            {
                                for (int a = 0; a < veList.Count; a++)
                                {
                                    ChangeCusCarWithOMViewModel ve = new ChangeCusCarWithOMViewModel();
                                    ve.TenantCode = veList[a].VehicleCode.ToString();
                                    ve.TenantName = veList[a].LicenceNumber;
                                   
                                    ve.iconSkin = "CarDeviceNo";
                                    vechileList.Add(ve);

                                }
                                list[j].Children[k].iconSkin = iconSkin;
                                list[j].Children[k].Children.AddRange(vechileList);
                            }
                        }
                    }
                }

                return list;
            }
            catch (Exception ex)
            {
                Logger.Error(ex.Message, ex);
                return list;
            }
             
        }