public ActionResult VehicleList()
        {
            var gridModel = new VehicleListGridModel();

            SetupVehicleListGrid(gridModel.VehicleListGrid);
            return(View(gridModel));
        }
        public ActionResult VehicleList_EditData(DXInfo.Models.Transport tp)
        {
            var gridModel = new VehicleListGridModel();

            SetupVehicleListGrid(gridModel.VehicleListGrid);
            if (gridModel.VehicleListGrid.AjaxCallBackMode == AjaxCallBackMode.EditRow)
            {
                MembershipUser user   = Membership.GetUser();
                Guid           userId = Guid.Parse(user.ProviderUserKey.ToString());
                using (var context = db)
                {
                    var oldtp = context.Transports.Where(w => w.Id == tp.Id).FirstOrDefault();
                    var dept  = context.aspnet_CustomProfile.Where(w => w.UserId == userId).FirstOrDefault();
                    if (oldtp == null)
                    {
                        return(gridModel.VehicleListGrid.ShowEditValidationMessage("未找到车辆记录"));
                    }

                    oldtp.BalanceType        = tp.BalanceType;
                    oldtp.AgreeFreightRate   = tp.AgreeFreightRate;
                    oldtp.FreightRate        = tp.FreightRate;
                    oldtp.Shipper            = tp.Shipper;
                    oldtp.Shipper_Telephone  = tp.Shipper_Telephone;
                    oldtp.Carrier            = tp.Carrier;
                    oldtp.Carrier_Telephone  = tp.Carrier_Telephone;
                    oldtp.Lines              = tp.Lines;
                    oldtp.Load_Quantity      = tp.Load_Quantity;
                    oldtp.Shipment_Quantity  = tp.Shipment_Quantity;
                    oldtp.Shipment_CheckUser = tp.Shipment_CheckUser;
                    oldtp.Comment            = tp.Comment;

                    oldtp.ModifyDate   = DateTime.Now;
                    oldtp.ModifyUserId = userId;
                    oldtp.ModifyDeptId = dept.DeptId;


                    DXInfo.Models.TransportsLog tl = new DXInfo.Models.TransportsLog();

                    tl.Id                 = Guid.NewGuid();
                    tl.tpId               = oldtp.Id;
                    tl.AgreeFreightRate   = oldtp.AgreeFreightRate;
                    tl.BalanceType        = oldtp.BalanceType;
                    tl.Card               = oldtp.Card;
                    tl.Carrier            = oldtp.Carrier;
                    tl.Carrier_Telephone  = oldtp.Carrier_Telephone;
                    tl.Comment            = oldtp.Comment;
                    tl.Driver             = oldtp.Driver;
                    tl.FreightRate        = oldtp.FreightRate;
                    tl.InFactory_Date     = oldtp.InFactory_Date;
                    tl.InFactory_DeptId   = oldtp.InFactory_DeptId;
                    tl.InFactory_UserId   = oldtp.InFactory_UserId;
                    tl.Lines              = oldtp.Lines;
                    tl.Load_Date          = oldtp.Load_Date;
                    tl.Load_DeptId        = oldtp.Load_DeptId;
                    tl.Load_Inventory     = oldtp.Load_Inventory;
                    tl.Load_Quantity      = oldtp.Load_Quantity;
                    tl.Load_UserId        = oldtp.Load_UserId;
                    tl.ModifyDate         = oldtp.ModifyDate;
                    tl.ModifyDeptId       = oldtp.ModifyDeptId;
                    tl.ModifyUserId       = oldtp.ModifyUserId;
                    tl.OutFactory_Date    = oldtp.OutFactory_Date;
                    tl.OutFactory_DeptId  = oldtp.OutFactory_DeptId;
                    tl.OutFactory_UserId  = oldtp.OutFactory_UserId;
                    tl.Shipment_CheckUser = oldtp.Shipment_CheckUser;
                    tl.Shipment_Date      = oldtp.Shipment_Date;
                    tl.Shipment_DeptId    = oldtp.Shipment_DeptId;
                    tl.Shipment_Quantity  = oldtp.Shipment_Quantity;
                    tl.Shipment_UserId    = oldtp.Shipment_UserId;
                    tl.Shipper            = oldtp.Shipper;
                    tl.Shipper_Telephone  = oldtp.Shipper_Telephone;
                    tl.Status             = oldtp.Status;


                    context.TransportsLog.Add(tl);

                    context.SaveChanges();
                }
            }
            return(RedirectToAction("VehicleList"));
        }
        public ActionResult ExportToExcel()
        {
            var gridModel = new VehicleListGridModel();

            SetupVehicleListGrid(gridModel.VehicleListGrid);
            var tps = (from t in db.Transports

                       join c in db.Cards on t.Card equals c.Id into tc
                       from tcs in tc.DefaultIfEmpty()

                       join v in db.Vehicles on tcs.Vehicle equals v.Id into cv
                       from cvs in cv.DefaultIfEmpty()

                       //join dr in db.Drivers on cvs.Driver equals dr.Id into vdr
                       //from vdrs in vdr.DefaultIfEmpty()

                       join dr1 in db.Drivers on t.Driver equals dr1.Id into tdr
                       from tdrs in tdr.DefaultIfEmpty()

                       join n in db.NameCode on t.BalanceType equals n.ID into tn
                       from tns in tn.DefaultIfEmpty()

                       join l in db.Lines on t.Lines equals l.Id into tl
                       from tls in tl.DefaultIfEmpty()

                       join d1 in db.Depts on t.InFactory_DeptId equals d1.DeptId into td1
                       from td1s in td1.DefaultIfEmpty()

                       join u1 in db.aspnet_CustomProfile on t.InFactory_UserId equals u1.UserId into tu1
                       from tu1s in tu1.DefaultIfEmpty()

                       join d2 in db.Depts on t.Load_DeptId equals d2.DeptId into td2
                       from td2s in td2.DefaultIfEmpty()

                       join u2 in db.aspnet_CustomProfile on t.Load_UserId equals u2.UserId into tu2
                       from tu2s in tu2.DefaultIfEmpty()

                       join i in db.Inventory on t.Load_Inventory equals i.Id into ti
                       from tis in ti.DefaultIfEmpty()

                       join um in db.UnitOfMeasures on tis.UnitOfMeasure equals um.Id into ium
                       from iums in ium.DefaultIfEmpty()

                       join d3 in db.Depts on t.Shipment_DeptId equals d3.DeptId into td3
                       from td3s in td3.DefaultIfEmpty()

                       join u3 in db.aspnet_CustomProfile on t.Shipment_UserId equals u3.UserId into tu3
                       from tu3s in tu3.DefaultIfEmpty()

                       join d4 in db.Depts on t.OutFactory_DeptId equals d4.DeptId into td4
                       from td4s in td4.DefaultIfEmpty()

                       join u4 in db.aspnet_CustomProfile on t.OutFactory_UserId equals u4.UserId into tu4
                       from tu4s in tu4.DefaultIfEmpty()

                       //join u5 in db.aspnet_CustomProfile on t.Shipment_CheckUserId equals u5.UserId into tu5
                       //from tu5s in tu5.DefaultIfEmpty()

                       join d6 in db.Depts on t.ModifyDeptId equals d6.DeptId into td6
                       from td6s in td6.DefaultIfEmpty()

                       join u6 in db.aspnet_CustomProfile on t.ModifyUserId equals u6.UserId into tu6
                       from tu6s in tu6.DefaultIfEmpty()
                       select new
            {
                t.Id,
                tcs.CardNo,
                t.Status,
                cvs.PlateNo,
                cvs.BrandModel,
                cvs.MotorNo,
                OwnName = cvs.OwnerName,
                DriverName = tdrs.Name,
                t.BalanceType,
                BalanceTypeName = tns.Name,
                t.AgreeFreightRate,
                t.FreightRate,
                t.Shipper,
                t.Shipper_Telephone,
                t.Carrier,
                t.Carrier_Telephone,
                t.Lines,
                LinesName = tls.Name,
                tls.Mileage,
                InFactory_Dept = td1s.DeptName,
                t.InFactory_Date,
                InFactory_Oper = tu1s.FullName,
                Load_Dept = td2s.DeptName,
                t.Load_Date,
                Load_Oper = tu2s.FullName,
                Load_Inventory = tis.Name,
                UnitName = iums.Name,
                tis.Specs,
                t.Load_Quantity,
                Shipment_Dept = td3s.DeptName,
                t.Shipment_Date,
                Shipment_Oper = tu3s.FullName,
                t.Shipment_Quantity,
                //t.Shipment_CheckUserId,
                t.Shipment_CheckUser,
                OutFactory_Dept = td4s.DeptName,
                t.OutFactory_Date,
                OutFactory_Oper = tu4s.FullName,
                Modify_Dept = td6s.DeptName,
                t.ModifyDate,
                Modify_Oper = tu6s.FullName,
                t.Comment
            }).ToList();
            //var tpls = tps.ToList();
            var tpls = tps.Select(s => new
            {
                s.Id,
                s.CardNo,
                Status = s.Status == 0 ? "进厂" : s.Status == 1 ? "装车" : s.Status == 2 ? "卸货" : "出厂",
                s.PlateNo,
                s.BrandModel,
                s.MotorNo,
                s.OwnName,
                s.DriverName,
                s.BalanceType,
                s.BalanceTypeName,
                s.AgreeFreightRate,
                s.FreightRate,
                s.Shipper,
                s.Shipper_Telephone,
                s.Carrier,
                s.Carrier_Telephone,
                s.Lines,
                s.LinesName,
                s.Mileage,
                s.InFactory_Dept,
                s.InFactory_Date,
                s.InFactory_Oper,
                s.Load_Dept,
                s.Load_Date,
                s.Load_Oper,
                s.Load_Inventory,
                s.UnitName,
                s.Specs,
                s.Load_Quantity,
                s.Shipment_Dept,
                s.Shipment_Date,
                s.Shipment_Oper,
                s.Shipment_Quantity,
                //s.Shipment_CheckUserId,
                s.Shipment_CheckUser,
                s.OutFactory_Dept,
                s.OutFactory_Date,
                s.OutFactory_Oper,
                s.Modify_Dept,
                s.ModifyDate,
                s.Modify_Oper,
                s.Comment
            });
            JQGridState gridState = Session["GridStateV"] as JQGridState;

            gridModel.VehicleListGrid.ExportToExcel(tpls.AsQueryable(), "车辆清单.xls", gridState);
            return(View());
        }