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
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
{
    public class Gy_ICBomBillController : ApiController
    {
        public DBUtility.ClsPub.Enum_BillStatus BillStatus;
 
        private json objJsonResult = new json();
        SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
        DataSet ds;
        [Route("Gy_ICBomBill/Gy_ICBomBillaveApi")]
        [HttpPost]
        public object Gy_ICBomBillaveApi([FromBody] JObject oMain)
        {
            try
            {
                var model = oMain["model"].ToString();
                var subModel = oMain["model"]["HENTRY"].ToString();
                //反序列化
                model = "[" + model + "]";
                List<Model.ClsGy_ICBomBillMain> mainList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Model.ClsGy_ICBomBillMain>>(model);
                List<Model.ClsGy_ICBomBillSub> subList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Model.ClsGy_ICBomBillSub>>(subModel);
                string sql = string.Empty;
                oCN.BeginTran();
                sql = $"delete Gy_ICBomBillMain where HinterID = {mainList[0].HInterID}";
                oCN.RunProc(sql);
                sql = $"delete Gy_ICBomBillSub where HinterID = {mainList[0].HInterID}";
                oCN.RunProc(sql);
                mainList[0].HBillNo =  DBUtility.ClsPub.CreateBillCode("3302", ref DBUtility.ClsPub.sExeReturnInfo,true);
                oCN.RunProc("Insert Into Gy_ICBomBillMain   " +
                "(HBillType,HInterID,HBillNo,HDate" +
                ",HYear,HPeriod,HRemark,HMaker,HMakeDate,HMaterTypeID,HStatus" +
                ",HMaterID,HParentID,HVersion,HPicNo,HPropertyID" +
                ",HUnitID,HQty,HProdRate,HJump" +
                ") " +
                " values('" + mainList[0].HBillType + "'," + mainList[0].HInterID.ToString() + ",'" + mainList[0].HBillNo + "','" + mainList[0].HDate + "'" +
                "," + mainList[0].HYear.ToString() + "," + mainList[0].HPeriod.ToString() + ",'" + mainList[0].HRemark + "','" + DBUtility.ClsPub.CurUserName + "',getdate(),'" + mainList[0].HMaterTypeID.ToString() + "','" + mainList[0].HStatus +
                "','" + mainList[0].HMaterID.ToString() + "'," + mainList[0].HParentID.ToString() + ",'" + mainList[0].HVersion + "','" + mainList[0].HPicNo + "'," + mainList[0].HPropertyID.ToString() +
                "," + mainList[0].HUnitID.ToString() + "," + mainList[0].HQty.ToString() + "," + mainList[0].HProdRate.ToString() + ",'" + mainList[0].HJump + "'" +
                ") ");
                //插入子表
                foreach (Model.ClsGy_ICBomBillSub oSub in subList)
                {
                    oCN.RunProc("Insert into Gy_ICBomBillSub " +
                      " (HInterID,HEntryID,HMaterID,HRemark2" +
                      ",HQty,HUnitID,HRemark3,HRelQty,HWasteRate" +
                      ",HProcID,HWhID,HRemark4,HChildType," +
                      "HCloseMan,HCloseType,HRemark," +
                      "HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HRelationQty,HRelationMoney" +
                      ") values("
                      + oSub.HInterID.ToString() + "," + oSub.HEntryID.ToString() + "," + oSub.HMaterID.ToString() + ",'" + oSub.HRemark2 + "'" +
                      "," + oSub.HQty.ToString() + "," + oSub.HUnitID.ToString() + ",'" + oSub.HRemark3 + "'," + oSub.HRelQty.ToString() + "," + oSub.HWasteRate.ToString() +
                      "," + oSub.HProcID.ToString() + "," + oSub.HWhID.ToString() + ",'" + oSub.HRemark4 + "','" + oSub.HChildType.ToString() + "'" +
                      ",'" + oSub.HCloseMan + "'," + Convert.ToString(oSub.HCloseType ? 1 : 0) + ",'" + oSub.HRemark + "'" +
                      "," + oSub.HSourceInterID.ToString() + "," + oSub.HSourceEntryID.ToString() + ",'" + oSub.HSourceBillNo + "','" + oSub.HSourceBillType + "'," + oSub.HRelationQty.ToString() + "," + oSub.HRelationMoney.ToString() +
                      ") ");
                }
                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;
            }
        }
    }
}