Пример #1
0
 public ExpressPrintWayBillViewModel()
 {
     Param                = new ExpressPrintWayBillParam();
     ShippingMethods      = new List <SelectListItem>();
     SearchWheres         = new List <SelectListItem>();
     VenderList           = new List <SelectListItem>();
     ExpressPrintWayBills = new PagedList <ExpressPrintWayBillExt>();
     WayBillPrintLogLists = new List <WayBillPrintLogModel>();
 }
Пример #2
0
        /// <summary>
        /// 物流快递打单列表
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public PagedList <ExpressPrintWayBillExt> GetExpressPrintWayBillList(ExpressPrintWayBillParam param)
        {
            var ctx = this.UnitOfWork as LMS_DbContext;

            Check.Argument.IsNotNull(ctx, "数据库对象");
            IQueryable <ExpressPrintWayBillExt> list;
            int satusHave      = WayBill.StatusEnum.Have.GetStatusValue();
            int satusWaitOrder = WayBill.StatusEnum.WaitOrder.GetStatusValue();
            int satusSend      = WayBill.StatusEnum.Send.GetStatusValue();
            Expression <Func <CustomerOrderInfo, bool> > filter          = o => true;
            Expression <Func <WayBillInfo, bool> >       filterWayBill   = o => o.Status == satusHave || o.Status == satusWaitOrder || o.Status == satusSend;
            Expression <Func <InStorageInfo, bool> >     filterInStorage = o => true;

            filter = filter.AndIf(p => p.CustomerCode == param.CustomerCode, param.CustomerCode != null);


            if (param.ShippingMethodType == 1)
            {
                filterWayBill = filterWayBill.AndIf(p => p.InShippingMethodID == param.ShippingMethodId,
                                                    param.ShippingMethodId != 0);
            }
            else if (param.ShippingMethodType == 2)
            {
                filterWayBill = filterWayBill.AndIf(p => p.OutShippingMethodID == param.ShippingMethodId,
                                                    param.ShippingMethodId != 0);
            }
            if (param.IsVender == 2)
            {
                filterWayBill = filterWayBill.And(p => p.VenderCode != null);
            }
            else if (param.IsVender == 3)
            {
                filterWayBill = filterWayBill.And(p => p.VenderCode == null);
            }
            filterWayBill = filterWayBill.AndIf(p => p.VenderCode == param.VenderCode, param.VenderCode != null)
                            .AndIf(p => p.SettleWeight >= param.StartWeight.Value, param.StartWeight.HasValue)
                            .AndIf(p => p.SettleWeight <= param.EndWeight.Value, param.EndWeight.HasValue);
            filterInStorage = filterInStorage
                              .AndIf(o => o.CreatedOn >= param.StartTime.Value, param.StartTime.HasValue)
                              .AndIf(o => o.CreatedOn <= param.EndTime.Value, param.EndTime.HasValue);

            if (!string.IsNullOrWhiteSpace(param.CountryCode))
            {
                var codes = param.CountryCode.Split(',').ToList();
                if (codes.Count > 0)
                {
                    filterWayBill = filterWayBill.And(p => codes.Contains(p.CountryCode));
                }
            }

            if (!string.IsNullOrWhiteSpace(param.SearchContext))
            {
                var numberList =
                    param.SearchContext.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries)
                    .ToList();
                if (param.SearchWhere.HasValue && numberList.Count > 0)
                {
                    switch (WayBill.ParseToSearchFilter(param.SearchWhere.Value))
                    {
                    case WayBill.SearchFilterEnum.WayBillNumber:
                        filterWayBill = filterWayBill.And(p => numberList.Contains(p.WayBillNumber));
                        break;

                    case WayBill.SearchFilterEnum.TrackingNumber:
                        filterWayBill = filterWayBill.And(p => numberList.Contains(p.TrackingNumber));
                        break;

                    case WayBill.SearchFilterEnum.CustomerOrderNumber:
                        filter = filter.And(p => numberList.Contains(p.CustomerOrderNumber));
                        break;
                    }
                }
            }

            IQueryable <WayBillInfo> queryWayBillInfos = from w in ctx.WayBillInfos.Where(filterWayBill) select w;

            //已打印
            if (param.PrintStatus == "1")
            {
                queryWayBillInfos = from w in ctx.WayBillInfos.Where(filterWayBill) where ctx.WayBillPrintLogs.Any(p => p.waybillnumber == w.WayBillNumber) select w;
            }
            //未打印
            if (param.PrintStatus == "2")
            {
                queryWayBillInfos = from w in ctx.WayBillInfos.Where(filterWayBill) where ctx.WayBillPrintLogs.All(p => p.waybillnumber != w.WayBillNumber) select w;
            }

            list = from w in queryWayBillInfos
                   join i in ctx.InStorageInfos.Where(filterInStorage) on w.InStorageID equals i.InStorageID
                   join o in ctx.CustomerOrderInfos.Where(filter) on w.CustomerOrderID equals o.CustomerOrderID
                   orderby i.CreatedOn descending
                   select new ExpressPrintWayBillExt
            {
                WayBillNumber       = w.WayBillNumber,
                CustomerOrderID     = w.CustomerOrderID,
                CustomerOrderNumber = o.CustomerOrderNumber,
                CountryCode         = w.CountryCode,
                TrackingNumber      = w.TrackingNumber,
                SettleWeight        = w.SettleWeight,
                Status              = w.Status,
                CustomerCode        = w.CustomerCode,
                InShippingMethodID  = w.InShippingMethodID,
                OutShippingMethodID = w.OutShippingMethodID,
                VenderCode          = w.VenderCode,
                VenderName          = "",
                CreatedOn           = i.CreatedOn,
                IsPrinted           = ctx.WayBillPrintLogs.Any(p => p.waybillnumber == w.WayBillNumber),
                IsPrinter           = ctx.ExpressResponses.Any(p => p.WayBillNumber == w.WayBillNumber),
            };

            return(list.ToPagedList(param.Page, param.PageSize));
        }