zgq
2020-11-18 a4cc393ec1226531172edc08e90e015e19086edf
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
using Newtonsoft.Json.Linq;
using Pub_Class;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Web.Http;
using WebAPI.Models;
namespace WebAPI.Controllers
{
    public class LMESController : ApiController
    {
        public DBUtility.ClsPub.Enum_BillStatus BillStatus;
 
        private json objJsonResult = new json();
        /// <summary>
        /// 返回进站扫描列表|工序进站接收单列表 
        ///参数:string sql。
        ///返回值:object。    
        /// </summary>
        [Route("LEMS/MES_StationInBillList_Json")]
        [HttpGet]
        public object MES_StationInBillList_Json(string sWhere)
        {
            DataSet ds;
            try
            {
                SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
                if (sWhere == null || sWhere.Equals(""))
                {
                    ds = oCN.RunProcReturn("select * from h_v_MES_StationInBillList", "h_v_MES_StationInBillList");
                }
                else 
                {
                    string sql1 = "select * from h_v_MES_StationInBillList where 1 = 1 ";
                    string sql = sql1 + sWhere;
                    ds = oCN.RunProcReturn(sql, "h_v_MES_StationInBillList");
                }
                
            }
            catch (Exception e)
            {
                ds = null;
            }
            return GetObjectJson(ds);
        }
 
        /// <summary>
        /// 返回工序流转卡维护列表主表
        ///参数:string sql。
        ///返回值:object。
        /// </summary>
        [Route("LEMS/MES_Sc_ProcessExchangeBillQuery_Json")]
        [HttpGet]
        public object MES_Sc_ProcessExchangeBillList_Json(string sWhere)
        {
            DataSet ds;
            try
            {
                SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
                if (sWhere == null || sWhere.Equals(""))
                {
                    ds = oCN.RunProcReturn("select * from h_v_Sc_ProcessExchangeBillQuery", "h_v_Sc_ProcessExchangeBillQuery");
                }
                else
                {
                    string sql1 = "select * from h_v_Sc_ProcessExchangeBillQuery where 1 = 1 ";
                    string sql = sql1 + sWhere;
                    ds = oCN.RunProcReturn(sql, "h_v_Sc_ProcessExchangeBillQuery");
                }
 
            }
            catch (Exception e)
            {
                ds = null;
            }
            return GetObjectJson(ds);
        }
 
        /// <summary>
        /// 返回工序流转卡维护列表从表
        ///参数:string sql。
        ///返回值:object。
        /// </summary>
        [Route("LEMS/MES_Sc_ProcessExchangeBillQuerySub_Json")]
        [HttpGet]
        public object MES_Sc_ProcessExchangeBillSub_Json(string sWhere)
        {
            DataSet ds;
            try
            {
                SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
                string sql = "select * from h_v_Sc_ProcessExchangeBillQuerySub where hmainid = ";
                string sql1 = sql + sWhere;
                ds = oCN.RunProcReturn(sql1, "h_v_Sc_ProcessExchangeBillQuerySub");
            }
            catch (Exception e)
            {
                ds = null;
            }
            return GetObjectJson(ds);
        }
 
        /// <summary>
        /// 返回工序出站汇报单列表
        ///参数:string sql。
        ///返回值:object。
        /// </summary>
        [Route("LEMS/MES_StationOutBillList_Json")]
        [HttpGet]
        public object MES_StationOutBillList_Json(string sWhere)
        {
            DataSet ds;
            try
            {
                SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
                if (sWhere == null || sWhere.Equals(""))
                {
                    ds = oCN.RunProcReturn("select * from h_v_MES_StationOutBillList ", "h_v_MES_StationInBillList");
                }
                else
                {
                    string sql1 = "select * from h_v_MES_StationOutBillList where 1 = 1 ";
                    string sql = sql1 + sWhere;
                    ds = oCN.RunProcReturn(sql, "h_v_MES_StationOutBillList");
                }
 
            }
            catch (Exception e)
            {
                ds = null;
            }
            return GetObjectJson(ds);
        }
 
