ZZDianXin_API - 郑州电信演示

IndexBaseController.cs 9.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. using CallCenter.Utility;
  2. using CallCenterApi.DB;
  3. using CallCenterApi.Interface.Controllers.Base;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Data;
  7. using System.Linq;
  8. using System.Web;
  9. using System.Web.Mvc;
  10. namespace CallCenterApi.Interface.Controllers.quality
  11. {
  12. public class IndexBaseController : BaseController
  13. {
  14. //获取指标列表
  15. public ActionResult GetList()
  16. {
  17. string sql = "";
  18. DataTable dt = new DataTable();
  19. string categoryid = RequestString.GetQueryString("categoryid");
  20. string key = WebHelper.UrlDecode(RequestString.GetQueryString("key"));
  21. string strpageindex = RequestString.GetQueryString("page");
  22. int pageindex = 1;
  23. string strpagesize = RequestString.GetQueryString("pagesize");
  24. int pagesize = 10;
  25. if (categoryid.Trim() != "")
  26. {
  27. sql += " and (F_CategoryId=" + categoryid + " or F_CategoryId in (select F_CategoryId from T_QC_IndexCategory where F_ParentId=" + categoryid + " )) ";
  28. }
  29. if (key.Trim() != "")
  30. {
  31. sql += " and (F_Title like '%" + key.Trim() + "%' or F_Content like '%" + key.Trim() + "%') ";
  32. }
  33. if (strpageindex.Trim() != "")
  34. {
  35. pageindex = Convert.ToInt32(strpageindex);
  36. }
  37. if (strpagesize.Trim() != "")
  38. {
  39. pagesize = Convert.ToInt32(strpagesize);
  40. }
  41. int recordCount = 0;
  42. dt = BLL.PagerBLL.GetListPager(
  43. "vw_QC_IndexBase",
  44. "F_IndexId",
  45. "*",
  46. " and F_DeleteFlag=0 " + sql,
  47. "ORDER BY F_Sort",
  48. pagesize,
  49. pageindex,
  50. true,
  51. out recordCount);
  52. var obj = new
  53. {
  54. rows = dt,
  55. total = recordCount
  56. };
  57. return Content(obj.ToJson());
  58. }
  59. //获取指标
  60. public ActionResult GetIndexBase(string id)
  61. {
  62. if (id.Trim() != "")
  63. {
  64. BLL.T_QC_IndexBase dBLL = new BLL.T_QC_IndexBase();
  65. Model.T_QC_IndexBase dModel = dBLL.GetModel(int.Parse(id.Trim()));
  66. if (dModel != null)
  67. {
  68. return Success("获取指标成功", dModel);
  69. }
  70. else
  71. {
  72. return Error("获取指标失败");
  73. }
  74. }
  75. else
  76. {
  77. return Error("获取参数失败");
  78. }
  79. }
  80. //添加指标
  81. public ActionResult AddIndexBase(string cid, string score, string sort, string title, string remark)
  82. {
  83. if (Request.IsAuthenticated)
  84. {
  85. Model.T_QC_IndexBase dModel = new Model.T_QC_IndexBase();
  86. if (!string.IsNullOrEmpty(cid))
  87. {
  88. dModel.F_CategoryId = int.Parse(cid.Trim());
  89. }
  90. if (!string.IsNullOrEmpty(sort))
  91. {
  92. if (double.Parse(sort.Trim()) > 100000)
  93. {
  94. return Error("排序过大,请重新输入");
  95. }
  96. else
  97. dModel.F_Sort = Convert.ToInt32(sort.Trim());
  98. }
  99. if (!string.IsNullOrEmpty(score))
  100. {
  101. if (double .Parse (score.Trim())>100000)
  102. {
  103. return Error("分值过大,请重新输入");
  104. }
  105. else
  106. dModel.F_Score = Convert.ToInt32(score.Trim());
  107. }
  108. if (!string.IsNullOrEmpty(title))
  109. {
  110. dModel.F_Title = title.Trim();
  111. }
  112. if (!string.IsNullOrEmpty(remark))
  113. {
  114. dModel.F_Remark = remark.Trim();
  115. }
  116. dModel.F_CreateOn = DateTime.Now;
  117. dModel.F_CreateBy = CurrentUser.UserData.F_UserId;
  118. dModel.F_DeleteFlag = 0;
  119. bool b = new BLL.T_QC_IndexBase().Add(dModel) > 0;
  120. if (b)
  121. {
  122. //添加成功后要将对应父级的分值增加上
  123. SetScoreByCategory(dModel.F_CategoryId.ToString());
  124. return Success("添加成功");
  125. }
  126. else
  127. {
  128. return Success("添加失败");
  129. }
  130. }
  131. return NoToken("未知错误,请重新登录");
  132. }
  133. //编辑指标
  134. public ActionResult EditIndexBase(string id, string cid, string title, string remark,string sort, string score)
  135. {
  136. if (Request.IsAuthenticated)
  137. {
  138. if (cid.Trim() != "")
  139. {
  140. BLL.T_QC_IndexBase dBLL = new BLL.T_QC_IndexBase();
  141. Model.T_QC_IndexBase dModel = dBLL.GetModel(int.Parse(id.Trim()));
  142. if (dModel != null)
  143. {
  144. if (!string.IsNullOrEmpty (cid))
  145. {
  146. dModel.F_CategoryId = int.Parse(cid.Trim());
  147. }
  148. if (!string.IsNullOrEmpty(sort))
  149. {
  150. if (double.Parse(sort.Trim()) > 100000)
  151. {
  152. return Error("排序过大,请重新输入");
  153. }
  154. else
  155. dModel.F_Sort = int .Parse(sort.Trim());
  156. }
  157. if (!string.IsNullOrEmpty(score))
  158. {
  159. if (double.Parse(score.Trim()) > 100000)
  160. {
  161. return Error("分值过大,请重新输入");
  162. }
  163. else
  164. dModel.F_Score = int.Parse(score.Trim());
  165. }
  166. if (!string.IsNullOrEmpty(title))
  167. {
  168. dModel.F_Title = title.Trim();
  169. }
  170. if (!string.IsNullOrEmpty(remark))
  171. {
  172. dModel.F_Remark = remark.Trim();
  173. }
  174. bool b = dBLL.Update(dModel);
  175. if (b)
  176. {
  177. SetScoreByCategory(dModel.F_CategoryId.ToString());
  178. return Success("编辑成功");
  179. }
  180. else
  181. {
  182. return Success("编辑失败");
  183. }
  184. }
  185. else
  186. return Error("获取信息失败");
  187. }
  188. else
  189. {
  190. return Error("请选择要编辑的指标");
  191. }
  192. }
  193. return NoToken("未知错误,请重新登录");
  194. }
  195. //删除指标记录
  196. public ActionResult DelIndexBase(string id, string cid)
  197. {
  198. DataTable dt = new DataTable();
  199. if (!string.IsNullOrEmpty(id.Trim()))
  200. {
  201. if (new BLL.T_QC_IndexBase().Delete(Convert.ToInt32(id)))
  202. {
  203. SetScoreByCategory(cid);
  204. return Success("删除成功");
  205. }
  206. else
  207. {
  208. return Error("删除失败");
  209. }
  210. }
  211. else
  212. {
  213. return Error("请选择要删除的记录");
  214. }
  215. }
  216. //设置指标分数
  217. private void SetScoreByCategory(string categoryid)
  218. {
  219. DataTable dt = new DataTable();
  220. try
  221. {
  222. Model.T_QC_IndexCategory model = new BLL.T_QC_IndexCategory().GetModel(Convert.ToInt32(categoryid));
  223. if (model != null)
  224. {
  225. string parentid = model.F_ParentId.ToString();
  226. dt = new BLL.T_QC_IndexBase().GetList("F_DeleteFlag=0 and (F_CategoryId=" + model.F_CategoryId + " or F_CategoryId in (select F_CategoryId from T_QC_IndexCategory where F_ParentId=" + categoryid + " )) ").Tables[0];
  227. int score = 0;
  228. for (int i = 0; i < dt.Rows.Count; i++)
  229. {
  230. score += Convert.ToInt32(dt.Rows[i]["F_Score"].ToString().Trim());
  231. }
  232. model.F_Expand1 = score.ToString();
  233. if (new BLL.T_QC_IndexCategory().Update(model))
  234. {
  235. if (parentid != "0")
  236. {
  237. SetScoreByCategory(parentid);
  238. }
  239. }
  240. }
  241. }
  242. catch { }
  243. finally
  244. {
  245. dt.Clear();
  246. dt.Dispose();
  247. }
  248. }
  249. }
  250. }