public static object[] SelectTags(string keyword, string groupIdSerial, int pageSize, int skipOffset)
        {
            using (AppDataContext db = new AppDataContext()) {
                //20091231: need to set filter
                if (Config.Settings.ModelHFilter != "")
                {
                    TagStatusView.aLicenseTagHFilter = Config.Settings.ModelHFilter.Split(';');
                }
                List <int> lHostTagIds = db.HostTags.Select(h => h.TagId).ToList();
                var        query       = Tag.AllValidTags
                                         //.Where(t => Config.Settings.ModelHFilter.Split(';').Contains(t.TagMac.Substring(0,5)))
                                         .Where(t => !lHostTagIds.Contains(t.Id))
                                         .Select(t => new {
                    Id      = t.Id,
                    TagName = t.TagMac.Substring(9, 8)
                });

                if (!string.IsNullOrEmpty(keyword))
                {
                    query = query.Where(t => t.TagName.Contains(keyword.Trim()));
                }
                if (!string.IsNullOrEmpty(groupIdSerial))
                {
                    var range1 = TagGroupCoverage.GetCoveredTagIdArray(Strings.ParseToArray <int>(groupIdSerial));
                    var range2 = HostTagGroupStatus.GetCoveredTagIdArray(Strings.ParseToArray <int>(groupIdSerial));
                    var range  = MergeTwoArrayWithoutDuplicates(range1, range2);
                    query = query.Where(t => range.Contains(t.Id));
                }

                query = query.OrderBy(t => t.TagName).Skip(skipOffset).Take(pageSize);

                return(query.ToArray());
            }
        }
Esempio n. 2
0
        private void LoadRepeater()
        {
            using (AppDataContext db = new AppDataContext())
            {
                var query = db.DBViewTagSettings
                            .Where(x => HostTag.All
                                   .Where(u => u.TagId != 0)
                                   .Select(u => u.TagId).ToArray()
                                   .Contains((int)x.Id));//x.TagId));
                switch (stateFilter.SelectedIndex)
                {
                default:
                case 0:
                    break;

                case 1:
                    query = query.Where(x => x.WorkingStatus == (byte)TagWorkingStatus.Locating);
                    break;

                case 2:
                    query = query.Where(x => x.WorkingStatus != (byte)TagWorkingStatus.Locating);
                    break;

                case 3:
                    query = query.Where(x => x.CommandState == null);
                    break;
                }

                string keyword = tagNameKeyword.Text == "关键字" ? string.Empty : tagNameKeyword.Text.Trim();
                if (keyword.Length != 0)
                {
                    query = query.Where(x => x.HostName.Contains(keyword));
                }

                if (groupSelector.SelectedGroupIdArray != null && groupSelector.SelectedGroupIdArray.Length > 0)
                {
                    var range = HostTagGroupStatus.GetCoveredTagIdArray(groupSelector.SelectedGroupIdArray);
                    query = query.Where(x => range.Contains((int)x.Id));//x.TagId));
                }

                p.RecordCount          = query.Count();
                settingList.DataSource = query.OrderByDescending(x => x.HostName).Skip(p.RecordOffset).Take(p.PageSize).ToList();
                settingList.DataBind();
                //settingList.DataSource = query.Skip(p.RecordOffset).Take(p.PageSize).OrderBy(x => x.TagName).ToList();
            }
        }