bklLiudl
2024-07-23 675b8bcc4a3630d95e3d0b97d933e63442075ecb
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
115
116
117
118
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Common;
using Model;
 
namespace BLL.DAL
{
    public class DAL_OperationRecord
    {
        public DataTable GetUserItems()
        {
            try
            {
                StringBuilder stringBuilder = new StringBuilder();
                stringBuilder.Append("select * from UserInfo where IsDel = 0 ");
                stringBuilder.Append("order by CreatTime ;");
 
                DataTable dt = DataFactory.SqlDataBase().GetDataTableBySQL(stringBuilder);
                return dt;
            }
            catch
            {
                throw new NotImplementedException();
            }
        }
 
        public IList<WCSLogOperationList> GetList(AjaxLogOperationList Json, ref PageInfo pageInfo)
        {
            try
            { 
                StringBuilder strSql = new StringBuilder();
                strSql.Append("Select WCSLogOperation.*,UserInfo.UserName as CreateUserName ,Dictionary.TypeName as TypeName from WCSLogOperation left join UserInfo on WCSLogOperation.CreateUser = UserInfo.ID left join Dictionary on WCSLogOperation.Type = Dictionary.Code where WCSLogOperation.Id>0 and Dictionary.TopCode = 'OperationType' ");
 
                if (!string.IsNullOrWhiteSpace(Json.MenuName))
                {
                    strSql.Append(" and MenuName like '%" + Json.MenuName + "%'  ");
                }
                if (!string.IsNullOrWhiteSpace(Json.UserCode))
                {
                    strSql.Append(" and CreateUser = '" + Json.UserCode + "'  ");
                }
 
                if (Json.BeginTime != DateTime.MinValue && Json.BeginTime != null && Json.BeginTime != DateTime.MaxValue)
                {
                    strSql.Append($"and CreateTime >= '{Convert.ToDateTime(Json.BeginTime).ToShortDateString()}' ");
                }
                if (Json.EndTime != DateTime.MinValue && Json.EndTime != null && Json.EndTime != DateTime.MaxValue)
                {
                    strSql.Append($"and CreateTime <= '{Convert.ToDateTime(Json.EndTime).ToShortDateString() + " 23:59:59.999"}' ");
                    
                }
 
                DataTable dt = DataFactory.SqlDataBase().GetPageList(strSql.ToString(), null, "CreateTime", "Desc", ref pageInfo);
                return ModelConvertHelper<WCSLogOperationList>.DataTableToModel(dt);
            }
            catch
            {
                throw new NotImplementedException();
            }
        }
 
 
        /// <summary>
        /// 添加操作日志
        /// </summary>
        /// <param name="model"></param> 
        /// <param name="loginName">登录人</param> 
        /// <returns></returns>
        public bool AddOperation(OperationModel model, string loginName)
        {
            bool result = false;
            try
            {
 
                StringBuilder sqlString = new StringBuilder(); 
                //查询菜单信息
                sqlString.Append($"select * from ResMenu where IsDel = 0 and ResName = '{model.MenuName}'; ");
                DataTable dt = DataFactory.SqlDataBase().GetDataTableBySQL(sqlString);
                if (dt.Rows.Count == 0)
                {
                    throw new Exception("未查询到菜单信息");
                }
                var parentNo = dt.Rows[0]["ParentNum"].ToString(); //模块号
                var menuNo = dt.Rows[0]["ResNum"].ToString();  //菜单号
 
                //查询操作类型
                sqlString.Clear();
                sqlString.Append($"select * from Dictionary where IsDel = 0 and TopCode = 'OperationType' and TypeName = '{model.Type}'; ");
                DataTable dt2 = DataFactory.SqlDataBase().GetDataTableBySQL(sqlString);
                if (dt2.Rows.Count == 0)
                {
                    throw new Exception("未查询到操作类型信息");
                }
                var operaType = dt2.Rows[0]["Code"].ToString();  //操作类型Code
                // 新增任务 
                sqlString.Clear();
                sqlString.Append("insert into WCSLogOperation (ParentNo,MenuNo,MenuName,FkNo,Type,Msg,CreateTime,CreateUser) values ( ");
                sqlString.Append($"'{parentNo}','{menuNo}','{model.MenuName}','{model.FkNo}','{operaType}','{model.Msg}',GETDATE(),'{loginName}');");
                var num = DataFactory.SqlDataBase().ExecuteBySql(sqlString);
 
                if (num == 1)
                {
                    result = true;
                }
                return result;
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
 
    }
}