        /// <summary>
        /// 返回工序委外发出单列表
        ///参数:string sql。
        ///返回值:object。
        /// </summary>
        [Route("LEMS/MES_StationEntrustInBillList_Json")]
        [HttpGet]
        public object MES_StationEntrustInBillList_Json(string sWhere)
        {
            DataSet ds;
            try
            {
                SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
                if (sWhere == null || sWhere.Equals(""))
                {
                    ds = oCN.RunProcReturn("select * from h_v_MES_StationEntrustInBillList ", "h_v_MES_StationEntrustInBillList");
                }
                else
                {
                    string sql1 = "select * from h_v_MES_StationEntrustInBillList where 1 = 1 ";
                    string sql = sql1 + sWhere;
                    ds = oCN.RunProcReturn(sql, "h_v_MES_StationEntrustInBillList");
                }
 
            }
            catch (Exception e)
            {
                ds = null;
            }
            return GetObjectJson(ds);
        }
 
        /// <summary>
        /// 返回工艺路线列表
        ///参数:string sql。
        ///返回值:object。
        /// </summary>
        [Route("LEMS/MES_Gy_RoutingBillList_Json")]
        [HttpGet]
        public object MES_Gy_RoutingBillList_Json(string sWhere)
        {
            DataSet ds;
            try
            {
                SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
                if (sWhere == null || sWhere.Equals(""))
                {
                    ds = oCN.RunProcReturn("select * from h_v_Gy_RoutingBillList ", "h_v_Gy_RoutingBillList");
                }
                else
                {
                    string sql1 = "select * from h_v_Gy_RoutingBillList where 1 = 1 ";
                    string sql = sql1 + sWhere;
                    ds = oCN.RunProcReturn(sql, "h_v_Gy_RoutingBillList");
                }
 
            }
            catch (Exception e)
            {
                ds = null;
            }
            return GetObjectJson(ds);
        }
 
        /// <summary>
        /// 返回生产任务单列表
        ///参数:string sql。
        ///返回值:object。
        /// </summary>
        [Route("LEMS/MES_IF_ICMOBillList_Json")]
        [HttpGet]
        public object MES_IF_ICMOBillList_Json(string sWhere)
        {
            DataSet ds;
            try
            {
                SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
                if (sWhere == null || sWhere.Equals(""))
                {
                    ds = oCN.RunProcReturn("select * from h_v_IF_ICMOBillList ", "h_v_IF_ICMOBillList");
                }
                else
                {
                    string sql1 = "select * from h_v_IF_ICMOBillList where 1 = 1 ";
                    string sql = sql1 + sWhere;
                    ds = oCN.RunProcReturn(sql, "h_v_IF_ICMOBillList");
                }
 
            }
            catch (Exception e)
            {
                ds = null;
            }
            return GetObjectJson(ds);
        }
 
        /// <summary>
        /// 返回工序委外接收单列表
        ///参数:string sql。
        ///返回值:object。
        /// </summary>
        [Route("LEMS/MES_StationEntrustOutBillList_Json")]
        [HttpGet]
        public object MES_StationEntrustOutBillList_Json(string sWhere)
        {
            DataSet ds;
            try
            {
                SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
                if (sWhere == null || sWhere.Equals(""))
                {
                    ds = oCN.RunProcReturn("select * from h_v_MES_StationEntrustOutBillList ", "h_v_MES_StationEntrustOutBillList");
                }
                else
                {
                    string sql1 = "select * from h_v_MES_StationEntrustOutBillList where 1 = 1 ";
                    string sql = sql1 + sWhere;
                    ds = oCN.RunProcReturn(sql, "h_v_MES_StationEntrustOutBillList");
                }
 
            }
            catch (Exception e)
            {
                ds = null;
            }
            return GetObjectJson(ds);
        }
 
        ///<summary>
        ///封装状态码及返回信息的公用方法。
        ///参数:DataSet。
        ///返回值:json。
        ///</summary>
        public object GetObjectJson(DataSet ds)
        {
            try
            {
                if (ds == null || ds.Tables[0].Rows.Count <= 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "没有返回任何记录!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                else
                {
                    objJsonResult.code = "0";
                    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;
            }
        }
 
        ///<summary>
        ///自定义错误信息方法。
        ///参数:string。
        ///返回值:object。
        ///</summary>
        public object CustomError(string msg)
        {
            objJsonResult.code = "0";
            objJsonResult.count = 0;
            objJsonResult.Message = msg;
            objJsonResult.data = null;
            return objJsonResult;
        }
 
        ///<summary>
        ///统一正确信息方法。
        ///参数:string。
        ///返回值:object。
        ///</summary>
        public object CustomCorrect(DataSet ds)
        {
            if (ds == null || ds.Tables[0].Rows.Count <= 0)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "没有返回任何记录!";
                objJsonResult.data = null;
                return objJsonResult;
            }
            else
            {
                objJsonResult.code = "0";
                objJsonResult.count = 1;
                objJsonResult.Message = "获取信息成功!";
                objJsonResult.data = ds.Tables[0];
                return objJsonResult;
            }
        }
 
