wxw
2025-05-12 c2dc3bd2569f8398e2710aca2685bb3115c77eb0
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
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Common;
using Model;
using Model;
 
namespace BLL.DAL
{
    public class DAL_ConveyorInfo
    {
        public IList<GetWCSConveyorInfo> GetList(AjaxConveyorInfoList Json, ref PageInfo pageInfo)
        {
            try
            {
                StringBuilder strSql = new StringBuilder();
                strSql.Append("select a.*,b.userName as CreateUserName,c.userName as UpdateUserName from WCSConveyorInfo a left join UserInfo b on a.CreateUser = b.Id left join UserInfo c on a.UpdateUser = c.Id where a.IsDel = '0' ");
 
                if (string.IsNullOrWhiteSpace(Json.SkuType) && string.IsNullOrWhiteSpace(Json.Conveyor) && string.IsNullOrWhiteSpace(Json.LotNo) && string.IsNullOrWhiteSpace(Json.IsEndLot) && string.IsNullOrWhiteSpace(Json.Status))
                {
                    strSql.Append(" and IsEndLot = '0'");
                }
 
                if (!string.IsNullOrWhiteSpace(Json.SkuType))
                {
                    strSql.Append(" and SkuType = '" + Json.SkuType + "'  ");
                }
                if (!string.IsNullOrWhiteSpace(Json.Conveyor))
                {
                    strSql.Append(" and Conveyor = '" + Json.Conveyor + "'  ");
                }
                if (!string.IsNullOrWhiteSpace(Json.LotNo))
                {
                    strSql.Append(" and LotNo like '%" + Json.LotNo + "%'  ");
                }
                if (!string.IsNullOrWhiteSpace(Json.IsEndLot))
                {
                    strSql.Append(" and IsEndLot = '" + Json.IsEndLot + "'  ");
                }
                if (!string.IsNullOrWhiteSpace(Json.Status))
                {
                    strSql.Append(" and Status = '" + Json.Status + "'  ");
                }
                if (Json.BeginTime != null && Json.BeginTime != DateTime.MinValue && Json.BeginTime != DateTime.MaxValue)
                {
                    strSql.Append($"and LoginTime >= '{Convert.ToDateTime(Json.BeginTime).ToShortDateString()}' ");
                }
                if (Json.BeginTime != null && Json.EndTime != DateTime.MinValue && Json.EndTime != DateTime.MaxValue)
                {
                    strSql.Append($"and LoginTime <= '{Convert.ToDateTime(Json.EndTime).ToShortDateString() + " 23:59:59.999"}' ");
 
                }
 
                DataTable dt = DataFactory.SqlDataBase().GetPageList(strSql.ToString(), null, "CreateTime", "Desc", ref pageInfo);
                return ModelConvertHelper<GetWCSConveyorInfo>.DataTableToModel(dt);
            }
            catch
            {
                throw new NotImplementedException();
            }
        }
 
        public GetWCSConveyorInfo GetConveyorInfo(string Id)
        {
            GetWCSConveyorInfo getWCS = new GetWCSConveyorInfo();
 
            StringBuilder strSql = new StringBuilder();
            strSql.Append($"select * from WCSConveyorInfo where Id = @id");
 
            //DataTable dt = DataFactory.SqlDataBase().GetDataTableBySQL(strSql);
 
            SqlParam[] para = new SqlParam[]
                {
                    new SqlParam("@id", Id),
                };
 
            IDataReader dt = DataFactory.SqlDataBase().GetDataReaderBySQL(strSql, para);
            getWCS = ModelConvertHelper<GetWCSConveyorInfo>.ReaderToModel(dt);
 
            return getWCS;
        }
 
        /// <summary>
        /// 添加物料输送信息
        /// </summary>
        /// <param name="model"></param>
        /// <param name="loginUser"></param>
        /// <returns></returns>
        public bool Add(WCSConveyorInfo model, string loginUser)
        {
            bool result = false;
            try
            {
                //转换user信息 user Code变成id
 
                UserInfo us = null;
                StringBuilder strSql = new StringBuilder();
                strSql.Append($"select * from UserInfo where IsDel = 0 and UserCode = '{loginUser}' ");
 
                IDataReader dt = DataFactory.SqlDataBase().GetDataReaderBySQL(strSql, null);
 
                us = ModelConvertHelper<UserInfo>.ReaderToModel(dt);
                if (us == null)
                {
                    return false;
                }
                Hashtable ht = new Hashtable();
 
                ht["SkuType"] = "'" + model.SkuType + "'";
                ht["Conveyor"] = "'" + model.Conveyor + "'";
                ht["LotNo"] = "'" + model.LotNo.Trim() + "'";
                ht["SupplierLot"] = "'" + model.SupplierLot + "'";
                ht["ManuFactureDate"] = "'" + model.ManuFactureDate + "'";
                ht["IsEndLot"] = "0";
                ht["Status"] = "0";
 
                ht["IsDel"] = "0";
                ht["CreateUser"] = "" + us.ID + "";
                ht["CreateTime"] = "GetDate()";
 
                var ret = DataFactory.SqlDataBase().InsertByHashtableNullParam("WCSConveyorInfo", ht);
 
                if (ret == 1) result = true;
 
                return result;
 
            }
            catch
            {
                return result;
            }
        }
 
