yl
2023-03-07 301936d643fe804b52b397dc594877d8d3cbe202
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
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
using Dapper;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using VueWebApi.Tools;
 
namespace VueWebApi.DLL.DAL
{
    public class SystemSettingDAL
    {
        public static DataTable dt;    //定义全局变量dt
        public static bool res;       //定义全局变量dt
        public static ToMessage mes = new ToMessage(); //定义全局返回信息对象
        public static string strProcName = ""; //定义全局sql变量
        public static List<SqlParameter> listStr = new List<SqlParameter>(); //定义全局参数集合
        public static SqlParameter[] parameters; //定义全局SqlParameter参数数组
 
 
        #region[编码规则查询]
        public static ToMessage EncodingRules(string rightname, string prefix, int startNum, int endNum, string prop, string order)
        {
            var dynamicParams = new DynamicParameters();
            string search = "";
            try
            {
                if (rightname != "" && rightname != null)
                {
                    search += "and A.right_name like '%'+@rightname+'%' ";
                    dynamicParams.Add("@rightname", rightname);
                }
                if (prefix != "" && prefix != null)
                {
                    search += "and B.prefix like '%'+@prefix+'%' ";
                    dynamicParams.Add("@prefix", prefix);
                }
                if (search == "")
                {
                    search = "and 1=1 ";
                }
                //search = search.Substring(3);//截取索引2后面的字符
                // --------------查询指定数据--------------
                var total = 0; //总条数
                var sql = @"select A.right_code,A.right_name,B.prefix,B.filingdate,B.incbit,A.Type  from TRight A
                            left join T_CodeRules B on A.right_code=B.rightcode
                            where  A.parent_id<>'0' and A.is_delete<>'1' " + search + "";
                var data = DapperHelper.GetPageList<object>(sql, dynamicParams, prop, order, startNum, endNum, out total);
                mes.code = "200";
                mes.Message = "查询成功!";
                mes.count = total;
                mes.data = data.ToList();
            }
            catch (Exception e)
            {
                mes.code = "300";
                mes.count = 0;
                mes.Message = e.Message;
                mes.data = null;
            }
            return mes;
        }
        #endregion
 
        #region[编码规则编辑保存]
        public static ToMessage SaveEncodingRules(string rightcode, string rightname, string prefix, string filingdate, string incbit, string lm_user)
        {
            var sql = "";
            List<object> list = new List<object>();
            var dynamicParams = new DynamicParameters();
            try
            {
                sql = @"select rightcode from  T_CodeRules  where rightcode=@rightcode";
                dynamicParams.Add("@rightcode", rightcode);
                var data = DapperHelper.selectdata(sql, dynamicParams);
                if (data.Rows.Count > 0)
                {
                    sql = @"update T_CodeRules set prefix=@prefix,filingdate=@filingdate,incbit=@incbit,lm_user=@lm_user,lm_date=@CreateDate where rightcode=@rightcode";
                    dynamicParams.Add("@prefix", prefix);
                    dynamicParams.Add("@filingdate", filingdate);
                    dynamicParams.Add("@incbit", incbit);
                    dynamicParams.Add("@lm_user", lm_user);
                    dynamicParams.Add("@CreateDate", DateTime.Now.ToString());
                    dynamicParams.Add("@rightcode", rightcode);
                    int cont = DapperHelper.SQL(sql, dynamicParams);
                    if (cont > 0)
                    {
                        mes.code = "200";
                        mes.count = 0;
                        mes.Message = "操作成功!";
                        mes.data = null;
                    }
                    else
                    {
                        mes.code = "300";
                        mes.count = 0;
                        mes.Message = "操作失败!";
                        mes.data = null;
                    }
                }
                else
                {
                    //首次写入前按位数补充0
                    string value = "";
                    for (int i = 0; i < int.Parse(incbit); i++)
                    {
                        value = value + "0";
                    }
                    //写入规则表
                    sql = @"insert into T_CodeRules(rightcode,rightname,prefix,filingdate,incbit,value,lm_user,lm_date) 
                            values(@rightcode,@rightname,@prefix,@filingdate,@incbit,@value,@lm_user,@lm_date)";
                    dynamicParams.Add("@rightcode", rightcode);
                    dynamicParams.Add("@rightname", rightname);
                    dynamicParams.Add("@prefix", prefix);
                    dynamicParams.Add("@filingdate", filingdate);
                    dynamicParams.Add("@incbit", incbit);
                    dynamicParams.Add("@value", value);
                    dynamicParams.Add("@lm_user", lm_user);
                    dynamicParams.Add("@lm_date", DateTime.Now.ToString());
                    int cont = DapperHelper.SQL(sql, dynamicParams);
                    if (cont > 0)
                    {
                        mes.code = "200";
                        mes.count = 0;
                        mes.Message = "操作成功!";
                        mes.data = null;
                    }
                    else
                    {
                        mes.code = "300";
                        mes.count = 0;
                        mes.Message = "操作失败!";
                        mes.data = null;
                    }
                }
            }
            catch (Exception e)
            {
                mes.code = "300";
                mes.count = 0;
                mes.Message = e.Message;
                mes.data = null;
            }
            return mes;
        }
        #endregion
 
