沈泽
2021-08-30 6dbb4801f817b738fddcde730919db972636544b
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
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
{
    //质量汇报单Controller
    //数据库主表Sc_QualityReportBillMain
    //数据库子表Sc_QualityReportBillSub
    public class Sc_QualityReportBillController : ApiController
    {
        public DBUtility.ClsPub.Enum_BillStatus BillStatus;
        private json objJsonResult = new json();
        SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
        DataSet ds;
 
        #region 返回生产质量汇报单列表
        [Route("Sc_QualityReportBill/list")]
        [HttpGet]
        public object list(string sWhere)
        {
            try
            {
                if (sWhere == null || sWhere.Equals(""))
                {
                    ds = oCN.RunProcReturn("select * from h_v_Sc_QualityReportBillListDetail " + sWhere, "h_v_Sc_QualityReportBillListDetail");
                }
                else
                {
                    string sql1 = "select * from h_v_Sc_QualityReportBillListDetail where 1 = 1 ";
                    string sql = sql1 + sWhere;
                    ds = oCN.RunProcReturn(sql, "h_v_Sc_QualityReportBillListDetail");
                }
                if (ds == null || ds.Tables[0].Rows.Count == 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "false!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                else
                {
                    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 质量汇报单根据源单类型获取信息-源单为生产状态临时表(3722)
        [Route("Sc_QualityReportBill/get_ICMOBillStatus_Tmp")]
        [HttpGet]
        public object get_ICMOBillStatus_Tmp(int HInterID, int HEntryID, string HBillType)
        {
            try
            {
                if (HInterID == 0 || HBillType.Equals(""))
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "参数不全,获取源单信息失败!HInterID:" + HInterID + ";HEntryID:" + HEntryID + ";HBillType:" + HBillType + ";";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                else
                {
                    ds = oCN.RunProcReturn
                        ("select a.HInterID,a.HBillType,a.HICMOBillNo,a.HICMOInterID,a.HMaterID" +
                        ",m.HNumber HMaterNumber,m.HName HMaterName,m.HModel HMaterModel " +
                        " from Sc_ICMOBillStatus_Tmp a " +
                        " left join Gy_Material m on a.HMaterID=m.HItemID " +
                        " Where a.HInterID=" + HInterID + " and a.HBillType="+ HBillType, "Sc_ICMOBillStatus_Tmp");
                }
                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 = "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("Sc_QualityReportBill/set_SaveBarCode")]
        [HttpPost]
        public object set_SaveBarCode([FromBody] JObject oMain)
        {
            var msg1 = oMain["oMain"].ToString();
            //保存单据
            return objJsonResult = AddBillMain(msg1);
        }
 
        public json AddBillMain(string msg1)
        {
            string[] sArray = msg1.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
            string msg = sArray[0].ToString();
            string OperationType = sArray[1].ToString().Trim();
            bool bResult;
            try
            {
                msg = "[" + msg.ToString() + "]";
                List<Model.ClsSc_ICMOBillQualityStatus_Tmp> mainList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Model.ClsSc_ICMOBillQualityStatus_Tmp>>(msg);
                DAL.ClsQC_FirstPieceCheckBill BillNew = new DAL.ClsQC_FirstPieceCheckBill();
                //判断会计期是否合理
                string s = "";
                int sYear = 0;
                int sPeriod = 0;
                DateTime HDate = mainList[0].HMakeDate;
                if (DBUtility.Xt_BaseBillFun.Fun_AllowYearPeriod(HDate, ref sYear, ref sPeriod, ref s) == false)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = s;
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                BillNew.omodel.HYear = sYear;
                BillNew.omodel.HPeriod = sPeriod;
                //固定赋值=================================
                BillNew.omodel.HInterID = mainList[0].HInterID;//递入type得到的单据ID
                //BillNew.omodel.HBillNo = mainList[0].HBillNo;//递入type得到的单据号
                //BillNew.omodel.HDate = HDate;
                //BillNew.omodel.HRemark = mainList[0].HRemark;//备注
                //BillNew.omodel.HMaker = mainList[0].HMaker;
                //BillNew.omodel.HSourceID = ClsPub.isLong(mainList[0].HSourceID);
                //BillNew.omodel.HICMOInterID = ClsPub.isLong(mainList[0].HICMOInterID);
                //BillNew.omodel.HICMOBillNo = ClsPub.isStrNull(mainList[0].HICMOBillNo);
                //BillNew.omodel.HICMOInterID = ClsPub.isLong(mainList[0].HICMOInterID);
                //BillNew.omodel.HICMOQty = ClsPub.isLong(mainList[0].HICMOQty);
                //BillNew.omodel.HProcExchInterID = ClsPub.isLong(mainList[0].HProcExchInterID);
                //BillNew.omodel.HProcExchEntryID = ClsPub.isLong(mainList[0].HProcExchEntryID);
                //BillNew.omodel.HProcExchBillNo = ClsPub.isStrNull(mainList[0].HProcExchBillNo);
                //BillNew.omodel.HProcExchQty = ClsPub.isLong(mainList[0].HProcExchQty);
                //BillNew.omodel.HMaterID = ClsPub.isLong(mainList[0].HMaterID);
                //BillNew.omodel.HFirstCheckEmp = ClsPub.isLong(mainList[0].HFirstCheckEmp);
                //BillNew.omodel.HLastResult = ClsPub.isBool(mainList[0].HLastResult);
                //BillNew.omodel.HMainSourceInterID = ClsPub.isLong(mainList[0].HMainSourceInterID);
                //BillNew.omodel.HMainSourceEntryID = ClsPub.isLong(mainList[0].HMainSourceEntryID);
                //BillNew.omodel.HMainSourceBillNo = ClsPub.isStrNull(mainList[0].HMainSourceBillNo);
                //BillNew.omodel.HMainSourceBillType = ClsPub.isStrNull(mainList[0].HMainSourceBillType);
                BillNew.omodel.HBillStatus = 1;
                //保存完毕后处理
                if (OperationType.Equals("1") || OperationType.Equals("2"))
                {
                    bResult = BillNew.AddBill(ref ClsPub.sExeReturnInfo);
                }
                else if (OperationType.Equals("3"))
                {
                    bResult = BillNew.ModifyBill(BillNew.omodel.HInterID, ref ClsPub.sExeReturnInfo);
                }
                else
                {
                    ClsPub.sExeReturnInfo = "无效的操作类型!";
                    bResult = false;
                }
                //提示
                if (bResult == true)
                {
                    objJsonResult.code = "1";
                    objJsonResult.count = 1;
                    //objJsonResult.Message = "单据存盘完毕!单据号:" + mainList[0].HBillNo.Trim();
                    objJsonResult.Message = ClsPub.sExeReturnInfo + "单据号:" ;
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                else
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "保存失败!原因:" + ClsPub.sExeReturnInfo;
                    objJsonResult.data = null;
                    return objJsonResult;
                }
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "Exception!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
 
    }
}