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.

LogoImgController.cs 6.0 KiB

4 years ago
4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. using Learun.Application.Base.SystemModule;
  2. using System;
  3. using System.IO;
  4. using System.Web;
  5. using System.Web.Mvc;
  6. using Learun.Application.TwoDevelopment.EducationalAdministration;
  7. namespace Learun.Application.Web.Areas.LR_SystemModule.Controllers
  8. {
  9. public class LogoImgController : MvcControllerBaseNoLogin
  10. {
  11. DatabaseLinkIBLL databaseLinkIbll = new DatabaseLinkBLL();
  12. private DgreeIBLL dgreeIBLL = new DgreeBLL();
  13. LR_Base_LogoIBLL baseLogoIbll = new LR_Base_LogoBLL();
  14. // GET: LR_SystemModule/LogoImg
  15. public ActionResult AppIndex()
  16. {
  17. return View();
  18. }
  19. public ActionResult UploadFile(string code)
  20. {
  21. HttpFileCollection files = System.Web.HttpContext.Current.Request.Files;
  22. //没有文件上传,直接返回
  23. if (files[0].ContentLength == 0 || string.IsNullOrEmpty(files[0].FileName))
  24. {
  25. return HttpNotFound();
  26. }
  27. DgreeEntity dgreeEntity = new DgreeEntity();
  28. dgreeEntity.ModuleID = "2fdc1fdb-50f4-4e9c-97c7-0d53b161f9da";
  29. dgreeEntity.Status = "1";
  30. dgreeIBLL.SaveEntity("", dgreeEntity);
  31. string fExtension = Path.GetExtension(files[0].FileName);
  32. string rootPath = Server.MapPath("/");
  33. try
  34. {
  35. string filepath = rootPath + "/Content/images/logo/" + DateTime.Now.ToString("yyyyMMdd");
  36. if (System.IO.Directory.Exists(filepath) == false)//如果不存在就创建file文件夹
  37. {
  38. System.IO.Directory.CreateDirectory(filepath);
  39. }
  40. files[0].SaveAs(filepath + "/" + code + ".png");
  41. LR_Base_LogoEntity logoEntity = baseLogoIbll.GetLR_Base_LogoEntityByCode(code);
  42. if (logoEntity == null)
  43. {
  44. logoEntity = new LR_Base_LogoEntity();
  45. logoEntity.Create();
  46. logoEntity.F_Code = code;
  47. logoEntity.F_FileName = filepath + "/" + code + ".png";
  48. baseLogoIbll.SaveEntity(null, logoEntity);
  49. }
  50. else
  51. {
  52. logoEntity.F_FileName = filepath + "/" + code + ".png";
  53. baseLogoIbll.SaveEntity(logoEntity.F_LId, logoEntity);
  54. }
  55. //switch (code)
  56. //{
  57. // case "default":
  58. // {
  59. // logoEntity.F_Code = code;
  60. // logoEntity.F_FileName = filepath + "/"+ code + ".png";
  61. // files[0].SaveAs(filepath + "/"+ code + ".png");
  62. // }
  63. // break;
  64. // case "accordion":
  65. // files[0].SaveAs(rootPath + "/Content/images/logo/accordion.png");
  66. // break;
  67. // case "windows":
  68. // files[0].SaveAs(rootPath + "/Content/images/logo/windows.png");
  69. // break;
  70. // case "top":
  71. // files[0].SaveAs(rootPath + "/Content/images/logo/top.png");
  72. // break;
  73. // case "applogo":
  74. // files[0].SaveAs(rootPath + "/Content/images/logo/applogo.png");
  75. // break;
  76. //}
  77. }
  78. catch (Exception e)
  79. {
  80. Console.WriteLine(e);
  81. throw;
  82. }
  83. return Success("保存成功!");
  84. }
  85. public ActionResult GetImg(string code)
  86. {
  87. string rootPath = Server.MapPath("/");
  88. string midPath = "Content/images/logo";
  89. try
  90. {
  91. LR_Base_LogoEntity logoEntity = baseLogoIbll.GetLR_Base_LogoEntityByCode(code);
  92. if (logoEntity != null)
  93. {
  94. var bytesdefault = System.IO.File.ReadAllBytes(logoEntity.F_FileName);
  95. return File(bytesdefault, "image/jpeg");
  96. }
  97. else
  98. {
  99. switch (code)
  100. {
  101. case "default":
  102. var bytesdefault = System.IO.File.ReadAllBytes(Path.Combine(rootPath, midPath, "default.png"));
  103. return File(bytesdefault, "image/jpeg");
  104. case "accordion":
  105. var bytesaccordion = System.IO.File.ReadAllBytes(Path.Combine(rootPath, midPath, "accordion.png"));
  106. return File(bytesaccordion, "image/jpeg");
  107. case "windows":
  108. var byteswindows = System.IO.File.ReadAllBytes(Path.Combine(rootPath, midPath, "windows.png"));
  109. return File(byteswindows, "image/jpeg");
  110. case "top":
  111. var bytestop = System.IO.File.ReadAllBytes(Path.Combine(rootPath, midPath, "top.png"));
  112. return File(bytestop, "image/jpeg");
  113. case "applogo":
  114. var byteapplogo = System.IO.File.ReadAllBytes(Path.Combine(rootPath, midPath, "applogo.png"));
  115. return File(byteapplogo, "image/jpeg");
  116. case "headbg":
  117. var byteheadbg = System.IO.File.ReadAllBytes(Path.Combine(rootPath, midPath, "headbg.png"));
  118. return File(byteheadbg, "image/jpeg");
  119. case "data":
  120. var bytedata = System.IO.File.ReadAllBytes(Path.Combine(rootPath, midPath, "data.png"));
  121. return File(bytedata, "image/jpeg");
  122. }
  123. }
  124. }
  125. catch (Exception e)
  126. {
  127. Console.WriteLine(e);
  128. throw;
  129. }
  130. return null;
  131. }
  132. public ActionResult PCIndex()
  133. {
  134. return View();
  135. }
  136. }
  137. }