public string GetCode(string Title)
        {
            var data   = KindCodeOperation.CodeData.Where(x => x.Title == Title).First();
            var result = DataMapperHelper.Map <CodeViewModel>(data);

            result.Kind = KindCodeOperation.Path_Kind(Title);
            return(JsonConvert.SerializeObject(result));
        }
 /// <summary>
 /// 获取代码给app
 /// </summary>
 /// <param name="title"></param>
 /// <returns></returns>
 public string GetCode(string title)
 {
     try
     {
         var data = KindCodeOperation.CodeData.Where(x => x.Title == title).First();
         data.Code = HttpUtility.UrlDecode(data.Code);
         data.Code = data.Code.Replace(" ", "\\b");
         var result = DataMapperHelper.Map <CodeViewModel>(data);
         result.Kind = KindCodeOperation.Path_Kind(title);
         return(JsonConvert.SerializeObject(result));
     }
     catch (Exception e)
     {
         return("您提交的数据标题为:" + title + "\n" + e.Message);
     }
 }
Exemplo n.º 3
0
        ///搜索
        public string SearchTitle(string Title, string Select)
        {
            List <ListData> result = new List <ListData>();//搜索完返回结果

            if (KindCodeOperation.CodeData == null)
            {
                return("还未初始化,请等待");
            }

            if (Select == "所有")//判断是否为所有
            {
                Titles("无");
            }
            else
            {
                string id = (from a in KindCodeOperation.KindData where a.ParentId == "无" && a.Name == Select select a).Single().objectId;
                Titles(id);
            }
            if (PublicPermission((string)SessionHelp.Get("UserName")))//判断是否为一半账户,分两组数据类分别存共有和私有
            {
                int i = 0;
                do
                {
                    string data = (string)selectTitles[i];
                    if (KindCodeOperation.CodeData.Where(x => x.Title == data).Single().Visible == "Invisible")
                    {
                        selectTitles.Remove(data); i--;
                    }
                    i++;
                } while (i < selectTitles.Count);
            }
            result = SearchEngines.Search(selectTitles, Title); //开始搜索并返回结果
            foreach (var a in result)                           //使得前端高亮匹配显示
            {
                List <int> count = new List <int>();
                for (int i = 0; i < a.Word.Length - 1; i++)
                {
                    int str = a.Search.ToLower().IndexOf(a.Word[i]);
                    for (int j = str; j < str + a.Word[i].Length; j++)
                    {
                        count.Add(j);
                    }
                }
                string Result = "<li onclick=\"ShowData(&quot;" + a.Search + "&quot;,this)\">";
                for (int i = 0; i < a.Search.Length; i++)
                {
                    if (count.Contains(i))
                    {
                        Result += "<div style=\"color:red\">" + a.Search.Substring(i, 1) + "</div>";
                    }
                    else
                    {
                        Result += "<div>" + a.Search.Substring(i, 1) + "</div>";
                    }
                }
                List <string> PathKind = new List <string>();//找出此标题的父分类
                var           data     = KindCodeOperation.CodeData.Where(x => x.Title == a.Search).Single();
                string        id       = KindCodeOperation.KindData.Where(x => x.objectId == data.KindObjectId).Single().ParentId;
                KindCodeOperation.KindPath(id, ref PathKind);
                Result += "<div class='seach-move'><div style='float:none'>分类:" + PathKind[PathKind.Count - 1] + "</div><div style='float:none'>作者:" + data.Author + "</div></div>";
                Result += "</li>";
                list.Add(new ReturnTitle()
                {
                    title = Result
                });
            }
            string jsonData = JsonConvert.SerializeObject(list);

            return(jsonData);
        }