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.

204 lines
6.8 KiB

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