Beispiel #1
0
        // GET: SerialPort
        public ActionResult Index(string searchkey, string index)
        {
            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;
            }


            DeviceQueryCondition condition = new DeviceQueryCondition();

            condition.searchkey     = searchkey;
            ViewData["requestData"] = condition;
            List <serialservice> totalList = null;

            try
            {
                using (mlrmsEntities db = new mlrmsEntities())
                {
                    int totalCount = db.serialservice.Count();
                    if (totalCount == 0)
                    {
                        return(View());
                    }
                    PageModel page = new PageModel()
                    {
                        SearchKeyWord = searchkey, SearchType = 0, CurrentIndex = Int32.Parse(index), TotalCount = totalCount
                    };
                    totalList             = db.serialservice.Where(p => p.name.ToLower().Contains(searchkey.ToLower()) || p.code.ToString().Contains(searchkey.ToLower())).OrderBy(m => m.name).Skip((page.CurrentIndex - 1) * page.PageSize).Take(page.PageSize).ToList();
                    ViewData["pagemodel"] = page;
                    return(View(totalList));
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error("设备列表加载失败", ex);
                return(View());
            }
        }
Beispiel #2
0
        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());
            }
        }