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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
using Commom.Utility;
using Common;
using Model;
using Model.WcsModel;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Text;
 
namespace BLL.DAL
{
    public class DAL_AlarmInfo
    {
        #region 报警维护
        /// <summary>
        /// 根据ID获取报警信息
        /// </summary>
        /// <returns></returns>
        public WCSAlarmInfo GetAlarmInfo(string Id)
        {
            try
            {
 
                StringBuilder strSql = new StringBuilder();
                strSql.Append($"select * from WCSAlarmInfo where IsDel = 0 and Id = '{Id}' order by createTime;");
 
                IDataReader dt = DataFactory.SqlDataBase().GetDataReaderBySQL(strSql);
                var model = ModelConvertHelper<WCSAlarmInfo>.ReaderToModel(dt);
                return model;
            }
            catch
            {
                throw new NotImplementedException();
            }
        }
 
        /// <summary>
        /// 获取报警信息数据集合
        /// </summary>
        /// <param name="Json">查询条件</param>
        /// <param name="pageInfo">分页信息</param>
        /// <returns></returns>
        public IList<WCSAlarmInfo> GetAlarmInfoList(AjaxAlarmInfoList Json, ref PageInfo pageInfo)
        {
            try
            {
                IList<WCSAlarmInfo> list = new List<WCSAlarmInfo>();
                StringBuilder sqlString = new StringBuilder();
                List<SqlParam> para = new List<SqlParam>();
 
                sqlString.Append("select tb1.*,tb2.RealName as CreateUserName ");
                sqlString.Append("from WCSAlarmInfo as tb1 left join UserInfo as tb2 on tb1.CreateUser = tb2.ID ");
                sqlString.Append("where tb1.IsDel = 0 ");
                if (!string.IsNullOrWhiteSpace(Json.AlarmCode))
                {
                    sqlString.Append($"and tb1.AlarmCode like '%{Json.AlarmCode}%' ");
                }
 
                if (!string.IsNullOrWhiteSpace(Json.AlarmName))
                {
                    sqlString.Append($"and tb1.AlarmName like '%{Json.AlarmName}%' ");
                }
 
                DataTable dt = DataFactory.SqlDataBase().GetPageList(sqlString.ToString(), null, "CreateTime", "DESC", ref pageInfo);
 
                list = ModelConvertHelper<WCSAlarmInfo>.DataTableToModel(dt);
 
                return list;
            }
            catch
            {
                throw new NotImplementedException();
            }
        }
 
        /// <summary>
        /// 删除报警信息
        /// </summary>
        /// <param name="ID">ID集合</param>
        /// <returns></returns>
        public bool DeleteAlarmInfo(string[] ID)
        {
            bool result = false;
            try
            {
                int dt = DataFactory.SqlDataBase().IsExist("WCSAlarmInfo", "ID", ID);
                if (dt >= ID.Length)
                {
                    int i = 0;
                    while (i < ID.Length)
                    {
                        StringBuilder sql = new StringBuilder();
                        sql.Append("update WCSAlarmInfo set IsDel=1 where Id='" + ID[i] + "'");
                        int _ret = DataFactory.SqlDataBase().ExecuteBySql(sql);
                        if (_ret >= ID.Length) result = true;
                        i++;
                    }
 
                }
                return result;
            }
            catch
            {
                return result;
            }
        }
 
