Beispiel #1
0
        public ActionResult Index(MachineModel machine, int? page, int? pageSize)
        {
            var pageNumber = page ?? 1;
             var size = pageSize ?? PageSize;

             using (LoveBankDBContext db = new LoveBankDBContext())
             {

                 var t_m = db.T_Machine;
                 var t_d = db.T_Department;

                 //var list = from m in mac select m;

                 var list = from m in t_m
                            join d in t_d on m.DeptId equals d.Id

                            select new MachineModel
                            {
                                Address = m.Address,
                                AddTime = m.AddTime,
                                AddUserDeptId = m.AddUserDeptId,
                                DeptId = m.DeptId,
                                Desc = m.Desc,
                                Id = m.ID,
                                MachineCode = m.MachineCode,
                                Name = m.Name,
                                State = m.State,
                                Title = m.Title,
                                Lat = m.Lat,
                                Lon = m.Lon,
                                Department = d

                            };

                 list = list.Where(x => x.State != RowState.删除 && x.DeptId.IndexOf(AdminUser.DeptId) > -1);
                 if (!string.IsNullOrEmpty(machine.Name)) list = list.Where(x => x.Name.Contains(machine.Name));
                 if (!string.IsNullOrEmpty(machine.MachineCode)) list = list.Where(x => x.MachineCode == machine.MachineCode);
                 if (!string.IsNullOrEmpty(machine.DeptId)) list = list.Where(x => x.DeptId.IndexOf(machine.DeptId) > -1);

                 machine.MachineModelList = list.OrderByDescending(x => x.Id).ToPagedList(pageNumber - 1, size);

                 var list2 = t_d.Where(x => x.Level <= 6 && x.Id.IndexOf(AdminUser.DeptId) > -1).ToList();
                 //if (!string.IsNullOrEmpty(machine.DeptId))
                 //{
                 //    list2.FirstOrDefault(x => x.Id == machine.DeptId).IsCheck = true;

                 //}

                 ViewData["Department_List"] = HelpSerializer.JSONSerialize<List<Department>>(list2);
                 return View(machine);
             }
        }
Beispiel #2
0
        public ActionResult BindMachine(MachineModel machine, int? page, int? pageSize)
        {
            var pageNumber = page ?? 1;
            var size = pageSize ?? PageSize;
            using (LoveBankDBContext db = new LoveBankDBContext())
            {

                var t_mp = db.T_MachineProduct;
                var t_m = db.T_Machine;
                var t_d = db.T_Department;
                var t_p = db.T_Product;

                if (t_p.Count(x=>x.AddUserId==AdminUser.ID&&x.ID== machine.ProductId)==0)
                {
                    MsgModel msgModel = new MsgModel();
                    msgModel.Message = "无权限操作,只能绑定自己新增的产品";
                    msgModel.WaitSecond =- 1;
                    msgModel.Title = "绑定机器无权操作";
                    return Message(msgModel);
                }

                var list = from m in t_m
                           join d in t_d on m.DeptId equals d.Id
                           join m in t_mp on m.ID equals m.MachineId into pm
                           let mlist = pm.Where(x => x.ProductId == machine.ProductId)
                           from m1 in mlist.DefaultIfEmpty()
                           select new MachineModel
                           {
                               Address = m.Address,
                               AddTime = m.AddTime,
                               AddUserDeptId = m.AddUserDeptId,
                               DeptId = m.DeptId,
                               Desc = m.Desc,
                               Id = m.ID,
                               MachineCode = m.MachineCode,
                               Name = m.Name,
                               State = m.State,
                               Title = m.Title,
                               ProductId = m1.ProductId,
                               Department = d

                           };

                list = list.Where(x => x.State != RowState.删除 && x.DeptId.IndexOf(AdminUser.DeptId) > -1);
                if (!string.IsNullOrEmpty(machine.Name)) list = list.Where(x => x.Name.Contains(machine.Name));
                if (!string.IsNullOrEmpty(machine.MachineCode)) list = list.Where(x => x.MachineCode == machine.MachineCode);
                if (!string.IsNullOrEmpty(machine.DeptId)) list = list.Where(x => x.DeptId.IndexOf(machine.DeptId) > -1);

                ViewBag.ProductId = machine.ProductId;
                machine.MachineModelList = list.OrderByDescending(x => x.Id).ToPagedList(pageNumber - 1, size);

                var list2 = t_d.Where(x => x.Level <= 6 && x.Id.IndexOf(AdminUser.DeptId) > -1).ToList();
                if (!string.IsNullOrEmpty(machine.DeptId))
                {
                    list2.FirstOrDefault(x => x.Id == machine.DeptId).IsCheck = true;
                    //list2[list2.FindIndex(x => x.Id == machine.DeptId)].IsCheck = true;
                }

                ViewData["Department_List"] = HelpSerializer.JSONSerialize<List<Department>>(list2);

                return View(machine);
            }
        }