ExportExcelsController.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. // /*
  2. // * excel导出数据
  3. // */
  4. // using System;
  5. // using System.Web;
  6. // using System.Collections.Generic;
  7. // using System.Diagnostics;
  8. // using System.Linq;
  9. // using System.Threading.Tasks;
  10. // using Microsoft.AspNetCore.Mvc;
  11. // using Microsoft.AspNetCore.Http;
  12. // using Microsoft.Extensions.Logging;
  13. // using Microsoft.Extensions.Options;
  14. // using MySystem.Models;
  15. // using Library;
  16. // using LitJson;
  17. // using MySystemLib;
  18. // namespace MySystem.Areas.Admin.Controllers
  19. // {
  20. // [Area("Admin")]
  21. // [Route("Admin/[controller]/[action]")]
  22. // public class ExportExcelsController : BaseController
  23. // {
  24. // public ExportExcelsController(IHttpContextAccessor accessor, ILogger<BaseController> logger, IOptions<Setting> setting) : base(accessor, logger, setting)
  25. // {
  26. // }
  27. // #region excel导出数据列表
  28. // /// <summary>
  29. // /// 根据条件查询excel导出数据列表
  30. // /// </summary>
  31. // /// <returns></returns>
  32. // public IActionResult Index(ExportExcels data, string right)
  33. // {
  34. // ViewBag.RightInfo = RightInfo;
  35. // ViewBag.right = right;
  36. // return View();
  37. // }
  38. // #endregion
  39. // #region 根据条件查询excel导出数据列表
  40. // /// <summary>
  41. // /// excel导出数据列表
  42. // /// </summary>
  43. // /// <returns></returns>
  44. // public JsonResult IndexData(ExportExcels data, int page = 1, int limit = 30)
  45. // {
  46. // Dictionary<string, string> Fields = new Dictionary<string, string>();
  47. // Fields.Add("CreateDate", "3"); //时间
  48. // Fields.Add("FileName", "1"); //文件名
  49. // Fields.Add("FileUrl", "1"); //文件路径
  50. // string condition = " and Status>-1";
  51. // Dictionary<string, object> obj = new AdminContent(_accessor.HttpContext, SystemPublicFuction.dbtables).IndexData("ExportExcels", Fields, "Id desc", "0", page, limit, condition);
  52. // List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  53. // foreach (Dictionary<string, object> dic in diclist)
  54. // {
  55. // }
  56. // return Json(obj);
  57. // }
  58. // #endregion
  59. // #region 增加excel导出数据
  60. // /// <summary>
  61. // /// 增加或修改excel导出数据信息
  62. // /// </summary>
  63. // /// <returns></returns>
  64. // public IActionResult Add(string right)
  65. // {
  66. // ViewBag.RightInfo = RightInfo;
  67. // ViewBag.right = right;
  68. // return View();
  69. // }
  70. // #endregion
  71. // #region 增加excel导出数据
  72. // /// <summary>
  73. // /// 增加或修改excel导出数据信息
  74. // /// </summary>
  75. // /// <returns></returns>
  76. // [HttpPost]
  77. // public string Add(ExportExcels data)
  78. // {
  79. // Dictionary<string, object> Fields = new Dictionary<string, object>();
  80. // Fields.Add("FileName", data.FileName); //文件名
  81. // Fields.Add("FileUrl", data.FileUrl); //文件路径
  82. // Fields.Add("SeoTitle", data.SeoTitle);
  83. // Fields.Add("SeoKeyword", data.SeoKeyword);
  84. // Fields.Add("SeoDescription", data.SeoDescription);
  85. // int Id = new AdminContent(_accessor.HttpContext, SystemPublicFuction.dbtables).Add("ExportExcels", Fields, 0);
  86. // AddSysLog(data.Id.ToString(), "ExportExcels", "add");
  87. // db.SaveChanges();
  88. // return "success";
  89. // }
  90. // #endregion
  91. // #region 修改excel导出数据
  92. // /// <summary>
  93. // /// 增加或修改excel导出数据信息
  94. // /// </summary>
  95. // /// <returns></returns>
  96. // public IActionResult Edit(string right, int Id = 0)
  97. // {
  98. // ViewBag.RightInfo = RightInfo;
  99. // ViewBag.right = right;
  100. // ExportExcels editData = db.ExportExcels.FirstOrDefault(m => m.Id == Id) ?? new ExportExcels();
  101. // ViewBag.data = editData;
  102. // return View();
  103. // }
  104. // #endregion
  105. // #region 修改excel导出数据
  106. // /// <summary>
  107. // /// 增加或修改excel导出数据信息
  108. // /// </summary>
  109. // /// <returns></returns>
  110. // [HttpPost]
  111. // public string Edit(ExportExcels data)
  112. // {
  113. // Dictionary<string, object> Fields = new Dictionary<string, object>();
  114. // Fields.Add("FileName", data.FileName); //文件名
  115. // Fields.Add("FileUrl", data.FileUrl); //文件路径
  116. // Fields.Add("SeoTitle", data.SeoTitle);
  117. // Fields.Add("SeoKeyword", data.SeoKeyword);
  118. // Fields.Add("SeoDescription", data.SeoDescription);
  119. // new AdminContent(_accessor.HttpContext, SystemPublicFuction.dbtables).Edit("ExportExcels", Fields, data.Id);
  120. // AddSysLog(data.Id.ToString(), "ExportExcels", "update");
  121. // db.SaveChanges();
  122. // return "success";
  123. // }
  124. // #endregion
  125. // #region 删除excel导出数据信息
  126. // /// <summary>
  127. // /// 删除excel导出数据信息
  128. // /// </summary>
  129. // /// <returns></returns>
  130. // public string Delete(string Id)
  131. // {
  132. // string[] idlist = Id.Split(new char[] { ',' });
  133. // AddSysLog(Id, "ExportExcels", "del");
  134. // foreach (string subid in idlist)
  135. // {
  136. // int id = int.Parse(subid);
  137. // Dictionary<string, object> Fields = new Dictionary<string, object>();
  138. // Fields.Add("Status", -1);
  139. // new AdminContent(_accessor.HttpContext, SystemPublicFuction.dbtables).Edit("ExportExcels", Fields, id);
  140. // }
  141. // db.SaveChanges();
  142. // return "success";
  143. // }
  144. // #endregion
  145. // #region 开启
  146. // /// <summary>
  147. // /// 开启
  148. // /// </summary>
  149. // /// <returns></returns>
  150. // public string Open(string Id)
  151. // {
  152. // string[] idlist = Id.Split(new char[] { ',' });
  153. // AddSysLog(Id, "ExportExcels", "open");
  154. // foreach (string subid in idlist)
  155. // {
  156. // int id = int.Parse(subid);
  157. // Dictionary<string, object> Fields = new Dictionary<string, object>();
  158. // Fields.Add("Status", 1);
  159. // new AdminContent(_accessor.HttpContext, SystemPublicFuction.dbtables).Edit("ExportExcels", Fields, id);
  160. // }
  161. // db.SaveChanges();
  162. // return "success";
  163. // }
  164. // #endregion
  165. // #region 关闭
  166. // /// <summary>
  167. // /// 关闭
  168. // /// </summary>
  169. // /// <returns></returns>
  170. // public string Close(string Id)
  171. // {
  172. // string[] idlist = Id.Split(new char[] { ',' });
  173. // AddSysLog(Id, "ExportExcels", "close");
  174. // foreach (string subid in idlist)
  175. // {
  176. // int id = int.Parse(subid);
  177. // Dictionary<string, object> Fields = new Dictionary<string, object>();
  178. // Fields.Add("Status", 0);
  179. // new AdminContent(_accessor.HttpContext, SystemPublicFuction.dbtables).Edit("ExportExcels", Fields, id);
  180. // }
  181. // db.SaveChanges();
  182. // return "success";
  183. // }
  184. // #endregion
  185. // #region 排序
  186. // /// <summary>
  187. // /// 排序
  188. // /// </summary>
  189. // /// <param name="Id"></param>
  190. // public string Sort(int Id, int Sort)
  191. // {
  192. // new AdminContent(_accessor.HttpContext, SystemPublicFuction.dbtables).Sort("ExportExcels", Sort, Id);
  193. // AddSysLog(Id.ToString(), "ExportExcels", "sort");
  194. // return "success";
  195. // }
  196. // #endregion
  197. // #region 导入数据
  198. // /// <summary>
  199. // /// 导入数据
  200. // /// </summary>
  201. // /// <param name="ExcelData"></param>
  202. // public string Import(string ExcelData)
  203. // {
  204. // ExcelData = HttpUtility.UrlDecode(ExcelData);
  205. // JsonData list = JsonMapper.ToObject(ExcelData);
  206. // for (int i = 1; i < list.Count; i++)
  207. // {
  208. // JsonData dr = list[i];
  209. // db.ExportExcels.Add(new ExportExcels()
  210. // {
  211. // CreateDate = DateTime.Now,
  212. // UpdateDate = DateTime.Now,
  213. // });
  214. // db.SaveChanges();
  215. // }
  216. // AddSysLog("0", "ExportExcels", "Import");
  217. // return "success";
  218. // }
  219. // #endregion
  220. // #region 导出Excel
  221. // /// <summary>
  222. // /// 导出Excel
  223. // /// </summary>
  224. // /// <returns></returns>
  225. // public JsonResult ExportExcel(ExportExcels data)
  226. // {
  227. // Dictionary<string, string> Fields = new Dictionary<string, string>();
  228. // Fields.Add("CreateDate", "3"); //时间
  229. // Fields.Add("FileName", "1"); //文件名
  230. // Fields.Add("FileUrl", "1"); //文件路径
  231. // string condition = " and Status>-1";
  232. // Dictionary<string, object> obj = new AdminContent(_accessor.HttpContext, SystemPublicFuction.dbtables).IndexData("ExportExcels", Fields, "Id desc", "0", 1, 20000, condition, "", false);
  233. // List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  234. // foreach (Dictionary<string, object> dic in diclist)
  235. // {
  236. // }
  237. // Dictionary<string, object> result = new Dictionary<string, object>();
  238. // result.Add("Status", "1");
  239. // result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  240. // result.Add("Obj", diclist);
  241. // Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  242. // result.Add("Fields", ReturnFields);
  243. // AddSysLog("0", "ExportExcels", "ExportExcel");
  244. // return Json(result);
  245. // }
  246. // #endregion
  247. // }
  248. // }