        /// <summary>
        /// 返回选择生产班组列表
        ///参数:string sql。
        ///返回值:object。
        /// </summary>
        [Route("LEMS/MES_GetProductionTeamList_Json")]
        [HttpGet]
        public object MES_GetProductionTeamList_Json(string sWhere)
        {
            DataSet ds;
            try
            {
                SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
                ds = oCN.RunProcReturn("Select HItemID,HNumber 班组代码,HName 班组 from h_v_IF_Group where HStopflag=0 " + sWhere + " Order by HItemID ", "h_v_IF_Group");
            }
            catch (Exception e)
            {
                ds = null;
            }
            return GetObjectJson(ds);
        }
 
        /// <summary>
        /// 返回选择生产资源列表
        ///参数:string sql。
        ///返回值:object。
        /// </summary>
        [Route("LEMS/MES_GetProductionResourcesList_Json")]
        [HttpGet]
        public object MES_GetProductionResourcesList_Json(string sWhere)
        {
            DataSet ds;
            try
            {
                SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
                ds = oCN.RunProcReturn("Select HItemID,HNumber 生产资源代码,HName 生产资源 from Gy_Source where HStopflag=0 " + sWhere + " Order by HItemID ", "Gy_Source");
            }
            catch (Exception e)
            {
                ds = null;
            }
            return GetObjectJson(ds);
        }
 
        /// <summary>
        /// 扫条码方法(进站接收单、出站汇报单)
        ///参数:string sql。
        ///返回值:object。
        /// </summary>
        [Route("LEMS/TxtHBarCode_KeyDown")]
        [HttpGet]
        public object TxtHBarCode_KeyDown(string sBillBarCode)
        {
            DataSet ds;
            try
            {
                SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
                if (sBillBarCode == null || sBillBarCode.Equals(""))
                {
                    return CustomError("未输入条形码!");
                }
                else
                {
                    //拆分条形码
                    string[] NewBarCode;
                    if (sBillBarCode.CompareTo("#") > 0)
                    {
                        NewBarCode = sBillBarCode.Split(Convert.ToChar("#"));
                        sBillBarCode = NewBarCode[0];
                    }
                    string sBillNo = sBillBarCode;
                    ds = oCN.RunProcReturn("select top 1 * from h_v_Sc_ProcessExchangeBillList  where 单据号= '" + sBillNo + "'", "h_v_Sc_ProcessExchangeBillList");
 
                }
 
            }
            catch (Exception e)
            {
                ds = null;
            }
            return CustomCorrect(ds);
        }
 
