using System; using System.Linq; using System.Web.Mvc; using DSWeb.MvcShipping.DAL.MsUerAuthority; using DSWeb.MvcShipping.Models.MsUserAuthority; using DSWeb.MvcShipping.Helper; using DSWeb.MvcShipping.Comm.Cookie; using System.Collections.Generic; using HcUtility.Comm; using HcUtility.Core; using DSWeb.TruckMng.Helper.Repository; using System.Web; using System.Text; namespace DSWeb.MvcShipping.Controllers { [JsonRequestBehavior] public class MsUserAuthorityController : Controller { // // GET: public ActionResult Index() { return View(); } // // GET: / public ActionResult Edit() { return View(); } // // GET: public ContentResult GetUserAuthorityList(int start, int limit, string sort,string userid) { var dataList = MsUerAuthorityDAL.GetUserAuthorityList(userid,sort); var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", totalCount = dataList.Count, data = dataList.ToList() }); return new ContentResult() { Content = json }; } public ContentResult GetUserTreeRefList(string PARENTID) { var dataList = MsUerAuthorityDAL.GetUserTreeRefList(PARENTID); var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", totalCount = dataList.Count, data = dataList.ToList() }); return new ContentResult() { Content = json }; } public ContentResult GetUserTreeExpRefList(string PARENTID, string condition = "") { var dataList = MsUerAuthorityDAL.GetUserTreeRefList(PARENTID,true, condition); var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", totalCount = dataList.Count, data = dataList.ToList() }); return new ContentResult() { Content = json }; } public ContentResult Save(string body) { var bodyList = JsonConvert.Deserialize>(body); var modb = new ModelObjectRepository(); DBResult result = MsUerAuthorityDAL.SaveDetail(bodyList, Convert.ToString(Session["USERID"])); var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message }; return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; } public ContentResult GetUserAuthorityCompanyList(int start, int limit, string sort, string userid, string authorityid) { var dataList = MsUerAuthorityDAL.GetUserAuthorityCompanyList(userid,authorityid,sort); var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", totalCount = dataList.Count, data = dataList.ToList() }); return new ContentResult() { Content = json }; } public ContentResult SaveAuthorityCompany(string body, string rtype) { var bodyList = JsonConvert.Deserialize>(body); var modb = new ModelObjectRepository(); DBResult result = MsUerAuthorityDAL.SaveAuthorityCompanyDetail(bodyList, Convert.ToString(Session["USERID"]), rtype); var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message }; return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; } /// /// 人员权限设置 右侧 选择人员列表 /// /// /// /// /// /// /// public ContentResult GetUserAuthorityOpList(int start, int limit, string sort, string userid, string authorityid) { var dataList = MsUerAuthorityDAL.GetUserAuthorityOpList(userid, authorityid, sort); var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", totalCount = dataList.Count, data = dataList.ToList() }); return new ContentResult() { Content = json }; } public ContentResult GetUserAuthorityVISIBLETreeList(string PARENTID, string USERID, string AUTHORITYID) { var CURRUSERID = ""; var CURRAUTHORITYID = ""; if (string.IsNullOrEmpty(USERID)) { if (PARENTID == "0") { var json1 = JsonConvert.Serialize(new { Success = true, Message = "" }); return new ContentResult() { Content = json1 }; }; try { CURRUSERID = HttpRuntime.Cache.Get(Convert.ToString(Session["USERID"]) + "_UserAuthorityVISIBLE_CURRUSERID").ToString(); CURRAUTHORITYID = HttpRuntime.Cache.Get(Convert.ToString(Session["USERID"]) + "_UserAuthorityVISIBLE_CURRAUTHORITYID").ToString(); } catch { var json0 = JsonConvert.Serialize(new { Success = false, Message = "" }); return new ContentResult() { Content = json0 }; } } else { CURRUSERID = USERID; CURRAUTHORITYID = AUTHORITYID; HttpRuntime.Cache.Insert(Convert.ToString(Session["USERID"]) + "_UserAuthorityVISIBLE_CURRUSERID", USERID); HttpRuntime.Cache.Insert(Convert.ToString(Session["USERID"]) + "_UserAuthorityVISIBLE_CURRAUTHORITYID", AUTHORITYID); } var dataList = MsUerAuthorityDAL.GetUserAuthorityVISIBLE_Tree(PARENTID, CURRUSERID, CURRAUTHORITYID); var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", data = dataList.ToList() }); return new ContentResult() { Content = json }; } public ContentResult GetUserAuthorityOPERATETreeList(string PARENTID, string USERID, string AUTHORITYID) { //var result = new JsonResponse(); var CURRUSERID = ""; var CURRAUTHORITYID = ""; if (string.IsNullOrEmpty(USERID)) { if (PARENTID == "0") { var json1 = JsonConvert.Serialize(new { Success = true, Message = "" }); return new ContentResult() { Content = json1 }; }; try { CURRUSERID = HttpRuntime.Cache.Get(Convert.ToString(Session["USERID"]) + "_UserAuthorityOPERATE_CURRUSERID").ToString(); CURRAUTHORITYID = HttpRuntime.Cache.Get(Convert.ToString(Session["USERID"]) + "_UserAuthorityOPERATE_CURRAUTHORITYID").ToString(); } catch { var json0 = JsonConvert.Serialize(new { Success = false, Message = "" }); return new ContentResult() { Content = json0 }; } } else { CURRUSERID = USERID; CURRAUTHORITYID = AUTHORITYID; HttpRuntime.Cache.Insert(Convert.ToString(Session["USERID"]) + "_UserAuthorityOPERATE_CURRUSERID", USERID); HttpRuntime.Cache.Insert(Convert.ToString(Session["USERID"]) + "_UserAuthorityOPERATE_CURRAUTHORITYID", AUTHORITYID); } var dataList = MsUerAuthorityDAL.GetUserAuthorityOPERATE_Tree(PARENTID, CURRUSERID, CURRAUTHORITYID); var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", data = dataList.ToList() }); return new ContentResult() { Content = json }; } public ContentResult SaveAuthorityOpDetail(string body, string rtype) { var bodyList = JsonConvert.Deserialize>(body); var modb = new ModelObjectRepository(); DBResult result = MsUerAuthorityDAL.SaveAuthorityOpDetail(bodyList, Convert.ToString(Session["USERID"]), rtype); var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message }; return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; } public ContentResult SaveAuthorityOpAll(string body, string rtype) { var bodyList = JsonConvert.Deserialize>(body); var AUTHORITYID = ""; var op = ""; if (bodyList.Count!=0) { AUTHORITYID = bodyList[0].AUTHORITYID; op = bodyList[0].USERID; } var modb = new ModelObjectRepository(); DBResult result = MsUerAuthorityDAL.SaveAuthorityOpDetailAll(AUTHORITYID, op,Convert.ToString(Session["USERID"]), rtype); var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message }; return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; } #region 参照部分 #endregion public ContentResult SaveAuthorityOpVsDetail_Tree(string body, string rtype) { var bodyList = JsonConvert.Deserialize>(body); UserAuthorityOp.SetOpVsValue(bodyList, rtype); var modb = new ModelObjectRepository(); DBResult result = MsUerAuthorityDAL.SaveAuthorityOpDetail(bodyList, Convert.ToString(Session["USERID"]), rtype); var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message }; return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; } public ContentResult SaveAuthorityOpVsAll_Tree(string USERID, string AUTHORITYID, string rtype) { var bodyList = MsUerAuthorityDAL.GetUserAuthority_All(USERID, AUTHORITYID); var modb = new ModelObjectRepository(); DBResult result = MsUerAuthorityDAL.SaveAuthorityOpDetailAll(AUTHORITYID, USERID, Convert.ToString(Session["USERID"]), rtype); var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message }; return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; } public ContentResult CopyAuthority(string USERID, string AUTHORITYID, string ToUSERIDLIST) { var useridlist = ToUSERIDLIST.Split(','); StringBuilder sqlstrbase = new StringBuilder(); sqlstrbase.Append("declare @USERID varchar(50) "); sqlstrbase.Append("declare @CREATEUSER varchar(50) "); sqlstrbase.Append("declare @FROMUSER varchar(50) "); sqlstrbase.Append("declare @AUTHORITYID varchar(50) "); sqlstrbase.Append("set @USERID='{0}' "); sqlstrbase.Append("set @CREATEUSER='{1}' "); sqlstrbase.Append("set @FROMUSER = '{2}' "); sqlstrbase.Append("set @AUTHORITYID = '{3}' "); sqlstrbase.Append("delete from user_authority_range where USERID=@USERID and AUTHORITYID=@AUTHORITYID "); sqlstrbase.Append("insert into user_authority_range (GID,USERID,AUTHORITYID,VISIBLERANGE,OPERATERANGE,CREATEUSER,CREATETIME,MODIFIEDUSER,MODIFIEDTIME) "); sqlstrbase.Append("select newid(),@USERID,AUTHORITYID,VISIBLERANGE,OPERATERANGE,@CREATEUSER,getdate(),@CREATEUSER,getdate() from user_authority_range where userid = @FROMUSER and AUTHORITYID=@AUTHORITYID "); sqlstrbase.Append("delete from user_authority_range_op where USERID=@USERID and AUTHORITYID=@AUTHORITYID "); sqlstrbase.Append("insert into user_authority_range_op (GID,USERID,AUTHORITYID,OPID,OPNAME,VISIBLERANGE,OPERATERANGE,CREATEUSER,CREATETIME,MODIFIEDUSER,MODIFIEDTIME) "); sqlstrbase.Append("select newid(),@USERID,AUTHORITYID,OPID,OPNAME,VISIBLERANGE,OPERATERANGE,@CREATEUSER,getdate(),@CREATEUSER,getdate() from user_authority_range_op where userid = @FROMUSER and AUTHORITYID=@AUTHORITYID "); sqlstrbase.Append("delete from user_authority_range_company where USERID=@USERID and AUTHORITYID=@AUTHORITYID "); sqlstrbase.Append("insert into user_authority_range_company (GID,USERID,AUTHORITYID,COMPANYID,VISIBLERANGE,OPERATERANGE,CREATEUSER,CREATETIME,MODIFIEDUSER,MODIFIEDTIME) "); sqlstrbase.Append("select newid(),@USERID,AUTHORITYID,COMPANYID,VISIBLERANGE,OPERATERANGE,@CREATEUSER,getdate(),@CREATEUSER,getdate() from user_authority_range_company where userid = @FROMUSER and AUTHORITYID=@AUTHORITYID "); foreach (var userid in useridlist) { string sqlstr = string.Format(sqlstrbase.ToString(), userid, Session["USERID"].ToString(), USERID, AUTHORITYID); var _r = Areas.CommMng.DAL.BasicDataRefDAL.ExecSql(sqlstr); if (_r == -1) { var jsonRespose2 = new MvcShipping.Helper.JsonResponse { Success = true, Message = "设置错误,请联系管理员!", Data = "" }; return new ContentResult() { Content = MvcShipping.Helper.JsonConvert.Serialize(jsonRespose2) }; } } var jsonRespose = new JsonResponse { Success = true, Message = "设置完成", Data = "" }; return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; } } }