HomeController.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.Mvc;
  6. using Ant.Service.Common.Enums;
  7. using MES.Production.Service.IService;
  8. using System.Text;
  9. using System.Collections;
  10. using System.Net;
  11. using Ant.Service.Common;
  12. using Central.Control.Domain;
  13. using System.IO;
  14. using Ant.ORM;
  15. using Ant.Data;
  16. using MES.Production.Entity;
  17. namespace ChangFa.Machinery.WebPage.Areas.SysManage.Controllers
  18. {
  19. /// <summary>
  20. /// 主页面
  21. /// add 作者: 季健国 QQ:181589805 by 2016-05-23
  22. /// </summary>
  23. public class HomeController : WebPage.Controllers.BaseController
  24. {
  25. #region 注入容器
  26. IModuleManage ModuleManage { get; set; }
  27. #endregion
  28. static string urlPath = string.Empty;
  29. public HomeController()
  30. {
  31. //string url = Request.Url.ToString();
  32. //var applicationPath = VirtualPathUtility.ToAbsolute("~") == "/" ? "" : VirtualPathUtility.ToAbsolute("~");
  33. }
  34. /// <summary>
  35. /// 加载主页面
  36. /// </summary>
  37. public ActionResult Index()
  38. {
  39. try
  40. {
  41. ViewData["CurrentUser"] = this.CurrentUser;
  42. //获取当前用户所展示的模块
  43. var Module = new List<SYS_MODULE>();
  44. ViewData["menu"] = GetMenu(out Module);
  45. ViewData["parentMenu"] = Module.FindAll(p => p.LEVELS == 0 && p.ISSHOW == 1).OrderBy(p => p.SHOWORDER).ToList();
  46. return View();
  47. }
  48. catch (Exception e)
  49. {
  50. WriteLog(enumOperator.Select, "系统主页面:", e);
  51. throw e.InnerException;
  52. }
  53. }
  54. public ActionResult UpLoadProcess(string id, string name, string type, string lastModifiedDate, int size, HttpPostedFileBase file)
  55. {
  56. string filePathName = string.Empty;
  57. var applicationPath = "http://" + Request.Url.Authority.ToString();
  58. urlPath = "/Upload/";
  59. var fileid = Guid.NewGuid().ToString("N");
  60. string localPath = Path.Combine(HttpRuntime.AppDomainAppPath, "Upload");
  61. if (Request.Files.Count == 0)
  62. {
  63. return Json(new { jsonrpc = 2.0, error = new { code = 102, message = "保存失败" }, id = id });
  64. }
  65. string ex = Path.GetExtension(file.FileName);
  66. filePathName = fileid + ex;
  67. if (!System.IO.Directory.Exists(localPath))
  68. {
  69. System.IO.Directory.CreateDirectory(localPath);
  70. }
  71. var filePath = urlPath + filePathName;
  72. file.SaveAs(Path.Combine(localPath, filePathName));
  73. var _result = "{\"jsonrpc\" : \"2.0\", \"result\" : null, \"id\" : \"" + filePath + "\"}";
  74. return Json(new
  75. {
  76. jsonrpc = "2.0",
  77. id = id,
  78. fileid = fileid,
  79. filePath = filePath
  80. });
  81. }
  82. /// <summary>
  83. ///
  84. /// </summary>
  85. /// <returns></returns>
  86. [HttpGet]
  87. public string UpdateAlarmInfo()
  88. {
  89. string reslut = "";
  90. using (AntORM orm = new AntORM())
  91. {
  92. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  93. RequestModel request = new RequestModel();
  94. request.newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "查询菜单的单个实体方法" };
  95. var updatereslut = orm.UpdateByLambda<YW_AlarmInformation>(p => new YW_AlarmInformation { IsRead = true }, p => p.IsRead == false, request);
  96. if (updatereslut.IsSuccess)
  97. {
  98. }
  99. }
  100. return reslut;
  101. }
  102. /// <summary>
  103. /// 获取故障报警信息
  104. /// </summary>
  105. /// <returns></returns>
  106. [HttpGet]
  107. public string GetAlarmInfo()
  108. {
  109. string HTMLSTR = "";
  110. int count = 1;// dc_popwin.getCount(userdpet);
  111. int ShareCount = 1;// dc_popwin.getSharCount(usercode);
  112. int SPCount = 1;//dc_popwin.getSPCount(usercode);
  113. int ShareUrgentCount = 1;//dc_popwin.getUrgentShare(usercode);
  114. int SPUrgentCount = 1;// dc_popwin.getUrgentSP(usercode);
  115. using (AntORM orm = new AntORM())
  116. {
  117. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  118. RequestModel request = new RequestModel();
  119. request.newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "查询菜单的单个实体方法" };
  120. var reslut = orm.Queryable<YW_AlarmInformation>().Where(p => p.IsRead == false).Top(10).OrderByDesc(p => p.Add_Time).ToList();
  121. if (reslut.IsSuccess)
  122. {
  123. HTMLSTR += "<fieldset><legendname>农机报警信息</legendname>";
  124. foreach (YW_AlarmInformation mod in reslut.ResultModel)
  125. {
  126. HTMLSTR += "<li>" + mod.Content + "</li>";//<button id='popbtn' onclick=\"switchWindow('2|4|1|3|5','/Configuration/zbwd/left_navigation.aspx?tag=spwd',null,null);\">查看</button>
  127. }
  128. }
  129. }
  130. //if (count != 0 || ShareCount != 0 || SPCount != 0 || ShareUrgentCount != 0 || SPUrgentCount != 0)
  131. //{
  132. // HTMLSTR += "<fieldset><legendname>其他待处理信息</legendname>";
  133. // if (ShareCount != 0)
  134. // {
  135. // HTMLSTR += "<li>您有" + ShareCount + "条目录文件没有完成共享,XXXXXXXXXXXXXXXXXXXdddddddddddddddddddXXXXXXXXXXXXXXXXXXXXXXX请注意查看&nbsp;&nbsp;<button id='popbtn' onclick=\"switchWindow('2|4|1|3|5','/Configuration/zbwd/left_navigation.aspx?tag=gxwd',null,null);\">查看</button></li>";
  136. // }
  137. // if (ShareUrgentCount != 0)
  138. // {
  139. // HTMLSTR += "<li>您有" + ShareUrgentCount + "条紧急目录文件没有完成共享,请注意查看&nbsp;&nbsp;<button id='popbtn' onclick=\"switchWindow('2|4|1|3|5','/Configuration/zbwd/left_navigation.aspx?tag=gxwd',null,null);\">查看</button></li>";
  140. // }
  141. // if (SPCount != 0)
  142. // {
  143. // HTMLSTR += "<li>您有" + SPCount + "条目录文件没有审批,请注意查看&nbsp;&nbsp;<button id='popbtn' onclick=\"switchWindow('2|4|1|3|5','/Configuration/zbwd/left_navigation.aspx?tag=spwd',null,null);\">查看</button></li>";
  144. // }
  145. // if (SPUrgentCount != 0)
  146. // {
  147. // HTMLSTR += "<li>您有" + SPUrgentCount + "条紧急目录文件没有审批,请注意查看&nbsp;&nbsp;<button id='popbtn' onclick=\"switchWindow('2|4|1|3|5','/Configuration/zbwd/left_navigation.aspx?tag=spwd',null,null);\">查看</button></li>";
  148. // }
  149. // HTMLSTR += "</fieldset>";
  150. //}
  151. return HTMLSTR;
  152. }
  153. /// <summary>
  154. /// 构造导航栏目JSON包
  155. /// </summary>
  156. string GetMenu(out List<SYS_MODULE> Module)
  157. {
  158. StringBuilder sbmenu = new StringBuilder();
  159. Module = ModuleManage.GetModule(this.CurrentUser.Id, this.CurrentUser.Permissions, this.siteId);
  160. sbmenu.Append("[");
  161. //一级栏目
  162. var firstModule = Module.FindAll(p => p.LEVELS == 0 && p.ISSHOW == 1);
  163. if (firstModule.Count > 0)
  164. {
  165. for (int i = 0; i < firstModule.Count; i++)
  166. {
  167. sbmenu.Append("{\"id\":\"" + firstModule[i].ALIAS + "\",");
  168. //默认打开模块为二级目的的第一个三级栏目
  169. var defaultModule = string.Empty;
  170. var has = Module.FindAll(c => c.PARENTID == firstModule[i].ID && c.LEVELS == 1 && c.ISSHOW == 1);
  171. if (has.Count > 0)
  172. {
  173. var nhas = Module.FindAll(c => c.LEVELS == 2 && c.PARENTID == has.First().ID);
  174. if (nhas.Count > 0)
  175. {
  176. defaultModule = nhas.First().ALIAS;
  177. }
  178. }
  179. sbmenu.Append("\"homePage\":\"" + defaultModule + "\",");
  180. sbmenu.Append("\"menu\":[");
  181. //二级栏目
  182. var secondModule = Module.FindAll(p => p.LEVELS == 1 && p.PARENTID == firstModule[i].ID && p.ISSHOW == 1);
  183. if (secondModule.Count > 0)
  184. {
  185. for (var j = 0; j < secondModule.Count; j++)
  186. {
  187. sbmenu.Append("{");
  188. sbmenu.Append("\"text\":\"" + secondModule[j].NAME + "\",");
  189. sbmenu.Append("\"icon\":\"" + secondModule[j].ICON + "\",");
  190. if (j > 0) { sbmenu.Append("\"collapsed\":true,"); }
  191. sbmenu.Append("\"items\":[");
  192. //三级栏目
  193. var threeModule = Module.FindAll(p => p.LEVELS == 2 && p.PARENTID == secondModule[j].ID && p.ISSHOW == 1);
  194. if (threeModule.Count > 0)
  195. {
  196. for (int k = 0; k < threeModule.Count; k++)
  197. {
  198. sbmenu.Append("{");
  199. sbmenu.Append("\"id\": \"" + threeModule[k].ALIAS + "\",");
  200. sbmenu.Append("\"text\": \"" + threeModule[k].NAME + "\",");
  201. sbmenu.Append("\"href\":\"" + threeModule[k].MODULEPATH + "\",");
  202. if (threeModule[k].ALIAS.ToLower() == "center")
  203. {
  204. sbmenu.Append("\"closeable\":false,");
  205. }
  206. sbmenu.Append("\"icon\": \"" + threeModule[k].ICON + "\"");
  207. sbmenu.Append("},");
  208. }
  209. sbmenu.Length -= 1;
  210. }
  211. sbmenu.Append("]},");
  212. }
  213. sbmenu.Length -= 1;
  214. }
  215. sbmenu.Append("]},");
  216. }
  217. sbmenu.Length -= 1;
  218. }
  219. sbmenu.Append("]");
  220. return sbmenu.ToString();
  221. }
  222. /// <summary>
  223. /// 管理中心
  224. /// </summary>
  225. public ActionResult Center()
  226. {
  227. return View();
  228. }
  229. /// <summary>
  230. /// 局部页
  231. /// </summary>
  232. public ActionResult Refresh()
  233. {
  234. //保存online表
  235. return View();
  236. }
  237. }
  238. }