        /// <summary>
        /// 流水号回车方法(进站接收单、出站汇报单)
        ///参数:string sql。
        ///返回值:object。
        /// </summary>
        [Route("LEMS/TxtHProcNo_KeyDown")]
        [HttpGet]
        public object TxtHProcNo_KeyDown(string sProcNo, string sBillNo)
        {
            DataSet ds;
            try
            {
                SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
                if (sProcNo == null || sProcNo.Equals("") || sBillNo == null || sBillNo.Equals(""))
                {
                    return CustomError("流水号或流转卡号为空!");
                }
                else
                {
                    ds = oCN.RunProcReturn("select top 1 * from h_v_Sc_ProcessExchangeBillList  where 单据号= '" + sBillNo + "' and 下道流转工序<>'转' and 委外标记=0 and 流转标记=1  and 工序号='" + sProcNo + "'", "h_v_Sc_ProcessExchangeBillList");
                }
 
            }
            catch (Exception e)
            {
                ds = null;
            }
            return CustomCorrect(ds);
        }
 
        
        /// <summary>
        /// 保存提交方法
        ///参数:string sql。
        ///返回值:object。
        /// </summary>
        [Route("LEMS/Sub_SaveBill_Json")]
        [HttpPost]
        public object Sub_SaveBill_Json([FromBody]JObject oMain)
        {
            var _value = oMain["oMain"].ToString();
            string msg1 = _value.ToString();
            try
            {
                List<Model.ClsSc_StationInBillSub> lsmain = new List<Model.ClsSc_StationInBillSub>();
                //反序列化
                msg1 = "[" + msg1.ToString() + "]";
                List<Model.ClsSc_StationInBillSub> list = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Model.ClsSc_StationInBillSub>>(msg1);
 
                DAL.ClsSc_StationInBill BillNew = new DAL.ClsSc_StationInBill();
                DAL.ClsSc_StationInBill BillOld = new DAL.ClsSc_StationInBill();
                bool bResult;
                //赋值ID
                if (BillStatus == DBUtility.ClsPub.Enum_BillStatus.BillStatus_Modify)
                    BillNew.omodel.HInterID = BillOld.omodel.HInterID;
                BillNew.omodel.HYear = 2011;
                BillNew.omodel.HPeriod = 1;
                //BillNew.omodel.HBillNo = DBUtility.ClsPub.isStrNull(list[0].HBillNo);
                //BillNew.omodel.HICMOBillNo = this.txtHICMOBillNo.Text.Trim();
                //BillNew.omodel.HICMOInterID = DBUtility.ClsPub.isLong(this.txtHICMOBillNo.Tag);
                //BillNew.omodel.HProcExchInterID = lngBillKey;
                //BillNew.omodel.HProcExchEntryID = lngBillSubKey;
                //BillNew.omodel.HProcExchBillNo = this.txtHProcExchBillNo.Text.Trim();
                //BillNew.omodel.HProcID = DBUtility.ClsPub.isLong(this.txtHProcID.Tag);
                //BillNew.omodel.HMaterID = DBUtility.ClsPub.isLong(this.txtHMaterID.Tag);
                //BillNew.omodel.HStationInTime = DBUtility.ClsPub.isDate(this.txtHStationInTime.Text);
                //BillNew.omodel.HEmpID = DBUtility.ClsPub.isLong(this.txtHEmpID.Tag);
                //BillNew.omodel.HSourceID = DBUtility.ClsPub.isLong(this.txtHSourceID.Tag);
                //BillNew.omodel.HGroupID = DBUtility.ClsPub.isLong(this.txtHGroupID.Tag);
                //BillNew.omodel.HICMOQty = DBUtility.ClsPub.isDoule(this.txtHICMOQty.Text);
                //BillNew.omodel.HPlanQty = DBUtility.ClsPub.isDoule(this.txtHPlanQty.Text);
                //BillNew.omodel.HQty = DBUtility.ClsPub.isDoule(this.txtHQty.Text);
                //BillNew.omodel.HPieceQty = DBUtility.ClsPub.isDoule(this.txtHPieceQty.Text);
                //BillNew.omodel.HSourceName = DBUtility.ClsPub.isStrNull(this.txtHSourceName.Text);
                //BillNew.omodel.HCenterID = DBUtility.ClsPub.isLong(this.txtHCenterID.Tag);
 
                //BillNew.omodel.HProcNo = DBUtility.ClsPub.isLong(this.txtHProcNo.Text);
                //BillNew.omodel.HOrderProcNO = DBUtility.ClsPub.isStrNull(this.txtHOrderProcNO.Text);
 
                //保存完毕后处理
                if (BillStatus == DBUtility.ClsPub.Enum_BillStatus.BillStatus_AddNew)
                {
                    bResult = BillNew.AddBill(ref ClsPub.sExeReturnInfo);
                }
                else
                {
                    bResult = BillNew.ModifyBill(BillNew.omodel.HInterID, ref ClsPub.sExeReturnInfo);
                }
                if (bResult == true)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "生成汇报单成功!单据号为:";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                else
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "上传失败!" + DBUtility.ClsPub.sErrInfo;
                    objJsonResult.data = null;
                    return objJsonResult;
                }
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "上传失败!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
 
        //以下是工序出站汇报单单据方法-----------
        
 
    //
    }
}