| 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; | 
|             } | 
|         } | 
|     } | 
| } |