        /// <summary>
        /// 添加物料输送信息
        /// </summary>
        /// <param name="model"></param>
        /// <param name="loginUser"></param>
        /// <returns></returns>
        public bool Upt(WCSConveyorInfo model, string loginUser)
        {
            bool result = false;
            try
            {
                UserInfo us = null;
                StringBuilder strSql = new StringBuilder();
                strSql.Append($"select * from UserInfo where IsDel = 0 and UserCode = '{loginUser}' ");
 
                IDataReader dt = DataFactory.SqlDataBase().GetDataReaderBySQL(strSql, null);
 
                us = ModelConvertHelper<UserInfo>.ReaderToModel(dt);
                if (us == null)
                {
                    return false;
                }
 
                
 
                StringBuilder sql = new StringBuilder();
                if (model.Conveyor == "1")
                {
                    model.Conveyor = "A";
                }
                else if (model.Conveyor == "2")
                {
                    model.Conveyor = "B";
                }
                else if (model.Conveyor == "3")
                {
                    model.Conveyor = "C";
                }
                else if (model.Conveyor == "4")
                {
                    model.Conveyor = "C1";
                }
                else if (model.Conveyor == "5")
                {
                    model.Conveyor = "D";
                }
 
                sql.Append($"update WcsConveyorInfo set SkuType = '{model.SkuType}',Conveyor = '{model.Conveyor}',LotNo = '{model.LotNo}',SupplierLot = '{model.SupplierLot}',ManuFactureDate = '{model.ManuFactureDate}',UpdateTime = getdate(),UpdateUser = '{us.ID}' Where Id = {model.Id}");
 
                int _ret = DataFactory.SqlDataBase().ExecuteBySql(sql);
                if (_ret > 0) result = true;
                return result;
            }
            catch
            {
                return result;
            }
        }
 
        public bool Delete(string[] infoIds, string loginUser)
        {
            bool result = false;
            try
            {
                UserInfo us = null;
                StringBuilder strSql = new StringBuilder();
                strSql.Append($"select * from UserInfo where IsDel = 0 and UserCode = '{loginUser}' ");
 
                IDataReader dt = DataFactory.SqlDataBase().GetDataReaderBySQL(strSql, null);
 
                us = ModelConvertHelper<UserInfo>.ReaderToModel(dt);
                if (us == null)
                {
                    return false;
                }
                var dt2 = DataFactory.SqlDataBase().IsExist("WcsConveyorInfo", "Id", infoIds);
                if (dt2 >= infoIds.Length)
                {
                    StringBuilder sql = new StringBuilder();
                    foreach (string code in infoIds)
                    {
                        sql.Append("update WcsConveyorInfo set IsDel=1,UpdateTime = getdate(),UpdateUser = '" + us.ID + "' where Id='" + code + "';");
                    }
 
                    int _ret = DataFactory.SqlDataBase().ExecuteBySql(sql);
                    if (_ret > infoIds.Length) result = true;
                }
                return result;
 
            }
            catch
            {
                return result;
            }
        }
 
        public bool Run(string[] infoIds, string loginUser)
        {
            bool result = false;
            try
            {
                UserInfo us = null;
                StringBuilder strSql = new StringBuilder();
                strSql.Append($"select * from UserInfo where IsDel = 0 and UserCode = '{loginUser}' ");
 
                IDataReader dt = DataFactory.SqlDataBase().GetDataReaderBySQL(strSql, null);
 
                us = ModelConvertHelper<UserInfo>.ReaderToModel(dt);
                if (us == null)
                {
                    return false;
                }
                var dt2 = DataFactory.SqlDataBase().IsExist("WCSConveyorInfo", "Id", infoIds);
                if (dt2 >= infoIds.Length)
                {
                    StringBuilder sql = new StringBuilder();
                    foreach (string code in infoIds)
                    {
                        StringBuilder sql2 = new StringBuilder();
                        sql2.Append($"select * from WCSConveyorInfo where IsDel = 0 and Id = '{code}' ");
 
                        IDataReader dt3 = DataFactory.SqlDataBase().GetDataReaderBySQL(sql2, null);
 
                        var info = ModelConvertHelper<WCSConveyorInfo>.ReaderToModel(dt3);
 
                        sql.Append("update WcsConveyorInfo set Status=1,UpdateTime = getdate(),UpdateUser = '" + us.ID + "' where Id='" + code + "';");
                        sql.Append("update WcsConveyorInfo set Status=0,UpdateTime = getdate(),UpdateUser = '" + us.ID + "' where Id !='" + code + "' and IsDel = '0' and Conveyor = '"+ info.Conveyor + "';");
                    }
 
                    int _ret = DataFactory.SqlDataBase().ExecuteBySql(sql);
                    if (_ret > infoIds.Length) result = true;
                }
                return result;
 
            }
            catch
            {
                return result;
            }
        }
 
        public bool JiePi(string[] infoIds, string loginUser)
        {
            bool result = false;
            try
            {
                UserInfo us = null;
                StringBuilder strSql = new StringBuilder();
                strSql.Append($"select * from UserInfo where IsDel = 0 and UserCode = '{loginUser}' ");
 
                IDataReader dt = DataFactory.SqlDataBase().GetDataReaderBySQL(strSql, null);
 
                us = ModelConvertHelper<UserInfo>.ReaderToModel(dt);
                if (us == null)
                {
                    return false;
                }
                var dt2 = DataFactory.SqlDataBase().IsExist("WCSConveyorInfo", "Id", infoIds);
                if (dt2 >= infoIds.Length)
                {
                    StringBuilder sql = new StringBuilder();
                    foreach (string code in infoIds)
                    {
                        sql.Append("update WcsConveyorInfo set IsEndLot=1,Status =0,UpdateTime = getdate(),UpdateUser = '" + us.ID + "' where Id='" + code + "';");
 
                    }
 
                    int _ret = DataFactory.SqlDataBase().ExecuteBySql(sql);
                    if (_ret > infoIds.Length) result = true;
                }
                return result;
 
            }
            catch
            {
                return result;
            }
        }
    }
}