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

99 lines
3.2 KiB

3 years ago
3 years 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 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. [HttpPost]
  30. /// <summary>
  31. /// 文件上传到本地
  32. /// </summary>
  33. public string UploadFile()
  34. {
  35. try
  36. {
  37. string str_Year = Request.Form["txt_Year"];
  38. String UPLoadType = Request.Form["UPLoadType"];
  39. HttpFileCollection hpFiles = System.Web.HttpContext.Current.Request.Files;
  40. if (hpFiles != null && hpFiles.Count > 0)
  41. {
  42. string IsXls = System.IO.Path.GetExtension(hpFiles[0].FileName).ToString().ToLower();//System.IO.Path.GetExtension获得文件的扩展名
  43. if (IsXls != ".xls" && IsXls != ".xlsx")
  44. {
  45. return "只可以选择Excel(.xls .xlsx)文件";//当选择的不是Excel文件时,返回
  46. }
  47. string filename = DateTime.Now.ToString("yyyyMMddhhmmss") + UPLoadType + IsXls; //获取Execle文件名 DateTime日期函数
  48. var folder = System.Web.HttpContext.Current.Server.MapPath("~\\File\\UPLoadFile"); //Server.MapPath 获得虚拟服务器相对路径
  49. if(!Directory.Exists(folder))
  50. Directory.CreateDirectory(folder);
  51. string savePath = Path.Combine(folder, filename);
  52. int iLen = hpFiles[0].ContentLength;
  53. if (Directory.Exists(savePath)) return "文件已存在";
  54. byte[] bData = new byte[iLen];
  55. hpFiles[0].InputStream.Read(bData, 0, iLen);
  56. FileStream newFile = new FileStream(savePath, FileMode.OpenOrCreate);
  57. newFile.Write(bData, 0, bData.Length);
  58. newFile.Flush();
  59. int _FileSizeTemp = hpFiles[0].ContentLength;
  60. newFile.Close();
  61. newFile.Dispose();
  62. //bool del = false;
  63. string mess = "";
  64. mess = INVApp.SetData_PR(savePath, str_Year);
  65. if (System.IO.File.Exists(savePath))//删除文件
  66. {
  67. System.IO.File.Delete(savePath);
  68. }
  69. return mess;
  70. }
  71. else
  72. {
  73. return "获取文件失败";
  74. }
  75. }
  76. catch (Exception ex)
  77. {
  78. return ex.ToString();
  79. }
  80. }
  81. }
  82. }