Açıklama Yok

PolicyController.cs 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. using CallCenter.Utility;
  2. using CallCenterApi.Interface.Controllers.Base;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Data;
  6. using System.Linq;
  7. using System.Web;
  8. using System.Web.Mvc;
  9. namespace CallCenterApi.Interface.Controllers.Wiki
  10. {
  11. public class PolicyController : BaseController
  12. {
  13. // GET: Policy
  14. /// <summary>
  15. /// 上传附件
  16. /// </summary>
  17. /// <returns></returns>
  18. public ActionResult UploadFile()
  19. {
  20. HttpFileCollection files = RequestString.GetFiles();
  21. if (files.Count > 0)
  22. {
  23. List<Model.T_Sys_Accessories> acs = new List<Model.T_Sys_Accessories>();
  24. string path = "/Upload/Wiki/" + DateTime.Now.ToString("yyyy") + "/" + DateTime.Now.ToString("MM") + "/" + DateTime.Now.ToString("dd") + "/";
  25. for (int i = 0; i < files.Count; i++)
  26. {
  27. HttpPostedFile file = files[i];
  28. FileUp fu = new FileUp();
  29. string name = fu.Upload(file, path);
  30. Model.T_Sys_Accessories model_T_Sys_Accessories = new Model.T_Sys_Accessories();
  31. model_T_Sys_Accessories.F_AddTime = DateTime.Now;//上传时间
  32. model_T_Sys_Accessories.F_FileName = name;//附件名称
  33. model_T_Sys_Accessories.F_FileType = System.IO.Path.GetExtension(file.FileName);//附件类型
  34. model_T_Sys_Accessories.F_FileUrl = path + name;//附件地址
  35. model_T_Sys_Accessories.F_Size = file.ContentLength;
  36. model_T_Sys_Accessories.F_UserCode = User.F_UserCode;//上传人
  37. int id = new BLL.T_Sys_Accessories().Add(model_T_Sys_Accessories);
  38. model_T_Sys_Accessories.F_FileId = id;
  39. acs.Add(model_T_Sys_Accessories);
  40. }
  41. return Success("成功", acs);
  42. }
  43. else
  44. {
  45. return Error("请选择要上传的文件");
  46. }
  47. }
  48. /// <summary>
  49. /// 列表
  50. /// </summary>
  51. /// <param name="page"></param>
  52. /// <param name="pagesize"></param>
  53. /// <param name="isdc"></param>
  54. /// <returns></returns>
  55. public ActionResult GetList(string keyvalue, string stime, string etime, int key = 0, int page = 1, int pagesize = 10, int isdc = 0)
  56. {
  57. DataTable dt = new DataTable();
  58. string sql = " and F_IsDelete=0 ";
  59. string sqldt = "";
  60. if (stime.Trim() != "" && stime != "undefined")
  61. {
  62. sql += " and F_FaBuShiJian >= '" + stime + " 00:00:00" + "' ";
  63. }
  64. if (etime.Trim() != "" && etime != "undefined")
  65. {
  66. sql += " and F_FaBuShiJian <= '" + etime + " 23:59:59" + "' ";
  67. }
  68. if (key > 0)
  69. {
  70. //sql += " and F_Key = " + key;
  71. sqldt = " INNER JOIN [GetValueId]('" + key + "') Value on a.F_Key = Value.F_ValueId";
  72. }
  73. if (!string.IsNullOrEmpty(keyvalue))
  74. {
  75. sql += " and (F_FaWenWenHao like '%" + keyvalue + "%' or F_FaWenDanWei like '%" + keyvalue + "%' orF_BiaoShiBianMa like '%" + keyvalue + "%' or F_ZhiNengBuMen like '%" + keyvalue + "%' or F_WenJianMingCheng like '%" + keyvalue + "%' or F_WenJianNeiRong like '%" + keyvalue + "%')";
  76. }
  77. string cols = "a.*,dbo.GetDictionaryName(F_Key) as KeyName";
  78. if (isdc > 0)
  79. {
  80. var dtdc = DB.DbHelperSQL.Query(" select " + cols + " from T_Wiki_Policy a with(nolock) " + sqldt + " where 1=1 " + sql).Tables[0];
  81. var msg = new NPOIHelper().ExportToExcel("办事指南", dtdc);
  82. if (msg == "")
  83. {
  84. return Success("导出成功");
  85. }
  86. else
  87. {
  88. return Error("导出失败");
  89. }
  90. }
  91. int recordCount = 0;
  92. dt = BLL.PagerBLL.GetListPager(
  93. "T_Wiki_Policy a with(nolock) " + sqldt,
  94. "F_Id",
  95. cols,
  96. sql,
  97. "ORDER BY F_DianJiLiang,F_CreateTime DESC",
  98. pagesize,
  99. page,
  100. true,
  101. out recordCount);
  102. var obj = new
  103. {
  104. state = "success",
  105. message = "成功",
  106. rows = dt,
  107. total = recordCount
  108. };
  109. return Content(obj.ToJson());
  110. }
  111. /// <summary>
  112. /// 获取
  113. /// </summary>
  114. /// <param name="id"></param>
  115. /// <returns></returns>
  116. public ActionResult GetModel(int id = 0)
  117. {
  118. if (id != 0)
  119. {
  120. var model = new BLL.T_Wiki_Policy().GetModel(id);
  121. if (model != null)
  122. {
  123. DB.DbHelperSQL.ExecuteSql(" update T_Wiki_Policy set F_DianJiLiang=F_DianJiLiang+1 where F_Id=" + id);
  124. DataTable dtkey = new DataTable();
  125. if (model.F_Key > 0)
  126. {
  127. dtkey = DB.DbHelperSQL.Query(" select * from View_KeysSplit where id=" + model.F_Key).Tables[0];
  128. }
  129. DataTable dtfile = new DataTable();
  130. var configfj = new BLL.T_Sys_SystemConfig().GetModelList(" F_ParamCode='FileUrlPath' ").FirstOrDefault();
  131. if (!string.IsNullOrEmpty(model.F_File) && configfj != null)
  132. {
  133. dtfile = DB.DbHelperSQL.Query("select * from T_Sys_Accessories WITH(NOLOCK) where F_FileId in (" + model.F_File + ")").Tables[0];
  134. foreach (DataRow dr in dtfile.Rows)
  135. {
  136. dr["F_FileUrl"] = configfj.F_ParamValue + dr["F_FileUrl"].ToString();
  137. }
  138. }
  139. var obj = new { model, dtkey, dtfile };
  140. return Success("成功", obj);
  141. }
  142. return Error("参数错误");
  143. }
  144. else
  145. {
  146. return Error("参数错误");
  147. }
  148. }
  149. /// <summary>
  150. /// 添加
  151. /// </summary>
  152. /// <param name="input"></param>
  153. /// <returns></returns>
  154. [HttpPost]
  155. public ActionResult AddModel(int id = 0, int key = 0)
  156. {
  157. string fabudanwei = RequestString.GetFormString("fabudanwei");
  158. string faburen = RequestString.GetFormString("faburen");
  159. string hangye = RequestString.GetFormString("hangye");
  160. string diqu = RequestString.GetFormString("diqu");
  161. string shengxiaoshijian = RequestString.GetFormString("shengxiaoshijian");
  162. string shixiaoshijian = RequestString.GetFormString("shixiaoshijian");
  163. string fabushijian = RequestString.GetFormString("fabushijian");
  164. string fawenwenhao = RequestString.GetFormString("fawenwenhao");
  165. string fawendanwei = RequestString.GetFormString("fawendanwei");
  166. string biaoshibianma = RequestString.GetFormString("biaoshibianma");
  167. string zhinengbumen = RequestString.GetFormString("zhinengbumen");
  168. string file = RequestString.GetFormString("file");
  169. string wenjianmingcheng = RequestString.GetFormString("wenjianmingcheng");
  170. string wenjianneirong = RequestString.GetFormString("wenjianneirong");
  171. Model.T_Wiki_Policy dModel = new Model.T_Wiki_Policy();
  172. if (id == 0)
  173. {
  174. //var list = new BLL.T_Wiki_Policy().GetList(" F_FaBuDanWei='" + fabudanwei + "' and F_IsDelete=0 ").Tables[0];
  175. //if (list.Rows.Count > 0)
  176. //{
  177. // return Error("已经存在");
  178. //}
  179. //else
  180. //{
  181. dModel.F_FaBuRen = faburen;
  182. dModel.F_FaBuDanWei = fabudanwei;
  183. dModel.F_HangYe = hangye;
  184. dModel.F_DiQu = diqu;
  185. try
  186. {
  187. dModel.F_ShengXiaoShiJian = DateTime.Parse(shengxiaoshijian);
  188. }
  189. catch { };
  190. try
  191. {
  192. dModel.F_ShiXiaoShiJian = DateTime.Parse(shixiaoshijian);
  193. }
  194. catch { };
  195. try
  196. {
  197. dModel.F_FaBuShiJian = DateTime.Parse(fabushijian);
  198. }
  199. catch { };
  200. dModel.F_Key = key;
  201. dModel.F_FaWenWenHao = fawenwenhao;
  202. dModel.F_FaWenDanWei = fawendanwei;
  203. dModel.F_BiaoShiBianMa = biaoshibianma;
  204. dModel.F_ZhiNengBuMen = zhinengbumen;
  205. dModel.F_File = file;
  206. dModel.F_WenJianMingCheng = wenjianmingcheng;
  207. dModel.F_WenJianNeiRong = wenjianneirong;
  208. dModel.F_DianJiLiang = 0;
  209. dModel.F_IsDelete = 0;
  210. dModel.F_CreateUser = User.F_UserCode;
  211. dModel.F_CreateTime = DateTime.Now;
  212. int n = new BLL.T_Wiki_Policy().Add(dModel);
  213. if (n > 0)
  214. return Success("添加成功", n);
  215. else
  216. return Error("添加失败");
  217. //}
  218. }
  219. else
  220. {
  221. dModel = new BLL.T_Wiki_Policy().GetModel(id);
  222. if (dModel != null)
  223. {
  224. //var list = new BLL.T_Wiki_Policy().GetList(" F_FaBuDanWei='" + fabudanwei + "' and F_IsDelete=0 and F_Id!='" + id + "' ").Tables[0];
  225. //if (list.Rows.Count > 0)
  226. //{
  227. // return Error("已经存在");
  228. //}
  229. //else
  230. //{
  231. dModel.F_FaBuRen = faburen;
  232. dModel.F_FaBuDanWei = fabudanwei;
  233. dModel.F_HangYe = hangye;
  234. dModel.F_DiQu = diqu;
  235. try
  236. {
  237. dModel.F_ShengXiaoShiJian = DateTime.Parse(shengxiaoshijian);
  238. }
  239. catch { };
  240. try
  241. {
  242. dModel.F_ShiXiaoShiJian = DateTime.Parse(shixiaoshijian);
  243. }
  244. catch { };
  245. try
  246. {
  247. dModel.F_FaBuShiJian = DateTime.Parse(fabushijian);
  248. }
  249. catch { };
  250. dModel.F_Key = key;
  251. dModel.F_FaWenWenHao = fawenwenhao;
  252. dModel.F_FaWenDanWei = fawendanwei;
  253. dModel.F_BiaoShiBianMa = biaoshibianma;
  254. dModel.F_ZhiNengBuMen = zhinengbumen;
  255. dModel.F_File = file;
  256. dModel.F_WenJianMingCheng = wenjianmingcheng;
  257. dModel.F_WenJianNeiRong = wenjianneirong;
  258. if (new BLL.T_Wiki_Policy().Update(dModel))
  259. return Success("修改成功");
  260. else
  261. return Error("修改失败");
  262. //}
  263. }
  264. else
  265. {
  266. return Error("修改失败");
  267. }
  268. }
  269. }
  270. /// <summary>
  271. /// 删除
  272. /// </summary>
  273. /// <param name="ids"></param>
  274. /// <returns></returns>
  275. public ActionResult DelModel(string[] ids)
  276. {
  277. if (ids == null || ids.Length <= 0)
  278. {
  279. return Error("请选择要删除的选项");
  280. }
  281. var idStr = string.Join(",", ids);
  282. if (string.IsNullOrEmpty(idStr.Trim()))
  283. {
  284. return Error("请选择要删除的选项");
  285. }
  286. int n = DB.DbHelperSQL.ExecuteSql(" update T_Wiki_Policy set F_IsDelete=1,F_DeleteUser='" + User.F_UserCode + "',F_DeleteTime=getdate() where F_Id in (" + idStr + ")");
  287. if (n > 0)
  288. {
  289. return Success("删除成功");
  290. }
  291. return Error("删除失败");
  292. }
  293. }
  294. }