NoticeController.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. using Ant.Data;
  2. using Ant.ORM;
  3. using Ant.SuperSocket.Common;
  4. using Ant.Service.Common;
  5. using Ant.Service.Common.Enums;
  6. using MES.Production.Entity;
  7. using MES.Production.Service.IService;
  8. using MES.Production.Service.ServiceImp;
  9. using Ant.Service.Utility;
  10. using ChangFa.Machinery.WebPage.Controllers;
  11. using System;
  12. using System.Collections.Generic;
  13. using System.Linq;
  14. using System.Web;
  15. using System.Web.Mvc;
  16. using JsonHelper = Ant.Service.Common.JsonHelper;
  17. namespace ChangFa.Machinery.WebPage.Areas.SysManage.Controllers
  18. {
  19. public class NoticeController : BaseController
  20. {
  21. /// <summary>
  22. /// 岗位
  23. /// </summary>
  24. IPostManage PostManage = new PostManage();
  25. /// <summary>
  26. /// 字典编码
  27. /// </summary>
  28. ICodeManage CodeManage = new CodeManage();
  29. // GET: SysManage/Notice
  30. [UserAuthorize(ModuleAlias = "NoticeList", OperaAction = "View")]
  31. public ActionResult Index()
  32. {
  33. string keyword = Request.QueryString["Search"];
  34. var result = BindList("", keyword);
  35. ViewBag.Search = keywords;
  36. return View(result);
  37. }
  38. [UserAuthorizeAttribute(ModuleAlias = "NoticeList", OperaAction = "Remove")]
  39. public ActionResult Delete(string idList)
  40. {
  41. JsonHelper json = new JsonHelper() { Status = "n", Msg = "删除用户成功" };
  42. try
  43. {
  44. //是否为空
  45. if (string.IsNullOrEmpty(idList)) { json.Msg = "未找到要删除的用户"; return Json(json); }
  46. string[] id = idList.Trim(',').Split(',');
  47. for (int i = 0; i < id.Length; i++)
  48. {
  49. var userId = (id[i]);
  50. using (AntORM orm = new AntORM())
  51. {
  52. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  53. RequestModel request = new RequestModel
  54. {
  55. newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "查询菜单的单个实体方法" },
  56. Oid = userId.ToString()
  57. };
  58. var reslut = orm.DeleteById<Ent_YW_Notice>(request);
  59. if (reslut.IsSuccess)
  60. {
  61. json.Status = "y";
  62. WriteLog(enumOperator.Remove, "删除公告:" + json.Msg, enumLog4net.WARN);
  63. }
  64. }
  65. }
  66. }
  67. catch (Exception e)
  68. {
  69. json.Msg = "删除用户发生内部错误!";
  70. WriteLog(enumOperator.Remove, "删除用户:", e);
  71. }
  72. return Json(json);
  73. }
  74. public ActionResult Detail(string id)
  75. {
  76. Ent_YW_Notice mod = new Ent_YW_Notice();
  77. ViewData["PostType"] = this.CodeManage.GetCode("POSTTYPE");
  78. ViewData["post"] = this.PostManage.LoadAll(null).OrderBy(p => p.SHOWORDER).ToList();
  79. using (AntORM orm = new AntORM())
  80. {
  81. try
  82. {
  83. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  84. RequestModel request = new RequestModel
  85. {
  86. newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "查询菜单的单个实体方法" },
  87. Oid = id
  88. };
  89. var reslut = orm.GetEntity<Ent_YW_Notice>(request);
  90. if (reslut.IsSuccess)
  91. {
  92. mod = reslut.ResultModel;
  93. }
  94. }
  95. catch (Exception e)
  96. {
  97. }
  98. }
  99. ViewBag.html = mod.Content;
  100. return View(mod);
  101. }
  102. /// <summary>
  103. ///
  104. /// </summary>
  105. /// <param name="content"></param>
  106. /// <returns></returns>
  107. [UserAuthorize(ModuleAlias = "NoticeList", OperaAction = "Add,Edit")]
  108. [ValidateInput(false)]
  109. [HttpPost]
  110. public ActionResult Save(string content, Ent_YW_Notice entity)
  111. {
  112. JsonHelper json = new JsonHelper() { Msg = "保存公告成功", Status = "n", ReUrl = "/Notice/Index" };
  113. try
  114. {
  115. var fileurl = Request.Form["hidfilename"];
  116. using (AntORM orm = new AntORM())
  117. {
  118. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  119. RequestModel request = new RequestModel();
  120. request.newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "查询菜单的单个实体方法" };
  121. if (entity.ID.IfNotNull() && entity.ID != Guid.Empty)
  122. {
  123. request.Oid = entity.ID.ToString();
  124. entity.ImgUrl = fileurl;
  125. if (entity.ImgUrl.IsEmpty())
  126. {
  127. entity.Noticetype = 1;
  128. }
  129. else
  130. {
  131. entity.Noticetype = 2;
  132. }
  133. entity.IsRead = false;
  134. var reslut = orm.UpdateById(entity, request);
  135. if (reslut.IsSuccess)
  136. {
  137. json.Status = "y";
  138. }
  139. else
  140. {
  141. json.Msg = "保存公告失败";
  142. }
  143. }
  144. else
  145. {
  146. entity.ID = Guid.NewGuid();
  147. entity.ImgUrl = fileurl;
  148. if (entity.ImgUrl.IsEmpty())
  149. {
  150. entity.Noticetype = 1;
  151. }
  152. else
  153. {
  154. entity.Noticetype = 2;
  155. }
  156. entity.createper = this.CurrentUser.Name;
  157. entity.createDate = DateTime.Now;
  158. entity.updateUser = "356802033381673";
  159. var reslut = orm.Save(entity, request);
  160. if (reslut.IsSuccess)
  161. {
  162. json.Status = "y";
  163. }
  164. else
  165. {
  166. json.Msg = "保存公告失败";
  167. }
  168. }
  169. }
  170. }
  171. catch (Exception ex)
  172. {
  173. json.Msg = "保存公告发生内部错误!";
  174. WriteLog(enumOperator.None, "保存公告:", ex);
  175. }
  176. if (json.Status == "y")
  177. {
  178. try
  179. {
  180. string imei = "356802033381673";
  181. var str = Ant.SuperSocket.Common.DataHelper.sendCarData(Convert.ToInt64(imei), "9944");
  182. var body = Ant.SuperSocket.Common.DataHelper.HexToByte(str);
  183. SocketClient client = new SocketClient();
  184. string ip = System.Web.Configuration.WebConfigurationManager.AppSettings["ip"].ToString();
  185. // string ip = "";
  186. int port = System.Web.Configuration.WebConfigurationManager.AppSettings["port"].ToInt32();
  187. client.Connect(ip, port);
  188. var flag = client.SendData(body);
  189. client.Disconnect();
  190. }
  191. catch (Exception e) { }
  192. }
  193. return Json(json);
  194. }
  195. /// <summary>
  196. ///
  197. /// </summary>
  198. /// <param name="content"></param>
  199. /// <returns></returns>
  200. [UserAuthorize(ModuleAlias = "NoticeList", OperaAction = "Add,Edit")]
  201. [ValidateInput(false)]
  202. [HttpPost]
  203. public ActionResult Savebak(string content, Ent_YW_Notice entity)
  204. {
  205. JsonHelper json = new JsonHelper() { Msg = "保存公告成功", Status = "n", ReUrl = "/Notice/Index" };
  206. try
  207. {
  208. var fileurl = Request.Form["hidfilename"];
  209. using (AntORM orm = new AntORM())
  210. {
  211. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  212. RequestModel request = new RequestModel();
  213. request.newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "查询菜单的单个实体方法" };
  214. if (entity.ID.IfNotNull() && entity.ID != Guid.Empty)
  215. {
  216. request.Oid = entity.ID.ToString();
  217. entity.ImgUrl = fileurl;
  218. if (entity.ImgUrl.IsEmpty())
  219. {
  220. entity.Noticetype = 1;
  221. }
  222. else
  223. {
  224. entity.Noticetype = 2;
  225. }
  226. var reslut = orm.UpdateById(entity, request);
  227. if (reslut.IsSuccess)
  228. {
  229. json.Status = "y";
  230. }
  231. else
  232. {
  233. json.Msg = "保存公告失败";
  234. }
  235. }
  236. else
  237. {
  238. entity.ID = Guid.NewGuid();
  239. entity.ImgUrl = fileurl;
  240. if (entity.ImgUrl.IsEmpty())
  241. {
  242. entity.Noticetype = 1;
  243. }
  244. else
  245. {
  246. entity.Noticetype = 2;
  247. }
  248. entity.createper = this.CurrentUser.Name;
  249. entity.createDate = DateTime.Now;
  250. var reslut = orm.Save(entity, request);
  251. if (reslut.IsSuccess)
  252. {
  253. json.Status = "y";
  254. }
  255. else
  256. {
  257. json.Msg = "保存公告失败";
  258. }
  259. }
  260. }
  261. }
  262. catch (Exception ex)
  263. {
  264. json.Msg = "保存公告发生内部错误!";
  265. WriteLog(enumOperator.None, "保存公告:", ex);
  266. }
  267. if (json.Status == "y")
  268. {
  269. // string title = "测试";
  270. int titlelen = entity.Title.Length;
  271. byte[] titlebytes = System.Text.Encoding.UTF8.GetBytes(entity.Title);
  272. var titlehex = DataHelper.byteToHexStr(titlebytes);
  273. string lenhex = DataHelper.DecToHex(titlebytes.Length).Replace("00 ", "");
  274. //string content = "标题内容,基本原则顶替23111!";
  275. content = content.Replace("<p>", "").Replace("</p>", "");
  276. byte[] contentbytes = System.Text.Encoding.UTF8.GetBytes(content);
  277. int contentlen = content.Length;
  278. var hexstr = DataHelper.byteToHexStr(contentbytes);
  279. string len = DataHelper.DecToHex(contentbytes.Length).Replace(" ", "");
  280. string str = lenhex + titlehex + len + hexstr;
  281. var num = lenhex.ToInt32() ^ titlelen ^ contentlen ^ len.ToInt32();
  282. var hexallbyte = DataHelper.DecToHex(num).Replace("00 ", "");
  283. str = str + hexallbyte;
  284. }
  285. return Json(json);
  286. }
  287. /// <summary>
  288. /// 绑定页面需要的属性
  289. /// </summary>
  290. public PageInfo BindList(string posttype, string FK_DPTID)
  291. {
  292. using (AntORM orm = new AntORM())
  293. {
  294. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  295. RequestModel request = new RequestModel();
  296. request.newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "查询菜单的单个实体方法" };
  297. var q = orm.Queryable<Ent_YW_Notice>();
  298. if (!string.IsNullOrEmpty(keywords))
  299. {
  300. q = q.Where(p => p.Title.Contains(keywords));
  301. }
  302. var reslut = q.OrderBy(a => a.ID).Skip(page - 1).Top(pagesize).ToList(request);
  303. //var reslut= orm.SqlQuery<YW_Bicycle>(string.Format("select top {0} * from YW_Bicycle where Id>@Id", 1), new { Id = "sfdfdfdf" }).ToList();
  304. if (reslut.IsSuccess)
  305. {
  306. return new PageInfo(base.page, base.pagesize, reslut.RecordNum, JsonConverter.JsonClass(reslut.ResultModel));
  307. }
  308. else
  309. {
  310. return new PageInfo(base.page, base.pagesize, reslut.RecordNum, JsonConverter.JsonClass(new List<EntYW_Bicycle>()));
  311. }
  312. }
  313. //return new PageInfo(result.Index, result.PageSize, result.Count, JsonConverter.JsonClass(list));
  314. }
  315. }
  316. }