县级监管平台

HomeController.cs 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  1. 
  2. using CallCenterApi.Common;
  3. using CallCenterApi.Interface.Controllers.Base;
  4. using CallCenterApi.Interface.Models.Common;
  5. using System;
  6. using System.Collections;
  7. using System.Collections.Generic;
  8. using System.Data;
  9. using System.Data.SqlTypes;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Threading;
  13. using System.Web;
  14. using System.Web.Caching;
  15. using System.Web.Mvc;
  16. namespace CallCenterApi.Interface.Controllers
  17. {
  18. public class HomeController : BaseController
  19. {
  20. // GET: Home
  21. public ActionResult Index()
  22. {
  23. return Success("成功");
  24. }
  25. [Authorize]
  26. public JsonResult json1()
  27. {
  28. var person = new
  29. {
  30. Name = "张三",
  31. Age = 22,
  32. Sex = "男"
  33. };
  34. return Json(person, JsonRequestBehavior.AllowGet);
  35. }
  36. public string json2()
  37. {
  38. var person = new
  39. {
  40. Name = "张三",
  41. Age = 22,
  42. Sex = "男",
  43. Date = DateTime.Now
  44. };
  45. return person.ToJson();
  46. }
  47. public string json2_()
  48. {
  49. var tt = new
  50. {
  51. exp = 20,
  52. money = 12
  53. };
  54. var person = new
  55. {
  56. Name = "张三",
  57. Age = 22,
  58. Sex = "男",
  59. other = tt,
  60. Date = DateTime.Now
  61. };
  62. return person.ToJson();
  63. }
  64. /// <summary>
  65. /// 演示 查询出来datatable的数据进行展示
  66. /// </summary>
  67. /// <returns></returns>
  68. public string json3()
  69. {
  70. DataTable tblDatas = new DataTable("Datas");
  71. DataColumn dc = null;
  72. dc = tblDatas.Columns.Add("Product", Type.GetType("System.String"));
  73. dc = tblDatas.Columns.Add("Version", Type.GetType("System.String"));
  74. dc = tblDatas.Columns.Add("Description", Type.GetType("System.String"));
  75. DataRow newRow;
  76. newRow = tblDatas.NewRow();
  77. newRow["Product"] = "大话西游";
  78. newRow["Version"] = "2.0";
  79. newRow["Description"] = "我很喜欢";
  80. tblDatas.Rows.Add(newRow);
  81. newRow = tblDatas.NewRow();
  82. newRow["Product"] = "梦幻西游";
  83. newRow["Version"] = "3.0";
  84. newRow["Description"] = "比大话更幼稚";
  85. tblDatas.Rows.Add(newRow);
  86. return tblDatas.ToJson();
  87. }
  88. public ActionResult json3_()
  89. {
  90. DataTable tblDatas = new DataTable("Datas");
  91. DataColumn dc = null;
  92. dc = tblDatas.Columns.Add("Product", Type.GetType("System.String"));
  93. dc = tblDatas.Columns.Add("Version", Type.GetType("System.String"));
  94. dc = tblDatas.Columns.Add("Description", Type.GetType("System.String"));
  95. DataRow newRow;
  96. newRow = tblDatas.NewRow();
  97. newRow["Product"] = "大话西游";
  98. newRow["Version"] = "2.0";
  99. newRow["Description"] = "我很喜欢";
  100. tblDatas.Rows.Add(newRow);
  101. newRow = tblDatas.NewRow();
  102. newRow["Product"] = "梦幻西游";
  103. newRow["Version"] = "3.0";
  104. newRow["Description"] = "比大话更幼稚";
  105. tblDatas.Rows.Add(newRow);
  106. return Success("成功", tblDatas);
  107. }
  108. public ActionResult excel()
  109. {
  110. DataTable tblDatas = new DataTable("Datas");
  111. DataColumn dc = null;
  112. dc = tblDatas.Columns.Add("Product", Type.GetType("System.String"));
  113. dc = tblDatas.Columns.Add("Version", Type.GetType("System.String"));
  114. dc = tblDatas.Columns.Add("Description", Type.GetType("System.String"));
  115. DataRow newRow;
  116. newRow = tblDatas.NewRow();
  117. newRow["Product"] = "大话西游";
  118. newRow["Version"] = "2.0";
  119. newRow["Description"] = "我很喜欢";
  120. tblDatas.Rows.Add(newRow);
  121. newRow = tblDatas.NewRow();
  122. newRow["Product"] = "梦幻西游";
  123. newRow["Version"] = "3.0";
  124. newRow["Description"] = "比大话更幼稚";
  125. tblDatas.Rows.Add(newRow);
  126. NPOIHelper npoi = new NPOIHelper();
  127. string[] s = { "列1", "列2", "列3" };
  128. if (npoi.ToExcel(tblDatas, "test", null, "D:/2.xlsx", s))
  129. {
  130. return Success("成功", tblDatas);
  131. }
  132. else
  133. {
  134. return Error("导出失败");
  135. }
  136. }
  137. public ActionResult excel1()
  138. {
  139. DataTable tblDatas = new DataTable("Datas");
  140. DataColumn dc = null;
  141. dc = tblDatas.Columns.Add("Product", Type.GetType("System.String"));
  142. dc = tblDatas.Columns.Add("Version", Type.GetType("System.String"));
  143. dc = tblDatas.Columns.Add("Description", Type.GetType("System.String"));
  144. DataRow newRow;
  145. newRow = tblDatas.NewRow();
  146. newRow["Product"] = "大话西游";
  147. newRow["Version"] = "2.0";
  148. newRow["Description"] = "我很喜欢";
  149. tblDatas.Rows.Add(newRow);
  150. newRow = tblDatas.NewRow();
  151. newRow["Product"] = "梦幻西游";
  152. newRow["Version"] = "3.0";
  153. newRow["Description"] = "比大话更幼稚";
  154. tblDatas.Rows.Add(newRow);
  155. NPOIHelper npoi = new NPOIHelper();
  156. if (npoi.ExportToExcel("test", tblDatas) == "")
  157. {
  158. return Success("成功", tblDatas);
  159. }
  160. else
  161. {
  162. return Error("导出失败");
  163. }
  164. }
  165. public ActionResult error()
  166. {
  167. return Error("不具备权限");
  168. }
  169. public string ss()
  170. {
  171. return "ss";
  172. }
  173. public string tt(string name, string pass)
  174. {
  175. return "sss " + name + pass;
  176. }
  177. /// <summary>
  178. /// 抛出HTTP 500
  179. /// </summary>
  180. /// <returns></returns>
  181. public ActionResult ThrowHttp500()
  182. {
  183. throw new HttpException(500, "服务器错误");
  184. }
  185. /// <summary>
  186. /// 抛出HTTP 404
  187. /// </summary>
  188. /// <returns></returns>
  189. public ActionResult ThrowHttp404()
  190. {
  191. throw new HttpException(404, "页面未找到");
  192. }
  193. /// <summary>
  194. /// 抛出未引用对象异常
  195. /// ,此处单独使用HandleError特性
  196. /// ,并指定异常类型及响应视图
  197. /// </summary>
  198. /// <returns></returns>
  199. [HandleError(ExceptionType = typeof(NullReferenceException), View = "CustomError")]
  200. public ActionResult ThrowNullReferenceException()
  201. {
  202. throw new NullReferenceException();
  203. }
  204. /// <summary>
  205. /// 引发输入字符串的格式不正确异常
  206. /// ,此处指定了响应的错误页面
  207. /// ,由于是不同的控制器所以要完整的相对路径
  208. /// </summary>
  209. /// <returns></returns>
  210. [HandleError(View = "~/Views/Error/CustomHttpError.cshtml")]
  211. public ActionResult ThrowFormatException()
  212. {
  213. string str = "";
  214. int count = Convert.ToInt32(str);
  215. return View("Index");
  216. }
  217. public ActionResult GetAllCache()
  218. {
  219. System.Web.Caching.Cache cache = HttpRuntime.Cache;
  220. IDictionaryEnumerator cacheEnum = cache.GetEnumerator();
  221. List<cacheobj> caches = new List<cacheobj>();
  222. StringBuilder sb = new StringBuilder();
  223. while (cacheEnum.MoveNext())
  224. {
  225. Dictionary<string, string> dic = null;
  226. try
  227. {
  228. dic = (Dictionary<string, string>)cacheEnum.Value;
  229. }
  230. catch
  231. {
  232. continue;
  233. }
  234. sb.Append($"F_UserCode={dic["F_UserCode"]}, ");
  235. sb.Append($"F_UserCode={dic["F_UserCode"]}, ");
  236. sb.Append($"F_UserName={dic["F_UserName"]} ");
  237. caches.Add(new cacheobj
  238. {
  239. key = cacheEnum.Key.ToString().Substring(0, 20),
  240. value = sb.ToString()
  241. });
  242. sb.Clear();
  243. }
  244. return Success("", new
  245. {
  246. count = caches.Count(),
  247. });
  248. }
  249. //public ActionResult MakeCache()
  250. //{
  251. // while (true)
  252. // {
  253. // Dictionary<string, string> Dic = new Dictionary<string, string>();
  254. // Dic.Add("F_UserCode", "1411");
  255. // Dic.Add("F_UserCode", "8000");
  256. // Dic.Add("F_DeptId", "1");
  257. // Dic.Add("F_UserName", "系统管理员");
  258. // Dic.Add("F_Telephone", "15537150907");
  259. // Dic.Add("F_RoleID", "1");
  260. // Dic.Add("F_SeatFlag", "1");
  261. // new CallCenterApi.BLL.T_Sys_LoginLogs().Add(new Model.T_Sys_LoginLogs()
  262. // {
  263. // F_LoginName = "8000",
  264. // F_LoginId = 1411,
  265. // F_Result = "登录成功",
  266. // F_LoginIP = Common.DTRequest.GetIP(),
  267. // F_Hostname = Common.DTRequest.GetIP(),
  268. // F_LoginDate = DateTime.Now,
  269. // F_Remark = "",
  270. // F_State = 0
  271. // });
  272. // var token = FormsPrincipal<Dictionary<string, string>>.GetCookieValue(Dic["F_UserCode"], Dic);
  273. // //放入缓存
  274. // CacheHelper.Insert(token, Dic, 2880, System.Web.Caching.CacheItemPriority.NotRemovable);
  275. // Response.Write(token.Substring(0, 20) + "</n>");
  276. // }
  277. //}
  278. public ActionResult TestCache()
  279. {
  280. int n = 0;
  281. while (n<100)
  282. {
  283. Dictionary<string, string> Dic = new Dictionary<string, string>();
  284. Dic.Add("F_UserCode", (1000 + n).ToString());
  285. Dic.Add("F_UserCode", (8000+n).ToString());
  286. Dic.Add("F_DeptId", "1");
  287. Dic.Add("F_UserName", "系统管理员" + n);
  288. Dic.Add("F_Telephone", "15537150907");
  289. Dic.Add("F_RoleID", "1");
  290. Dic.Add("F_SeatFlag", "1");
  291. var token = FormsPrincipal<Dictionary<string, string>>.GetCookieValue(Dic["F_UserCode"], Dic);
  292. CacheItemRemovedCallback cacheItemRemovedCallback = new CacheItemRemovedCallback(onRemove);
  293. //放入缓存
  294. CacheHelper.Insert(token, Dic, 1, System.Web.Caching.CacheItemPriority.NotRemovable, cacheItemRemovedCallback);
  295. n++;
  296. }
  297. return Success(n.ToString());
  298. }
  299. /// <summary>
  300. /// 移除缓存后调用
  301. /// </summary>
  302. /// <param name="key"></param>
  303. /// <param name="val"></param>
  304. /// <param name="reason"></param>
  305. public void onRemove(string key, object val, CacheItemRemovedReason reason)
  306. {
  307. var obj = new
  308. {
  309. key = key,
  310. val = val,
  311. reason = reason
  312. };
  313. Error(obj.ToJson());
  314. }
  315. }
  316. public class cacheobj
  317. {
  318. public string key { get; set; }
  319. public string value { get; set; }
  320. }
  321. }