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
{
///
/// 岗位
///
IPostManage PostManage = new PostManage();
///
/// 字典编码
///
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(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(request);
if (reslut.IsSuccess)
{
mod = reslut.ResultModel;
}
}
catch (Exception e)
{
}
}
ViewBag.html = mod.Content;
return View(mod);
}
///
///
///
///
///
[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);
}
///
///
///
///
///
[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("", "").Replace("
", "");
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);
}
///
/// 绑定页面需要的属性
///
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();
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(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()));
}
}
//return new PageInfo(result.Index, result.PageSize, result.Count, JsonConverter.JsonClass(list));
}
}
}