public ActionResult Index(string searchkey, string index, int?searchType) { string name, error; if (CookieHelper.HasCookie(out name, out error) == false) { return(RedirectToAction("", "LoginUI")); } else { new RoleHelper().GetRoles(name, out role, out department1Code, out LoginName); ViewData["VisitorRole"] = role; ViewData["username"] = LoginName; } if (string.IsNullOrEmpty(index)) { index = "1"; } if (searchkey == string.Empty) { return(RedirectToAction("", "Device")); } if (searchkey == null) { searchkey = string.Empty; } if (searchType == null) { searchType = (int)QueryDeviceSubType.ALL; } DeviceQueryCondition condition = new DeviceQueryCondition(); condition.searchkey = searchkey; if (string.IsNullOrEmpty(searchkey)) { searchType = (int)QueryDeviceSubType.ALL; //当searchkey为空时,默认加载全部 } condition.queryType = (QueryDeviceSubType)searchType; ViewData["requestData"] = condition; List <device> totalList = null; try { using (mlrmsEntities db = new mlrmsEntities()) { int totalCount = db.device.Count(); if (totalCount == 0) { return(View()); } PageModel page = new PageModel() { SearchKeyWord = searchkey, SearchType = searchType, CurrentIndex = Int32.Parse(index), TotalCount = totalCount }; totalList = db.device.Where(p => p.name.ToLower().Contains(searchkey.ToLower()) || p.slaveid.ToString().Contains(searchkey.ToLower())).OrderBy(m => m.type).Skip((page.CurrentIndex - 1) * page.PageSize).Take(page.PageSize).ToList(); pageList = new List <DeviceInfo>(); foreach (var item in totalList) { DeviceInfo info = new DeviceInfo(); info.slaveID = item.slaveid; info.note = item.note; info.devName = item.name; info.serviceCode = item.servicecode; info.serviceName = item.servicename; info.port = item.port; info.runStatus = 1; info.type = item.type; info.typeName = EnumParser.TypeParser(item.type); info.subType = item.subtype.HasValue ?item.subtype.Value : -1; info.subTypeName = EnumParser.SubTypeParser(info.subType); pageList.Add(info); } ViewData["pagemodel"] = page; return(View(pageList)); } } catch (Exception ex) { LogHelper.Error("设备列表加载失败", ex); return(View()); } }
public List <HeatPumpParas> GetAllAttendanceInfos(string beginTime1, string endTime1, string searchkey, string slaveCode) { DateTime dtStart = DateTime.Parse(beginTime1); DateTime dtEnd = DateTime.Parse(endTime1); int slaveID = int.Parse(slaveCode); List <HeatPumpParas> attendances = new List <HeatPumpParas>(); try { using (mlrmsEntities db = new mlrmsEntities()) { IQueryable <HeatPumpParas> dynamicAttendance = null; if (slaveCode != "0") { dynamicAttendance = (from heatPump in db.device join dev in db.heatmeterstatistics on heatPump.slaveid equals dev.slaveid into h from c in h.DefaultIfEmpty() where (heatPump.servicecode == c.servicecode && heatPump.port == c.port) where heatPump.type == 2 where c.slaveid == slaveID where (c.time >= dtStart && c.time <= dtEnd) where (heatPump.name.ToLower().Contains(searchkey.ToLower())) select new HeatPumpParas { coldEnergy = c.coldenergy, warmEnergy = c.warmenergy, slaveID = heatPump.slaveid, name = heatPump.name, type = heatPump.type, time = c.time, subType = heatPump.subtype }).OrderByDescending(m => m.time); } else { dynamicAttendance = (from heatPump in db.device join dev in db.heatmeterstatistics on heatPump.slaveid equals dev.slaveid into h from c in h.DefaultIfEmpty() where (heatPump.servicecode == c.servicecode && heatPump.port == c.port) where heatPump.type == 2 where (c.time >= dtStart && c.time <= dtEnd) where (heatPump.name.ToLower().Contains(searchkey.ToLower())) select new HeatPumpParas { coldEnergy = c.coldenergy, warmEnergy = c.warmenergy, slaveID = heatPump.slaveid, name = heatPump.name, type = heatPump.type, time = c.time, subType = heatPump.subtype }).OrderByDescending(m => m.time); } attendances = dynamicAttendance.ToList(); if (attendances == null || attendances.Count == 0) { return(null); } foreach (var item in attendances) { item.typeName = EnumParser.TypeParser(item.type); item.subTypeName = item.subType.HasValue ? EnumParser.SubTypeParser(item.subType.Value) : string.Empty; } } } catch (Exception ex) { LogHelper.Error("获取热泵记录失败", ex); } return(attendances); }