You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

209 lines
5.9 KiB

4 days ago
  1. using Newtonsoft.Json;
  2. using NFine.Application.KBSSRM;
  3. using NFine.Code;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Data;
  7. using System.IO;
  8. using System.Linq;
  9. using System.Web;
  10. using System.Web.Mvc;
  11. namespace NFine.Web.Areas.KBSSRM.Controllers
  12. {
  13. public class MaterialImportController : ControllerBase
  14. {
  15. private MaterialImportApp App = new MaterialImportApp();
  16. // GET: KBSSRM/MaterialImport
  17. public ActionResult MaterialImport()
  18. {
  19. return View();
  20. }
  21. [HttpGet]
  22. public ActionResult SelectColumnName(string BeginTime, string EndTime)
  23. {
  24. var data = App.SelectColumnName(BeginTime, EndTime);
  25. return Content(data.ToJson());
  26. }
  27. [HttpGet]
  28. public ActionResult GetListGridJsonTOZ( string queryJson, Pagination pagination)
  29. {
  30. DataTable ListData = App.GetListGridJsonTOZ2(queryJson, ref pagination);
  31. var JsonData = new
  32. {
  33. total = pagination.total,
  34. page = pagination.page,
  35. records = pagination.records,
  36. rows = ListData,
  37. };
  38. return Content(JsonData.ToJson());
  39. }
  40. /// <summary>
  41. /// 文件上传到本地
  42. /// </summary>
  43. public ActionResult UploadFile(string JSDateDay)
  44. {
  45. string mess = "";
  46. try
  47. {
  48. HttpFileCollection hpFiles = System.Web.HttpContext.Current.Request.Files;
  49. if (hpFiles != null && hpFiles.Count > 0)
  50. {
  51. string IsXls = System.IO.Path.GetExtension(hpFiles[0].FileName).ToString().ToLower();//System.IO.Path.GetExtension获得文件的扩展名
  52. if (IsXls != ".xls" && IsXls != ".xlsx")
  53. {
  54. mess = "只可以选择Excel(.xls .xlsx)文件";//当选择的不是Excel文件时,返回
  55. }
  56. string filename = DateTime.Now.ToString("yyyyMMddhhmmss") + Guid.NewGuid() + IsXls; //获取Execle文件名 DateTime日期函数
  57. string Paths= System.Web.HttpContext.Current.Server.MapPath("~\\File\\UPLoadFile");
  58. if (!Directory.Exists(Paths))
  59. {
  60. Directory.CreateDirectory(Paths);
  61. }
  62. string savePath = System.Web.HttpContext.Current.Server.MapPath("~\\File\\UPLoadFile\\" + filename);//Server.MapPath 获得虚拟服务器相对路径
  63. int iLen = hpFiles[0].ContentLength;
  64. if (Directory.Exists(savePath)) mess = "文件已存在";
  65. byte[] bData = new byte[iLen];
  66. hpFiles[0].InputStream.Read(bData, 0, iLen);
  67. FileStream newFile = new FileStream(savePath, FileMode.OpenOrCreate);
  68. newFile.Write(bData, 0, bData.Length);
  69. newFile.Flush();
  70. int _FileSizeTemp = hpFiles[0].ContentLength;
  71. newFile.Close();
  72. newFile.Dispose();
  73. //bool del = false;
  74. mess = App.SetData_PR(savePath);
  75. if (System.IO.File.Exists(savePath))//删除文件
  76. {
  77. System.IO.File.Delete(savePath);
  78. }
  79. }
  80. }
  81. catch (Exception ex)
  82. {
  83. mess = ex.Message;
  84. //return Error(ex.Message);
  85. }
  86. var JsonData = new
  87. {
  88. mass = mess,
  89. };
  90. return Content(JsonData.ToJson());
  91. }
  92. [HttpPost]
  93. [HandlerAjaxOnly]
  94. public ActionResult SaveAndUpdate(string ICSInvImport)
  95. {
  96. string msg = App.SaveAndUpdate(ICSInvImport);
  97. if (!string.IsNullOrEmpty(msg))
  98. {
  99. return Error(msg);
  100. }
  101. else
  102. {
  103. return Success("添加成功!");
  104. }
  105. }
  106. public ActionResult EmailNotice(string ICSInvImport)
  107. {
  108. DataTable dt = JsonConvert.DeserializeObject<DataTable>(ICSInvImport);
  109. string mess = "";
  110. try
  111. {
  112. string msg = App.EmailNotice(dt);
  113. }
  114. catch (Exception ex)
  115. {
  116. mess = ex.Message;
  117. //return Error(ex.Message);
  118. }
  119. var JsonData = new
  120. {
  121. mass = mess,
  122. };
  123. return Content(JsonData.ToJson());
  124. }
  125. [HttpPost]
  126. [HandlerAjaxOnly]
  127. [ValidateAntiForgeryToken]
  128. public ActionResult Delete(string ICSInvImport)
  129. {
  130. string msg = App.Delete(ICSInvImport);
  131. if (string.IsNullOrEmpty(msg))
  132. {
  133. return Success("删除成功!");
  134. }
  135. else
  136. {
  137. return Error(msg);
  138. }
  139. }
  140. [HttpPost]
  141. public void StatementExportAll(string ICSInvImport)
  142. {
  143. //ICSInvImport= Uri.EscapeDataString(ICSInvImport);
  144. ICSInvImport = HttpUtility.UrlDecode(ICSInvImport);
  145. DataTable dt = JsonConvert.DeserializeObject<DataTable>(ICSInvImport);
  146. AsposeCell.Export(dt);
  147. }
  148. public ActionResult GetStartMonth(string keyValue)
  149. {
  150. var rows = App.GetStartMonth(keyValue);
  151. return Content(rows.ToJson());
  152. }
  153. [HttpPost]
  154. [HandlerAjaxOnly]
  155. public ActionResult KBSTZ(string ICSInvImport)
  156. {
  157. string msg = App.KBSTZ(ICSInvImport);
  158. if (!string.IsNullOrEmpty(msg))
  159. {
  160. return Error(msg);
  161. }
  162. else
  163. {
  164. return Success("添加成功!");
  165. }
  166. }
  167. }
  168. }