季铭对接T+畅捷通,看板API
yl
2023-12-25 72a27b4fd84622ebc51150a07b16d13b7135ebf9
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
using Dapper;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using VueWebApi.Models;
using VueWebApi.Tools;
 
namespace VueWebApi.DLL.DAL
{
    public class AppQualityManagementDAL
    {
        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 InFactoryCheckScanLabCode(string labcode)
        {
            string sql = "";
            var dynamicParams = new DynamicParameters();
            Dictionary<string, object> list = new Dictionary<string, object>();
            try
            {
                //判断条码是否有效(采购到货功能编码:2060)
                sql = @"select *  from T_BarCodeBill where hbarcode=@labcode and rightcode=@rightcode and hbarcodestatus='Y'";
                dynamicParams.Add("@labcode", labcode);
                dynamicParams.Add("@rightcode", "2060");
                var data0 = DapperHelper.selectdata(sql, dynamicParams);
                if (data0.Rows.Count <= 0)
                {
                    mes.code = "300";
                    mes.count = 0;
                    mes.Message = "不是有效的标签条码!";
                    mes.data = null;
                    return mes;
                }
                //判断条码是否需要检验
                sql = @"select *  from TMateriel_Info where partcode=@partcode and is_incheck='N'";
                dynamicParams.Add("@partcode", data0.Rows[0]["hmaterialcode"].ToString());
                var data_0 = DapperHelper.selectdata(sql, dynamicParams);
                if (data_0.Rows.Count > 0)
                {
                    mes.code = "300";
                    mes.count = 0;
                    mes.Message = "此标签条码免检!";
                    mes.data = null;
                    return mes;
                }
                //判断条码是否检验
                sql = @"select *  from TStepCheckRecord where hbarcode=@labcode and check_type='InCheck'";
                dynamicParams.Add("@labcode", labcode);
                var data = DapperHelper.selectdata(sql, dynamicParams);
                if (data.Rows.Count > 0)
                {
                    mes.code = "300";
                    mes.count = 0;
                    mes.Message = "此标签条码已检验!";
                    mes.data = null;
                    return mes;
                }
                //获取标签信息
                sql = @"select A.hbillno,A.hmaterialcode as partcode,M.partname,M.partspec,A.hbarcode,M.stocktype_code,A.hqty,
                        A.hcustomercode,C.name as hcustomername,A.hbatchno,A.qualitystatus
                        from T_BarCodeBill A
                        left join TMateriel_Info M on A.hmaterialcode=M.partcode
                        left join TCustomer C on A.hcustomercode=C.code
                        where A.hbarcode=@labcode and A.hbarcodestatus='Y'";
                dynamicParams.Add("@labcode", labcode);
                var data1 = DapperHelper.selectdata(sql, dynamicParams);
                if (data1.Rows.Count > 0)
                {
                    //获取绑定的入厂质检方案、抽样方式、样本数
                    sql = @"select code as checkstandcode,name as checkstandname,sampmethod,sampscare   
                            from TStepCheckStandard
                            where (PATINDEX('%,' + RTRIM(@partcode) + ',%',',' + suitpart + ',')>0 or PATINDEX('%,' + RTRIM(@stocktype_code) + ',%',',' + suitpart + ',')>0)
                            and checktype='InCheck'";
                    dynamicParams.Add("@partcode", data1.Rows[0]["partcode"].ToString());//物料编码
                    dynamicParams.Add("@stocktype_code", data1.Rows[0]["stocktype_code"].ToString());//存货类型编码
                    var data2 = DapperHelper.selectdata(sql, dynamicParams);
                    list.Add("labcont", data1);
                    list.Add("chekstand", data2);
                    mes.code = "200";
                    mes.count = 0;
                    mes.Message = "查询成功!";
                    mes.data = list;
                }
                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[入厂检验,根据选择的检验方案查找检验项目]
        public static ToMessage InFactoryCheckItem(string checkstandcode)
        {
            string sql = "";
            var dynamicParams = new DynamicParameters();
            try
            {
                //质检方案编码获取检验项
                sql = @"select A.stepcheckitem_seq, B.code,B.name,A.required,A.numberjudge,A.unit,A.decimalnum,
                        A.standvalue,A.uppervalue,A.lowervalue,A.stepcheckitem_desc   
                        from TStepCheckStandardSub A
                        left join TStepCheckItem B on A.stepcheckitem_code=B.code
                        where A.stepstaned_code=@checkstandcode
                        order by A.stepcheckitem_seq";
                dynamicParams.Add("@checkstandcode", checkstandcode);//质检方案编码
                var data = DapperHelper.selectdata(sql, dynamicParams);
                if (data.Rows.Count > 0)
                {
                    mes.code = "200";
                    mes.count = 0;
                    mes.Message = "查询成功!";
                    mes.data = data;
                }
                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 InFactoryCheckSave(string hbillno, string labcode, string checkstandcode, string check_type, string sampmethod, string partcode, string customercode, string batchno, string qualitystatus, string labqty, string sampleqty, string goodqty, string ngqty, string issyncbatch, string checkitemcont, string username)
        {
            var sql = "";
            List<object> list = new List<object>();
            List<ObjectData> obj = new List<ObjectData>();
            var dynamicParams = new DynamicParameters();
            try
            {
                string datetime = DateTime.Now.ToString(); //获取系统时间
                //获取检验项目信息
                JArray arra = (JArray)Newtonsoft.Json.JsonConvert.DeserializeObject(checkitemcont);
                list.Clear();
                if (issyncbatch == "Y")  //同步相同批次
                {
                    //查找相同批次条码(功能编码、单据号、单据类型、条码类型、物料编码、批次号、条码状态)
                    sql = @"select hbarcode,hqty  from T_BarCodeBill
                            where rightcode=@rightcode and hbillno=@hbillno and hbilltype=@hbilltype and hbarcodetype=@hbarcodetype 
                            and hmaterialcode=@hmaterialcode and hbatchno=@hbatchno and hbarcodestatus=@hbarcodestatus";
                    dynamicParams.Add("@rightcode", "2060");
                    dynamicParams.Add("@hbillno", hbillno);
                    dynamicParams.Add("@hbilltype", "1103");
                    dynamicParams.Add("@hbarcodetype", "P");
                    dynamicParams.Add("@hmaterialcode", partcode);
                    dynamicParams.Add("@hbatchno", batchno);
                    dynamicParams.Add("@hbarcodestatus", "Y");
                    var data = DapperHelper.selectdata(sql, dynamicParams);
                    if (data.Rows.Count > 0)
                    {
                        for (int i = 0; i < data.Rows.Count; i++)
                        {
                            ObjectData tbj = new ObjectData();
                            tbj.code = data.Rows[i]["hbarcode"].ToString();
                            tbj.name = data.Rows[i]["hqty"].ToString();
                            obj.Add(tbj);
                        }
                    }
                    else
                    {
                        ObjectData tbj = new ObjectData();
                        tbj.code = labcode;
                        tbj.name = labqty;
                        obj.Add(tbj);
                    }
                }
                else
                {
                    ObjectData tbj = new ObjectData();
                    tbj.code = labcode;
                    tbj.name = labqty;
                    obj.Add(tbj);
                }
 
                //循环标签个数
                for (int i = 0; i <obj.Count; i++)
                {
                    //写入检验记录主表
                    sql = @"insert into  TStepCheckRecord(hbarcode,wo_code,partcode,checkstaned_code,customer_code,check_user,check_type,check_typename,sampmethod,check_result,check_qty,good_qty,ng_qty,lm_user,lm_date) 
                                values(@hbarcode,@wo_code,@partcode,@checkstaned_code,@customer_code,@check_user,@check_type,@check_typename,@sampmethod,@check_result,@check_qty,@good_qty,@ng_qty,@lm_user,@lm_date)";
                    list.Add(new
                    {
                        str = sql,
                        parm = new
                        {
                            hbarcode = obj[i].code,
                            wo_code = hbillno,
                            partcode = partcode,
                            checkstaned_code = checkstandcode,
                            customer_code=customercode,
                            check_user = username,
                            check_type = check_type,
                            check_typename = "入厂检验",
                            sampmethod = sampmethod,
                            check_result = qualitystatus,
                            check_qty = decimal.Parse(sampleqty),
                            good_qty = decimal.Parse(goodqty),
                            ng_qty = decimal.Parse(ngqty),
                            lm_user = username,
                            lm_date = datetime
                        }
                    });
                    //获取主表最大ID
                    sql = @"select ISNULL(IDENT_CURRENT('TStepCheckRecord')+@num,1) as id";
                    dynamicParams.Add("@num", i+1);
                    var dt = DapperHelper.selectdata(sql, dynamicParams);
                    //写入检验记录子表
                    for (int j = 0; j < arra.Count; j++)
                    {
                        sql = @"insert into  TStepCheckRecordSub(m_id,checknum,checkitem_seq,checkitem_code,checkitem_name,checkitem_descr,check_value,check_result,lm_user,lm_date) 
                                values(@m_id,@checknum,@checkiem_seq,@checkitem_code,@checkitem_name,@checkitem_descr,@check_value,@check_result,@lm_user,@lm_date)";
                        list.Add(new
                        {
                            str = sql,
                            parm = new
                            {
                                m_id = int.Parse(dt.Rows[0]["ID"].ToString()),
                                checknum = arra[j]["checknum"].ToString(),
                                checkiem_seq = arra[j]["checkiem_seq"].ToString(),
                                checkitem_code = arra[j]["checkitem_code"].ToString(),
                                checkitem_name = arra[j]["checkitem_name"].ToString(),
                                checkitem_descr = arra[j]["checkitem_descr"].ToString(),
                                check_value = arra[j]["check_value"].ToString(),
                                check_result = arra[j]["check_result"].ToString(),
                                lm_user = username,
                                lm_date = datetime
                            }
                        });
                    }
                }
                //回写条码档案表标签质检状态
                sql = @"update T_BarCodeBill set qualitystatus=@qualitystatus  where rightcode=@rightcode and hbillno=@hbillno and hbilltype=@hbilltype 
                        and hbarcodetype=@hbarcodetype  and hmaterialcode=@hmaterialcode and hbatchno=@hbatchno and hbarcodestatus=@hbarcodestatus";
                list.Add(new
                {
                    str = sql,
                    parm = new
                    {
                        qualitystatus= qualitystatus,
                        rightcode = "2060",
                        hbillno = hbillno,
                        hbilltype = "1103",
                        hbarcodetype = "P",
                        hmaterialcode = partcode,
                        hbatchno = batchno,
                        hbarcodestatus = "Y"
                    }
                });
 
                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
    }
}