ch
2021-07-02 3e291c359a5ee1a024ccf4daa1c8694d0b1acc3c
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
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Data;
using System.Web.Http;
using WebAPI.Models;
using Pub_Class;
namespace WebAPI.Controllers
{
    /**
     * 找货单单
     */
    public class Sc_MouldOtherInBillController : ApiController
    {
        private json objJsonResult = new json();
        public DataSet ds = new DataSet();
        public WebServer webserver = new WebServer();
        SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
 
        /// <summary>
        /// 根据包装单 返回此包装单内的相关信息
        /// </summary>
        /// <returns></returns>
 
        /// <summary>
        /// 模具其他入库单列表
        /// </summary>
        /// <returns></returns>
        [Route("Sc_MouldOtherInBill/GetMouldOtherInBillList")]
        [HttpGet]
        public object GetMouldOtherInBillList(string sWhere)
        {
            try
            {
 
                ds = Sc_MouldOtherInBillList_s(sWhere);
                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 ex)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "没有返回任何记录!" + ex.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
 
        #region sql语句
 
 
        public static DataSet Sc_MouldOtherInBillList_s(string sWhere)
        {
            return new SQLHelper.ClsCN().RunProcReturn("select * from h_v_Sc_MouldOtherInBillList ", "h_v_Sc_MouldOtherInBillList");
        }
 
 
 
 
        #endregion
 
        /// <summary>
        /// 修改单据-保存按钮
        ///参数:string sql。
        ///返回值:object。
        /// </summary>
        [Route("Sc_MouldOtherInBill/AddBill1")]
        [HttpPost]
        public object AddBill1([FromBody] JObject oMain)
        {
 