        #region[获取规则生成的编码]
        public static ToMessage NewEncodingRules(string rightcode)
        {
            mes = SeachEncode.EncodingSeach(rightcode);
            return mes;
        }
        #endregion
 
 
        #region[车间公告列表]
        public static ToMessage SystemAnnouncementSearch(string wkspcode, string ancetitle, string ancecont, string cancel, string level, int startNum, int endNum, string prop, string order)
        {
            var dynamicParams = new DynamicParameters();
            string search = "";
            try
            {
                if (wkspcode != "" && wkspcode != null)
                {
                    search += "and A.wksp_code=@wkspcode ";
                    dynamicParams.Add("@wkspcode", wkspcode);
                }
                if (ancetitle != "" && ancetitle != null)
                {
                    search += "and A.title like '%'+@ancetitle+'%' ";
                    dynamicParams.Add("@ancetitle", ancetitle);
                }
                if (ancecont != "" && ancecont != null)
                {
                    search += "and A.contents like '%'+@ancecont+'%' ";
                    dynamicParams.Add("@ancecont", ancecont);
                }
                if (cancel != "" && cancel != null)
                {
                    search += "and A.if_cancel=@cancel ";
                    dynamicParams.Add("@cancel", cancel);
                }
                if (level != "" && level != null)
                {
                    search += "and A.priority=@level ";
                    dynamicParams.Add("@level", level);
                }
                if (search == "")
                {
                    search = "and 1=1 ";
                }
                //search = search.Substring(3);//截取索引2后面的字符
                // --------------查询指定数据--------------
                var total = 0; //总条数
                var sql = @"select A.id,A.wksp_code,T.org_name as wksp_name,A.title,A.contents,U.username as lm_user,A.lm_date,A.if_cancel,A.cancel_date,A.priority
                            from TSystemAnnouncement A
                            left join TOrganization T on A.wksp_code=T.org_code
                            left join TUser U on A.lm_user=U.usercode
                            where T.description='W' and A.is_delete='0' " + search + "";
                var data = DapperHelper.GetPageList<object>(sql, dynamicParams, prop, order, startNum, endNum, out total);
                mes.code = "200";
                mes.Message = "查询成功!";
                mes.count = total;
                mes.data = data.ToList();
            }
            catch (Exception e)
            {
                mes.code = "300";
                mes.count = 0;
                mes.Message = e.Message;
                mes.data = null;
            }
            return mes;
        }
        #endregion
 
        #region[车间公告新增编辑提交]
        public static ToMessage SystemAnnouncementAddUpdate(string id, DataTable dt, string ancetitle, string ancecont, string cancel, string level, string username, string opertype)
        {
            var sql = "";
            var dynamicParams = new DynamicParameters();
            List<object> list = new List<object>();
            string cancel_date = "";
            try
            {
                if (cancel == "Y")
                {
                    cancel_date = DateTime.Now.ToString();
                }
                if (opertype == "Add")
                {
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        //写入工单表
                        sql = @"insert into TSystemAnnouncement(wksp_code,title,contents,if_cancel,cancel_date,lm_user,lm_date,priority)
                                values(@wksp_code,@title,@contents,@if_cancel,@cancel_date,@lm_user,@lm_date,@priority)";
                        list.Add(new
                        {
                            str = sql,
                            parm = new
                            {
                                wksp_code = dt.Rows[i]["WKSP_CODE"].ToString(),
                                title = ancetitle,
                                contents = ancecont,
                                if_cancel = cancel,
                                cancel_date = cancel_date,
                                lm_user = username,
                                lm_date = DateTime.Now.ToString(),
                                priority = level
                            }
                        });
                    }
 
                    bool aa = DapperHelper.DoTransaction(list);
                    if (aa)
                    {
                        mes.code = "200";
                        mes.count = 0;
                        mes.Message = "操作成功!";
                        mes.data = null;
                    }
                    else
                    {
                        mes.code = "300";
                        mes.count = 0;
                        mes.Message = "操作失败!";
                        mes.data = null;
                    }
                }
                if (opertype == "Update")
                {
                    sql = @"update TSystemAnnouncement set wksp_code=@wksp_code,title=@title,contents=@contents,if_cancel=@if_cancel,cancel_date=@cancel_date,lm_user=@lm_user,lm_date=@lm_date,priority=@priority where id=@id";
                    list.Add(new
                    {
                        str = sql,
                        parm = new
                        {
                            id = id,
                            wksp_code = dt.Rows[0]["WKSP_CODE"].ToString(),
                            title = ancetitle,
                            contents = ancecont,
                            if_cancel = cancel,
                            cancel_date = cancel_date,
                            lm_user = username,
                            lm_date = DateTime.Now.ToString(),
                            priority = level
                        }
                    });
                    bool aa = DapperHelper.DoTransaction(list);
                    if (aa)
                    {
                        mes.code = "200";
                        mes.count = 0;
                        mes.Message = "修改操作成功!";
                        mes.data = null;
                    }
                    else
                    {
                        mes.code = "300";
                        mes.count = 0;
                        mes.Message = "修改操作失败!";
                        mes.data = null;
                    }
                }
            }
            catch (Exception e)
            {
                mes.code = "300";
                mes.count = 0;
                mes.Message = e.Message;
                mes.data = null;
            }
            return mes;
        }
        #endregion
 