        /// <summary>
        /// 新增编辑报警信息
        /// </summary>
        /// <param name="model">流程字信息</param>
        /// <returns>true:保存成功 false:保存失败</returns>
        public bool AddAlarmInfo(AjaxAlarmInfo model, string loginName)
        {
            bool bl = false;
            try
            {
                int rowCount = 0;
                Hashtable ht = new Hashtable();
                if (model.Operation == "Add")
                {
                    // add
                    ht["PlcIP"] = model.PlcIP.AddQuotes();
                    ht["AlarmCode"] = model.AlarmCode.AddQuotes();
                    ht["AlarmName"] = model.AlarmName.AddQuotes();
                    ht["AlarmType"] = model.AlarmType.AddQuotes();
                    ht["LedIP"] = model.LedIP.AddQuotes();
                    ht["Type"] = model.Type.AddQuotes();
                    ht["AlarmTime"] = model.AlarmTime.AddQuotes();
                    ht["LedStatus"] = 0;
                    ht["CreateUser"] = model.CreateUser;
 
                    rowCount = DataFactory.SqlDataBase().InsertByHashtableNullParam("WCSAlarmInfo", ht);
 
                    StringBuilder sql = new StringBuilder();
                    sql.Append($"");
 
                    if (rowCount >= 1)
                    {
                        DAL_OperationRecord oper = new DAL_OperationRecord();
                        var operation = new OperationModel()
                        {
                            MenuName = "报警维护",
                            FkNo = model.AlarmCode + "-" + model.AlarmName,
                            Msg = "添加报警维护",
                            Type = "添加",
                        };
                        oper.AddOperation(operation, loginName);
                        bl = true;
                    }
                    if (rowCount >= 1)
                    {
                        DAL_AlarmLog oper = new DAL_AlarmLog();
                        var operation = new WCSAlarmLogModel()
                        {
                            PlcIP = model.PlcIP,
                            AlarmCode = model.AlarmCode,
                            AlarmName = model.AlarmName,
                            AlarmType = model.AlarmType,
                            LedIP = model.LedIP,
                            Type = model.Type,
                            AlarmTime = model.AlarmTime,
                            LedStatus = model.LedStatus,
                            CreateUser = model.CreateUser.ToInt(),
                        };
                        oper.AddAlarmLog(operation, loginName);
                        bl = true;
                    }
 
                }
                else
                {
                    // Edit
                    ht["PlcIP"] = model.PlcIP.AddQuotes();
                    ht["AlarmCode"] = model.AlarmCode.AddQuotes();
                    ht["AlarmName"] = model.AlarmName.AddQuotes();
                    ht["AlarmType"] = model.AlarmType.AddQuotes();
                    ht["LedIP"] = model.LedIP.AddQuotes();
                    ht["Type"] = model.Type.AddQuotes();
                    ht["LedStatus"] = 0;
                    //ht["CreateUser"] = "";
 
                    rowCount = DataFactory.SqlDataBase().UpdateByHashtable("WCSAlarmInfo", "id", model.Id.ToString(), ht);
 
                    if (rowCount >= 1)
                    {
                        DAL_OperationRecord oper = new DAL_OperationRecord();
                        var operation = new OperationModel()
                        {
                            MenuName = "报警维护",
                            FkNo = model.AlarmCode + "-" + model.AlarmName,
                            Msg = "修改报警维护",
                            Type = "修改",
                        };
                        oper.AddOperation(operation, loginName);
                        bl = true;
                    }
                    if (rowCount >= 1)
                    {
                        DAL_AlarmLog oper = new DAL_AlarmLog();
                        var operation = new WCSAlarmLogModel()
                        {
                            PlcIP = model.PlcIP,
                            AlarmCode = model.AlarmCode,
                            AlarmName = model.AlarmName,
                            AlarmType = model.AlarmType,
                            LedIP = model.LedIP,
                            Type = model.Type,
                            AlarmTime = model.AlarmTime,
                            LedStatus = model.LedStatus,
                            CreateUser = model.CreateUser.ToInt(),
                        };
                        oper.AddAlarmLog(operation, loginName);
                        bl = true;
                    }
                }
 
                if (rowCount == 1)
                {
                    bl = true;
                }
            }
            catch (Exception)
            {
                bl = false;
            }
 
            return bl;
        }
 
 
        /// <summary>
        /// 获取设备下拉框  (此方法不启用 liudl)
        /// </summary>
        /// <param name="PlcInfoId">工位ID</param>
        /// <returns></returns>
        public string GetAlarmInfoHtml(string PlcInfoId = "")
        {
            try
            {
                StringBuilder sb = new StringBuilder();
                string resMenuTemplate = "<option value='{0}' {1}>{2}</option>";
                sb.AppendFormat(resMenuTemplate, "", "", "选择");
 
                StringBuilder sqlString = new StringBuilder();
                sqlString.Append("select * from WCSIP where IsDel = 0;");
                DataTable dt = DataFactory.SqlDataBase().GetDataTableBySQL(sqlString);
 
                foreach (DataRow row in dt.Rows)
                {
                    sb.AppendFormat(resMenuTemplate, row["Id"].ToString(), row["Id"].ToString() == PlcInfoId ? "selected='selected'" :
                        string.Empty, row["Type"].ToString() + "-" + row["Text"].ToString());
                }
 
                return sb.ToString();
            }
            catch
            {
                return "";
            }
        }
 
 
        /// <summary>
        /// 验证是否存在重复项
        /// </summary>
        /// <param name="sqlWhere">查询条件</param>
        /// <returns></returns>
        public bool IsExist(string sqlWhere)
        {
            return DataFactory.SqlDataBase().IsExist("WCSAlarmInfo", sqlWhere);
        }
        #endregion
 
        #region 报警日志
        /// <summary>
        /// 获取报警日志数据集合
        /// </summary>
        /// <param name="Json">查询条件</param>
        /// <param name="pageInfo">分页信息</param>
        /// <returns></returns>
        public IList<WCSAlarmInfo> GetAlarmLogList(AjaxAlarmInfoList Json, ref PageInfo pageInfo)
        {
            try
            {
                IList<WCSAlarmInfo> list = new List<WCSAlarmInfo>();
                StringBuilder sqlString = new StringBuilder();
                List<SqlParam> para = new List<SqlParam>();
 
                sqlString.Append("select tb1.*,tb2.RealName as CreateUserName ");
                sqlString.Append("from WCSAlarmLog as tb1 left join UserInfo as tb2 on tb1.CreateUser = tb2.ID ");
                sqlString.Append("where tb1.IsDel = 0 ");
                if (!string.IsNullOrWhiteSpace(Json.AlarmCode))
                {
                    sqlString.Append($"and tb1.AlarmCode like '%{Json.AlarmCode}%' ");
                }
 
                if (!string.IsNullOrWhiteSpace(Json.AlarmName))
                {
                    sqlString.Append($"and tb1.AlarmName like '%{Json.AlarmName}%' ");
                }
 
                if (!string.IsNullOrWhiteSpace(Json.BeAlarmTime))
                {
                    sqlString.Append($"and AlarmTime >= '{Json.BeAlarmTime}' ");
                }
                if (!string.IsNullOrWhiteSpace(Json.EnAlarmTime))
                {
                    sqlString.Append($"and AlarmTime <= '{Json.EnAlarmTime}' ");
                }
 
                DataTable dt = DataFactory.SqlDataBase().GetPageList(sqlString.ToString(), null, "CreateTime", "DESC", ref pageInfo);
 
                list = ModelConvertHelper<WCSAlarmInfo>.DataTableToModel(dt);
 
                return list;
            }
            catch
            {
                throw new NotImplementedException();
            }
        }
        #endregion
    }
}