            try
            {
                DAL.ClsSc_MouldOtherInBill oMould = new DAL.ClsSc_MouldOtherInBill();
 
                var _value = oMain["oMain"].ToString();
                string msg1 = _value.ToString();
                string[] sArray = msg1.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
                string msg2 = sArray[0].ToString();
                string msg3 = sArray[1].ToString();
                string msg4 = sArray[2].ToString();
                string msg5 = sArray[3].ToString();
                //反序列化
                msg2 = "[" + msg2.ToString() + "]";
                List<Sc_MouldStockBillMain> list = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Sc_MouldStockBillMain>>(msg2);
 
                long HItemID = list[0].HInterID;
                string HBillNo = list[0].HBillNo;
                DateTime HDate = list[0].HDate;
                long HSCWHID = list[0].HSCWHID;
                long HWHID = list[0].HWHID;
                long HSupID = list[0].HSupID;
                long HSecManagerID = list[0].HSecManagerID;
                long HRepairID = list[0].HRepairID;
                long HManagerID = list[0].HManagerID;
                string HUpDater = list[0].HUpDater;
                long HDeptID = list[0].HDeptID;
 
 
 
               
 
 
                //若MAINDI重复则重新获取
                oCN.BeginTran();
                //主表
                oCN.RunProc("Update Sc_MouldStockBillMain set " +
                    " HSCWHID=" + HSCWHID +
                    ",HWHID=" + HWHID +
                    ",HSupID=" + HSupID +
                    ",HSecManagerID=" + HSecManagerID +
                    ",HManagerID= " + HManagerID + " Where HInterID=" + HItemID, ref DBUtility.ClsPub.sExeReturnInfo);
                //修改子项目代码
                //oCN.RunProc("exec h_p_Gy_UpdateNumber Gy_EquipMent,'" + HNumber + ".','" + this.HOldNumber + ".'", ref DBUtility.ClsPub.sExeReturnInfo);
                //将上级 为非末级
                //oCN.RunProc("Update Gy_EquipMent set HEndflag=0 where HItemID=" + HParentID, ref DBUtility.ClsPub.sExeReturnInfo);
                //
                oCN.Commit();
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "修改单据成功!";
                //objJsonResult.data = null;
                return objJsonResult;
            }
            catch (Exception e)
            {
                oCN.RollBack();
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "Exception!" + e.Message;
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
 
 
 
        /// <summary>
        /// 模具入库单列表删除按钮
        ///参数:string sql。
        ///返回值:object。
        /// </summary>
        [Route("Sc_MouldOtherInBill/Delete_Json")]
        [HttpGet]
        public object Delete_Json(long HItemID)
        {
            DAL.ClsSc_MouldOtherInBill oMould = new DAL.ClsSc_MouldOtherInBill();
            try
            {
                if (oMould.omodel.HBillStatus > 1)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "单据当前处于不能删除状态,不能删除!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                if (oMould.omodel.HChecker != "")
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "单据已经审核,不能删除!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                    //
                    if (oMould.DeleteBill(HItemID, ref DBUtility.ClsPub.sExeReturnInfo))
                    {
                        //写入日志
                        ClsPub.Add_Log("", "删除项目,代码:" + oMould.omodel.HNumber + ",名称:" + oMould.omodel.HName, ClsPub.CurUserName);
                        //更新上级为 末级
                        objJsonResult.code = "1";
                        objJsonResult.count = 1;
                        objJsonResult.Message = "删除成功";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                    else
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "删除失败";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                //ds = oCN.RunProcReturn("delete from Gy_Department where HItemID =  " + HItemID, "Gy_Department");
 
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "删除成功";
                objJsonResult.data = null;
                return objJsonResult;
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "Exception!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
 
 
 
 
/// <summary>
/// 新增单据-保存按钮
///参数:string sql。
///返回值:object。
/// </summary>
[Route("Sc_MouldOtherInBill/AddBill")]
        [HttpPost]
        public object AddBill([FromBody] JObject sMainSub)
        {
            var _value = sMainSub["sMainSub"].ToString();
            string msg1 = _value.ToString();
            oCN.BeginTran();
            //保存主表
            objJsonResult = AddBillMain(msg1);
            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 = "新增单据成功!";
            objJsonResult.data = null;
            return objJsonResult;
        }
 
        public json AddBillMain(string msg1)
        {
            string[] sArray = msg1.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
            string msg2 = sArray[0].ToString();
            string msg3 = sArray[1].ToString();
            try
            {
                msg2 = "[" + msg2.ToString() + "]";
                List<Sc_MouldStockBillMain> mainList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Sc_MouldStockBillMain>>(msg2);
                string BillType = "3795";
                long HInterID = mainList[0].HInterID;//递入type得到的单据ID
                string HBillNo = mainList[0].HBillNo;//递入type得到的单据号
                DateTime HDate = mainList[0].HDate;//日期
                int HYear = 2021;
                double HPeriod = 1;
                string HRemark = mainList[0].HRemark;//备注
                string HMaker = mainList[0].HMaker;//制单人
                long HSCWHID = mainList[0].HSCWHID;//
                long HSupID = mainList[0].HSupID;//
                long HEmpID = mainList[0].HEmpID;
                long HManagerID = mainList[0].HManagerID;//
                long HWHID = mainList[0].HWHID;//
                long HProcID = mainList[0].HProcID;//
                long HSecManagerID = mainList[0].HSecManagerID;//
                long HKeeperID = mainList[0].HKeeperID;//
                long HDeptID = mainList[0].HDeptID;
                string HExplanation = mainList[0].HExplanation;//
                string HInnerBillNo = mainList[0].HInnerBillNo;//
                string HRedBlueFlag = mainList[0].HRedBlueFlag;//
                string HRepairType = mainList[0].HRepairType;//
                long HRepairID = mainList[0].HRepairID;//
 
                //主表
                oCN.RunProc("Insert Into Sc_MouldStockBillMain   " +
                "(HBillType,HBillSubType,HInterID,HBillNo,HDate" +
                ",HYear,HPeriod,HRemark,HMaker,HMakeDate" +
                ",HSupID,HWHID,HSCWHID,HEmpID,HManagerID,HSecManagerID" +
                ",HKeeperID,HDeptID,HExplanation,HInnerBillNo,HRedBlueFlag" +
                ") " +
                " values('" + BillType + "','" + BillType + "'," + HInterID + ",'" + HBillNo + "','" + HDate + "'" +
                "," + HYear + "," + HPeriod + ",'" + HRemark + "','" + HMaker + "',getdate()" + 
                "," + HSupID + "," + HWHID + "," + HSCWHID + "," + HEmpID + "," + HManagerID + "," + HSecManagerID +
                "," + HKeeperID + "," + HDeptID + ",'" + HExplanation + "','" + HInnerBillNo + "','" + HRedBlueFlag + "'" +
                ") ");
 
                //保存子表
                objJsonResult = AddBillSub(msg3, HInterID);
                if (objJsonResult.code == "0")
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = objJsonResult.Message;
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                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(string msg3, long HInterID)
        {
            List<Sc_MouldStockBillSub> subList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Sc_MouldStockBillSub>>(msg3);
            for (int i = 0; i < subList.ToArray().Length; i++)
            {
                long HMaterID = 0;//物料ID
                long HPropertyID = 0;//
                long HSecUnitID = 0;//
                long HUnitID = 0;//
                long HWHID = 0;//
                long HSCWHID = 0;//
                long HSPID = 0;//
                long HSCSPID = 0;//
                long HSPGroupID = 0;//
                long HLifeUnitID = 0;//
 
                oCN.RunProc("Insert into Sc_MouldStockBillSub " +
                         " (HInterID,HEntryID,HCloseMan,HEntryCloseDate,HCloseType,HRemark" +
                      ",HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HRelationQty,HRelationMoney" +
                      ",HMaterID,HPropertyID,HSecUnitID,HSecUnitRate,HUnitID,HQtyMust" +
                      ",HQty,HPrice,HMoney,HWHID,HSCWHID,HSPID" +
                      ",HDesignLife,HLeaveLife,HUseLife,HUseLifeQty" +
                      ",HSCSPID,HSPGroupID,HBatchNo" +
                      ",HNewModel,HWallThickness,HHardness,HLastProdModel,HDiameter,HBackFlag" +
                        ",HQtyRel,HNewLifeQty,HNowModel,HNowLife" +
                        ",HMouldType,HInitModel,HInitDesignLife,HLifeUnitID" +
                         ") values("
                      + HInterID + "," + i + ",'','','','" + subList[i].HRemark + "'" +
                      "," + subList[i].HSourceInterID + "," + subList[i].HSourceEntryID + ",'" + subList[i].HSourceBillNo + "','" + subList[i].HSourceBillType + "','" + subList[i].HrelationQty + "','" + subList[i].HrelationQty + "'" +
                      "," + HMaterID + "," + HPropertyID + "," + HSecUnitID + ",'" + subList[i].HSecUnitRate + "','" + HUnitID + "','" + subList[i].HQtyMust + "'" +
                      ",'" + subList[i].HQty + "','" + subList[i].HPrice + "','" + subList[i].HMoney + "'," + HWHID + "," + HSCWHID + "," + HSPID +
                      ",'" + subList[i].HDesignLife + "','" + subList[i].HLeaveLife + "','" + subList[i].HUseLife + "','" + subList[i].HUseLifeQty + "'" +
                      "," + HSCSPID + "," + HSPGroupID + ",'" + subList[i].HBatchNo + "'" + 
                     ",'" + subList[i].HNewModel + "','" + subList[i].HWallThickness + "','" + subList[i].HHardness + "','" + subList[i].HLastProdModel + "','" + subList[i].HDiameter + "','" + subList[i].HBackFlag + "'" +
                     ",'" + subList[i].HQtyRel + "','" + subList[i].HNewLifeQty + "','" + subList[i].HNowModel + "','" + subList[i].HNowLife + "'" +
                     ",'" + subList[i].HMouldType + "','" + subList[i].HInitModel + "','" + subList[i].HInitDesignLife + "'," + HLifeUnitID +
                     ") ");
            }
 
            objJsonResult.code = "1";
            objJsonResult.count = 1;
            objJsonResult.Message = null;
            objJsonResult.data = null;
            return objJsonResult;
        }
 
 
    }
}