        #region[车间公告删除]
        public static ToMessage SystemAnnouncementDelete(string id)
        {
            var sql = "";
            List<object> list = new List<object>();
            var dynamicParams = new DynamicParameters();
            try
            {
                list.Clear();
                sql = @"delete TSystemAnnouncement where id=@id";
                list.Add(new { str = sql, parm = new { id = id } });
 
                bool aa = DapperHelper.DoTransaction(list);
                if (aa)
                {
                    mes.code = "200";
                    mes.count = 0;
                    mes.Message = "操作成功!";
                    mes.data = null;
                }
                else
                {
                    mes.code = "300";
                    mes.count = 0;
                    mes.Message = "操作失败!";
                    mes.data = null;
                }
            }
            catch (Exception e)
            {
                mes.code = "300";
                mes.count = 0;
                mes.Message = e.Message;
                mes.data = null;
            }
            return mes;
        }
        #endregion
 
 
        #region[SOP列表查询]
        public static ToMessage SystemSopSearch(string search, string check, int startNum, int endNum, string prop, string order)
        {
            var dynamicParams = new DynamicParameters();
            string sech = "";
            try
            {
                if (search != "" && search != null)
                {
                    sech += "and concat(isnull(AA.partcode,''),isnull(AA.partname,''),isnull(AA.partspec,''),isnull(AA.eqptype_name,''),isnull(AA.filetype_name,''),isnull(AA.define_name,''),isnull(AA.file_version,''),isnull(AA.username,'')) like '%'+@search+'%' ";
                    dynamicParams.Add("@search", search);
                }
                if (check == "Y")
                {
                    sech += "and AA.rn=1 ";
                    dynamicParams.Add("@rn", 1);
                }
 
                if (sech == "")
                {
                    sech = "and 1=1 ";
                }
                sech = sech.Substring(3);//截取索引2后面的字符
                // --------------查询指定数据--------------
                var total = 0; //总条数
                var sql = @"select AA.id,AA.partcode,AA.partname,AA.partspec,AA.eqptype_code,AA.eqptype_name,AA.filetype_code,AA.filetype_name,AA.file_name,AA.define_name,AA.file_version,AA.file_path,
                            AA.username,AA.lm_date,AA.rn  from(
                            select top 100  A.id,M.partcode,M.partname,M.partspec,A.eqptype_code,T.name as eqptype_name,A.filetype_code,
                            (case when A.filetype_code='P001' then '作业指导书' when A.filetype_code='P002' then '检验指导书' when A.filetype_code='P003' then '图纸'  end) as filetype_name,
                            A.file_name,A.define_name,A.file_version,A.file_path,U.username,A.lm_date,
                            row_number() over(partition by A.materiel_code,A.filetype_code order by replace(A.file_version,'V','') desc) rn  
                            from  TK_Sop_Matfile A
                            left  join TMateriel_Info M on A.materiel_code=M.partcode
                            left  join TEqpType T on A.eqptype_code=T.code
                            left  join TUser U on A.lm_user=U.usercode
                            ) as AA  where  " + sech + "";
                var data = DapperHelper.GetPageList<object>(sql, dynamicParams, prop, order, startNum, endNum, out total);
                mes.code = "200";
                mes.Message = "查询成功!";
                mes.count = total;
                mes.data = data.ToList();
            }
            catch (Exception e)
            {
                mes.code = "300";
                mes.count = 0;
                mes.Message = e.Message;
                mes.data = null;
            }
            return mes;
        }
        #endregion
 
