/// <summary> /// 搜索页面修改代码数据 /// </summary> /// <param name="Title"></param> /// <param name="Code"></param> /// <param name="Visible"></param> /// <returns></returns> public string ModifyCode(string Title, string Code, string Visible) { var data = CodeData.Where(x => x.Title == Title).Single(); if (code.ModifyData(new CodeModel { fTable = "Code_tb", Visible = Visible, Title = Title, Code = Code, objectId = data.objectId })) { data.Code = Code; data.Visible = Visible; data.Title = Title; //添加修改记录-------------------- if (Visible == "Visible") { OperationModel operationModel = new OperationModel("OperationNews_tb"); operationModel.User = (string)SessionHelp.Get("UserName"); operationModel.Operate = "修改了"; operationModel.Title = Title; List <string> PathKind = new List <string>(); string id; id = KindData.Where(x => x.objectId == data.KindObjectId).Single().ParentId; KindPath(id, ref PathKind); operationModel.Kind = PathKind[PathKind.Count - 1]; operate.Create(operationModel); } //添加修改记录------------------- return("修改成功"); } return("修改失败"); }
/// <summary> /// 添加代码 /// </summary> /// <param name="Title"></param> /// <param name="Kind"></param> /// <param name="Code"></param> /// <param name="Author"></param> /// <returns></returns> public string AddData(CodeModel model) { try { string codeId, ParentId = model.objectId;//将model里的分类id提取出来作为父项分类id,之前暂存进去的 string kindId; var data = CodeData.Where(x => x.Title == model.Title).ToList(); if (data.Count > 0) { return("出错,此标题已存在"); } KindModel kindmodel = new KindModel("Kind_tb"); kindmodel.ParentId = ParentId; kindmodel.Name = model.Title; kindId = kind.Create(kindmodel); if (kindId != null) { kindmodel.objectId = kindId; KindData.Add(kindmodel); model.KindObjectId = kindId; codeId = code.Create(model);; if (codeId != null) { model.objectId = codeId; CodeData.Add(model); if (model.Visible == "Visible") { OperationModel operationModel = new OperationModel("OperationNews_tb"); operationModel.User = (string)SessionHelp.Get("UserName"); List <string> PathKind = new List <string>(); KindPath(ParentId, ref PathKind); operationModel.Kind = PathKind[PathKind.Count - 1]; operationModel.Operate = "添加了"; operationModel.Title = model.Title; operate.Create(operationModel); } return(kindId); } else { return("出错,添加代码成功,添加标题失败"); } } else { return("出错,添加代码失败"); } } catch (Exception e) { return("出错," + e.Message); } }
/// <summary> /// 修改代码数据 /// </summary> /// <param name="Title"></param> /// <param name="Code"></param> /// <param name="Id"></param> /// <returns></returns> public string ModifyCode(string Title, string Code, string Id, string OldTitle, string Visible) { if (Title != OldTitle) { var test = CodeData.Where(x => x.Title == Title).ToList(); if (test.Count > 0) { return(ToJson("出错,已存在改标题")); } KindModel kindmodel = new KindModel("Kind_tb"); kindmodel.objectId = Id; kindmodel.Name = Title; if (kind.ModifyData(kindmodel)) { var data_ = KindData.Where(x => x.objectId == Id).Single(); data_.Name = Title; } else { return(ToJson("出错,修改分类失败")); } } var data = CodeData.Where(x => x.Title == OldTitle).Single(); CodeModel model = new CodeModel("Code_tb"); model.objectId = data.objectId; model.Title = Title; model.Code = Code; model.Visible = Visible; if (code.ModifyData(model)) { data.Title = Title; data.Code = Code; data.Visible = Visible; } //添加修改记录-------------------- if (Visible == "Visible") { OperationModel operationModel = new OperationModel("OperationNews_tb"); operationModel.User = (string)SessionHelp.Get("UserName"); operationModel.Operate = "修改了"; operationModel.Title = Title; List <string> PathKind = new List <string>(); string id; id = KindData.Where(x => x.objectId == Id).Single().ParentId; KindPath(id, ref PathKind); operationModel.Kind = PathKind[PathKind.Count - 1]; operate.Create(operationModel); } //添加修改记录------------------- return(ToJson("修改成功")); }
/// <summary> /// 获取操作记录 /// </summary> /// <returns></returns> /// public string GetAllOperate() { DateTime date = DateTime.Now.AddDays(-5); var data = (from a in operate.GetAll("OperationNews_tb") where Convert.ToDateTime(a.createdAt) > date && a.User != (string)SessionHelp.Get("UserName") orderby a.createdAt descending select a).ToList(); return(JsonConvert.SerializeObject(data)); }
//获取单条数据 //获取当前登陆用户 public string GetUserName() { string username = (string)SessionHelp.Get("UserName"); return(username); }
///搜索 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("" + a.Search + "",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); }
/// <summary> /// Json序列化所有分类 /// </summary> /// <param name="table"></param> /// <returns></returns> public string ToKindJson(IEnumerable <KindModel> KindTable, IEnumerable <CodeModel> CodeTable) { List <TreeModel> list = new List <TreeModel>(); foreach (KindModel row in KindTable) { string Color = "blue"; string Icon = "glyphicon glyphicon-folder-open"; bool pri = false;//判断是否为私有账户,true为私有账户,跳过添加 if (row.ParentId == "无") { Color = "brown"; Icon = "glyphicon glyphicon-folder-open"; } else { var data = CodeData.Where(x => x.KindObjectId == row.objectId).ToList(); if (data.Count == 1) { if (data.First().Visible == "Invisible" && PublicPermission((string)SessionHelp.Get("UserName"))) { pri = true; } Color = "black"; Icon = "glyphicon glyphicon-pencil"; } else { foreach (KindModel row_ in KindTable) { if (row_.ParentId.ToString() == row.objectId) { Color = "#4B0082"; Icon = "glyphicon glyphicon-folder-open"; break; } } } if (pri) { continue; } } list.Add(new TreeModel() { Id = row.objectId, ParentId = row.ParentId, text = row.Name, color = Color, icon = Icon }); } string JsonData = JsonConvert.SerializeObject(list); return(JsonData); }