|  |  |  | 
|---|
|  |  |  | using System; | 
|---|
|  |  |  | using DBUtility; | 
|---|
|  |  |  | using Newtonsoft.Json.Linq; | 
|---|
|  |  |  | using System; | 
|---|
|  |  |  | using System.Collections.Generic; | 
|---|
|  |  |  | using System.Data; | 
|---|
|  |  |  | using System.Linq; | 
|---|
|  |  |  | using System.Net; | 
|---|
|  |  |  | using System.Net.Http; | 
|---|
|  |  |  | using System.Web.Http; | 
|---|
|  |  |  | using System.Web.UI.WebControls; | 
|---|
|  |  |  | using WebAPI.Models; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | namespace WebAPI.Controllers | 
|---|
|  |  |  | 
|---|
|  |  |  | #endregion | 
|---|
|  |  |  |  | 
|---|
|  |  |  | #endregion | 
|---|
|  |  |  |  | 
|---|
|  |  |  | #region 用户关联权限 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | #region 条件查询权限列表 | 
|---|
|  |  |  | [Route("PublicPageMethod/PowerList")] | 
|---|
|  |  |  | [HttpGet] | 
|---|
|  |  |  | public object PowerList(string czybm,string sGnbm) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | try | 
|---|
|  |  |  | { | 
|---|
|  |  |  | string sName = ""; | 
|---|
|  |  |  | if (sGnbm != "" && sGnbm != null) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | if (sGnbm == "权限管理-用户") | 
|---|
|  |  |  | { | 
|---|
|  |  |  | sName = ""; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | else { | 
|---|
|  |  |  | sName = sGnbm; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | ds = oCN.RunProcReturn("select * from  Gy_Czygl where czybm='" + czybm + "'", "Gy_Czygl"); | 
|---|
|  |  |  | string AuthorityID = ClsPub.isStrNull(ds.Tables[0].Rows[0]["AuthorityID"]); | 
|---|
|  |  |  | ds = oCN.RunProcReturn("SELECT id hid,case when id<=" + AuthorityID.Length + " then case when SUBSTRING('" + AuthorityID + "',id,1)=1 then 1 else 0 end else 0 end AuthorityID,'' AuthorityHID, gnms ,gnbm hgnbm FROM  xt_xtgnb where useflag=1 and sjgnbm='" + sName + "'  and rightflag=1  order by gnbm", "xt_xtgnb"); | 
|---|
|  |  |  | if (ds == null || ds.Tables[0].Rows.Count == 0) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | objJsonResult.code = "0"; | 
|---|
|  |  |  | objJsonResult.count = 0; | 
|---|
|  |  |  | objJsonResult.Message = "无功能列表数据!"; | 
|---|
|  |  |  | objJsonResult.data = null; | 
|---|
|  |  |  | return objJsonResult; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | else | 
|---|
|  |  |  | { | 
|---|
|  |  |  | objJsonResult.code = "1"; | 
|---|
|  |  |  | objJsonResult.count = 1; | 
|---|
|  |  |  | objJsonResult.Message = "Sucess!"; | 
|---|
|  |  |  | objJsonResult.data = ds.Tables[0]; | 
|---|
|  |  |  | return objJsonResult; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | catch (Exception e) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | objJsonResult.code = "0"; | 
|---|
|  |  |  | objJsonResult.count = 0; | 
|---|
|  |  |  | objJsonResult.Message = "Exception!" + e.ToString(); | 
|---|
|  |  |  | objJsonResult.data = null; | 
|---|
|  |  |  | return objJsonResult; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | #endregion | 
|---|
|  |  |  |  | 
|---|
|  |  |  | #region 树型列表功能列表数据 | 
|---|
|  |  |  | [Route("Gy_MaintenanceMode/PowerLoadTree")] | 
|---|
|  |  |  | [HttpGet] | 
|---|
|  |  |  | public object PowerLoadTree() | 
|---|
|  |  |  | { | 
|---|
|  |  |  | SQLHelper.ClsCN SubCn = new SQLHelper.ClsCN(); | 
|---|
|  |  |  | string sql = string.Format(@"select '权限管理-用户' id,'' HNumber,'权限管理--用户' title,'' ParentID | 
|---|
|  |  |  | union all | 
|---|
|  |  |  | select gnbm id,gnsy HNumber,gnmc as title, case when sjgnbm='' then '权限管理--用户' else sjgnbm end  ParentID  from Xt_Xtgnb where sjgnbm='' | 
|---|
|  |  |  | union all | 
|---|
|  |  |  | Select gnbm id,gnsy HNumber,gnmc as title,sjgnbm as ParentID | 
|---|
|  |  |  | from Xt_Xtgnb  where mjbz=0 and useflag=1 and rightflag=1 and sjgnbm in( | 
|---|
|  |  |  | select gnbm  from Xt_Xtgnb  where mjbz=0 and useflag=1 and rightflag=1 | 
|---|
|  |  |  | ) "); | 
|---|
|  |  |  | ds = oCN.RunProcReturn(sql, "Xt_Xtgnb"); | 
|---|
|  |  |  | if (ds == null || ds.Tables[0].Rows.Count == 0) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | objJsonResult.code = "0"; | 
|---|
|  |  |  | objJsonResult.count = 0; | 
|---|
|  |  |  | objJsonResult.Message = "无功能列表数据!"; | 
|---|
|  |  |  | objJsonResult.data = null; | 
|---|
|  |  |  | return objJsonResult; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | else | 
|---|
|  |  |  | { | 
|---|
|  |  |  | objJsonResult.code = "1"; | 
|---|
|  |  |  | objJsonResult.count = 1; | 
|---|
|  |  |  | objJsonResult.Message = "Sucess!"; | 
|---|
|  |  |  | objJsonResult.data = ds.Tables[0]; | 
|---|
|  |  |  | return objJsonResult; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | #endregion | 
|---|
|  |  |  |  | 
|---|
|  |  |  | #region 用户关联权限提交 | 
|---|
|  |  |  | [Route("Gy_MaintenanceMode/SaverPower")] | 
|---|
|  |  |  | [HttpPost] | 
|---|
|  |  |  | public object SaverPower([FromBody] JObject msg) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | var _value = msg["msg"].ToString(); | 
|---|
|  |  |  | string msg1 = _value.ToString(); | 
|---|
|  |  |  | string[] sArray = msg1.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries); | 
|---|
|  |  |  | string msg2 = sArray[0].ToString(); | 
|---|
|  |  |  | string msg3 = sArray[1].ToString(); | 
|---|
|  |  |  | string msg4 = sArray[2].ToString(); | 
|---|
|  |  |  | ListModels oListModels = new ListModels(); | 
|---|
|  |  |  | try | 
|---|
|  |  |  | { | 
|---|
|  |  |  | List<Models.UserPower> lsmain = new List<Models.UserPower>(); | 
|---|
|  |  |  | msg3 = msg3.Substring(1, msg3.Length - 2); | 
|---|
|  |  |  | msg3 = msg3.Replace("\\", ""); | 
|---|
|  |  |  | msg3 = msg3.Replace("\n", "");  //\n | 
|---|
|  |  |  | lsmain = oListModels.getObjectByJson_UserPower(msg3); | 
|---|
|  |  |  | ds = oCN.RunProcReturn("select * from  Gy_Czygl where czybm='" + msg4.Trim() + "'", "Gy_Czygl"); | 
|---|
|  |  |  | string AuthorityID = ClsPub.isStrNull(ds.Tables[0].Rows[0]["AuthorityID"]); | 
|---|
|  |  |  | string Auth_str = AuthorityID; | 
|---|
|  |  |  | string MKID = ""; | 
|---|
|  |  |  | int lENSTR = 0; //模块ID | 
|---|
|  |  |  | DataSet oDs = new DataSet(); | 
|---|
|  |  |  | for (int i = 0; i < lsmain.Count; i++) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | MKID = ClsPub.isStrNull(lsmain[i].hid); | 
|---|
|  |  |  | lENSTR = ClsPub.isInt(MKID.Substring(0, MKID.Length)); | 
|---|
|  |  |  | if (lsmain[i].AuthorityHID == "1") | 
|---|
|  |  |  | { | 
|---|
|  |  |  | for (int h = Auth_str.Trim().Length; h <= lENSTR - 1; h++) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | Auth_str = Auth_str.Trim() + "0"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Auth_str = Auth_str.Substring(0, lENSTR - 1) + "1" + Auth_str.Substring(lENSTR, Auth_str.Length - lENSTR); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | else | 
|---|
|  |  |  | { | 
|---|
|  |  |  | if (Auth_str.Length >= lENSTR) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | Auth_str = Auth_str.Substring(0, lENSTR - 1) + "0" + Auth_str.Substring(lENSTR, Auth_str.Length - lENSTR); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | oDs = oCN.RunProcReturn("select * from  xt_xtgnb where useflag=1 and gnbm like '" + lsmain[i].hgnbm + "%'", "xt_xtgnb"); | 
|---|
|  |  |  | if (oDs.Tables[0].Rows.Count != 0) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | for (int k = 0; k < oDs.Tables[0].Rows.Count; k++) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | int ID = ClsPub.isInt(oDs.Tables[0].Rows[k]["id"]); | 
|---|
|  |  |  | if (lsmain[i].AuthorityHID == "1") | 
|---|
|  |  |  | { | 
|---|
|  |  |  | if (lsmain[i].AuthorityHID == "1") | 
|---|
|  |  |  | { | 
|---|
|  |  |  | for (int h = Auth_str.Trim().Length; h <= ID - 1; h++) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | Auth_str = Auth_str.Trim() + "0"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Auth_str = Auth_str.Substring(0, ID - 1) + "1" + Auth_str.Substring(ID, Auth_str.Length - ID); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | else | 
|---|
|  |  |  | { | 
|---|
|  |  |  | if (Auth_str.Length >= ID) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | Auth_str = Auth_str.Substring(0, ID - 1) + "0" + Auth_str.Substring(ID, Auth_str.Length - ID); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | oDs = null; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | oCN.RunProc("UPDATE  Gy_Czygl SET AuthorityID='" + Auth_str + "' WHERE czybm='" + msg4.Trim() + "'"); | 
|---|
|  |  |  | objJsonResult.code = "1"; | 
|---|
|  |  |  | objJsonResult.count = 1; | 
|---|
|  |  |  | objJsonResult.Message = "授权成功!"; | 
|---|
|  |  |  | objJsonResult.data = ds.Tables[0]; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | catch (Exception e) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | objJsonResult.code = "0"; | 
|---|
|  |  |  | objJsonResult.count = 0; | 
|---|
|  |  |  | objJsonResult.Message = e.Message; | 
|---|
|  |  |  | objJsonResult.data =null; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return objJsonResult; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | #endregion | 
|---|
|  |  |  |  | 
|---|
|  |  |  | #endregion | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|