        #region[SOP文件上传查找设备类型数据]
        public static ToMessage SystemSopDeviceSearch()
        {
            string sql = "";
            try
            {
                //获取设备类型
                sql = @"select code,name   from TEqpType order by code";
                var data = DapperHelper.selecttable(sql);
                mes.code = "200";
                mes.Message = "查询成功!";
                mes.data = data;
            }
            catch (Exception e)
            {
                mes.code = "300";
                mes.count = 0;
                mes.Message = e.Message;
                mes.data = null;
            }
            return mes;
        }
        #endregion
 
        #region[SOP文件作业文件上传获取最大版本号]
        public static ToMessage SystemSopMaxVersion(string devicetypecode, string filetypecode, string partcode)
        {
            string sql = "";
            var dynamicParams = new DynamicParameters();
            try
            {
                //获取SOP文件作业文件上传获取最大版本号
                sql = @"select isnull(max(substring(file_version,charindex('V',file_version)+1,len(file_version)-charindex('V',file_version))),0)+1 as file_version    
                        from TK_Sop_Matfile where materiel_code=@partcode and eqptype_code=@devicetypecode and filetype_code=@filetypecode ";
                dynamicParams.Add("@devicetypecode", devicetypecode);
                dynamicParams.Add("@filetypecode", filetypecode);
                dynamicParams.Add("@partcode", partcode);
                var data = DapperHelper.selectdata(sql, dynamicParams);
                if (data.Rows.Count > 0)
                {
                    mes.code = "200";
                    mes.Message = "获取版本号成功!";
                    mes.data = "V" + data.Rows[0]["file_version"].ToString();
                }
                else
                {
                    mes.code = "300";
                    mes.Message = "获取版本号失败!";
                    mes.data = null;
                }
            }
            catch (Exception e)
            {
                mes.code = "300";
                mes.count = 0;
                mes.Message = e.Message;
                mes.data = null;
            }
            return mes;
        }
        #endregion
 
        #region[SOP文件上传提交]
        public static ToMessage SystemSopSava(string devicetypecode, string filetypecode, string partcode, string fileversion,string file_name, string defilename, string username, string strPath)
        {
            var sql = "";
            List<object> list = new List<object>();
            try
            {
                //写入SOP文件表
                sql = @"insert into TK_Sop_Matfile(materiel_code,eqptype_code,filetype_code,file_name,define_name,file_version,file_path,lm_user,lm_date)
                        values(@materiel_code,@eqptype_code,@filetype_code,@file_name,@define_name,@file_version,@file_path,@lm_user,@lm_date)";
                list.Add(new
                {
                    str = sql,
                    parm = new
                    {
                        materiel_code = partcode,
                        eqptype_code = devicetypecode,
                        filetype_code = filetypecode,
                        file_name = file_name,
                        define_name = defilename,
                        file_version= fileversion,
                        file_path= strPath,
                        lm_user = username,
                        lm_date = DateTime.Now.ToString()
                    }
                });
                bool aa = DapperHelper.DoTransaction(list);
                if (aa)
                {
                    mes.code = "200";
                    mes.count = 0;
                    mes.Message = "上传成功!";
                    mes.data = null;
                }
                else
                {
                    mes.code = "300";
                    mes.count = 0;
                    mes.Message = "上传失败!";
                    mes.data = null;
                }
 
            }
            catch (Exception e)
            {
                mes.code = "300";
                mes.count = 0;
                mes.Message = e.Message;
                mes.data = null;
            }
            return mes;
        }
        #endregion
 
        #region[SOP文件删除]
        public static ToMessage SystemSopDelete(string id, string filepath)
        {
            var sql = "";
            List<object> list = new List<object>();
            try
            {
                list.Clear();
                sql = @"delete TK_Sop_Matfile where id=@id";
                list.Add(new { str = sql, parm = new { id = id } });
                bool aa = DapperHelper.DoTransaction(list);
                string FilePath = System.Web.HttpContext.Current.Server.MapPath(filepath);//获取文件路径
                if (System.IO.File.Exists(FilePath))//判断文件是否存在
                {
                    System.IO.File.Delete(FilePath);//执行IO文件删除,需引入命名空间System.IO;
                }
                if (aa)
                {
                    mes.code = "200";
                    mes.count = 0;
                    mes.Message = "删除成功!";
                    mes.data = null;
                }
                else
                {
                    mes.code = "300";
                    mes.count = 0;
                    mes.Message = "删除失败!";
                    mes.data = null;
                }
            }
            catch (Exception e)
            {
                mes.code = "300";
                mes.count = 0;
                mes.Message = e.Message;
                mes.data = null;
            }
            return mes;
        }
        #endregion
 
    }
}