public ActionResult BindProduct(MachineProductModel machine, int? page, int? pageSize) { var pageNumber = page ?? 1; var size = pageSize ?? PageSize; using (LoveBankDBContext db = new LoveBankDBContext()) { var t_d = db.T_Department; var t_p = db.T_Product; var t_m = db.T_MachineProduct; var list = from p in t_p join d in t_d on p.DeptId equals d.Id join m in t_m on p.ID equals m.ProductId into pm let mlist = pm.Where(x => x.MachineId == machine.MachineId) from m1 in mlist.DefaultIfEmpty() select new ProductModel { BarCode = p.BarCode, CostScore = p.CostScore, Count = p.Count, DeptId = p.DeptId, Id = p.ID, EndTime = p.EndTime, MachineId = m1.MachineId, Name = p.Name, Price = p.Price, StartTime = p.StartTime, State = p.State, Type = p.Type, AddUserId=p.AddUserId, DeptIdName=d.Name }; list = list.Where(x => x.State != RowState.删除 && x.DeptId.IndexOf(AdminUser.DeptId) > -1); if (!string.IsNullOrEmpty(machine.BarCode)) list = list.Where(x => x.BarCode == machine.BarCode); if (!string.IsNullOrEmpty(machine.ProductName)) list = list.Where(x => x.Name.Contains(machine.ProductName)); //list = list.Where(x => x.AddUserId==AdminUser.ID);//限制只能绑定自己新增的产品 ViewBag.MachineId = machine.MachineId; //return PartialView(list.OrderByDescending(x => x.Id).ToPagedList(pageNumber - 1, size)); return View(list.OrderByDescending(x => x.Id).ToPagedList(pageNumber - 1, size)); } }
/// <summary> /// /// </summary> /// <param name="machineId"> /// 必须参数:MachineCode(机器的Id) /// ProductName:产品名称,可以模糊搜索 /// BarCode:条形码 /// </param> /// <param name="page"></param> /// <param name="pageSize"></param> /// <returns></returns> public ActionResult App_GetProduct(MachineProductModel machine, int page = 1, int pageSize = 80) { JsonMessage retJson = new JsonMessage(); using (LoveBankDBContext db = new LoveBankDBContext()) { var t_p = db.T_Product; var t_mp = db.T_MachineProduct; var t_m = db.T_Machine; var t_s = db.T_SourceFile; string nulllogo = "http://www.24hmart.cn:8082/TeamProjectImg/20151103/661488175855828992.jpg"; var list = from p in t_p join m1 in t_mp on p.ID equals m1.ProductId join m2 in t_m on m1.MachineId equals m2.ID where m2.MachineCode == machine.MachineCode&&p.DeptId==m2.DeptId //&&p.StartTime>=DateTime.Now //&&DateTime.Now<=p.EndTime && p.Count > 0 select new ProductModel { BarCode = p.BarCode, CostScore = p.CostScore, Count = p.Count, DeptId = p.DeptId, Id = p.ID, EndTime = p.EndTime, MachineId = m1.MachineId, Name = p.Name, Price = p.Price, StartTime = p.StartTime, State = p.State, Type = p.Type, Desc=p.Desc, Sponsors=p.Sponsors, //SourceFileList = t_s.Where(x => x.Guid == p.Guid).ToList() AppSourceFileList = (from s in t_s where s.Guid == p.Guid select new AppImgUrlModel { ImgHttpUrl = s.Domain + s.Path }).ToList(), AppSourceFileListLogo = (from s in t_s where s.Guid == p.LogoGuid select new AppImgUrlModel { ImgHttpUrl = s.Domain + s.Path }).ToList(), //AppSourceFileListAd = (from s in t_s where s.Guid == p.AdGuid select new AppImgUrlModel { ImgHttpUrl = string.IsNullOrEmpty((s.Domain + s.Path)) ? nulllogo : (s.Domain + s.Path) }).ToList() AppSourceFileListAd = (from s in t_s where s.Guid == p.AdGuid select new AppImgUrlModel { ImgHttpUrl = nulllogo }).ToList() }; list = list.Where(x => x.State != RowState.删除); if (!string.IsNullOrEmpty(machine.BarCode)) list = list.Where(x => x.BarCode == machine.BarCode); if (!string.IsNullOrEmpty(machine.ProductName)) list = list.Where(x => x.Name.Contains(machine.ProductName)); List<ProductModel> resList = list.OrderBy(x => x.Id).ToPagedList(page - 1, pageSize).ToList(); retJson.Status = true; retJson.Data = resList; return Json(retJson); } }