123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.Mvc;
- using Ant.Service.Common;
- using MES.Production.Service.IService;
- using Ant.Service.Common.Enums;
- using Central.Control.Domain;
- using ChangFa.Machinery.WebPage.Controllers;
- using Ant.ORM;
- using Ant.Data;
- using JsonHelper = Ant.Service.Common.JsonHelper;
- namespace ChangFa.Machinery.WebPage.Areas.SysManage.Controllers
- {
- /// <summary>
- /// 数据字典管理
- /// add 作者: 季健国 QQ:181589805 by 2016-05-22
- /// </summary>
- public class CodeController : BaseController
- {
- #region 声明容器
- /// <summary>
- /// 编码管理
- /// </summary>
- ICodeManage CodeManage { get; set; }
- #endregion
- #region 基本视图
- /// <summary>
- /// 加载主页
- /// </summary>
- [UserAuthorizeAttribute(ModuleAlias = "Warehouse", OperaAction = "View")]
- public ActionResult Index()
- {
- try
- {
- #region 处理查询参数
- string codetype = Request.QueryString["codetype"];
- #endregion
- #region 加载列表
- var result = BindList(codetype);
- ViewBag.Search = base.keywords;
- ViewData["codeType"] = ClsDic.DicCodeType;
- ViewData["codet"] = codetype;
- #endregion
- return View(result);
- }
- catch (Exception e)
- {
- WriteLog(enumOperator.Select, "数据字典管理加载主页:", e);
- throw e.InnerException;
- }
- }
- /// <summary>
- /// 加载列表
- /// </summary>
- private PageInfo BindList(string codetype)
- {
- //var predicate = PredicateBuilder.True<SYS_CODE>();
- ////关键词
- //if (!string.IsNullOrEmpty(keywords))
- //{
- // predicate = predicate.And(p => p.NAMETEXT.Contains(keywords));
- //}
- ////编码类型
- //if (!string.IsNullOrEmpty(codetype))
- //{
- // predicate = predicate.And(p => p.CODETYPE == codetype);
- //}
- //var query = this.CodeManage.LoadAll(predicate).OrderByDescending(p => p.CREATEDATE).
- // OrderBy(p => p.SHOWORDER).OrderBy(p => p.CODETYPE);//.OrderByDescending(p => p.UPDATEDATE)
- //return this.CodeManage.Query(query, base.page, base.pagesize);
- #region 加载列表
- PageInfo pageInfo = new PageInfo(base.page, base.pagesize, 0, JsonConverter.JsonClass(new List<SYS_CODE>()));
- using (AntORM orm = new AntORM())
- {
- orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
- RequestModel res = new RequestModel();
- res.newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取学校列表" };
- var syscodeList = orm.Queryable<SYS_CODE>();
- int pageno = (base.page - 1) * base.pagesize;
- //if (!nameOrProject.IsEmpty())
- //{
- // syscodeList = syscodeList.Where(p => (!string.IsNullOrEmpty(p.Name) && p.Name.Contains(nameOrProject)));
- //}
- //编码类型
- if (!string.IsNullOrEmpty(codetype))
- {
- syscodeList = syscodeList.Where(p => p.CODETYPE == codetype);
- }
- if(!keywords.IsEmpty())
- {
- syscodeList = syscodeList.Where(p => (!string.IsNullOrEmpty(p.NAMETEXT) && p.NAMETEXT.Contains(keywords)));
- }
- var reslut = syscodeList.OrderByDesc(p => p.CODETYPE).ThenBy(p=>p.SHOWORDER).Skip(pageno).Top(pagesize).ToList(res);
- if (reslut.IsSuccess)
- {
- reslut.RecordNum = syscodeList.Count();
- pageInfo = new PageInfo(base.page, base.pagesize, reslut.RecordNum, JsonConverter.JsonClass(reslut.ResultModel));
- }
- }
-
- //ViewData["nameOrProject"] = nameOrProject;
- return pageInfo;
- #endregion
- }
- /// <summary>
- /// 加载详情
- /// </summary>
- /// <param name="id">编码ID</param>
- /// <returns></returns>
- [UserAuthorizeAttribute(ModuleAlias = "Warehouse", OperaAction = "Detail")]
- public ActionResult Detail(int? id)
- {
- var entity = this.CodeManage.Get(p => p.ID == id) ?? new SYS_CODE();
- ViewData["codeType"] = ClsDic.DicCodeType;
- return View(entity);
- }
- /// <summary>
- /// 保存编码
- /// </summary>
- [UserAuthorizeAttribute(ModuleAlias = "Warehouse", OperaAction = "Add,Edit")]
- public ActionResult Save(SYS_CODE entity)
- {
- bool isEdit = false;
- JsonHelper json = new JsonHelper() { Msg = "保存编码成功", Status = "n" };
- try
- {
- if (entity != null)
- {
- entity.ISCODE = !string.IsNullOrEmpty(Request.Form["ISCODE"]) ? 1 : 0;
- var _entity = new SYS_CODE();
- //添加
- if (entity.ID <= 0)
- {
- _entity = entity;
- _entity.CREATEDATE = DateTime.Now;
- _entity.CREATEUSER = this.CurrentUser.Name;
- _entity.UPDATEDATE = DateTime.Now;
- _entity.UPDATEUSER = this.CurrentUser.Name;
- }
- else //修改
- {
- _entity = this.CodeManage.Get(p => p.ID == entity.ID);
- entity.CREATEDATE = _entity.CREATEDATE;
- entity.CREATEUSER = _entity.CREATEUSER;
- entity.UPDATEDATE = DateTime.Now;
- entity.UPDATEUSER = this.CurrentUser.Name;
- _entity = entity;
- isEdit = true;
- }
- //判断岗位是否重名
- if (!this.CodeManage.IsExist(p => p.NAMETEXT == _entity.NAMETEXT && p.CODETYPE == _entity.CODETYPE && p.ID != _entity.ID))
- {
- if (CodeManage.SaveOrUpdate(entity, isEdit))
- {
- json.Status = "y";
- }
- else
- {
- json.Msg = "保存失败";
- }
- }
- else
- {
- json.Msg = "编码" + _entity.NAMETEXT + "已存在,不能重复添加";
- }
- }
- else
- {
- json.Msg = "未找到需要保存的编码记录";
- }
- if (isEdit)
- {
- WriteLog(enumOperator.Edit, "修改编码,结果:" + json.Msg, enumLog4net.INFO);
- }
- else
- {
- WriteLog(enumOperator.Add, "添加编码,结果:" + json.Msg, enumLog4net.INFO);
- }
- }
- catch (Exception e)
- {
- json.Msg = "保存编码发生内部错误!";
- WriteLog(enumOperator.None, "保存编码:", e);
- }
- return Json(json);
- }
- /// <summary>
- /// 删除编码
- /// </summary>
- /// <param name="idList">编码ID字符串</param>
- [UserAuthorizeAttribute(ModuleAlias = "Warehouse", OperaAction = "Remove")]
- public ActionResult Delete(string idList)
- {
- var json = new JsonHelper() { Msg = "删除编码完毕", Status = "n" };
- try
- {
- if (!string.IsNullOrEmpty(idList))
- {
- var idList1 = idList.Trim(',').Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).Select(p => int.Parse(p)).ToList();
- this.CodeManage.Delete(p => idList1.Any(e => e == p.ID));
- json.Status = "y";
- }
- else
- {
- json.Msg = "未找到要删除的记录";
- }
- WriteLog(enumOperator.Remove, "删除编码,结果:" + json.Msg, enumLog4net.WARN);
- }
- catch (Exception e) { WriteLog(enumOperator.Remove, "删除编码出现异常:", e); }
- return Json(json);
- }
- #endregion
- #region 其他调用
- /// <summary>
- /// 根据类别获取上下级关系
- /// </summary>
- public ActionResult GetParentCode()
- {
- var json = new JsonHelper() { Status = "n", Data = "" };
- string codetype = Request.Form["type"];
- if (!string.IsNullOrEmpty(codetype))
- {
- var result = this.CodeManage.LoadListAll(p => p.CODETYPE == codetype);
- if (result != null && result.Count > 0)
- {
- json.Data = result;
- json.Status = "y";
- }
- }
- return Json(json);
- }
- #endregion
- }
- }
|