HomeController.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using MES.Production.Service.IService;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Web;
  7. using System.Web.Mvc;
  8. namespace ChangFa.Machinery.WebPage.Controllers
  9. {
  10. public class HomeController : Controller
  11. {
  12. static string urlPath = string.Empty;
  13. ISystemManage SystemManage { get; set; }
  14. public ActionResult Index()
  15. {
  16. //var str = SystemManage.LoadAll(null);
  17. string url = Request.Url.AbsoluteUri;
  18. return Redirect(url + "sys/Account/index");
  19. }
  20. public HomeController()
  21. {
  22. var applicationPath = VirtualPathUtility.ToAbsolute("~") == "/" ? "" : VirtualPathUtility.ToAbsolute("~");
  23. urlPath = applicationPath + "/Upload";
  24. }
  25. public ActionResult UpLoadProcess(string id, string name, string type, string lastModifiedDate, int size, HttpPostedFileBase file)
  26. {
  27. string filePathName = string.Empty;
  28. string localPath = Path.Combine(HttpRuntime.AppDomainAppPath, "Upload");
  29. if (Request.Files.Count == 0)
  30. {
  31. return Json(new { jsonrpc = 2.0, error = new { code = 102, message = "保存失败" }, id = "id" });
  32. }
  33. string ex = Path.GetExtension(file.FileName);
  34. filePathName = Guid.NewGuid().ToString("N") + ex;
  35. if (!System.IO.Directory.Exists(localPath))
  36. {
  37. System.IO.Directory.CreateDirectory(localPath);
  38. }
  39. file.SaveAs(Path.Combine(localPath, filePathName));
  40. return Json(new
  41. {
  42. jsonrpc = "2.0",
  43. id = id,
  44. filePath = urlPath + "/" + filePathName
  45. });
  46. }
  47. }
  48. }