bklLiudl
2024-07-23 277bbae216debe7e6c04e8cc6ee6e1ba9763e14b
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
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_Led
    {
        /// <summary>
        /// 根据ID获取Led信息
        /// </summary>
        /// <returns></returns>
        public WCSLed GetLed(string Id)
        {
            try
            {
 
                StringBuilder strSql = new StringBuilder();
                strSql.Append($"select * from WCSLed where IsDel = 0 and Id = '{Id}' order by createTime;");
 
                IDataReader dt = DataFactory.SqlDataBase().GetDataReaderBySQL(strSql);
                var model = ModelConvertHelper<WCSLed>.ReaderToModel(dt);
                return model;
            }
            catch
            {
                throw new NotImplementedException();
            }
        }
 
        /// <summary>
        /// 获取所有Led设置
        /// </summary>
        /// <param name="Json">查询条件</param>
        /// <param name="pageInfo">分页信息</param>
        /// <returns></returns>
        public IList<WCSLed> GetLedList(AjaxLedList Json, ref PageInfo pageInfo)
        {
            try
            {
                IList<WCSLed> list = new List<WCSLed>();
                StringBuilder sqlString = new StringBuilder();
                List<SqlParam> para = new List<SqlParam>();
 
                sqlString.Append("select tb1.Id,tb1.Ip,tb1.Name, ");
                sqlString.Append("tb1.CreateUser,tb2.RealName as CreateUserName,tb1.CreateTime ");
                sqlString.Append("from WCSLed as tb1 left join UserInfo as tb2 on tb1.CreateUser = tb2.ID ");
                sqlString.Append("where tb1.IsDel = 0 ");
                if (!string.IsNullOrWhiteSpace(Json.Ip))
                {
                    sqlString.Append($"and tb1.Ip like '%{Json.Ip}%' ");
                }
 
                if (!string.IsNullOrWhiteSpace(Json.Name))
                {
                    sqlString.Append($"and tb1.Name like '%{Json.Name}%' ");
                }
 
                DataTable dt = DataFactory.SqlDataBase().GetPageList(sqlString.ToString(), null, "CreateTime", "DESC", ref pageInfo);
 
                list = ModelConvertHelper<WCSLed>.DataTableToModel(dt);
 
                return list;
            }
            catch
            {
                throw new NotImplementedException();
            }
        }
 
        /// <summary>
        /// 删除LedIp
        /// </summary>
        /// <param name="ID">ID集合</param>
        /// <returns></returns>
        public bool DeleteLed(string[] ID)
        {
            bool result = false;
            try
            {
                int dt = DataFactory.SqlDataBase().IsExist("WCSLed", "ID", ID);
                if (dt >= ID.Length)
                {
                    int i = 0;
                    while (i < ID.Length)
                    {
                        StringBuilder sql = new StringBuilder();
                        sql.Append("update WCSLed 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>
        /// 新增编辑LEd地址信息
        /// </summary>
        /// <param name="model">Led地址名称数据集</param>
        /// <returns>true:保存成功 false:保存失败</returns>
        public bool AddLed(AjaxLeds model)
        {
            bool bl = false;
            try
            {
                int rowCount = 0;
                Hashtable ht = new Hashtable();
                if (model.Operation == "Add")
                {
                    // add
                    ht["Ip"] = model.Ip.AddQuotes();
                    ht["Name"] = model.Name.AddQuotes();
                    ht["CreateUser"] = model.CreateUser;
 
                    rowCount = DataFactory.SqlDataBase().InsertByHashtableNullParam("WCSLed", ht);
                }
                else
                {
                    // Edit
                    ht["Ip"] = model.Ip.AddQuotes();
                    ht["Name"] = model.Name.AddQuotes();
 
                    rowCount = DataFactory.SqlDataBase().UpdateByHashtable("WCSLed", "id", model.Id.ToString(), ht);
                }
 
                if (rowCount == 1)
                {
                    bl = true;
                }
            }
            catch (Exception)
            {
                bl = false;
            }
 
            return bl;
        }
 
 
        /// <summary>
        /// 验证是否存在重复项
        /// </summary>
        /// <param name="sqlWhere">查询条件</param>
        /// <returns></returns>
        public bool IsExist(string sqlWhere)
        {
            return DataFactory.SqlDataBase().IsExist("WCSLed", sqlWhere);
        }
    }
}