From 82694a18fbd90ca4b1bfefdd4945d388909c46a0 Mon Sep 17 00:00:00 2001
From: YL <YL@LAPTOP-SE03PLUR>
Date: 星期四, 11 十一月 2021 01:28:56 +0800
Subject: [PATCH] 用户权限功能

---
 WebAPI/Models/UserPower.cs                       |   17 +++++
 WebAPI/ListModels.cs                             |   11 +++
 WebAPI/Controllers/WebAPIController.cs           |    4 
 WebAPI/WebAPI.csproj                             |    1 
 WebAPI/Controllers/PublicPageMethodController.cs |  114 +++++++++++++++++++++++++++++++++++--
 5 files changed, 138 insertions(+), 9 deletions(-)

diff --git a/WebAPI/Controllers/PublicPageMethodController.cs b/WebAPI/Controllers/PublicPageMethodController.cs
index 26339ef..dc37059 100644
--- a/WebAPI/Controllers/PublicPageMethodController.cs
+++ b/WebAPI/Controllers/PublicPageMethodController.cs
@@ -1,4 +1,5 @@
 锘縰sing DBUtility;
+using Newtonsoft.Json.Linq;
 using System;
 using System.Collections.Generic;
 using System.Data;
@@ -3366,16 +3367,18 @@
                 string sName = "";
                 if (sGnbm != "" && sGnbm != null)
                 {
-                     sName = sGnbm.Substring(1, sGnbm.Length - 1);
-                    if (sName == "鏉冮檺绠$悊-鐢ㄦ埛") 
+                    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 鏄惁鏉冮檺,gnms 鍔熻兘璇存槑,gnbm hgnbm FROM  xt_xtgnb where useflag=1 and sjgnbm='" + sName + "'  and rightflag=1  order by gnbm", "xt_xtgnb");
+                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";
@@ -3410,10 +3413,14 @@
         public object PowerLoadTree()
         {
             SQLHelper.ClsCN SubCn = new SQLHelper.ClsCN();
-            string sql = string.Format(@"select 'T鏉冮檺绠$悊-鐢ㄦ埛' id,'' HNumber,'鏉冮檺绠$悊--鐢ㄦ埛' title,'' ParentID, 'true' spread 
+            string sql = string.Format(@"select '鏉冮檺绠$悊-鐢ㄦ埛' id,'' HNumber,'鏉冮檺绠$悊--鐢ㄦ埛' title,'' ParentID
                                          union all
-                                         Select 'T'+gnbm id,gnsy HNumber,gnmc as title,case when sjgnbm<>null then sjgnbm else 'T鏉冮檺绠$悊-鐢ㄦ埛' end ParentID, 'true' spread 
-                                         from Xt_Xtgnb where useflag=1 and rightflag=1 and (gnbm NOT LIKE '99%') and sjgnbm='' and mjbz=0 ");
+                                         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)
             {
@@ -3434,7 +3441,100 @@
         }
         #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
+
+    }
 }
diff --git a/WebAPI/Controllers/WebAPIController.cs b/WebAPI/Controllers/WebAPIController.cs
index ab01574..37c0a4a 100644
--- a/WebAPI/Controllers/WebAPIController.cs
+++ b/WebAPI/Controllers/WebAPIController.cs
@@ -2242,7 +2242,7 @@
 
                 objJsonResult.code = "1";
                 objJsonResult.count = 1;
-                objJsonResult.Message = "鍒犻櫎鎴愬姛锛�";
+                objJsonResult.Message = "鏌ヨ鎴愬姛锛�";
                 objJsonResult.data = Newtonsoft.Json.JsonConvert.SerializeObject(mu);
                 return objJsonResult;
             }
@@ -2250,7 +2250,7 @@
             {
                 objJsonResult.code = "0";
                 objJsonResult.count = 0;
-                objJsonResult.Message = "鍒犻櫎澶辫触锛�";
+                objJsonResult.Message = "鏌ヨ澶辫触锛�";
                 objJsonResult.data = e.ToString();
                 return objJsonResult;
             }
diff --git a/WebAPI/ListModels.cs b/WebAPI/ListModels.cs
index e9c88df..763a0f1 100644
--- a/WebAPI/ListModels.cs
+++ b/WebAPI/ListModels.cs
@@ -1638,5 +1638,16 @@
             return list;
         }
 
+        /// <summary>
+        /// 鐢ㄦ埛鏉冮檺鐨刯son
+        /// </summary>
+        /// <param name="jsonString"></param>
+        /// <returns></returns>
+        public List<Models.UserPower> getObjectByJson_UserPower(string jsonString)
+        {
+            jsonString = "[" + jsonString.ToString() + "]";
+            List<Models.UserPower> list = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Models.UserPower>>(jsonString);
+            return list;
+        }
     }
 } 
\ No newline at end of file
diff --git a/WebAPI/Models/UserPower.cs b/WebAPI/Models/UserPower.cs
new file mode 100644
index 0000000..0dcccae
--- /dev/null
+++ b/WebAPI/Models/UserPower.cs
@@ -0,0 +1,17 @@
+锘縰sing System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Web;
+
+namespace WebAPI.Models
+{
+    public class UserPower
+    {
+        public string hgnbm { get; set; }
+        public string hid { get; set; }
+        public string AuthorityHID { get; set; }
+        public string AuthorityID { get; set; }
+        public string gnms { get; set; }
+    }
+ 
+}
\ No newline at end of file
diff --git a/WebAPI/WebAPI.csproj b/WebAPI/WebAPI.csproj
index 2c57ce7..ef9998a 100644
--- a/WebAPI/WebAPI.csproj
+++ b/WebAPI/WebAPI.csproj
@@ -474,6 +474,7 @@
     <Compile Include="Models\Gy_WorkPayType.cs" />
     <Compile Include="Models\QC_POStockInCheckBillSub.cs" />
     <Compile Include="Models\QC_POStockInCheckBill.cs" />
+    <Compile Include="Models\UserPower.cs" />
     <Compile Include="Models\Xt_DataDictionary_Proc.cs" />
     <Compile Include="Models\Xt_DataDictionary_View.cs" />
     <Compile Include="Models\Xt_DataDictionary_Table.cs" />

--
Gitblit v1.9.1