yangle
2023-10-31 52e9c09747672c7d185e17dd6461900f67a97ee4
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
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}')");
 
            objJsonResult.code = "1";
            objJsonResult.count = 1;
            objJsonResult.Message = null;
            objJsonResult.data = null;
            return objJsonResult;
        }
        #endregion
    }
}