纽威
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.

104 lines
3.3 KiB

11 months ago
11 months ago
  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 UpdateBinCodeController : ControllerBase
  18. {
  19. UpdateBinCodeApp INVApp = new UpdateBinCodeApp();
  20. // GET: WMS/UpdateBinCode
  21. public ActionResult BinCodeImport()
  22. {
  23. return View();
  24. }
  25. public ActionResult BinCodeImportUpLoad()
  26. {
  27. return View();
  28. }
  29. public ActionResult WarehouseLotReport()
  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. var folder = System.Web.HttpContext.Current.Server.MapPath("~\\File\\UPLoadFile"); //Server.MapPath 获得虚拟服务器相对路径
  53. if(!Directory.Exists(folder))
  54. Directory.CreateDirectory(folder);
  55. string savePath = Path.Combine(folder, filename);
  56. int iLen = hpFiles[0].ContentLength;
  57. if (Directory.Exists(savePath)) return "文件已存在";
  58. byte[] bData = new byte[iLen];
  59. hpFiles[0].InputStream.Read(bData, 0, iLen);
  60. FileStream newFile = new FileStream(savePath, FileMode.OpenOrCreate);
  61. newFile.Write(bData, 0, bData.Length);
  62. newFile.Flush();
  63. int _FileSizeTemp = hpFiles[0].ContentLength;
  64. newFile.Close();
  65. newFile.Dispose();
  66. //bool del = false;
  67. string mess = "";
  68. mess = INVApp.SetData_PR(savePath, str_Year);
  69. if (System.IO.File.Exists(savePath))//删除文件
  70. {
  71. System.IO.File.Delete(savePath);
  72. }
  73. return mess;
  74. }
  75. else
  76. {
  77. return "获取文件失败";
  78. }
  79. }
  80. catch (Exception ex)
  81. {
  82. return ex.ToString();
  83. }
  84. }
  85. }
  86. }