地铁二期项目正式开始

ClassController.cs 7.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. using Newtonsoft.Json;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.IO;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Web;
  9. using System.Web.Mvc;
  10. using YTSoft.BaseCallCenter.Model;
  11. using YTSoft.BaseCallCenter.MVCWeb.Models;
  12. /// <summary>
  13. /// 标签快捷管理
  14. /// </summary>
  15. namespace YTSoft.BaseCallCenter.MVCWeb.Controllers
  16. {
  17. public class ClassController : BaseController
  18. {
  19. BLL.T_Com_Class busClass = new BLL.T_Com_Class();
  20. #region 纯视图
  21. /// <summary>
  22. /// 回复列表
  23. /// </summary>
  24. /// <returns></returns>
  25. public ActionResult GetList()
  26. {
  27. return View();
  28. }
  29. /// <summary>
  30. /// 添加 视图
  31. /// </summary>
  32. /// <returns></returns>
  33. public ActionResult Add()
  34. {
  35. return View();
  36. }
  37. /// <summary>
  38. /// 修改 视图
  39. /// </summary>
  40. /// <returns></returns>
  41. public ActionResult Edit()
  42. {
  43. return View();
  44. }
  45. #endregion
  46. #region 增删改查
  47. [ActionName("GetListData")]
  48. public string GetListData(string key = "", int page = 0, int limit = 20)
  49. {
  50. string strWhere = " 1=1 ";
  51. if (!string.IsNullOrEmpty(key))
  52. {
  53. strWhere += string.Format(" and Classname like '%{0}%'", key);
  54. }
  55. DataTable dt = busClass.GetListByPage(strWhere, " Classid desc ", (page - 1) * limit, limit).Tables[0];
  56. int count = busClass.GetRecordCount(strWhere);
  57. return Success("成功", dt, count);
  58. }
  59. [ActionName("GetData")]
  60. public string GettData(int id)
  61. {
  62. if (id==0)
  63. return Error("请输入ID");
  64. Model.T_Com_Class model = busClass.GetModel(id);
  65. return Success("成功", model, 1);
  66. }
  67. [ActionName("deletedata")]
  68. public string DeleteData(int id)
  69. {
  70. if (busClass.Delete(id))
  71. {
  72. //AddLog("T_Com_LogAction", model.Id, "删除消息", model, "");
  73. return Success("删除成功");
  74. }
  75. else
  76. return Error("失败");
  77. }
  78. [ActionName("adddata")]
  79. public string AddData(T_Com_Class modelinput)
  80. {
  81. T_Com_Class model = new T_Com_Class();
  82. model.Classcode = modelinput.Classcode;
  83. model.Classname = modelinput.Classname;
  84. //model.Parentcode = modelinput.Parentcode;
  85. model.Parentid = modelinput.Parentid;
  86. model.Remark = modelinput.Remark;
  87. model.Sort = modelinput.Sort;
  88. if (modelinput.Parentid != 0)
  89. {
  90. T_Com_Class modeltemp = busClass.GetModel(modelinput.Parentid);
  91. if (modeltemp.Parentid == 0)
  92. model.typeid = modeltemp.Classid;
  93. else
  94. model.typeid = modeltemp.typeid;
  95. }
  96. if (string.IsNullOrEmpty(modelinput.Classname))
  97. {
  98. return Error("请输入值Classname");
  99. }
  100. string strWhere = string.Format(" Classname='{0}' and Parentid='{1}' ", model.Classname, model.Parentid);
  101. int count = busClass.GetRecordCount(strWhere);
  102. if (count > 0)
  103. {
  104. return Error("已存在");
  105. }
  106. if (busClass.Add(model) >0)
  107. {
  108. //AddLog("T_Com_Tag", model.F_Id.ToString(), "添加标签", "", model);
  109. return Success("成功", modelinput, 1);
  110. }
  111. else
  112. return Error("失败");
  113. }
  114. [ActionName("editdata")]
  115. public string EditData(T_Com_Class modelinput)
  116. {
  117. if (string.IsNullOrEmpty(modelinput.Classname))
  118. {
  119. return Error("请输入值Classname");
  120. }
  121. if (modelinput.Classid == 0)
  122. return Error("请输入值Classid");
  123. string strWhere = string.Format(" Classname='{0}' and Parentid='{1}' and Classid!={2} ", modelinput.Classname, modelinput.Parentid, modelinput.Classid);
  124. int count = busClass.GetRecordCount(strWhere);
  125. if (count > 0)
  126. {
  127. return Error("已存在");
  128. }
  129. Model.T_Com_Class model = busClass.GetModel(modelinput.Classid);
  130. model.Classname = modelinput.Classname;
  131. model.Parentid = modelinput.Parentid;
  132. model.Remark = modelinput.Remark;
  133. model.Sort = modelinput.Sort;
  134. model.Classcode = modelinput.Classcode;
  135. if (modelinput.Parentid != 0)
  136. {
  137. T_Com_Class modeltemp = busClass.GetModel(modelinput.Parentid);
  138. if (modeltemp.Parentid == 0)
  139. model.typeid = modeltemp.Classid;
  140. else
  141. model.typeid = modeltemp.typeid;
  142. }
  143. if (busClass.Update(model))
  144. {
  145. //AddLog("T_Com_Tag", model.F_Id.ToString(), "修改消息", modelold, model);
  146. return Success("成功", model, 1);
  147. }
  148. else
  149. return Error("失败");
  150. }
  151. #endregion
  152. #region 获取树结构
  153. /// <summary>
  154. /// 获得当前节点下的所有子集以tree的格式
  155. /// </summary>
  156. public TreeNodeModel GetTreeJsonModel(int parentId, int type = 0)
  157. {
  158. TreeNodeModel returnModel = new TreeNodeModel();
  159. DataSet ds = busClass.GetList(string.Format("Parentid={0} Order by sort desc", parentId));
  160. if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
  161. {
  162. TreeNodeModel model = new TreeNodeModel();
  163. if (!false)
  164. {
  165. List<TreeNodeModel> modelList = new List<TreeNodeModel>();
  166. model.id = 0;
  167. model.name = "通用字典";
  168. model.code = 0;
  169. model.iconClose = "../../Content/layui/zTree/v3/css/zTreeStyle/img/diy/1_close.png";
  170. model.iconOpen = "../../Content/layui/zTree/v3/css/zTreeStyle/img/diy/1_open.png";
  171. model.open = "true";
  172. model.children = modelList;
  173. }
  174. returnModel = GetTreeModel(ds.Tables[0], model, type);
  175. }
  176. return returnModel;
  177. }
  178. /// <summary>
  179. /// 获取chlid
  180. /// </summary>
  181. /// <param name="table">数据结合</param>
  182. /// <param name="model">当前model</param>
  183. /// <returns></returns>
  184. public TreeNodeModel GetTreeModel(DataTable table, TreeNodeModel model, int type)
  185. {
  186. DataSet ds = busClass.GetList(string.Format("Parentid={0} Order by sort desc", model.code));
  187. if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
  188. {
  189. foreach (DataRow row in ds.Tables[0].Rows)
  190. {
  191. List<TreeNodeModel> modelList = new List<TreeNodeModel>();
  192. TreeNodeModel childModel = new TreeNodeModel();
  193. childModel.id = int.Parse(row["Classid"].ToString());
  194. childModel.name = row["Classname"].ToString();
  195. childModel.code = int.Parse(row["Parentid"].ToString());
  196. childModel.iconClose = "../../Content/layui/zTree/v3/css/zTreeStyle/img/diy/1_close.png";
  197. childModel.iconOpen = "../../Content/layui/zTree/v3/css/zTreeStyle/img/diy/1_open.png";
  198. childModel.open = "true";
  199. childModel.children = modelList;
  200. model.children.Add(childModel);
  201. GetTreeModel(table, childModel, type);
  202. }
  203. }
  204. return model;
  205. }
  206. #endregion
  207. }
  208. }