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

94 lines
3.0 KiB

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. string savePath = System.Web.HttpContext.Current.Server.MapPath("~\\File\\UPLoadFile\\" + filename);//Server.MapPath 获得虚拟服务器相对路径
  49. int iLen = hpFiles[0].ContentLength;
  50. if (Directory.Exists(savePath)) return "文件已存在";
  51. byte[] bData = new byte[iLen];
  52. hpFiles[0].InputStream.Read(bData, 0, iLen);
  53. FileStream newFile = new FileStream(savePath, FileMode.OpenOrCreate);
  54. newFile.Write(bData, 0, bData.Length);
  55. newFile.Flush();
  56. int _FileSizeTemp = hpFiles[0].ContentLength;
  57. newFile.Close();
  58. newFile.Dispose();
  59. //bool del = false;
  60. string mess = "";
  61. mess = INVApp.SetData_PR(savePath, str_Year);
  62. if (System.IO.File.Exists(savePath))//删除文件
  63. {
  64. System.IO.File.Delete(savePath);
  65. }
  66. return mess;
  67. }
  68. else
  69. {
  70. return "获取文件失败";
  71. }
  72. }
  73. catch (Exception ex)
  74. {
  75. return ex.ToString();
  76. }
  77. }
  78. }
  79. }