Пример #1
0
        private static void SearchGroupChidren(SearchGroupModel sgroupmodel, List <Options> grouplist, List <SearchGroupModel> sgroup)
        {
            List <Options> optionlist = grouplist.FindAll(o => o.tag.ToString() == sgroupmodel.groupvalue.ToString());

            if (optionlist != null)
            {
                SearchGroupModel tsgm;
                foreach (Options option in optionlist)
                {
                    tsgm = sgroup.Find(o => o.groupvalue == option.id);
                    if (tsgm != null)
                    {
                        sgroupmodel.groupcount += tsgm.groupcount;
                        sgroupmodel.grouptags  += tsgm.groupvalue + ",";
                        sgroupmodel.children.Add(tsgm);

                        tsgm.children = new List <SearchGroupModel>();
                        SearchGroupChidren(tsgm, grouplist, sgroup);
                        if (string.IsNullOrEmpty(tsgm.grouptags))
                        {
                            tsgm.grouptags = tsgm.groupvalue;
                        }
                        else
                        {
                            tsgm.grouptags = tsgm.grouptags.Trim(',');
                        }
                    }
                }
            }
        }
Пример #2
0
        public static List <SearchGroupModel> GetClassGroupTree(int parentid, List <SearchGroupModel> sgrouplist)
        {
            List <SearchGroupModel> grouptree     = new List <SearchGroupModel>();
            List <Options>          optiononelist = classList[parentid].FindAll(o => o.tag.ToString() == parentid.ToString());
            SearchGroupModel        tsgm;

            if (optiononelist != null)
            {
                foreach (Options option in optiononelist)
                {
                    tsgm = sgrouplist.Find(o => o.groupvalue == option.id);
                    if (tsgm == null)
                    {
                        tsgm = new SearchGroupModel()
                        {
                            groupvalue = option.id,
                            groupname  = option.text,
                            groupcount = 0,
                        };
                    }
                    tsgm.children = new List <SearchGroupModel>();
                    grouptree.Add(tsgm);
                    SearchGroupChidren(tsgm, classList[parentid], sgrouplist);
                    if (string.IsNullOrEmpty(tsgm.grouptags))
                    {
                        tsgm.grouptags = tsgm.groupvalue;
                    }
                    else
                    {
                        tsgm.grouptags = tsgm.grouptags.Trim(',');
                    }
                }
            }
            return(grouptree);
        }
Пример #3
0
        public object SearchExtend(QuerySearchModel query)
        {
            if (query == null)
            {
                return new { Rcode = -1, Rmsg = "错误请求" }
            }
            ;

            string       errmsg  = null;
            TimeSpan     usetime = new TimeSpan();
            SearchResult result  = SearchBLL.SearchQuery(query, ref usetime, ref errmsg);

            if (!string.IsNullOrEmpty(errmsg) || result == null)
            {
                return new { Rcode = -1, Rmsg = errmsg }
            }
            ;
            else if (result.TotalCount == 0)
            {
                return new { Rcode = 0, total = 0, Rmsg = "没有符合条件的数据" }
            }
            ;
            else
            {
                if (string.IsNullOrEmpty(query.groupName))
                {
                    DataTable rdt = new DataTable();
                    //   int pagecount = result.ResultCount % query.rows == 0 ? result.ResultCount / query.rows : result.ResultCount / query.rows + 1;
                    if (result.Attrs != null && result.Attrs.Length > 0)
                    {
                        rdt.Columns.Add(new DataColumn("seqid"));
                        foreach (AttrMatch am in result.Attrs)
                        {
                            rdt.Columns.Add(new DataColumn(am.AttrName));
                        }
                    }
                    DataRow dr;
                    foreach (ResultMatches match in result.Matches)
                    {
                        dr          = rdt.NewRow();
                        dr["seqid"] = match.DocumentID;
                        foreach (DataColumn dc in rdt.Columns)
                        {
                            if (dc.ColumnName != "seqid")
                            {
                                dr[dc.ColumnName] = match.GetAttrValue(dc.ColumnName);
                            }
                        }
                        rdt.Rows.Add(dr);
                    }
                    return(new
                    {
                        Rcode = 1,
                        list = rdt,
                        total = result.TotalCount,
                        PageCount = result.TotalCount,
                        usetime = usetime.TotalMilliseconds
                    });
                }
                else
                {
                    int            classparentid = 12;
                    string         _errmsg;
                    List <Options> optionlist = null;
                    switch (query.groupName.Trim())
                    {
                    case "restype":
                        SearchBLL.GetResTypeOptions(out _errmsg);
                        optionlist = SearchBLL.restypeList;
                        break;

                    case "classid":
                        SearchBLL.GetClassOptions(classparentid, out _errmsg);
                        optionlist = SearchBLL.classList[classparentid];
                        break;

                    case "languageid":
                        SearchBLL.GetDicOptions(out _errmsg);
                        optionlist = SearchBLL.dictList["language"];
                        break;

                    case "authorstr":
                        SearchBLL.GetAuthorOptions(out _errmsg);
                        optionlist = SearchBLL.authorsList;
                        break;
                    }
                    List <SearchGroupModel> grouplist = new List <SearchGroupModel>();
                    SearchGroupModel        group;
                    foreach (ResultMatches match in result.Matches)
                    {
                        group            = new SearchGroupModel();
                        group.groupvalue = match.GetAttrValue("@groupby").ToString().Trim();
                        group.groupcount = int.Parse(match.GetAttrValue("@count").ToString());
                        Options option = optionlist != null?optionlist.Find(o => o.id == group.groupvalue) : null;

                        if (option != null)
                        {
                            group.groupname = option.text;
                        }
                        else
                        {
                            group.groupname = group.groupvalue;
                        }
                        grouplist.Add(group);
                    }
                    if (query.groupName.Trim().Equals("classid"))
                    {
                        grouplist = SearchBLL.GetClassGroupTree(classparentid, grouplist);
                    }
                    return(new
                    {
                        Rcode = 1,
                        list = grouplist,
                        total = result.TotalCount,
                        PageCount = result.TotalCount,
                        usetime = usetime.TotalMilliseconds
                    });
                }
            }
        }