123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739 |
- using System;
- using System.Linq;
- using System.Web.Mvc;
- using Central.Control.Domain;
- using Ant.Service.Common.Enums;
- using Ant.Service.Common;
- using System.Collections.Generic;
- using MES.Production.Service.IService;
- using System.Collections;
- using System.Globalization;
- using ChangFa.Machinery.WebPage.Controllers;
- using System.Web;
- using System.Xml;
- using System.Text;
- using System.IO;
- using System.Net;
- using System.Drawing;
- using Ant.Service.Utility;
- using System.Text.RegularExpressions;
- using Newtonsoft.Json;
- using MES.Production.Entity;
- using Ant.ORM;
- using Ant.Data;
- using MES.Production.Entity.Entity;
- using JsonHelper = Ant.Service.Common.JsonHelper;
- using JsonConverter = Ant.Service.Common.JsonConverter;
- namespace ChangFa.Machinery.WebPage.Areas.SysManage.Controllers
- {
- /// <summary>
- /// 部门管理控制器
- /// add 作者: 季健国 QQ:181589805 by 2016-05-25
- /// </summary>
- public class DepartmentController : BaseController
- {
- #region 声明容器
- /// <summary>
- /// 部门
- /// </summary>
- IDepartmentManage DepartmentManage { get; set; }
- /// <summary>
- /// 用户部门
- /// </summary>
- IUserDepartmentManage UserDepartmentManage { get; set; }
- /// <summary>
- /// 岗位人员
- /// </summary>
- IPostUserManage PostUserManage { get; set; }
- /// <summary>
- /// 岗位部门
- /// </summary>
- IPostDepartmentManage PostDepartmentManage { get; set; }
- #endregion
- /// <summary>
- /// 加载导航页
- /// </summary>
- /// <returns></returns>
- [UserAuthorizeAttribute(ModuleAlias = "Department", OperaAction = "View")]
- public ActionResult Home()
- {
- return View();
- }
- /// <summary>
- /// 加载主页
- /// </summary>
- [UserAuthorizeAttribute(ModuleAlias = "Department", OperaAction = "View")]
- public ActionResult Index()
- {
- try
- {
- #region 处理查询参数
- string dptId = Request.QueryString["dptid"];
- #endregion
- #region 加载列表
- //加载部门信息
- var result = this.DepartmentManage.Get(p => p.ID == dptId) ?? new SYS_DISTRIBUTORS();
- if (!string.IsNullOrEmpty(dptId))
- {
- //加载岗位
- var postlist = this.PostDepartmentManage.GetPostIDByDptId(dptId);
- ViewData["postInfo"] = postlist;
- //加载部门岗位关系ID
- var postIdStr = postlist.Aggregate(string.Empty, (current, t) => current + t.ID + ",").TrimEnd(',');
- //读取相关用户,构造用户,增加岗位ID列
- var userList = this.PostUserManage.LoadAll(p => postIdStr.Contains(p.SYS_POST_DEPARTMENT.FK_POST_ID) && p.SYS_POST_DEPARTMENT.FK_DEPARTMENT_ID == dptId).Select(c => new
- {
- POSTID = c.SYS_POST_DEPARTMENT.FK_POST_ID,
- c.SYS_USER.NAME
- }).GroupBy(c => c).Select(d => new { POSTID = d.Key.POSTID, NAME = d.Key.NAME }).ToList();
- ViewData["userInfo"] = JsonConverter.JsonClass(userList);
- }
- #endregion
- return View(result);
- }
- catch (Exception e)
- {
- WriteLog(enumOperator.Select, "经销商管理加载主页:", e);
- throw e.InnerException;
- }
- }
- /// <summary>
- /// 加载详情页
- /// </summary>
- [HttpGet]
- [UserAuthorizeAttribute(ModuleAlias = "Department", OperaAction = "Detail")]
- public ActionResult Detail(string id)
- {
- try
- {
- string filePathName = string.Empty;
- DistributorUser distributorUser = new DistributorUser();
- SYS_DISTRIBUTORS entity = new SYS_DISTRIBUTORS();
- int uid = 0;
- if (CurrentUser.USERTYPE == 2)
- {
- uid = CurrentUser.Id;
- }
- ViewBag.moduleparent = this.DepartmentManage.GetDepartmentByDetailNew(uid);
- //添加子部门
- string parentId = Request.QueryString["parentId"];
- if (!string.IsNullOrEmpty(parentId))
- {
- //entity.PARENTID = parentId;
- distributorUser.distributorInfo.PARENTID = parentId;
- return View(distributorUser);
- }
- if (!string.IsNullOrEmpty(id))
- {
- entity = this.DepartmentManage.Get(p => p.ID == id);
- distributorUser.distributorInfo = entity;
- using (AntORM orm = new AntORM())
- {
- orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
- RequestModel res = new RequestModel
- {
- newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取公告信息" }
- };
- var reslut = orm.Queryable<EntYW_UserDistributor>().Where(p => p.distributorId == id).ToList();
- if (reslut.IsSuccess)
- {
- string strlist = "";
- foreach (EntYW_UserDistributor mod in reslut.ResultModel)
- {
- int userid = mod.userId.ToInt32();
- var userreslut = orm.Queryable<En_SYS_USER>().Where(p => p.ID == userid).FirstOrDefault(res);
- if (userreslut.IsSuccess)
- {
- En_SYS_USER usermod = userreslut.ResultModel;
- strlist += usermod.ID + "|" + usermod.NAME;
- }
- }
- ViewData["userid"] = strlist;
- }
- var usereslut = orm.Queryable<En_SYS_USER>().Where(p => p.DPTID == entity.ID).FirstOrDefault(res);
- if (usereslut.IsSuccess)
- {
- distributorUser.userInfo = usereslut.ResultModel;
- }
- }
- }
- else
- {
- distributorUser.distributorInfo = new SYS_DISTRIBUTORS();
- distributorUser.distributorInfo.PARENTID = "32f7a4bd-84de-4587-be29-734d65ad6f70";
- distributorUser.userInfo = new En_SYS_USER() { ISCANLOGIN = false };
- }
- return View(distributorUser);
- }
- catch (Exception e)
- {
- WriteLog(enumOperator.Select, "经销商管理加载详情页:", e);
- throw e.InnerException;
- }
- }
- /// <summary>
- /// 保存部门
- /// </summary>
- [ValidateInput(false)]
- [UserAuthorizeAttribute(ModuleAlias = "Department", OperaAction = "Add,Edit")]
- public ActionResult Save(DistributorUser entity)
- {
- bool isEdit = false; bool bz = true;
- var fileid = Request.Form["hidfileid"];
- var fileurl = Request.Form["hidfilename"];
- var paretid = Request.Form["PARENTID"];
- int userid = 0;
- var citystr = Request.Form["hkprov"] + "," + Request.Form["hkcity"] + "," + Request.Form["hkcountry"];
- var json = new JsonHelper() { Msg = "保存成功", Status = "n" };
- try
- {
- var _entity = new SYS_DISTRIBUTORS(); var _userenty = new En_SYS_USER();
- if (entity.distributorInfo != null)
- {
- if (!string.IsNullOrEmpty(entity.distributorInfo.ID))
- {
- EntYW_UserDistributor yW_User = new EntYW_UserDistributor();
- using (AntORM orm = new AntORM())
- {
- orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
- RequestModel res = new RequestModel
- {
- newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取公告信息" }
- };
- var disreult = orm.DeleteByLambda<EntYW_UserDistributor>(p => p.distributorId == entity.distributorInfo.ID, res);
- foreach (string str in Request.Form["hidsendUserid"].Split(','))
- {
- if (!str.IsEmpty())
- {
- EntYW_UserDistributor entmod = new EntYW_UserDistributor();
- entmod.userId = str.ToInt32();
- entmod.distributorId = entity.distributorInfo.ID;
- entmod.ID = Guid.NewGuid();
- var reslutuser = orm.Save(entmod, res);
- }
- }
- }
- #region 修改
- _entity = this.DepartmentManage.Get(p => p.ID == entity.distributorInfo.ID);
- entity.distributorInfo.CREATEDATE = _entity.CREATEDATE;
- entity.distributorInfo.CREATEPERID = _entity.CREATEPERID;
- entity.distributorInfo.PARENTID = paretid;
- entity.distributorInfo.UPDATEDATE = DateTime.Now;
- entity.distributorInfo.UPDATEUSER = this.CurrentUser.Name;
- entity.distributorInfo.Address = Request.Form["distributorInfo.Address"];
- entity.distributorInfo.FenceRadius = Request.Form["example_length"].ToInt32();
- entity.distributorInfo.LICENSEURL = fileurl;
- entity.distributorInfo.LICENSEVALUE = fileid;
- entity.distributorInfo.ProvinceCity = citystr;
- if (entity.distributorInfo.PARENTID != _entity.PARENTID)
- {
- entity.distributorInfo.CODE = this.DepartmentManage.CreateCode(entity.distributorInfo.PARENTID);
- }
- else
- {
- entity.distributorInfo.CODE = _entity.CODE;
- }
- //获取父级记录
- if (string.IsNullOrEmpty(paretid))
- {
- //业务等级
- entity.distributorInfo.BUSINESSLEVEL = 1;
- entity.distributorInfo.PARENTCODE = null;
- }
- else
- {
- var parententity = this.DepartmentManage.Get(p => p.ID == _entity.PARENTID);
- entity.distributorInfo.BUSINESSLEVEL = parententity.BUSINESSLEVEL + 1;
- entity.distributorInfo.PARENTCODE = parententity.CODE;
- entity.distributorInfo.ParentName = parententity.NAME;
- }
- #endregion
- _entity = entity.distributorInfo;
- _userenty = entity.userInfo;
- _userenty.ACCOUNT = _userenty.PHONE;
- _userenty.USERTYPE = 2;
- isEdit = true;
- using (AntORM orm = new AntORM())
- {
- orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
- RequestModel res = new RequestModel
- {
- newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取公告信息" }
- };
- var resuser = orm.UpdateById(_userenty, res);
- }
- }
- else
- {
- #region 添加
- _entity = entity.distributorInfo;
- _entity.ID = Guid.NewGuid().ToString();
- _entity.CREATEDATE = DateTime.Now;
- _entity.CREATEPERID = this.CurrentUser.Name;
- _entity.PARENTID = paretid;
- _entity.UPDATEDATE = DateTime.Now;
- _entity.UPDATEUSER = this.CurrentUser.Name;
- _entity.Address = entity.distributorInfo.Address;
- _entity.FenceRadius = Request.Form["example_length"].ToInt32();
- _entity.LICENSEURL = fileurl;
- _entity.LICENSEVALUE = fileid;
- _entity.ProvinceCity = citystr;
- _entity.Province = Request.Form["hkprov"].ToInt32();
- _entity.City = Request.Form["hkcity"].ToInt32();
- _entity.Area = Request.Form["hkcountry"].ToInt32();
- _userenty = entity.userInfo;
- _userenty.DPTID = _entity.ID;
- var pwd = PasswordUtils.MD5_Encrypt("111111", 32);
- _userenty.USERTYPE = 2;
- _userenty.ACCOUNT = _userenty.PHONE;
- _userenty.PASSWORD = pwd;
- _userenty.CREATEDATE = DateTime.Now;
- _userenty.CREATEPER = this.CurrentUser.Name;
- _userenty.UPDATEDATE = DateTime.Now;
- _userenty.UPDATEUSER = this.CurrentUser.Name;
- using (AntORM orm = new AntORM())
- {
- orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
- RequestModel res = new RequestModel
- {
- newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取公告信息" }
- };
- var resuser = orm.SaveHaveNull(_userenty, res);
- if (resuser.IsSuccess)
- {
- userid = resuser.RecordNum;
- _userenty.ID = userid;
- }
- }
- //根据上级部门的ID确定当前部门的CODE
- _entity.CODE = this.DepartmentManage.CreateCode(_entity.PARENTID);
- //获取父级记录
- if (string.IsNullOrEmpty(_entity.PARENTID))
- {
- //业务等级
- entity.distributorInfo.BUSINESSLEVEL = 1;
- entity.distributorInfo.PARENTCODE = null;
- }
- else
- {
- var parententity = this.DepartmentManage.Get(p => p.ID == _entity.PARENTID);
- entity.distributorInfo.BUSINESSLEVEL = parententity.BUSINESSLEVEL + 1;
- entity.distributorInfo.PARENTCODE = parententity.CODE;
- entity.distributorInfo.ParentName = parententity.NAME;
- }
- #endregion
- EntYW_UserDistributor yW_User = new EntYW_UserDistributor();
- using (AntORM orm = new AntORM())
- {
- orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
- RequestModel res = new RequestModel
- {
- newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取公告信息" }
- };
- foreach (string str in Request.Form["hidsendUserid"].Split(','))
- {
- if (!str.IsEmpty())
- {
- int uid = str.ToInt32();
- var num = orm.Queryable<EntYW_UserDistributor>().Where(p => p.distributorId == _entity.ID && p.userId == uid).Count();
- if (num > 0)
- {
- bz = false;
- }
- }
- }
- if (bz)
- {
- foreach (string str in Request.Form["hidsendUserid"].Split(','))
- {
- EntYW_UserDistributor entmod = new EntYW_UserDistributor();
- entmod.userId = str.ToInt32();
- entmod.distributorId = _entity.ID;
- entmod.ID = Guid.NewGuid();
- var reslutuser = orm.Save(entmod, res);
- }
- }
- }
- EntSYS_USER_ROLE roleMod = new EntSYS_USER_ROLE();
- using (AntORM orm = new AntORM())
- {
- orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
- RequestModel res = new RequestModel
- {
- newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取公告信息" }
- };
- roleMod.FK_ROLEID = 3;
- roleMod.FK_USERID = _userenty.ID.ToInt32();
- orm.Save(roleMod, res);
- }
- }
- //先取消电子围栏
- var addressmod = AddressToGPS(entity.distributorInfo.Address);
- if (addressmod.Geocodes.Count > 0)
- {
- foreach (Geocode mod in addressmod.Geocodes)
- {
- string lnglatstr = mod.Location;
- _entity.Theodolite = lnglatstr;
- }
- }
- #region 老版创建电子围栏
- //var addressmod = AddressToGPS(entity.distributorInfo.Address);
- //if (addressmod.Geocodes.Count > 0)
- //{
- // foreach (Geocode mod in addressmod.Geocodes)
- // {
- // string lnglatstr = mod.Location;
- // _entity.Theodolite = lnglatstr;
- // if (lnglatstr.IndexOf(',') >= 0)
- // {
- // string lng = lnglatstr.Split(',')[0];
- // string lat = lnglatstr.Split(',')[1];
- // if (entity.distributorInfo.FenceID.IsEmpty())
- // {
- // var reslutFences = ToolGPSamap.CreaterGeofence(lng.ToDou(), lat.ToDou(), entity.distributorInfo.FenceRadius.ToDou(), entity.distributorInfo.NAME);
- // if (!reslutFences.data.gid.IsEmpty())
- // {
- // entity.distributorInfo.FenceID = reslutFences.data.gid;
- // _userenty = entity.userInfo;
- // _userenty.DPTID = _entity.ID;
- // var pwd = PasswordUtils.MD5_Encrypt("111111", 32);
- // _userenty.USERTYPE = 2;
- // _userenty.PASSWORD = pwd;
- // _userenty.CREATEDATE = DateTime.Now;
- // _userenty.CREATEPER = this.CurrentUser.Name;
- // _userenty.UPDATEDATE = DateTime.Now;
- // _userenty.UPDATEUSER = this.CurrentUser.Name;
- // using (AntORM orm = new AntORM())
- // {
- // orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
- // RequestModel res = new RequestModel
- // {
- // newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取公告信息" }
- // };
- // var resuser = orm.Save(_userenty, res);
- // }
- // }
- // else
- // {
- // json.Status = "n";
- // json.Msg = reslutFences.data.message;
- // return Json(json);
- // }
- // }
- // else
- // {
- // RequestQueryFence request = new RequestQueryFence();
- // request.gid = entity.distributorInfo.FenceID;
- // var FenceReslut = ToolGPSamap.QueryGeoFence(request);
- // var list = FenceReslut.Data.RsList;
- // foreach (RsList mm in list)
- // {
- // var fencereslut = ToolGPSamap.UpdateGeofence(lng.ToDou(), lat.ToDou(), entity.distributorInfo.FenceRadius.ToDou(), entity.distributorInfo.NAME, mm.Gid);
- // }
- // }
- // }
- // }
- //}
- //else
- //{
- // string lnglatstr = _entity.Theodolite;
- // if (lnglatstr.IndexOf(',') >= 0)
- // {
- // string lng = lnglatstr.Split(',')[0];
- // string lat = lnglatstr.Split(',')[1];
- // if (entity.distributorInfo.FenceID.IsEmpty())
- // {
- // var reslutFences = ToolGPSamap.CreaterGeofence(lng.ToDou(), lat.ToDou(), entity.distributorInfo.FenceRadius.ToDou(), entity.distributorInfo.NAME);
- // if (!reslutFences.data.gid.IsEmpty())
- // {
- // entity.distributorInfo.FenceID = reslutFences.data.gid;
- // _userenty = entity.userInfo;
- // _userenty.DPTID = _entity.ID;
- // var pwd = PasswordUtils.MD5_Encrypt("111111", 32);
- // _userenty.USERTYPE = 2;
- // _userenty.PASSWORD = pwd;
- // _userenty.CREATEDATE = DateTime.Now;
- // _userenty.CREATEPER = this.CurrentUser.Name;
- // _userenty.UPDATEDATE = DateTime.Now;
- // _userenty.UPDATEUSER = this.CurrentUser.Name;
- // using (AntORM orm = new AntORM())
- // {
- // orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
- // RequestModel res = new RequestModel
- // {
- // newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取公告信息" }
- // };
- // var resuser = orm.Save(_userenty, res);
- // }
- // }
- // }
- // else
- // {
- // RequestQueryFence request = new RequestQueryFence();
- // request.gid = entity.distributorInfo.FenceID;
- // var FenceReslut = ToolGPSamap.QueryGeoFence(request);
- // var list = FenceReslut.Data.RsList;
- // foreach (RsList mm in list)
- // {
- // var fencereslut = ToolGPSamap.UpdateGeofence(lng.ToDou(), lat.ToDou(), entity.distributorInfo.FenceRadius.ToDou(), entity.distributorInfo.NAME, mm.Gid);
- // }
- // }
- // }
- //}
- #endregion
- //判断同一个部门下,是否重名
- var predicate = PredicateBuilder.True<SYS_DISTRIBUTORS>();
- predicate = predicate.And(p => p.PARENTID == _entity.PARENTID);
- predicate = predicate.And(p => p.NAME == _entity.NAME);
- predicate = predicate.And(p => p.ID != _entity.ID);
- if (!this.DepartmentManage.IsExist(predicate))
- {
- if (this.DepartmentManage.SaveOrUpdate(_entity, isEdit))
- {
- json.Status = "y";
- try
- {
- //string imei = "356802032734930";
- string imei = "333333333333333";
- string discode = Ant.SuperSocket.Common.DataHelper.StringToHex(_entity.CODE);
- var str = Ant.SuperSocket.Common.DataHelper.sendCarData(Convert.ToInt64(imei), "9922" + discode);
- 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 ex) { }
- }
- else
- {
- json.Msg = "保存失败";
- }
- }
- else
- {
- json.Msg = "经销商" + entity.distributorInfo.NAME + "已存在,不能重复添加";
- }
- }
- 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>
- /// 将地址转GPS
- /// </summary>
- /// <param name="address"></param>
- /// <returns></returns>
- private AddressGPS AddressToGPS(string address)
- {
- WebClient server = new WebClient();
- string url = String.Format("http://restapi.amap.com/v3/geocode/geo?key={0}&address={1}&city={2}", "fa36ec6323075f37020083ceffe8eb24", address, "");
- var replyBuffer = server.DownloadData(url);
- var reply = System.Text.Encoding.UTF8.GetString(replyBuffer);
- var mod = JsonConvert.DeserializeObject<AddressGPS>(reply);
- return mod;
- }
- /// <summary>
- /// 删除部门
- /// </summary>
- [UserAuthorizeAttribute(ModuleAlias = "Department", OperaAction = "Remove")]
- public ActionResult Delete(string idList)
- {
- JsonHelper json = new JsonHelper() { Msg = "删除经销商成功", ReUrl = "/Department/Index", Status = "n" };
- try
- {
- if (!string.IsNullOrEmpty(idList))
- {
- idList = idList.TrimEnd(',');
- //判断是否有下属部门
- if (!this.DepartmentManage.DepartmentIsExists(idList))
- {
- //判断是否有用户归属该部门
- if (!this.UserDepartmentManage.IsExist(p => idList.Contains(p.DEPARTMENT_ID)))
- {
- //判断该部门是否有岗位
- if (!this.PostDepartmentManage.IsExist(p => idList.Contains(p.FK_DEPARTMENT_ID)))
- {
- var idList1 = idList.Split(',').ToList();
- this.DepartmentManage.Delete(p => idList.Contains(p.ID));
- json.Status = "y";
- }
- else
- {
- json.Msg = "该经销商有岗位信息不能删除,请先取消岗位分配";
- }
- }
- else
- {
- json.Msg = "该经销商存在用户不能删除";
- }
- }
- else
- {
- json.Msg = "该经销商有下属部门不能删除";
- }
- }
- else
- {
- json.Msg = "未找到要删除的部门记录";
- }
- WriteLog(enumOperator.Remove, "删除部门:" + json.Msg, enumLog4net.WARN);
- }
- catch (Exception e)
- {
- json.Msg = "删除经销商发生内部错误!";
- WriteLog(enumOperator.Remove, "删除部门:", e);
- }
- return Json(json);
- }
- #region 帮助方法及其他控制器调用
- /// <summary>
- /// 获取部门导航树
- /// </summary>
- public string GetTree()
- {
- string type = Request.Form["type"];
- JsonHelper json = new JsonHelper() { Msg = "Success", Status = "y" };
- try
- {
- var query = this.DepartmentManage.LoadAll(null).OrderBy(p => p.SHOWORDER).ToList();
- var result = query.Select(m => new
- {
- id = m.ID,
- pId = m.PARENTID,
- name = m.NAME,
- open = true,
- target = "DeployBase",
- url = GetType(type) + "?dptid=" + m.ID.ToString(CultureInfo.InvariantCulture)
- }).ToList();
- json.Data = result;
- }
- catch (Exception e)
- {
- json.Status = "Error";
- json.Msg = "获取经销商导航树发生内部错误!";
- WriteLog(enumOperator.Select, "经销商管理,获取经销商导航树:", e);
- }
- return JsonConverter.Serialize(json, true);
- }
- private string GetType(string type)
- {
- if (type == "0")
- {
- return "/Sys/User/Index";
- }
- else
- {
- return "/Sys/Department/Index";
- }
- }
- /// <summary>
- /// 选择部门视图
- /// </summary>
- [UserAuthorizeAttribute(ModuleAlias = "Department", OperaAction = "Select")]
- public ActionResult GetSelectDpt()
- {
- return View();
- }
- /// <summary>
- /// 获取部门导航树,带复选框
- /// </summary>
- public ActionResult GetSelectTree()
- {
- string olddptlist = Request.Form["dptlist"];
- JsonHelper json = new JsonHelper() { Msg = "Success", Status = "y" };
- try
- {
- //获取部门列表
- var dptlist = this.DepartmentManage.LoadAll(null).OrderBy(p => p.SHOWORDER).ToList();
- if (dptlist != null && dptlist.Count > 0)
- {
- var result = new List<object>();
- result.AddRange(dptlist.Select(p => new
- {
- id = p.ID,
- name = p.NAME,
- pId = p.PARENTID,
- open = true,
- checkeds = olddptlist.Split(',').Any(c => c.Equals(p.ID))
- }));
- json.Data = JsonConverter.Serialize(result).Replace("checkeds", "checked");
- }
- }
- catch (Exception e)
- {
- json.Status = "n";
- json.Msg = "获取经销商导航树发生内部错误!";
- WriteLog(enumOperator.Select, "获取经销商导航树(带复选框):", e);
- }
- return Json(json);
- }
- #endregion
- }
- }
|