123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354 |
- using Ant.Data;
- using Ant.ORM;
- using Ant.SuperSocket.Common;
- using Ant.Service.Common;
- using Ant.Service.Common.Enums;
- using MES.Production.Entity;
- using MES.Production.Service.IService;
- using MES.Production.Service.ServiceImp;
- using Ant.Service.Utility;
- using ChangFa.Machinery.WebPage.Controllers;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.Mvc;
- using JsonHelper = Ant.Service.Common.JsonHelper;
- namespace ChangFa.Machinery.WebPage.Areas.SysManage.Controllers
- {
- public class NoticeController : BaseController
- {
- /// <summary>
- /// 岗位
- /// </summary>
- IPostManage PostManage = new PostManage();
- /// <summary>
- /// 字典编码
- /// </summary>
- ICodeManage CodeManage = new CodeManage();
- // GET: SysManage/Notice
- [UserAuthorize(ModuleAlias = "NoticeList", OperaAction = "View")]
- public ActionResult Index()
- {
- string keyword = Request.QueryString["Search"];
- var result = BindList("", keyword);
- ViewBag.Search = keywords;
- return View(result);
- }
- [UserAuthorizeAttribute(ModuleAlias = "NoticeList", OperaAction = "Remove")]
- public ActionResult Delete(string idList)
- {
- JsonHelper json = new JsonHelper() { Status = "n", Msg = "删除用户成功" };
- try
- {
- //是否为空
- if (string.IsNullOrEmpty(idList)) { json.Msg = "未找到要删除的用户"; return Json(json); }
- string[] id = idList.Trim(',').Split(',');
- for (int i = 0; i < id.Length; i++)
- {
- var userId = (id[i]);
- using (AntORM orm = new AntORM())
- {
- orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
- RequestModel request = new RequestModel
- {
- newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "查询菜单的单个实体方法" },
- Oid = userId.ToString()
- };
- var reslut = orm.DeleteById<Ent_YW_Notice>(request);
- if (reslut.IsSuccess)
- {
- json.Status = "y";
- WriteLog(enumOperator.Remove, "删除公告:" + json.Msg, enumLog4net.WARN);
- }
- }
- }
- }
- catch (Exception e)
- {
- json.Msg = "删除用户发生内部错误!";
- WriteLog(enumOperator.Remove, "删除用户:", e);
- }
- return Json(json);
- }
- public ActionResult Detail(string id)
- {
- Ent_YW_Notice mod = new Ent_YW_Notice();
- ViewData["PostType"] = this.CodeManage.GetCode("POSTTYPE");
- ViewData["post"] = this.PostManage.LoadAll(null).OrderBy(p => p.SHOWORDER).ToList();
- using (AntORM orm = new AntORM())
- {
- try
- {
- orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
- RequestModel request = new RequestModel
- {
- newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "查询菜单的单个实体方法" },
- Oid = id
- };
- var reslut = orm.GetEntity<Ent_YW_Notice>(request);
- if (reslut.IsSuccess)
- {
- mod = reslut.ResultModel;
- }
- }
- catch (Exception e)
- {
- }
- }
- ViewBag.html = mod.Content;
- return View(mod);
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="content"></param>
- /// <returns></returns>
- [UserAuthorize(ModuleAlias = "NoticeList", OperaAction = "Add,Edit")]
- [ValidateInput(false)]
- [HttpPost]
- public ActionResult Save(string content, Ent_YW_Notice entity)
- {
- JsonHelper json = new JsonHelper() { Msg = "保存公告成功", Status = "n", ReUrl = "/Notice/Index" };
- try
- {
- var fileurl = Request.Form["hidfilename"];
- using (AntORM orm = new AntORM())
- {
- orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
- RequestModel request = new RequestModel();
- request.newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "查询菜单的单个实体方法" };
- if (entity.ID.IfNotNull() && entity.ID != Guid.Empty)
- {
- request.Oid = entity.ID.ToString();
- entity.ImgUrl = fileurl;
- if (entity.ImgUrl.IsEmpty())
- {
- entity.Noticetype = 1;
- }
- else
- {
- entity.Noticetype = 2;
- }
- entity.IsRead = false;
- var reslut = orm.UpdateById(entity, request);
- if (reslut.IsSuccess)
- {
- json.Status = "y";
- }
- else
- {
- json.Msg = "保存公告失败";
- }
- }
- else
- {
- entity.ID = Guid.NewGuid();
- entity.ImgUrl = fileurl;
- if (entity.ImgUrl.IsEmpty())
- {
- entity.Noticetype = 1;
- }
- else
- {
- entity.Noticetype = 2;
- }
- entity.createper = this.CurrentUser.Name;
- entity.createDate = DateTime.Now;
- entity.updateUser = "356802033381673";
- var reslut = orm.Save(entity, request);
- if (reslut.IsSuccess)
- {
- json.Status = "y";
- }
- else
- {
- json.Msg = "保存公告失败";
- }
- }
- }
- }
- catch (Exception ex)
- {
- json.Msg = "保存公告发生内部错误!";
- WriteLog(enumOperator.None, "保存公告:", ex);
- }
- if (json.Status == "y")
- {
- try
- {
- string imei = "356802033381673";
- var str = Ant.SuperSocket.Common.DataHelper.sendCarData(Convert.ToInt64(imei), "9944");
- var body = Ant.SuperSocket.Common.DataHelper.HexToByte(str);
- SocketClient client = new SocketClient();
- string ip = System.Web.Configuration.WebConfigurationManager.AppSettings["ip"].ToString();
- // string ip = "";
- int port = System.Web.Configuration.WebConfigurationManager.AppSettings["port"].ToInt32();
- client.Connect(ip, port);
- var flag = client.SendData(body);
- client.Disconnect();
- }
- catch (Exception e) { }
- }
- return Json(json);
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="content"></param>
- /// <returns></returns>
- [UserAuthorize(ModuleAlias = "NoticeList", OperaAction = "Add,Edit")]
- [ValidateInput(false)]
- [HttpPost]
- public ActionResult Savebak(string content, Ent_YW_Notice entity)
- {
- JsonHelper json = new JsonHelper() { Msg = "保存公告成功", Status = "n", ReUrl = "/Notice/Index" };
- try
- {
- var fileurl = Request.Form["hidfilename"];
- using (AntORM orm = new AntORM())
- {
- orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
- RequestModel request = new RequestModel();
- request.newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "查询菜单的单个实体方法" };
- if (entity.ID.IfNotNull() && entity.ID != Guid.Empty)
- {
- request.Oid = entity.ID.ToString();
- entity.ImgUrl = fileurl;
- if (entity.ImgUrl.IsEmpty())
- {
- entity.Noticetype = 1;
- }
- else
- {
- entity.Noticetype = 2;
- }
- var reslut = orm.UpdateById(entity, request);
- if (reslut.IsSuccess)
- {
- json.Status = "y";
- }
- else
- {
- json.Msg = "保存公告失败";
- }
- }
- else
- {
- entity.ID = Guid.NewGuid();
- entity.ImgUrl = fileurl;
- if (entity.ImgUrl.IsEmpty())
- {
- entity.Noticetype = 1;
- }
- else
- {
- entity.Noticetype = 2;
- }
- entity.createper = this.CurrentUser.Name;
- entity.createDate = DateTime.Now;
- var reslut = orm.Save(entity, request);
- if (reslut.IsSuccess)
- {
- json.Status = "y";
- }
- else
- {
- json.Msg = "保存公告失败";
- }
- }
- }
- }
- catch (Exception ex)
- {
- json.Msg = "保存公告发生内部错误!";
- WriteLog(enumOperator.None, "保存公告:", ex);
- }
- if (json.Status == "y")
- {
- // string title = "测试";
- int titlelen = entity.Title.Length;
- byte[] titlebytes = System.Text.Encoding.UTF8.GetBytes(entity.Title);
- var titlehex = DataHelper.byteToHexStr(titlebytes);
- string lenhex = DataHelper.DecToHex(titlebytes.Length).Replace("00 ", "");
- //string content = "标题内容,基本原则顶替23111!";
- content = content.Replace("<p>", "").Replace("</p>", "");
- byte[] contentbytes = System.Text.Encoding.UTF8.GetBytes(content);
- int contentlen = content.Length;
- var hexstr = DataHelper.byteToHexStr(contentbytes);
- string len = DataHelper.DecToHex(contentbytes.Length).Replace(" ", "");
- string str = lenhex + titlehex + len + hexstr;
- var num = lenhex.ToInt32() ^ titlelen ^ contentlen ^ len.ToInt32();
- var hexallbyte = DataHelper.DecToHex(num).Replace("00 ", "");
- str = str + hexallbyte;
- }
- return Json(json);
- }
- /// <summary>
- /// 绑定页面需要的属性
- /// </summary>
- public PageInfo BindList(string posttype, string FK_DPTID)
- {
- using (AntORM orm = new AntORM())
- {
- orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
- RequestModel request = new RequestModel();
- request.newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "查询菜单的单个实体方法" };
- var q = orm.Queryable<Ent_YW_Notice>();
- if (!string.IsNullOrEmpty(keywords))
- {
- q = q.Where(p => p.Title.Contains(keywords));
- }
- var reslut = q.OrderBy(a => a.ID).Skip(page - 1).Top(pagesize).ToList(request);
- //var reslut= orm.SqlQuery<YW_Bicycle>(string.Format("select top {0} * from YW_Bicycle where Id>@Id", 1), new { Id = "sfdfdfdf" }).ToList();
- if (reslut.IsSuccess)
- {
- return new PageInfo(base.page, base.pagesize, reslut.RecordNum, JsonConverter.JsonClass(reslut.ResultModel));
- }
- else
- {
- return new PageInfo(base.page, base.pagesize, reslut.RecordNum, JsonConverter.JsonClass(new List<EntYW_Bicycle>()));
- }
- }
- //return new PageInfo(result.Index, result.PageSize, result.Count, JsonConverter.JsonClass(list));
- }
- }
- }
|