333
schangxiang@126.com
2025-09-19 18966e02fb573c7e2bb0c6426ed792b38b910940
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
using logtxtWrite;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using wcftest.EnumDefine.Sys;
using wcftest.orm;
 
namespace wcftest.BussinessExtension
{
    public class SystemHelper
    {
        /// <summary>
        /// 查询按钮权限字符串 【EditBy shaocx,2022-09-13】
        /// </summary>
        /// <param name="mod"></param>
        /// <param name="roleId"></param>
        /// <param name="menuIdEnum"></param>
        /// <returns></returns>
        public static List<string> QueryButtonPermission(int roleId, Menu_IdEnum menuIdEnum)
        {
            List<string> retList = new List<string>();
            using (dbModel mod = new dbModel())
            {
                //使用权限
                string roleSQL = "SELECT * FROM [YrtWMS_Siemens2].[dbo].[Sys_RoleAuth] where Menu_Id=" + (int)menuIdEnum + " and Role_Id=" + roleId;
                var roleishave = mod.Database.SqlQuery<Sys_RoleAuth>(roleSQL).ToList();
                if (roleishave.Count > 0)
                {
                    //Browse=1,Search=1,Add=1,Update=0,Delete=0,Export=0
                    //因为字符串形式是这种形式,所以,我们后台需要将他解析出来
                    var str = roleishave[0].AuthValue;
                    if (!string.IsNullOrEmpty(str))
                    {
                        var arr = str.Split(',');
                        for (int i = 0; i < arr.Length; i++)
                        {
                            if (arr[i].IndexOf("=1") > -1)
                            {
                                retList.Add(arr[i].Substring(0, arr[i].IndexOf("=1")));//需要去掉=1
                            }
                        }
                        return retList;
                    }
                    return retList;
                }
                return retList;
            }
        }
 
        /// <summary>
        /// 增加用户操作日志
        /// </summary>
        /// <param name="userName">用户名</param>
        /// <param name="operationInfo">操作内容</param>
        /// <param name="OperateType">操作名称</param>
        public static void addOperation(string userName, string operationInfo, string OperateType)
        {
            try
            {
                using (dbModel mod = new dbModel())
                {
                    addOperation(mod, userName, operationInfo, OperateType);
                }
            }
            catch (Exception)
            {
 
                logtxt.txtWrite("添加日志保存失败 用户名" + userName + "操作内容" + operationInfo, 2);
            }
 
        }
 
        /// <summary>
        /// 增加用户操作日志
        /// </summary>
        /// <param name="userName">用户名</param>
        /// <param name="operationInfo">操作内容</param>
        /// <param name="OperateType">操作名称</param>
        public static void addOperation(dbModel mod, string userName, string operationInfo, string OperateType)
        {
            try
            {
 
                Sys_User_Log moveStocklog = new Sys_User_Log();
                moveStocklog.UserTrueName = userName;
                moveStocklog.OperateType = OperateType;
                moveStocklog.Action = operationInfo;
                moveStocklog.Creator = userName;
                moveStocklog.CreateDate = DateTime.Now;
                moveStocklog.UserProduct_Id = 1007;
                moveStocklog.UserProductCode = "100000001";
                mod.Sys_User_Log.Add(moveStocklog);
                int result = mod.SaveChanges();
                if (result == 0)//失败再保存一次
                {
                    result = mod.SaveChanges();
                    if (result == 0)
                    {
                        logtxt.txtWrite("添加日志保存失败 用户名" + userName + "操作内容" + operationInfo, 2);
                    }
 
                }
            }
            catch (Exception)
            {
 
                logtxt.txtWrite("添加日志保存失败 用户名" + userName + "操作内容" + operationInfo, 2);
            }
 
        }
    }
}