yangle
2023-11-07 0f72c941f402f624cc6b5d364724d08d6f60dfc3
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
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Pub_Class;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Web.Http;
using WebAPI.Models;
 
namespace WebAPI.Controllers.CJGL
{
    public class Cj_SingleStationController : ApiController
    {
        private json objJsonResult = new json();
        SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
        DataSet ds;
 
        #region 工序单品不良采集  用户查询关联字段
        [Route("Cj_SingleStation/Cj_CollectionOfSingleProductDefectsUserList")]
        [HttpGet]
        public object Cj_CollectionOfSingleProductDefectsUserList(string sWhere, string user)
        {
            try
            {
 
                if (sWhere == null || sWhere.Equals(""))
                {
                    objJsonResult.code = "1";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "Sucess!";
                    objJsonResult.data = new DataTable();
                    return objJsonResult;
                }
 
                ds = oCN.RunProcReturn("select * from h_v_Cj_UserAssociationList where 1=1 "+sWhere, "h_v_Cj_UserAssociationList");
 
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "Sucess!";
                objJsonResult.data = ds.Tables[0];
                return objJsonResult;
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "Exception!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
 
        #region  工序单品不良采集 扫码查询
        [Route("Cj_SingleStation/HBardCodeList")]
        [HttpGet]
        public object HBardCodeList(string HBarCode, string user)
        {
            try
            {
 
                ds = oCN.RunProcReturn(@"select * from h_v_Gy_BarCodeBillHICOMProcessExchange where 条码='" + HBarCode + "'", "h_v_Gy_BarCodeBillHICOMProcessExchange");
                if (ds.Tables[0].Rows.Count == 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "条码查无数据!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                else
                {
                    objJsonResult.code = "1";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "";
                    objJsonResult.data = ds.Tables[0];
                }
 
                return objJsonResult;
            }
            catch (Exception e)
            {
 
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "没有返回任何记录!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
 
        #region 工序单品不良采集 保存
        [Route("Cj_SingleStation/ProcessBLSave")]
        [HttpPost]
        public object ProcessBLSave([FromBody] JObject sMainSub)
        {
            var _value = sMainSub["sMainSub"].ToString();
            string msg1 = _value.ToString();
            string[] sArray = msg1.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
            string msg2 = sArray[0].ToString(); //主表数据
            string HResult = sArray[1].ToString();
            string user = sArray[2].ToString();
 
            try
            {
                var msg3 = msg2.ToString();
                msg2 = "[" + msg2.ToString() + "]";
                List<Model.ClsSc_QualityReportBillMain> mainList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Model.ClsSc_QualityReportBillMain>>(msg2);
 
                long HInterID = mainList[0].HInterID;//递入type得到的单据ID
                string HBillNo = mainList[0].HBillNo;//递入type得到的单据号
                DateTime HDate = DateTime.Now;//日期
                string HRemark = mainList[0].HRemark;//备注
                long HEmpID = mainList[0].HEmpID;//质检员
                long HGroupID = mainList[0].HGroupID;//班组
                long HDeptID = mainList[0].HDeptID;//车间
                string HMaker = user;//制单人
 
                ds = oCN.RunProcReturn("select * from Sc_QualityReportBillMain where HInterID=" + HInterID + " and HBillNo='" + HBillNo + "'", "Sc_QualityReportBillMain");
                if (ds.Tables[0].Rows.Count != 0) {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "单据已存在!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
 
                oCN.BeginTran();
 
                if (ds.Tables[0].Rows.Count == 0)//新增
                {
                    //主表
                    oCN.RunProc(@"Insert Into Sc_QualityReportBillMain   
(HBillType,HBillSubType,HBillStatus,HInterID,HBillNo,HDate
,HYear,HPeriod,HRemark,HMaker,HMakeDate
,HEmpID,HGroupID,HDeptID)
                        values('3717','3717',1," + HInterID + ",'" + HBillNo + "','" + HDate + "'" +
                    "," + DateTime.Now.Year + "," + DateTime.Now.Month + ",'" + HRemark + "','" + HMaker + "',getdate()" +
                    ",'" + HEmpID + "'," + HGroupID + "," + HDeptID + ") ");
 
                }
               
                //保存子表
                objJsonResult = AddBillSub_NoTable(msg3, HInterID, HResult);
 
                if (objJsonResult.code == "0")
                {
                    oCN.RollBack();
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = objJsonResult.Message;
                    objJsonResult.data = null;
                    return objJsonResult;
                }
 
                oCN.Commit();
 
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = null;
                objJsonResult.data = null;
                return objJsonResult;
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "Exception!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
 
        public json AddBillSub_NoTable(string msg3, long HInterID, string HResult)
        {
           Model.ClsSc_QualityReportBillSub oSub = Newtonsoft.Json.JsonConvert.DeserializeObject<Model.ClsSc_QualityReportBillSub>(msg3);
 
            if (oSub.HMaterID == 0)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "物料不能为空";
                objJsonResult.data = null;
                return objJsonResult;
            }
 
            oCN.RunProc($@"Insert into Sc_QualityReportBillSub 
(HInterID,HENTRYID,HBillNo_bak,HEmpID,HBarCode,HBadReasonID,HAddr,HMaker,HMakeDate
,HMaterID,HUnitID,HRemark,HSourceID,HICMOInterID,HICMOEntryID,HICMOBillNo,HReportType
,HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HRelationQty,HRelationMoney
,HQty,HResult,HProcExchInterID,HProcExchEntryID,HProcExchBillNo) 
values({HInterID},1,'{oSub.HBillNo_bak}',{oSub.HEmpID},'{oSub.HBarCode}',{oSub.HBadReasonID},'','{oSub.HMaker}','{oSub.HMakeDate}'
,{oSub.HMaterID},{oSub.HUnitID},'{oSub.HRemark}',{oSub.HSourceID},{oSub.HICMOInterID},{oSub.HICMOEntryID},'{oSub.HICMOBillNo}',{oSub.HReportType}
,0,0,'','',0,0
,0,'{HResult}',{oSub.HProcExchInterID},{oSub.HProcExchEntryID},'{oSub.HProcExchBillNo}')");
 
            //修改条码表的状态
            oCN.RunProc("update Gy_BarCodeBill set HStatus='"+ HResult + "' where HBarCode='"+ oSub.HBarCode + "'");
 
            //修改出站单的 不良 报废数量
            if (HResult == "不良") {
                oCN.RunProc("update Sc_StationOutBillMain set HBadCount+=1  where HProcExchBillNo='" + oSub.HProcExchBillNo + "' and HProcID=" + oSub.HProcID);
            }
            else if (HResult == "报废")
            {
                oCN.RunProc("update Sc_StationOutBillMain set HWasterQty+=1  where HProcExchBillNo='" + oSub.HProcExchBillNo + "' and HProcID=" + oSub.HProcID);
            }
 
            objJsonResult.code = "1";
            objJsonResult.count = 1;
            objJsonResult.Message = null;
            objJsonResult.data = null;
            return objJsonResult;
        }
        #endregion
 
        #region  工序单品过站 流转卡查询关键件清单
        [Route("Cj_SingleStation/HBardCodeBomList")]
        [HttpGet]
        public object HBardCodeBomList(string HBarCode, string user)
        {
            try
            {
 
                ds = oCN.RunProcReturn(@"select * from h_v_Gy_BarCodeBillHICOMProcessExchange where 条码='" + HBarCode + "'", "h_v_Gy_BarCodeBillHICOMProcessExchange");
                if (ds.Tables[0].Rows.Count == 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "条码查无数据!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                else
                {
                    objJsonResult.code = "1";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "";
                    objJsonResult.data = ds.Tables[0];
                }
 
                return objJsonResult;
            }
            catch (Exception e)
            {
 
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "没有返回任何记录!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
 
        #region 工序单品返修台 获取表格数据
        [Route("Cj_SingleStation/ProcessItemRepair")]
        [HttpGet]
        public object ProcessItemRepair( string sWhere, string user)
        {
            try
            {
                List<object> columnNameList = new List<object>();
 
                string sql = @"select * from h_v_Cj_BarCodeProcessItemRepair  where  1=1 " + sWhere + " order by 日期 desc, HInterID desc, HEntryID desc";
                ds = oCN.RunProcReturn(sql, "h_v_Cj_BarCodeProcessItemRepair");
 
                //添加列名
                foreach (DataColumn col in ds.Tables[0].Columns)
                {
                    Type dataType = col.DataType;
                    string ColmString = "{\"ColmCols\":\"" + col.ColumnName + "\",\"ColmType\":\"" + dataType.Name + "\"}";
                    columnNameList.Add(JsonConvert.DeserializeObject(ColmString));//获取到DataColumn列对象的列名
                }
 
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "Sucess!";
                objJsonResult.data = ds.Tables[0];
                objJsonResult.list = columnNameList;
                return objJsonResult;
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "Exception!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
 
        #region 工序单品返修台--配件更换 查询更换记录
        [Route("Cj_SingleStation/Sc_SourceLineRepairBillSub_MaterList")]
        [HttpGet]
        public object Sc_SourceLineRepairBillSub_MaterList(string sWhere, string user)
        {
            try
            {
                List<object> columnNameList = new List<object>();
 
                string sql = @"select * from Sc_SourceLineRepairBillSub_Mater  where  1=1 " + sWhere + " order by   HInterID asc, HEntryID asc";
                ds = oCN.RunProcReturn(sql, "Sc_SourceLineRepairBillSub_Mater");
 
                //添加列名
                foreach (DataColumn col in ds.Tables[0].Columns)
                {
                    Type dataType = col.DataType;
                    string ColmString = "{\"ColmCols\":\"" + col.ColumnName + "\",\"ColmType\":\"" + dataType.Name + "\"}";
                    columnNameList.Add(JsonConvert.DeserializeObject(ColmString));//获取到DataColumn列对象的列名
                }
 
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "Sucess!";
                objJsonResult.data = ds.Tables[0];
                objJsonResult.list = columnNameList;
                return objJsonResult;
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "Exception!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
    }
}