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.

228 lines
7.2 KiB

3 weeks ago
  1. using NFine.Application.PNWMS;
  2. using NFine.Code;
  3. using NFine.Data.Extensions;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Data;
  7. using System.Data.SqlClient;
  8. using System.IO;
  9. using System.Linq;
  10. using System.Web;
  11. using System.Web.Mvc;
  12. namespace NFine.Web.Areas.PNWMS.Controllers
  13. {
  14. public class BasicSettingsController : ControllerBase
  15. {
  16. BasicSettingsApp App = new BasicSettingsApp();
  17. // GET: PNWMS/BasicSettings
  18. public ActionResult ICSStackWMS()
  19. {
  20. return View();
  21. }
  22. public ActionResult ICSStackWMSAdd()
  23. {
  24. return View();
  25. }
  26. /// <summary>
  27. /// 删除库位
  28. /// </summary>
  29. /// <returns></returns>
  30. [HttpPost]
  31. [HandlerAjaxOnly]
  32. [ValidateAntiForgeryToken]
  33. public ActionResult DeleteStack(string keyValue)
  34. {
  35. string msg = App.DeleteStack(keyValue);
  36. if (string.IsNullOrEmpty(msg))
  37. {
  38. return Success("删除成功!");
  39. }
  40. else
  41. {
  42. return Error(msg);
  43. //throw new Exception(msg);
  44. }
  45. }
  46. //库位导入
  47. [HttpPost]
  48. /// <summary>
  49. /// 文件上传到本地
  50. /// </summary>
  51. public string UploadFile()
  52. {
  53. try
  54. {
  55. HttpFileCollection hpFiles = System.Web.HttpContext.Current.Request.Files;
  56. if (hpFiles != null && hpFiles.Count > 0)
  57. {
  58. string IsXls = System.IO.Path.GetExtension(hpFiles[0].FileName).ToString().ToLower();//System.IO.Path.GetExtension获得文件的扩展名
  59. if (IsXls != ".xls" && IsXls != ".xlsx")
  60. {
  61. return "只可以选择Excel(.xls .xlsx)文件";//当选择的不是Excel文件时,返回
  62. }
  63. string filename = DateTime.Now.ToString("yyyyMMddhhmmss") + Guid.NewGuid() + IsXls; //获取Execle文件名 DateTime日期函数
  64. string savePath = System.Web.HttpContext.Current.Server.MapPath("~\\File\\UPLoadFile\\" + filename);//Server.MapPath 获得虚拟服务器相对路径
  65. int iLen = hpFiles[0].ContentLength;
  66. if (Directory.Exists(savePath)) return "文件已存在";
  67. byte[] bData = new byte[iLen];
  68. hpFiles[0].InputStream.Read(bData, 0, iLen);
  69. FileStream newFile = new FileStream(savePath, FileMode.OpenOrCreate);
  70. newFile.Write(bData, 0, bData.Length);
  71. newFile.Flush();
  72. int _FileSizeTemp = hpFiles[0].ContentLength;
  73. newFile.Close();
  74. newFile.Dispose();
  75. //bool del = false;
  76. string mess = "";
  77. mess = App.SetData_PR(savePath);
  78. if (System.IO.File.Exists(savePath))//删除文件
  79. {
  80. System.IO.File.Delete(savePath);
  81. }
  82. return mess;
  83. }
  84. else
  85. {
  86. return "获取文件失败";
  87. }
  88. }
  89. catch (Exception ex)
  90. {
  91. return ex.ToString();
  92. }
  93. }
  94. /// <summary>
  95. /// 导入Excel
  96. /// </summary>
  97. /// <param name="fileURL"></param>
  98. /// <returns></returns>
  99. [HttpPost]
  100. public ActionResult Import(string fileURL)
  101. {
  102. var fileName = "";
  103. var filePath = fileURL;
  104. string path = Path.Combine(filePath, fileName);
  105. //file.SaveAs(path);
  106. DataTable excelTable = new DataTable();
  107. //excelTable =SqlHelper.GetExcelDataTable(path);
  108. DataTable dbdata = new DataTable();
  109. dbdata.Columns.Add("LocationCode");
  110. dbdata.Columns.Add("LocationName");
  111. dbdata.Columns.Add("Musername");
  112. dbdata.Columns.Add("MUSER");
  113. dbdata.Columns.Add("EATTRIBUTE1");
  114. for (int i = 0; i < excelTable.Rows.Count; i++)
  115. {
  116. string LocationCode = "";
  117. string LocationName = "";
  118. DataRow dr = excelTable.Rows[i];
  119. DataRow dr_ = dbdata.NewRow();
  120. if (!string.IsNullOrWhiteSpace(dr["区"].ToString().ToUpper()))
  121. {
  122. LocationCode += "-" + dr["区"].ToString().ToUpper();
  123. LocationName += dr["区"].ToString().ToUpper() + "区";
  124. }
  125. if (!string.IsNullOrWhiteSpace(dr["排"].ToString().ToUpper()))
  126. {
  127. LocationCode += "-" + dr["排"].ToString().ToUpper();
  128. LocationName += dr["排"].ToString().ToUpper() + "排";
  129. }
  130. if (!string.IsNullOrWhiteSpace(dr["货架"].ToString().ToUpper()))
  131. {
  132. LocationCode += "-" + dr["货架"].ToString().ToUpper();
  133. LocationName += dr["货架"].ToString().ToUpper() + "货架";
  134. }
  135. if (!string.IsNullOrWhiteSpace(dr["层"].ToString().ToUpper()))
  136. {
  137. LocationCode += "-" + dr["层"].ToString().ToUpper();
  138. LocationName += dr["层"].ToString().ToUpper() + "层";
  139. }
  140. if (!string.IsNullOrWhiteSpace(dr["格"].ToString().ToUpper()))
  141. {
  142. LocationCode += "-" + dr["格"].ToString().ToUpper();
  143. LocationName += dr["格"].ToString().ToUpper() + "格";
  144. }
  145. dr_["LocationCode"] = LocationCode;
  146. dr_["LocationName"] = LocationName;
  147. dr_["Musername"] = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  148. dr_["MUSER"] = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  149. dr_["Musername"] = "";
  150. dbdata.Rows.Add(dr_);
  151. }
  152. SqlHelper.RemoveEmpty(dbdata);
  153. SqlHelper.SqlBulkCopyByDatatable("ICSLocation", dbdata);
  154. return View();
  155. }
  156. /// <summary>
  157. /// 获取库位信息
  158. /// </summary>
  159. /// <returns></returns>
  160. public ActionResult GetWarehouse()
  161. {
  162. DataTable dt = App.GetWarehouse();
  163. return Content(dt.ToJson());
  164. }
  165. [HttpPost]
  166. [HandlerAjaxOnly]
  167. public ActionResult UpdateStack(string keyValue)
  168. {
  169. string msg = App.UpdateStack(keyValue);
  170. if (!string.IsNullOrEmpty(msg))
  171. {
  172. return Error(msg);
  173. }
  174. else
  175. {
  176. return Success("修改成功!");
  177. }
  178. }
  179. [HttpPost]
  180. [HandlerAjaxOnly]
  181. public ActionResult InsertStack(string keyValue)
  182. {
  183. string msg = App.InsertStack(keyValue);
  184. if (!string.IsNullOrEmpty(msg))
  185. {
  186. return Error(msg);
  187. }
  188. else
  189. {
  190. return Success("添加成功!");
  191. }
  192. }
  193. }
  194. }