| using Model.生产管理; | 
| 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 | 
| { | 
|     //生产用料Controller | 
|     public class Sc_PPBomBillController : ApiController | 
|     { | 
|         //获取系统参数 | 
|         Pub_Class.ClsXt_SystemParameter oSystemParameter = new Pub_Class.ClsXt_SystemParameter(); | 
|         public DBUtility.ClsPub.Enum_BillStatus BillStatus; | 
|   | 
|         private json objJsonResult = new json(); | 
|         SQLHelper.ClsCN oCN = new SQLHelper.ClsCN(); | 
|         DataSet ds; | 
|   | 
|   | 
|         /// <summary> | 
|         /// 返回生产用料清单列表 | 
|         ///参数:string sql。 | 
|         ///返回值:object。 | 
|         /// </summary> | 
|         [Route("Sc_PPBomBill/list")] | 
|         [HttpGet] | 
|         public object list(string sWhere, string user) | 
|         { | 
|             try | 
|             { | 
|                 List<object> a = new List<object>(); | 
|                 //判断是否有查询权限 | 
|                 if (!DBUtility.ClsPub.Security_Log("Sc_PPBomBillList_Query", 1, false, user)) | 
|                 { | 
|                     objJsonResult.code = "0"; | 
|                     objJsonResult.count = 0; | 
|                     objJsonResult.Message = "无权限查询!"; | 
|                     objJsonResult.data = null; | 
|                     return objJsonResult; | 
|                 } | 
|   | 
|                 if (sWhere == null || sWhere.Equals("")) | 
|                 { | 
|                     ds = oCN.RunProcReturn("select * from h_v_IF_PPBomBillList order by hmainid desc ", "h_v_IF_PPBomBillList"); | 
|                 } | 
|                 else | 
|                 { | 
|                     string sql1 = "select * from h_v_IF_PPBomBillList where 1 = 1 "; | 
|                     string sql = sql1 + sWhere + " order by hmainid desc "; | 
|                     ds = oCN.RunProcReturn(sql, "h_v_IF_PPBomBillList"); | 
|                 } | 
|                 foreach (DataColumn col in ds.Tables[0].Columns)//遍历ds中第一个表(Tables[0])的所有列(Columns)每次循环中,col变量会持有当前列的引用 | 
|                 { | 
|                     Type dataType = col.DataType; //获取当前数据类型传入 自定义变量datadataType | 
|                     string ColmString = "{\"ColmCols\":\"" + col.ColumnName + "\",\"ColmType\":\"" + dataType.Name + "\"}"; //字符串拼接         // 将列名和数据类型信息拼接成一个JSON格式的字符串 | 
|                     a.Add(JsonConvert.DeserializeObject(ColmString));//获取到DataColumn列对象的列名 | 
|                 } | 
|   | 
|                 //if (ds.Tables[0].Rows.Count != 0 || ds != null) | 
|                 //{ | 
|                 objJsonResult.code = "1"; | 
|                 objJsonResult.count = 1; | 
|                 objJsonResult.Message = "Sucess!"; | 
|                 objJsonResult.data = ds.Tables[0]; | 
|                 objJsonResult.list = a; | 
|                 return objJsonResult; | 
|                 //} | 
|                 //else | 
|                 //{ | 
|                 //objJsonResult.code = "0"; | 
|                 //objJsonResult.count = 0; | 
|                 //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; | 
|             } | 
|         } | 
|   | 
|         [Route("Sc_PPBomBill/Editlist")] | 
|         [HttpGet] | 
|         public object Editlist(string sWhere) | 
|         { | 
|             try | 
|             { | 
|                 List<object> a = new List<object>(); | 
|                 //判断是否有查询权限 | 
|                 | 
|   | 
|                 if (sWhere == null || sWhere.Equals("")) | 
|                 { | 
|                     ds = oCN.RunProcReturn("select * from h_v_IF_PPBomBillList order by hmainid desc ", "h_v_IF_PPBomBillList"); | 
|                 } | 
|                 else | 
|                 { | 
|                     string sql1 = "select * from h_v_IF_PPBomBillList where 1 = 1 "; | 
|                     string sql = sql1 + sWhere + " order by hmainid desc "; | 
|                     ds = oCN.RunProcReturn(sql, "h_v_IF_PPBomBillList"); | 
|                 } | 
|                 foreach (DataColumn col in ds.Tables[0].Columns)//遍历ds中第一个表(Tables[0])的所有列(Columns)每次循环中,col变量会持有当前列的引用 | 
|                 { | 
|                     Type dataType = col.DataType; //获取当前数据类型传入 自定义变量datadataType | 
|                     string ColmString = "{\"ColmCols\":\"" + col.ColumnName + "\",\"ColmType\":\"" + dataType.Name + "\"}"; //字符串拼接         // 将列名和数据类型信息拼接成一个JSON格式的字符串 | 
|                     a.Add(JsonConvert.DeserializeObject(ColmString));//获取到DataColumn列对象的列名 | 
|                 } | 
|   | 
|                 objJsonResult.code = "1"; | 
|                 objJsonResult.count = 1; | 
|                 objJsonResult.Message = "Sucess!"; | 
|                 objJsonResult.data = ds.Tables[0]; | 
|                 objJsonResult.list = a; | 
|                 return objJsonResult; | 
|             } | 
|             catch (Exception e) | 
|             { | 
|                 objJsonResult.code = "0"; | 
|                 objJsonResult.count = 0; | 
|                 objJsonResult.Message = "Exception!" + e.ToString(); | 
|                 objJsonResult.data = null; | 
|                 return objJsonResult; | 
|             } | 
|         } | 
|   | 
|   | 
|         #region 生产用料清单列表分页列表 | 
|         [Route("Sc_PPBomBill/page")] | 
|         [HttpGet] | 
|         public object page(string sWhere, string user,int page,int size) | 
|         { | 
|             try | 
|             { | 
|                 List<object> columnNameList = new List<object>(); | 
|                 //编辑权限 | 
|                 if (!DBUtility.ClsPub.Security_Log_second("Sc_PPBomBillList_Query", 1, false, user)) | 
|                 { | 
|                     objJsonResult.code = "0"; | 
|                     objJsonResult.count = 0; | 
|                     objJsonResult.Message = "无查看权限!"; | 
|                     objJsonResult.data = null; | 
|                     return objJsonResult; | 
|                 } | 
|                 if (sWhere == null || sWhere.Equals("")) | 
|                 { | 
|                     ds = oCN.RunProcReturn("exec h_p_Sc_PPBomBillList " + page + "," + size + "," + "''", "h_p_Sc_PPBomBillList"); | 
|                 } | 
|                 else | 
|                 { | 
|                     ds = oCN.RunProcReturn("exec h_p_Sc_PPBomBillList " + page + "," + size + ",'"  + sWhere + "'", "h_p_Sc_PPBomBillList"); | 
|                 } | 
|   | 
|                 //添加列名 | 
|                 foreach (DataColumn col in ds.Tables[0].Columns) | 
|                 { | 
|                     Type dataType = col.DataType; | 
|                     string ColmString = "{\"ColmCols\":\"" + col.ColumnName + "\",\"ColmType\":\"" + dataType.Name + "\"}"; | 
|                     columnNameList.Add(JsonConvert.DeserializeObject(ColmString));//获取到DataColumn列对象的列名 | 
|                 } | 
|   | 
|                 objJsonResult.code = "1"; | 
|                 objJsonResult.count = int.Parse(ds.Tables[1].Rows[0]["count"].ToString()); | 
|                 objJsonResult.Message = "Sucess!"; | 
|                 objJsonResult.list = columnNameList; | 
|                 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("Sc_PPBomBill/DeOrAuditBill")] | 
|         [HttpGet] | 
|         public object DeOrAuditBill(int HInterID, int IsAudit, string CurUserName) | 
|         { | 
|             string ModRightNameCheck = "Sc_PPBomBillList_Check"; //该模块的审核功能 | 
|             DBUtility.ClsPub.CurUserName = CurUserName;//存储用户名 | 
|             try | 
|             { | 
|                 //判断是否有审核权限 | 
|                 if (!DBUtility.ClsPub.Security_Log_second(ModRightNameCheck, 1, false, CurUserName)) | 
|                 { | 
|                     objJsonResult.code = "0"; | 
|                     objJsonResult.count = 0; | 
|                     objJsonResult.Message = "审核失败!无权限!"; | 
|                     objJsonResult.data = null; | 
|                     return objJsonResult; | 
|                 } | 
|   | 
|                 //判断id是否小于0 | 
|                 if (HInterID <= 0) | 
|                 { | 
|                     objJsonResult.code = "0"; | 
|                     objJsonResult.count = 0; | 
|                     objJsonResult.Message = "ID小于0"; | 
|                     objJsonResult.data = null; | 
|                     return objJsonResult; | 
|                 } | 
|   | 
|                 Int64 lngBillKey = 0; | 
|                 lngBillKey = DBUtility.ClsPub.isLong(HInterID); | 
|   | 
|                 //查询审核的这条数据 | 
|                 ds = oCN.RunProcReturn("select *  from  Sc_PPBomBillMain where HInterID=" + lngBillKey, "Sc_PPBomBillMain"); | 
|                 if (ds.Tables[0].Rows.Count != 0) | 
|                 { | 
|                     var HChecker = ds.Tables[0].Rows[0]["HChecker"].ToString().Trim(); | 
|                     //审核 | 
|                     if (IsAudit == 0) | 
|                     { | 
|                         if (HChecker != "") | 
|                         { | 
|                             objJsonResult.code = "0"; | 
|                             objJsonResult.count = 0; | 
|                             objJsonResult.Message = "单据已审核,不能再次审核!"; | 
|                             objJsonResult.data = null; | 
|                             return objJsonResult; | 
|                         } | 
|                     } | 
|   | 
|                     if (IsAudit == 1) | 
|                     { | 
|                         if (HChecker == "") | 
|                         { | 
|                             objJsonResult.code = "0"; | 
|                             objJsonResult.count = 0; | 
|                             objJsonResult.Message = "单据未审核,不能反审核!"; | 
|                             objJsonResult.data = null; | 
|                             return objJsonResult; | 
|                         } | 
|                     } | 
|                 } | 
|                 else | 
|                 { | 
|                     objJsonResult.code = "0"; | 
|                     objJsonResult.count = 0; | 
|                     objJsonResult.Message = "单据不存在,原因:" + DBUtility.ClsPub.sExeReturnInfo; | 
|                     objJsonResult.data = null; | 
|                     return objJsonResult; | 
|                 } | 
|   | 
|                 //审核提交 | 
|                 if (IsAudit == 0) | 
|                 { | 
|                     if (CheckBill(lngBillKey, ref DBUtility.ClsPub.sExeReturnInfo)) | 
|                     { | 
|                         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; | 
|                     } | 
|                 } | 
|                 //反审核 | 
|                 if (IsAudit == 1) | 
|                 { | 
|                     if (AbandonCheck(lngBillKey, ref DBUtility.ClsPub.sExeReturnInfo)) | 
|                     { | 
|                         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; | 
|                     } | 
|                 } | 
|                 return objJsonResult; | 
|             } | 
|             catch (Exception e) | 
|             { | 
|                 objJsonResult.code = "0"; | 
|                 objJsonResult.count = 0; | 
|                 objJsonResult.Message = "审核失败或反审核失败" + e.ToString(); | 
|                 objJsonResult.data = null; | 
|                 return objJsonResult; | 
|             } | 
|         } | 
|         //审核 | 
|         public bool CheckBill(Int64 lngBillKey, ref string sReturn) | 
|         { | 
|             try | 
|             { | 
|                 string HChecker = DBUtility.ClsPub.CurUserName;//用户名 | 
|                 oCN.BeginTran();//打开事务 | 
|                 oCN.RunProc("update Sc_PPBomBillMain set HBillStatus=2,hchecker='" + HChecker + "',hcheckdate='" + DateTime.Now + "' where  HInterID=" + lngBillKey); | 
|                 oCN.Commit();//关闭事务 | 
|                 sReturn = "审核成功"; | 
|                 return true; | 
|             } | 
|             catch (Exception e) | 
|             { | 
|                 sReturn = e.Message; | 
|                 throw (e); | 
|             } | 
|         } | 
|         //反审核 | 
|         public bool AbandonCheck(Int64 lngBillKey, ref string sReturn) | 
|         { | 
|             try | 
|             { | 
|                 string HChecker = DBUtility.ClsPub.CurUserName;//用户名 | 
|                 oCN.BeginTran();//打开事务 | 
|                 oCN.RunProc("update Sc_PPBomBillMain set HBillStatus=1,hchecker='',hcheckdate=null where  HInterID=" + lngBillKey); | 
|                 oCN.Commit();//关闭事务 | 
|                 sReturn = "反审核成功"; | 
|                 return true; | 
|             } | 
|             catch (Exception e) | 
|             { | 
|                 sReturn = e.Message; | 
|                 throw (e); | 
|             } | 
|         } | 
|         #endregion | 
|   | 
|         #region 生产用料单 保存/编辑功能 新方法 | 
|         [Route("Sc_PPBomBill/sc_PPBomBillAdd")] | 
|         [HttpPost] | 
|         public object sc_PPBomBillAdd([FromBody] JObject sMainSub) | 
|         { | 
|             var _value = sMainSub["sMainSub"].ToString(); | 
|             string msg1 = _value.ToString(); | 
|             string[] sArray = msg1.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries); | 
|           | 
|             try | 
|             { | 
|                 string msg2 = sArray[0].ToString(); //主表数据 | 
|                 string msg3 = sArray[1].ToString(); //子表数据 | 
|                 int OperationType = int.Parse(sArray[2].ToString()); // 数据类型 1添加 3修改 | 
|                 string user = sArray[3].ToString(); | 
|   | 
|                 //判断是否有编辑权限 | 
|                 if (!DBUtility.ClsPub.Security_Log("QC_TestSampleCheckBill_Edit", 1, false, user)) | 
|                 { | 
|                     objJsonResult.code = "0"; | 
|                     objJsonResult.count = 0; | 
|                     objJsonResult.Message = "无编辑权限!"; | 
|                     objJsonResult.data = null; | 
|                     return objJsonResult; | 
|                 } | 
|   | 
|                 ClsSc_PPBomBillMain list = Newtonsoft.Json.JsonConvert.DeserializeObject<ClsSc_PPBomBillMain>(msg2); | 
|                 string BillType = "3720"; | 
|                 string HBillSubType = "3720"; | 
|                 long HInterID = list.HInterID;//递入type得到的单据ID | 
|                 string HBillNo = list.HBillNo;//递入type得到的单据号 | 
|                 int HBillStatus = 1; | 
|                 string HMaker = user;//制单人 | 
|                 int HYear = DateTime.Now.Year; | 
|                 double HPeriod = DateTime.Now.Month; | 
|                 long HICMOInterID = list.HICMOInterID;//任务单ID | 
|                 long HICMOEntryID = list.HICMOEntryID;//任务单ID | 
|                 string HICMOBillNo = list.HICMOBillNo;//任务单ID | 
|                 long HMaterID = list.HMaterID;//产品ID | 
|                 long HUnitID = list.HUnitID;//计量单位 | 
|                 long HPRDORGID = list.HPRDORGID;//组织ID | 
|                 long HICMOEntrySEQ = list.HICMOEntrySEQ;  | 
|                 DateTime HDate = list.HDate;  | 
|                 double HQty = list.HQty; | 
|                 long HDeptID = list.HDeptID; | 
|                 string HRemark = list.HRemark; | 
|                 string HChecker = ""; | 
|                 string HCheckDate = ""; | 
|                 string HSeOrderBillNo = ""; | 
|                 long HSeOrderInterID = 0; | 
|                 long HSeOrderEntryID = 0; | 
|                 long HENTRUSTORGID = 0; | 
|                 long HPARENTOWNERID = 0; | 
|                 long HPARENTOWNERTYPEID = 0; | 
|                 long HERPInterID = 0; | 
|                 long HSeOrderEntrySEQ = 0; | 
|                 string HERPBillType = ""; | 
|                 string HREQSRC = ""; | 
|   | 
|                 oCN.BeginTran(); | 
|                 if (OperationType== 1) | 
|                 { | 
|                     ds = oCN.RunProcReturn("select * from Sc_PPBomBillMain where HBillNo='" + HBillNo + "'", "Sc_PPBomBillMain"); | 
|                     if (ds.Tables[0].Rows.Count == 1) | 
|                     { | 
|                         oCN.RollBack(); | 
|                         objJsonResult.code = "0"; | 
|                         objJsonResult.count = 0; | 
|                         objJsonResult.Message = "单据号重复!"; | 
|                         objJsonResult.data = null; | 
|                         return objJsonResult; | 
|                     } | 
|                     //主表 | 
|                     oCN.RunProc(@"Insert Into Sc_PPBomBillMain    | 
|                         (HInterID,HYear,HPeriod,HBillType,HBillSubType,HDate,HBillNo,HBillStatus,HICMOInterID | 
|                         ,HICMOEntryID,HMaterID,HUnitID,HQty,HDeptID,HMaker,HMakeDate,HChecker,HCheckDate | 
|                         ,HSeOrderBillNo,HSeOrderInterID,HSeOrderEntryID,HPRDORGID,HENTRUSTORGID,HPARENTOWNERID | 
|                         ,HPARENTOWNERTYPEID,HERPInterID,HERPBillType,HSeOrderEntrySEQ,HICMOEntrySEQ,HREQSRC,HRemark) | 
|                         values(" + HInterID + "," + DateTime.Now.Year + "," + DateTime.Now.Month + ",'" + BillType + "','" + | 
|                     HBillSubType + "','" + HDate + "','" + HBillNo + "','" + HBillStatus + "'," + HICMOInterID + | 
|                     "," + HICMOEntryID + ",'" + HMaterID + "'," + HUnitID + "," + HQty + "," + HDeptID + | 
|                     ",'" + HMaker + "',getdate(),'" + HChecker + "','" + HCheckDate + "','" + HSeOrderBillNo + "'," + HSeOrderInterID + "," + HSeOrderEntryID + "," + HPRDORGID + "," + HENTRUSTORGID + "," + HPARENTOWNERID + "," + | 
|                     HPARENTOWNERTYPEID + "," + HERPInterID + ",'" + HERPBillType + "'," + HSeOrderEntrySEQ + "," + HICMOEntrySEQ + ",'" + HREQSRC + "','"+ HRemark + "')"); | 
|                 } | 
|                 else  if (OperationType == 3 ) | 
|                 { //修改 | 
|                     oCN.RunProc("update Sc_PPBomBillMain  set " + | 
|                                 "HRemark='" + HRemark + "', HChecker='" + HMaker + "', HCheckDate=getdate()" + | 
|                                 ",HDeptID=" + HDeptID + ",HICMOInterID=" + HICMOInterID + ",HICMOEntryID=" + HICMOEntryID + ",HMaterID=" + HMaterID + ",HUnitID=" + HUnitID + ",HICMOEntrySEQ=" + HICMOEntrySEQ + " ,HQty=" + HQty + " where HInterID=" + HInterID); | 
|   | 
|                     //删除子表 | 
|                     oCN.RunProc("delete from Sc_PPBomBillSub where HInterID='" + HInterID + "'"); | 
|                 } | 
|                 else | 
|                 { | 
|                     oCN.RollBack(); | 
|                     objJsonResult.code = "0"; | 
|                     objJsonResult.count = 0; | 
|                     objJsonResult.Message = "操作类型无效!"; | 
|                     objJsonResult.data = null; | 
|                     return objJsonResult; | 
|                 } | 
|   | 
|                 List<ClsSc_PPBomBillSub> DetailColl = Newtonsoft.Json.JsonConvert.DeserializeObject<List<ClsSc_PPBomBillSub>>(msg3); | 
|                 int i = 0; | 
|                 foreach (ClsSc_PPBomBillSub oSub in DetailColl) | 
|                 { | 
|                     i++; | 
|                     string HMaterNumber = oSub.HMaterNumber; | 
|                     string HUnitNumber = oSub.HUnitNumber; | 
|                     long HQtyMust = 0; | 
|                     long HSourceInterID = oSub.HSourceInterID; | 
|                     long HSourceEntryID = oSub.HSourceEntryID; | 
|                     long HCHILDSUPPLYORGID = oSub.HCHILDSUPPLYORGID; | 
|                     long HSUPPLYORGID = oSub.HSUPPLYORGID; | 
|                     long HENTRUSTPICKORGID = oSub.HENTRUSTPICKORGID; | 
|                     long HSRCTRANSORGID = oSub.HSRCTRANSORGID; | 
|                     long HGROUPBYOWNERID = oSub.HGROUPBYOWNERID; | 
|                     long HOWNERID = oSub.HOWNERID; | 
|                     long HAuxPropID = oSub.HAuxPropID; | 
|                     long HERPEntryID = oSub.HERPEntryID; | 
|                     long HProcessID = oSub.HProcessID; | 
|                     long HICMOENTRYSEQ = oSub.HICMOENTRYSEQ; | 
|                     long HOPERID = oSub.HOPERID; | 
|                     long HSEQ = i; | 
|                     long HSTOCKSTATUSID = oSub.HSTOCKSTATUSID; | 
|                     long HOPTQUEUE = oSub.HOPTQUEUE; | 
|                     long HLOT = oSub.HLOT; | 
|                     long HRESERVETYPE = oSub.HRESERVETYPE; | 
|                     string HOWNERTYPEID = oSub.HOWNERTYPEID; | 
|                     double HRelationQty = oSub.HRelationQty; | 
|                     double HMoveStockQty = oSub.HMoveStockQty; | 
|                     double HQtyScrap = oSub.HQtyScrap; | 
|                     double HBackRelationQty = oSub.HBackRelationQty; | 
|                     double HNumerator = oSub.HNumerator; | 
|                     double HDenominator = oSub.HDenominator; | 
|                     double HSelPickedQty = oSub.HSelPickedQty; | 
|                     double HSELPRCDRETURNQTY = oSub.HSELPRCDRETURNQTY; | 
|                     string HSourceBillNo = oSub.HSourceBillNo; | 
|                     string HSourceBillType = oSub.HSourceBillType; | 
|                     string HBatchNO = oSub.HBatchNO; | 
|                     string HMTONo = oSub.HMTONo; | 
|                     string HPROJECTNO = oSub.HPROJECTNO; | 
|   | 
|                     if (oSub.HQty <= 0 || oSub.HQty == null) | 
|                     { | 
|                         objJsonResult.code = "0"; | 
|                         objJsonResult.count = 0; | 
|                         objJsonResult.Message = "第" + i + "行,数量不能为0或者小于0"; | 
|                         objJsonResult.data = null; | 
|                         return objJsonResult; | 
|                     } | 
|   | 
|                     if (oSub.HMaterID == 0) | 
|                     { | 
|                         objJsonResult.code = "0"; | 
|                         objJsonResult.count = 0; | 
|                         objJsonResult.Message = "第" + i + "行,物料不能为空"; | 
|                         objJsonResult.data = null; | 
|                         return objJsonResult; | 
|                     } | 
|   | 
|                     if (oSub.HUnitID == 0) | 
|                     { | 
|                         objJsonResult.code = "0"; | 
|                         objJsonResult.count = 0; | 
|                         objJsonResult.Message = "第" + i + "行,计量单位不能为空"; | 
|                         objJsonResult.data = null; | 
|                         return objJsonResult; | 
|                     } | 
|   | 
|                     Int64 NewHEntryID = i; | 
|   | 
|                     oCN.RunProc($@"Insert into Sc_PPBomBillSub  | 
|                 (HInterID,HEntryID,HMaterID,HMaterNumber,HUnitID,HUnitNumber,HSPID,HQty,HQtyMust,HWHID,HRemark | 
|                 ,HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HICMOInterID,HICMOEntryID,HICMOBillNo | 
|                 ,HCHILDSUPPLYORGID,HSUPPLYORGID,HENTRUSTPICKORGID,HSRCTRANSORGID,HGROUPBYOWNERID,HOWNERID,HOWNERTYPEID | 
|                 ,HRelationQty,HMoveStockQty,HAuxPropID,HBatchNO,HMTONo,HQtyScrap,HERPInterID,HERPEntryID | 
|                 ,HBackRelationQty,HNumerator,HDenominator,HBASEUNITID,HProcessID,HICMOENTRYSEQ,HPROJECTNO | 
|                 ,HOPERID,HSEQ,HSTOCKSTATUSID,HLOT,HOPTQUEUE,HRESERVETYPE,HSelPickedQty,HSELPRCDRETURNQTY)  | 
|                  values({HInterID},{NewHEntryID},{oSub.HMaterID},'{HMaterNumber}',{oSub.HUnitID},'{HUnitNumber}',{oSub.HSPID},{(oSub.HQty == null ? 0 : oSub.HQty)} | 
|                 ,{HQtyMust},{oSub.HWHID},'{oSub.HRemark}',{HSourceInterID},{HSourceEntryID},'{HSourceBillNo}','{HSourceBillType}',{HICMOInterID},{HICMOEntryID},'{HICMOBillNo}',{HCHILDSUPPLYORGID},{HSUPPLYORGID},{HENTRUSTPICKORGID},{HSRCTRANSORGID},{HGROUPBYOWNERID},{HOWNERID},'{HOWNERTYPEID}',{HRelationQty},{HMoveStockQty},{HAuxPropID},'{HBatchNO}','{HMTONo}',{HQtyScrap},{HERPInterID}, | 
|                   {HERPEntryID},{HBackRelationQty},{HNumerator},{HDenominator},{oSub.HBASEUNITID},{HProcessID},{HICMOENTRYSEQ},'{HPROJECTNO}',{HOPERID},{HSEQ},{HSTOCKSTATUSID},{HLOT},{HOPTQUEUE},{HRESERVETYPE},{HSelPickedQty},{HSELPRCDRETURNQTY})"); | 
|                 } | 
|   | 
|   | 
|   | 
|                 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.ToString(); | 
|                 objJsonResult.data = null; | 
|                 return objJsonResult; | 
|             } | 
|         } | 
|   | 
|         | 
|   | 
|         #endregion | 
|   | 
|         #region 生产用料单 保存/编辑功能 | 
|         [Route("Sc_PPBomBill/PPBomBillEdit")] | 
|         [HttpPost] | 
|         public object PPBomBillEdit([FromBody] JObject sMainSub) | 
|         { | 
|             try | 
|             { | 
|                 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; | 
|   | 
|             } | 
|             catch (Exception e) | 
|             { | 
|                 oCN.RollBack(); | 
|                 objJsonResult.code = "0"; | 
|                 objJsonResult.count = 0; | 
|                 objJsonResult.Message = "保存失败!" + e.ToString(); | 
|                 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(); //子表数据 | 
|             int OperationType = int.Parse(sArray[2].ToString()); // 数据类型 1添加 3修改 | 
|             string user = sArray[3].ToString(); | 
|             string msg_allVal = sArray[4].ToString(); //主表+子表所有数据 | 
|   | 
|             try | 
|             { | 
|                 msg2 = "[" + msg2.ToString() + "]"; | 
|                 List<ClsSc_PPBomBillMain> mainList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<ClsSc_PPBomBillMain>>(msg2); | 
|   | 
|                 string HBillNo = mainList[0].HBillNo;     //单据号 | 
|                 long HMaterID = mainList[0].HMaterID;  //物料 | 
|                 long HUnitID = mainList[0].HUnitID;  //计量单位 | 
|                 long HDeptID = mainList[0].HDeptID;    //部门 | 
|                 DateTime HDate = mainList[0].HDate;  //日期 | 
|                 double HQty = mainList[0].HQty;  //数量 | 
|                 string HRemark = mainList[0].HRemark;   //备注 | 
|   | 
|   | 
|                 List<ClsSc_PPBomBillMain> mainList2 = Newtonsoft.Json.JsonConvert.DeserializeObject<List<ClsSc_PPBomBillMain>>(msg2); | 
|                 DateTime dt = DateTime.Now; | 
|   | 
|                 long HYear = mainList2[0].HYear == null ? 0 : mainList2[0].HYear; | 
|                 long HPeriod = mainList2[0].HPeriod == null ? 0 : mainList2[0].HPeriod; | 
|                 string HBillType = mainList2[0].HBillType == null ? "''" : mainList2[0].HBillType; // 单据类型 | 
|                 string HBillSubType = mainList2[0].HBillSubType == null ? "''" : mainList2[0].HBillSubType; // 子类型 | 
|                 long HInterID = mainList2[0].HInterID == null ? 0 : mainList2[0].HInterID; | 
|                 long HBillStatus = mainList2[0].HBillStatus == null ? 0 : mainList2[0].HBillStatus;        //单据状态 | 
|                 long HCheckItemNextID = mainList2[0].HCheckItemNextID == null ? 0 : mainList2[0].HCheckItemNextID;  //待审核项目(默认值 0) | 
|                 long HCheckFlowID = mainList2[0].HCheckFlowID == null ? 0 : mainList2[0].HCheckFlowID;  //审批流(默认值 0)  界面上不需要显示 | 
|                 string HBacker = mainList2[0].HBacker == null ? "''" : mainList2[0].HBacker; //退回人  (默认为'') | 
|                 string HBackDate = mainList2[0].HBackDate == null ? "''" : mainList2[0].HBackDate;  //退回日期 (允许NULL) | 
|                 string HChecker = mainList2[0].HChecker == null ? "''" : mainList2[0].HChecker;   //审核人 (默认为'') | 
|                 string HCheckDate = mainList2[0].HCheckDate == null ? "''" : mainList2[0].HCheckDate;          //审核日期 (允许NULL) | 
|                 string HMaker = mainList2[0].HMaker == null ? "''" : mainList2[0].HMaker;          //制单人 | 
|                 string HMakeDate = mainList2[0].HMakeDate == null ? "''" : mainList2[0].HMakeDate;             //制单日期 | 
|                 string HUpDater = mainList2[0].HUpDater == null ? "''" : mainList2[0].HUpDater;                 //修改人 (默认为'') | 
|                 string HUpDateDate = mainList2[0].HUpDateDate == null ? "''" : mainList2[0].HUpDateDate;         //修改日期 (允许NULL) | 
|                 string HCloseMan = mainList2[0].HCloseMan == null ? "''" : mainList2[0].HCloseMan;          //关闭人 (默认为'') | 
|                 string HCloseDate = mainList2[0].HCloseDate == null ? "''" : mainList2[0].HCloseDate;         //关闭日期 (允许NULL) | 
|                 long HCloseType = mainList2[0].HCloseType == null ? 0 : mainList2[0].HCloseType;           //关闭类型   (默认为0) | 
|                 string HDeleteMan = mainList2[0].HDeleteMan == null ? "''" : mainList2[0].HDeleteMan;           //作废人 (默认为'') | 
|                 string HDeleteDate = mainList2[0].HDeleteDate == null ? "''" : mainList2[0].HDeleteDate;           //作废日期 (允许NULL) | 
|                 long HICMOInterID = mainList2[0].HICMOInterID == null ? 0 : mainList2[0].HICMOInterID;  //生产订单内码 | 
|                 long HCheckItemNowID = mainList2[0].HCheckItemNowID == null ? 0 : mainList2[0].HCheckItemNowID;      //当前审核项目(默认值 0) | 
|                 long HSeOrderInterID = mainList2[0].HSeOrderInterID == null ? 0 : mainList2[0].HSeOrderInterID;  //销售订单内码 | 
|                 long HSeOrderEntryID = mainList2[0].HSeOrderEntryID == null ? 0 : mainList2[0].HSeOrderEntryID;  //销售订单子内码 | 
|                 string HSeOrderBillNo = mainList2[0].HSeOrderBillNo == null ? "''" : mainList2[0].HSeOrderBillNo;  //销售订单号 | 
|                 string HType = mainList2[0].HType == null ? "''" : mainList2[0].HType; // 类型(可能是 委外和生产) | 
|                 long HSeOrderEntrySEQ = mainList2[0].HSeOrderEntrySEQ == null ? 0 : mainList2[0].HSeOrderEntrySEQ;  //销售订单行号 | 
|                 long HICMOEntrySEQ = mainList2[0].HICMOEntrySEQ == null ? 0 : mainList2[0].HICMOEntrySEQ;  //生产订单行号 | 
|                 string HREQSRC = mainList2[0].HREQSRC == null ? "''" : mainList2[0].HREQSRC;   //需求来源 | 
|   | 
|                 long HICMOEntryID = mainList2[0].HICMOEntryID == null ? 0 : mainList2[0].HICMOEntryID; | 
|                 long HPRDORGID = mainList2[0].HPRDORGID == null ? 0 : mainList2[0].HPRDORGID; | 
|                 long HENTRUSTORGID = mainList2[0].HENTRUSTORGID == null ? 0 : mainList2[0].HENTRUSTORGID; | 
|                 long HPARENTOWNERID = mainList2[0].HPARENTOWNERID == null ? 0 : mainList2[0].HPARENTOWNERID; | 
|                 string HPARENTOWNERTYPEID = mainList2[0].HPARENTOWNERTYPEID == null ? "''" : mainList2[0].HPARENTOWNERTYPEID; | 
|                 long HERPInterID = mainList2[0].HERPInterID == null ? 0 : mainList2[0].HERPInterID; | 
|                 string HERPBillType = mainList2[0].HERPBillType == null ? "''" : mainList2[0].HERPBillType; | 
|   | 
|   | 
|                 ds = oCN.RunProcReturn("select * from h_v_IF_PPBomBillList where hmainid=" + HInterID + " and 单据号='" + HBillNo + "'", "h_v_IF_PPBomBillList"); | 
|   | 
|                 if ((OperationType == 1 || OperationType == 2) && ds.Tables[0].Rows.Count == 0)//新增 | 
|                 { | 
|                     //主表 | 
|                     oCN.RunProc(@"Insert Into Sc_PPBomBillMain    | 
|                         (HInterID,HYear,HPeriod,HBillType,HBillSubType,HDate,HBillNo,HBillStatus,HICMOInterID | 
|                         ,HICMOEntryID,HMaterID,HUnitID,HQty,HDeptID,HMaker,HMakeDate,HChecker,HCheckDate | 
|                         ,HSeOrderBillNo,HSeOrderInterID,HSeOrderEntryID,HPRDORGID,HENTRUSTORGID,HPARENTOWNERID | 
|                         ,HPARENTOWNERTYPEID,HERPInterID,HERPBillType,HSeOrderEntrySEQ,HICMOEntrySEQ,HREQSRC) | 
|                         values(" + HInterID + "," + DateTime.Now.Year + "," + DateTime.Now.Month + ",'" + 3720 + "','" + | 
|                     HBillSubType + "','" + HDate + "','" + HBillNo + "','" + HBillStatus + "'," + HICMOInterID + | 
|                     "," + HICMOEntryID + ",'" + HMaterID + "'," + HUnitID + "," + HQty + "," + HDeptID + | 
|                     ",'" + HMaker + "','" + HMakeDate + "','" + HChecker + "','" + HCheckDate + "','" + HSeOrderBillNo + "'," + HSeOrderInterID + "," + HSeOrderEntryID + "," + HPRDORGID + "," + HENTRUSTORGID + "," + HPARENTOWNERID + "," + | 
|                     HPARENTOWNERTYPEID + "," + HERPInterID + ",'" + HERPBillType + "'," + HSeOrderEntrySEQ + "," + HICMOEntrySEQ + ",'" + HREQSRC + "')"); | 
|                 } | 
|                 else if (OperationType == 3 || ds.Tables[0].Rows.Count != 0) | 
|                 { //修改 | 
|                     oCN.RunProc("update Sc_PPBomBillMain  set " + | 
|                                 "HRemark='" + HRemark + "', HChecker='" + HMaker + "', HCheckDate=getdate()" + | 
|                                 ",HDeptID=" + HDeptID + " where HInterID=" + HInterID); | 
|   | 
|                     //删除子表 | 
|                     oCN.RunProc("delete from Sc_PPBomBillSub where HInterID='" + HInterID + "'"); | 
|                 } | 
|                 //保存子表 | 
|                 objJsonResult = AddBillSub(msg3, HInterID, OperationType); | 
|   | 
|                 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, int OperationType) | 
|         { | 
|             List<ClsSc_PPBomBillSub> DetailColl = Newtonsoft.Json.JsonConvert.DeserializeObject<List<ClsSc_PPBomBillSub>>(msg3); | 
|   | 
|             List<ClsSc_PPBomBillSub> DetailColl2 = Newtonsoft.Json.JsonConvert.DeserializeObject<List<ClsSc_PPBomBillSub>>(msg3); | 
|   | 
|             DateTime dt = DateTime.Now; | 
|   | 
|             decimal HQtyMust = DetailColl2[0].HQtyMust == null ? 0 : DetailColl2[0].HQtyMust; //应发数量 | 
|             double HNumerator = DetailColl2[0].HNumerator == null ? 0 : DetailColl2[0].HNumerator;  //分子 | 
|             double HDenominator = DetailColl2[0].HDenominator == null ? 0 : DetailColl2[0].HDenominator;  //分母 | 
|             double HQtyScrap = DetailColl2[0].HQtyScrap == null ? 0 : DetailColl2[0].HQtyScrap;  //损耗率 | 
|             DateTime HSendDate = DetailColl2[0].HSendDate == null ? dt : DetailColl2[0].HSendDate;  //发料日期 | 
|             long HBomInterID = DetailColl2[0].HBomInterID == null ? 0 : DetailColl2[0].HBomInterID; //BOM | 
|             long HProcID = DetailColl2[0].HProcID == null ? 0 : DetailColl2[0].HProcID;      //工序内码 | 
|             long HKeyMaterID_Line = DetailColl2[0].HKeyMaterID_Line == null ? 0 : DetailColl2[0].HKeyMaterID_Line;  //关键件绑定标记 | 
|             long HKeyMaterID_InStock = DetailColl2[0].HKeyMaterID_InStock == null ? 0 : DetailColl2[0].HKeyMaterID_InStock;     //关键件入库标记 | 
|             long HKeyMaterID_Ready = DetailColl2[0].HKeyMaterID_Ready == null ? 0 : DetailColl2[0].HKeyMaterID_Ready;  //关键件齐套标记 | 
|             long HICMOInterID = DetailColl2[0].HICMOInterID == null ? 0 : DetailColl2[0].HICMOInterID;   //任务单ID | 
|             string HICMOBillNo = DetailColl2[0].HICMOBillNo == null ? "''" : DetailColl2[0].HICMOBillNo;  //任务单号 | 
|             string HSeOrderBillNo = DetailColl2[0].HSeOrderBillNo == null ? "''" : DetailColl2[0].HSeOrderBillNo;  //(销售订单号) | 
|             long HSeOrderInterID = DetailColl2[0].HSeOrderInterID == null ? 0 : DetailColl2[0].HSeOrderInterID;    //(销售订单主内码) | 
|             long HSeOrderEntryID = DetailColl2[0].HSeOrderEntryID == null ? 0 : DetailColl2[0].HSeOrderEntryID;     //(销售订单子内码) | 
|             long HChangeTimes = DetailColl2[0].HChangeTimes == null ? 0 : DetailColl2[0].HChangeTimes;         //变更次数 | 
|             long HProcessID = DetailColl2[0].HProcessID == null ? 0 : DetailColl2[0].HProcessID; //作业, | 
|             long HICMOENTRYSEQ = DetailColl2[0].HICMOENTRYSEQ == null ? 0 : DetailColl2[0].HICMOENTRYSEQ;//生产订单行号, | 
|             long HICMOEntryID = DetailColl2[0].HICMOEntryID == null ? 0 : DetailColl2[0].HICMOEntryID;//生产订单子内码 | 
|             string HPROJECTNO = DetailColl2[0].HPROJECTNO == null ? "''" : DetailColl2[0].HPROJECTNO;  //项目编号, | 
|             long HOPERID = DetailColl2[0].HOPERID == null ? 0 : DetailColl2[0].HOPERID;//金蝶工序, | 
|             long HSEQ = DetailColl2[0].HSEQ == null ? 0 : DetailColl2[0].HSEQ;//行号, | 
|             long HSTOCKSTATUSID = DetailColl2[0].HSTOCKSTATUSID == null ? 0 : DetailColl2[0].HSTOCKSTATUSID; //库存状态, | 
|             long HLOT = DetailColl2[0].HLOT == null ? 0 : DetailColl2[0].HLOT; //批次内码, | 
|             long HOPTQUEUE = DetailColl2[0].HOPTQUEUE == null ? 0 : DetailColl2[0].HOPTQUEUE;//工序序列, | 
|             long HRESERVETYPE = DetailColl2[0].HRESERVETYPE == null ? 0 : DetailColl2[0].HRESERVETYPE;//预留类型, | 
|             double HSelPickedQty = DetailColl2[0].HSelPickedQty == null ? 0 : DetailColl2[0].HSelPickedQty; //领料选单数量, | 
|             double HSELPRCDRETURNQTY = DetailColl2[0].HSELPRCDRETURNQTY == null ? 0 : DetailColl2[0].HSELPRCDRETURNQTY;  //退料选单数量, | 
|             string HCloseMan = DetailColl2[0].HCloseMan == null ? "''" : DetailColl2[0].HCloseMan; //行关闭(默认为'') | 
|             DateTime HEntryCloseDate = DetailColl2[0].HEntryCloseDate == null ? dt : DetailColl2[0].HEntryCloseDate;    //行关闭(默认为'') | 
|             long HCloseType = DetailColl2[0].HCloseType == null ? 0 : DetailColl2[0].HCloseType; //关闭类型(默认为0) | 
|             long HSourceInterID = DetailColl2[0].HSourceInterID == null ? 0 : DetailColl2[0].HSourceInterID;     //源单ID | 
|             long HSourceEntryID = DetailColl2[0].HSourceEntryID == null ? 0 : DetailColl2[0].HSourceEntryID; //源单子ID | 
|             string HSourceBillNo = DetailColl2[0].HSourceBillNo == null ? "''" : DetailColl2[0].HSourceBillNo; //源单单号 | 
|             string HSourceBillType = DetailColl2[0].HSourceBillType == null ? "''" : DetailColl2[0].HSourceBillType; //源单类型 | 
|             double HRelationQty = DetailColl2[0].HRelationQty == null ? 0 : DetailColl2[0].HRelationQty;     //关联数量 | 
|             double HRelationMoney = DetailColl2[0].HRelationMoney == null ? 0 : DetailColl2[0].HRelationMoney; //关联金额 | 
|   | 
|   | 
|             long HCHILDSUPPLYORGID = DetailColl2[0].HCHILDSUPPLYORGID == null ? 0 : DetailColl2[0].HCHILDSUPPLYORGID; | 
|             long HSUPPLYORGID = DetailColl2[0].HSUPPLYORGID == null ? 0 : DetailColl2[0].HSUPPLYORGID; | 
|             long HENTRUSTPICKORGID = DetailColl2[0].HENTRUSTPICKORGID == null ? 0 : DetailColl2[0].HENTRUSTPICKORGID; | 
|             long HSRCTRANSORGID = DetailColl2[0].HSRCTRANSORGID == null ? 0 : DetailColl2[0].HSRCTRANSORGID; | 
|             long HGROUPBYOWNERID = DetailColl2[0].HGROUPBYOWNERID == null ? 0 : DetailColl2[0].HGROUPBYOWNERID; | 
|             long HOWNERID = DetailColl2[0].HOWNERID == null ? 0 : DetailColl2[0].HOWNERID; | 
|             long HAuxPropID = DetailColl2[0].HAuxPropID == null ? 0 : DetailColl2[0].HAuxPropID; | 
|             long HERPInterID = DetailColl2[0].HERPInterID == null ? 0 : DetailColl2[0].HERPInterID; | 
|             long HERPEntryID = DetailColl2[0].HERPEntryID == null ? 0 : DetailColl2[0].HERPEntryID; | 
|             double HMoveStockQty = DetailColl2[0].HMoveStockQty == null ? 0 : DetailColl2[0].HMoveStockQty; | 
|             double HBackRelationQty = DetailColl2[0].HBackRelationQty == null ? 0 : DetailColl2[0].HBackRelationQty; | 
|             string HOWNERTYPEID = DetailColl2[0].HOWNERTYPEID == null ? "''" : DetailColl2[0].HOWNERTYPEID; | 
|             string HBatchNO = DetailColl2[0].HBatchNO == null ? "''" : DetailColl2[0].HBatchNO; | 
|             string HMTONo = DetailColl2[0].HMTONo == null ? "''" : DetailColl2[0].HMTONo; | 
|   | 
|             string HRemark = DetailColl2[0].HRemark == null ? "''" : DetailColl2[0].HRemark; | 
|             string HMaterNumber = DetailColl2[0].HMaterNumber == null ? "''" : DetailColl2[0].HMaterNumber; | 
|             string HUnitNumber = DetailColl2[0].HUnitNumber == null ? "''" : DetailColl2[0].HUnitNumber; | 
|   | 
|             int i = 0; | 
|             foreach (ClsSc_PPBomBillSub oSub in DetailColl) | 
|             { | 
|                 i++; | 
|                 if (oSub.HQty <= 0 || oSub.HQty == null) | 
|                 { | 
|                     objJsonResult.code = "0"; | 
|                     objJsonResult.count = 0; | 
|                     objJsonResult.Message = "第" + i + "行,数量不能为0或者小于0"; | 
|                     objJsonResult.data = null; | 
|                     return objJsonResult; | 
|                 } | 
|   | 
|                 if (oSub.HMaterID == 0) | 
|                 { | 
|                     objJsonResult.code = "0"; | 
|                     objJsonResult.count = 0; | 
|                     objJsonResult.Message = "第" + i + "行,物料不能为空"; | 
|                     objJsonResult.data = null; | 
|                     return objJsonResult; | 
|                 } | 
|   | 
|                 //if (oSub.HSourceID == 0) | 
|                 //{ | 
|                 //    objJsonResult.code = "0"; | 
|                 //    objJsonResult.count = 0; | 
|                 //    objJsonResult.Message = "第" + i + "行,生产资源不能为空"; | 
|                 //    objJsonResult.data = null; | 
|                 //    return objJsonResult; | 
|                 //} | 
|   | 
|                 if (oSub.HUnitID == 0) | 
|                 { | 
|                     objJsonResult.code = "0"; | 
|                     objJsonResult.count = 0; | 
|                     objJsonResult.Message = "第" + i + "行,计量单位不能为空"; | 
|                     objJsonResult.data = null; | 
|                     return objJsonResult; | 
|                 } | 
|   | 
|                 DataSet Cs; | 
|                 Int64 NewHEntryID = 1; | 
|                 Cs = oCN.RunProcReturn("select MAX(HEntryID)HEntryID from Sc_PPBomBillSub", "Sc_PPBomBillSub"); | 
|                 if (Cs.Tables[0].Rows.Count != 0 && ClsPub.isLong(Cs.Tables[0].Rows[0]["HEntryID"].ToString()) != 0) | 
|                 { | 
|                     NewHEntryID = ClsPub.isLong(Cs.Tables[0].Rows[0]["HEntryID"].ToString()); | 
|                     NewHEntryID += 1; | 
|                 } | 
|   | 
|   | 
|                 oCN.RunProc($@"Insert into Sc_PPBomBillSub  | 
|                 (HInterID,HEntryID,HMaterID,HMaterNumber,HUnitID,HUnitNumber,HSPID,HQty,HQtyMust,HWHID,HRemark | 
|                 ,HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HICMOInterID,HICMOEntryID,HICMOBillNo | 
|                 ,HCHILDSUPPLYORGID,HSUPPLYORGID,HENTRUSTPICKORGID,HSRCTRANSORGID,HGROUPBYOWNERID,HOWNERID,HOWNERTYPEID | 
|                 ,HRelationQty,HMoveStockQty,HAuxPropID,HBatchNO,HMTONo,HQtyScrap,HERPInterID,HERPEntryID | 
|                 ,HBackRelationQty,HNumerator,HDenominator,HBASEUNITID,HProcessID,HICMOENTRYSEQ,HPROJECTNO | 
|                 ,HOPERID,HSEQ,HSTOCKSTATUSID,HLOT,HOPTQUEUE,HRESERVETYPE,HSelPickedQty,HSELPRCDRETURNQTY)  | 
|                  values({HInterID},{NewHEntryID},{oSub.HMaterID},'{HMaterNumber}',{oSub.HUnitID},'{HUnitNumber}',{oSub.HSPID},{(oSub.HQty == null ? 0 : oSub.HQty)} | 
|                 ,{HQtyMust},{oSub.HWHID},'{HRemark}',{HSourceInterID},{HSourceEntryID},{HSourceBillNo},{HSourceBillType},{HICMOInterID},{HICMOEntryID},{HICMOBillNo},{HCHILDSUPPLYORGID},{HSUPPLYORGID},{HENTRUSTPICKORGID},{HSRCTRANSORGID},{HGROUPBYOWNERID},{HOWNERID},{HOWNERTYPEID},{HRelationQty},{HMoveStockQty},{HAuxPropID},{HBatchNO},{HMTONo},{HQtyScrap},{HERPInterID}, | 
|                   {HERPEntryID},{HBackRelationQty},{HNumerator},{HDenominator},{oSub.HBASEUNITID},{HProcessID},{HICMOENTRYSEQ},{HPROJECTNO},{HOPERID},{HSEQ},{HSTOCKSTATUSID},{HLOT},{HOPTQUEUE},{HRESERVETYPE},{HSelPickedQty},{HSELPRCDRETURNQTY})"); | 
|             } | 
|   | 
|             objJsonResult.code = "1"; | 
|             objJsonResult.count = 1; | 
|             objJsonResult.Message = null; | 
|             objJsonResult.data = null; | 
|             return objJsonResult; | 
|         } | 
|   | 
|         [Route("Sc_PPBomBill/Sc_PPBomBillSaveApi")] | 
|         [HttpPost] | 
|         public object Sc_PPBomBillSaveApi([FromBody] JObject sMainSub) | 
|         { | 
|             try | 
|             { | 
|                 var model = sMainSub["model"].ToString(); | 
|                 var entry = sMainSub["model"]["HENTRY"].ToString(); | 
|                 | 
|   | 
|                 model = "[" + model.ToString() + "]"; | 
|                 List<ClsSc_PPBomBillMain> mainList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<ClsSc_PPBomBillMain>>(model); | 
|                 List<ClsSc_PPBomBillSub> subList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<ClsSc_PPBomBillSub>>(entry); | 
|                 string sql = string.Empty; | 
|                 oCN.BeginTran(); | 
|                 sql = $"delete Sc_PPBomBillMain where HinterID = {mainList[0].HInterID}"; | 
|                 oCN.RunProc(sql); | 
|                 sql = $"delete Sc_PPBomBillSub where HinterID = {mainList[0].HInterID}"; | 
|                 oCN.RunProc(sql); | 
|                 //主表 | 
|                 oCN.RunProc(@"Insert Into Sc_PPBomBillMain    | 
|                         (HInterID,HYear,HPeriod,HBillType,HBillSubType,HDate,HBillNo,HBillStatus,HICMOInterID | 
|                         ,HICMOEntryID,HMaterID,HUnitID,HQty,HDeptID,HMaker,HMakeDate,HChecker,HCheckDate | 
|                         ,HSeOrderBillNo,HSeOrderInterID,HSeOrderEntryID,HPRDORGID,HENTRUSTORGID,HPARENTOWNERID | 
|                         ,HPARENTOWNERTYPEID,HERPInterID,HERPBillType,HSeOrderEntrySEQ,HICMOEntrySEQ,HREQSRC) | 
|                         values(" + mainList[0].HInterID + "," + DateTime.Now.Year + "," + DateTime.Now.Month + ",'" + 3720 + "','" + | 
|                 mainList[0].HBillSubType + "','" + mainList[0].HDate + "','" + mainList[0].HBillNo + "','" + mainList[0].HBillStatus + "'," + mainList[0].HICMOInterID + | 
|                 "," + mainList[0].HICMOEntryID + ",'" + mainList[0].HMaterID + "'," + mainList[0].HUnitID + "," + mainList[0].HQty + "," + mainList[0].HDeptID + | 
|                 ",'" + mainList[0].HMaker + "','" + mainList[0].HMakeDate + "','" + mainList[0].HChecker + "','" + mainList[0].HCheckDate + "','" + mainList[0].HSeOrderBillNo + "'," + mainList[0].HSeOrderInterID + "," + mainList[0].HSeOrderEntryID + "," + mainList[0].HPRDORGID + "," + mainList[0].HENTRUSTORGID + "," + mainList[0].HPARENTOWNERID + ",'" + | 
|                 mainList[0].HPARENTOWNERTYPEID + "'," + mainList[0].HERPInterID + ",'" + mainList[0].HERPBillType + "'," + mainList[0].HSeOrderEntrySEQ + "," + mainList[0].HICMOEntrySEQ + ",'" + mainList[0].HREQSRC + "')"); | 
|                 //保存主表 | 
|                 foreach (var oSub in subList) | 
|                 { | 
|                     oCN.RunProc($@"Insert into Sc_PPBomBillSub  | 
|                 (HInterID,HEntryID,HMaterID,HMaterNumber,HUnitID,HUnitNumber,HSPID,HQty,HQtyMust,HWHID,HRemark | 
|                 ,HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HICMOInterID,HICMOEntryID,HICMOBillNo | 
|                 ,HCHILDSUPPLYORGID,HSUPPLYORGID,HENTRUSTPICKORGID,HSRCTRANSORGID,HGROUPBYOWNERID,HOWNERID,HOWNERTYPEID | 
|                 ,HRelationQty,HMoveStockQty,HAuxPropID,HBatchNO,HMTONo,HQtyScrap,HERPInterID,HERPEntryID | 
|                 ,HBackRelationQty,HNumerator,HDenominator,HBASEUNITID,HProcessID,HICMOENTRYSEQ,HPROJECTNO | 
|                 ,HOPERID,HSEQ,HSTOCKSTATUSID,HLOT,HOPTQUEUE,HRESERVETYPE,HSelPickedQty,HSELPRCDRETURNQTY,HProcName)  | 
|                  values('{oSub.HInterID}','{oSub.HEntryID}','{oSub.HMaterID}','{oSub.HMaterNumber}','{oSub.HUnitID}','{oSub.HUnitNumber}','{oSub.HSPID}','{oSub.HQty}' | 
|                 ,'{oSub.HQtyMust}','{oSub.HWHID}','{oSub.HRemark}','{oSub.HSourceInterID}','{oSub.HSourceEntryID}','{oSub.HSourceBillNo}','{oSub.HSourceBillType}','{oSub.HICMOInterID}','{oSub.HICMOEntryID}','{oSub.HICMOBillNo}','{oSub.HCHILDSUPPLYORGID}','{oSub.HSUPPLYORGID}','{oSub.HENTRUSTPICKORGID}','{oSub.HSRCTRANSORGID}','{oSub.HGROUPBYOWNERID}','{oSub.HOWNERID}','{oSub.HOWNERTYPEID}','{oSub.HRelationQty}','{oSub.HMoveStockQty}','{oSub.HAuxPropID}','{oSub.HBatchNO}','{oSub.HMTONo}','{oSub.HQtyScrap}','{oSub.HERPInterID}','{oSub.HERPEntryID}','{oSub.HBackRelationQty}','{oSub.HNumerator}','{oSub.HDenominator}','{oSub.HBASEUNITID}','{oSub.HProcessID}','{oSub.HICMOENTRYSEQ}','{oSub.HPROJECTNO}','{oSub.HOPERID}','{oSub.HSEQ}','{oSub.HSTOCKSTATUSID}','{oSub.HLOT}','{oSub.HOPTQUEUE}','{oSub.HRESERVETYPE}','{oSub.HSelPickedQty}','{oSub.HSELPRCDRETURNQTY}','{oSub.HProcName}')"); | 
|                 } | 
|                 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 = "保存失败!" + e.ToString(); | 
|                 objJsonResult.data = null; | 
|                 return objJsonResult; | 
|             } | 
|         } | 
|         #endregion | 
|   | 
|         /// <summary> | 
|         ///删除功能 | 
|         /// </summary> | 
|         /// <returns></returns> | 
|         [Route("Sc_PPBomBill/DeltetPPBomBillBill")] | 
|         [HttpGet] | 
|         public object DeltetSeOrderBill(string HInterID) | 
|         { | 
|             try | 
|             { | 
|                 oCN.BeginTran(); | 
|                 oCN.RunProc("Delete From Sc_PPBomBillMain where HInterID = " + HInterID); | 
|                 oCN.RunProc("Delete From Sc_PPBomBillSub where HInterID = " + HInterID); | 
|                 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.ToString(); | 
|                 objJsonResult.data = null; | 
|                 return objJsonResult; | 
|             } | 
|         } | 
|   | 
|         #region [同步单据] | 
|         [Route("Sc_PPBomBill/Sc_PPBomBillViewApi")] | 
|         [HttpGet] | 
|         public json Sc_PPBomBillViewApi(string BillNo, string BillType) | 
|         { | 
|             string sql = string.Empty; | 
|             string sReturn = ""; | 
|             if (oSystemParameter.ShowBill(ref sReturn) == true) | 
|             { | 
|                 //系统参数是否为私有云模式,N为公有云模式,Y为私有云模式 | 
|                 if (oSystemParameter.omodel.WMS_CloudMode == "Y") | 
|                 { | 
|                     #region [私有云模式,直接调用数据库存储过程更新] | 
|                     try | 
|                     { | 
|                         oCN.BeginTran(); | 
|                         SQLHelper.ClsCN oCn = new SQLHelper.ClsCN(); | 
|                         DataSet DS = oCn.RunProcReturn("exec h_p_WMS_ERPSourceBillToLocal '" + BillNo + "','" + BillType + "'", "h_p_WMS_ERPSourceBillToLocal"); | 
|                         if (DS == null) | 
|                         { | 
|                             objJsonResult.code = "0"; | 
|                             objJsonResult.count = 0; | 
|                             objJsonResult.Message = "单据同步失败"; | 
|                             objJsonResult.data = null; | 
|                             return objJsonResult; | 
|                         } | 
|                         else | 
|                         { | 
|                             if (DBUtility.ClsPub.isStrNull(DS.Tables[0].Rows[0]["HBack"]) == "2") | 
|                             { | 
|                                 objJsonResult.code = "0"; | 
|                                 objJsonResult.count = 0; | 
|                                 objJsonResult.Message = "ERP中不存在该单据号"; | 
|                                 objJsonResult.data = null; | 
|                                 return objJsonResult; | 
|                             } | 
|                             else | 
|                             { | 
|                                 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; | 
|                     } | 
|                     #endregion | 
|                 } | 
|                 else | 
|                 { | 
|                     #region [公有云模式,调用WEBAPI的方式进行更新] | 
|                     var json = new | 
|                     { | 
|                         CreateOrgId = 0, | 
|                         Number = BillNo, | 
|                         Id = "" | 
|                     }; | 
|                     #region [金蝶部分] | 
|                     //登录金蝶 | 
|                     var loginRet = InvokeHelper.Login(); | 
|                     var isSuccess = JObject.Parse(loginRet)["LoginResultType"].Value<int>(); | 
|                     //判断是否登录成功 | 
|                     if (isSuccess < 0) | 
|                     { | 
|                         objJsonResult.code = "0"; | 
|                         objJsonResult.count = 0; | 
|                         objJsonResult.Message = loginRet; | 
|                         objJsonResult.data = null; | 
|                         return objJsonResult; | 
|                     } | 
|                     //查看 获取数据                     | 
|                     var _result = InvokeHelper.View("PRD_PPBOM", JsonConvert.SerializeObject(json)); | 
|                     var _saveObj = JObject.Parse(_result); | 
|                     //判断数据是否获取成功 | 
|                     if (_saveObj["Result"]["ResponseStatus"]["IsSuccess"].ToString().ToUpper() != "TRUE") | 
|                     { | 
|                         objJsonResult.code = "0"; | 
|                         objJsonResult.count = 0; | 
|                         objJsonResult.Message = "金蝶生产用料单同步失败jsonRoot:" + _result; | 
|                         objJsonResult.data = null; | 
|                         return objJsonResult; | 
|                     } | 
|   | 
|                     #endregion | 
|                     //获取主表数据 | 
|                     DataSet Ds; | 
|                     Int64 InterID = 0; | 
|                     Ds = oCN.RunProcReturn("select * from Sc_PPBomBillMain where HBillNo = '" + BillNo + "'", "Sc_PPBomBillMain"); | 
|                     if (Ds.Tables[0].Rows.Count != 0 && ClsPub.isLong(Ds.Tables[0].Rows[0]["HInterID"].ToString()) != 0) | 
|                     { | 
|                         InterID = ClsPub.isLong(Ds.Tables[0].Rows[0]["HInterID"].ToString()); | 
|                     } | 
|   | 
|                     #region [主表数据赋值] | 
|                     var jsonData = new | 
|                     { | 
|                         HInterID = _saveObj["Result"]["Result"]["Id"], | 
|                         HYear = DateTime.Now.Year, | 
|                         HPeriod = DateTime.Now.Month, | 
|                         HBillType = 3720, | 
|                         HBillSubType = 3720, | 
|                         HDate = _saveObj["Result"]["Result"]["CreateDate"], | 
|                         HBillNo = _saveObj["Result"]["Result"]["BillNo"], | 
|                         HBillStatus         = _saveObj["Result"]["Result"]["ApproverId_Id"].ToString() == Convert.ToString(0) ? 1 : 2, | 
|                         HICMOInterID        = _saveObj["Result"]["Result"]["MoId"], | 
|                         HICMOEntryID        = _saveObj["Result"]["Result"]["MOEntryID"], | 
|                         HMaterID            = _saveObj["Result"]["Result"]["MaterialID_Id"], | 
|                         HUnitID             = _saveObj["Result"]["Result"]["UnitID_Id"], | 
|                         HQty                = _saveObj["Result"]["Result"]["Qty"], | 
|                         HDeptID             = _saveObj["Result"]["Result"]["WorkshopID_Id"], | 
|                         HMaker              = _saveObj["Result"]["Result"]["CreatorId"]["Name"], | 
|                         HMakeDate           = _saveObj["Result"]["Result"]["CreateDate"], | 
|                         HChecker            = _saveObj["Result"]["Result"]["ApproverId"]["Name"], | 
|                         HCheckDate          = _saveObj["Result"]["Result"]["ApproveDate"], | 
|                         HSeOrderBillNo      = _saveObj["Result"]["Result"]["SALEORDERNO"], | 
|                         HSeOrderInterID     = _saveObj["Result"]["Result"]["SaleOrderId"], | 
|                         HSeOrderEntryID     = _saveObj["Result"]["Result"]["SaleOrderEntryId"], | 
|                         HPRDORGID           = _saveObj["Result"]["Result"]["PrdOrgId_Id"], | 
|                         HENTRUSTORGID       = _saveObj["Result"]["Result"]["EntrustOrgId_Id"], | 
|                         HPARENTOWNERID      = _saveObj["Result"]["Result"]["ParentOwnerId_Id"], | 
|                         HPARENTOWNERTYPEID  = _saveObj["Result"]["Result"]["ParentOwnerTypeId"], | 
|                         HREQSRC             = _saveObj["Result"]["Result"]["ReqSrc"], | 
|                         HERPInterID = _saveObj["Result"]["Result"]["Id"], | 
|                         HERPBillType              = "PPBOM", | 
|                         HSeOrderEntrySEQ          = _saveObj["Result"]["Result"]["SaleOrderEntrySeq"], | 
|                         HICMOEntrySEQ = _saveObj["Result"]["Result"]["MOEntrySeq"] | 
|                     }; | 
|                     #endregion | 
|                     // 删除主表对应数据 | 
|                     sql = $"delete from Sc_PPBomBillMain where HInterID = " + InterID; | 
|                     oCN.RunProc(sql); | 
|   | 
|                     //插入主表 | 
|                     sql = $@" | 
|                 insert into Sc_PPBomBillMain | 
|                 (HInterID,HYear,HPeriod,HBillType,HBillSubType,HDate | 
|                 ,HBillNo,HBillStatus,HICMOInterID,HICMOEntryID | 
|                 ,HMaterID,HUnitID,HQty,HDeptID,HMaker,HMakeDate,HChecker,HCheckDate | 
|                 ,HSeOrderBillNo,HSeOrderInterID,HSeOrderEntryID | 
|                 ,HPRDORGID,HENTRUSTORGID,HPARENTOWNERID,HPARENTOWNERTYPEID,HREQSRC | 
|                 ,HERPInterID,HERPBillType,HSeOrderEntrySEQ,HICMOEntrySEQ | 
|                  ) | 
|                 values | 
|                 ({jsonData.HInterID},{jsonData.HYear},{jsonData.HPeriod},{jsonData.HBillType},{jsonData.HBillSubType}, | 
|                 '{jsonData.HDate}','{jsonData.HBillNo}',{jsonData.HBillStatus},{jsonData.HICMOInterID},{jsonData.HICMOEntryID}, | 
|                 {jsonData.HMaterID},{jsonData.HUnitID},{jsonData.HQty},{jsonData.HDeptID},'{jsonData.HMaker}','{jsonData.HMakeDate}','{jsonData.HChecker}', | 
|                 '{jsonData.HCheckDate}','{jsonData.HSeOrderBillNo}',{jsonData.HSeOrderInterID},{jsonData.HSeOrderEntryID},{jsonData.HPRDORGID}, | 
|                 {jsonData.HENTRUSTORGID},{jsonData.HPARENTOWNERID},'{jsonData.HPARENTOWNERTYPEID}','{jsonData.HREQSRC}',{jsonData.HERPInterID}, | 
|                 '{jsonData.HERPBillType}',{jsonData.HSeOrderEntrySEQ},'{jsonData.HICMOEntrySEQ}')"; | 
|   | 
|                     oCN.RunProc(sql); | 
|   | 
|                     #region [申请子表变量] | 
|                     var dataArr = _saveObj["Result"]["Result"]["PPBomEntry"]; | 
|   | 
|                     DataSet Cs; | 
|                     double RelationQty = 0; | 
|                     #endregion | 
|                     int i = 0; | 
|   | 
|                     // 获取子表数据 | 
|                     Cs = oCN.RunProcReturn("select * from Sc_PPBomBillSub where HInterID = " + InterID, "Sc_PPBomBillSub"); | 
|                     // 删除子表对应数据 | 
|                     sql = $"delete from Sc_PPBomBillSub where HInterID = " + InterID; | 
|                     oCN.RunProc(sql); | 
|   | 
|                     foreach (var oSub in dataArr) | 
|                     { | 
|                         #region [子表数据赋值] | 
|   | 
|                         if (Cs.Tables[0].Rows.Count != 0 && ClsPub.isLong(Cs.Tables[0].Rows[0]["HInterID"].ToString()) != 0) | 
|                         { | 
|                             RelationQty = ClsPub.isDoule(Cs.Tables[0].Rows[i]["HRelationQty"].ToString()); | 
|   | 
|                             i++; | 
|                         } | 
|   | 
|                         var subData = new | 
|                         { | 
|                             HInterID = _saveObj["Result"]["Result"]["Id"], | 
|                             HEntryID = oSub["Id"], | 
|                             HMaterID = oSub["MaterialID_Id"], | 
|                             HUnitID           = oSub["UnitID_Id"], | 
|                             HQty              = oSub["NeedQty"], | 
|                             HQtyMust          = oSub["NeedQty"], | 
|                             HWHID             = oSub["StockID_Id"], | 
|                             HRemark           = "CLOUD导入", | 
|                             HSourceInterID    = oSub["MoId"], | 
|                             HSourceEntryID    = oSub["MoEntryId"], | 
|                             HSourceBillNo     = oSub["MoBillNo"], | 
|                             HSourceBillType   = 3710, | 
|                             HICMOInterID      = oSub["MoId"], | 
|                             HICMOEntryID      = oSub["MoEntryId"], | 
|                             HICMOBillNo       = oSub["MoBillNo"], | 
|                             HCHILDSUPPLYORGID = oSub["ChildSupplyOrgId_Id"], | 
|                             HSUPPLYORGID      = oSub["SupplyOrg_Id"], | 
|                             HENTRUSTPICKORGID = oSub["EntrustPickOrgId_Id"], | 
|                             HSRCTRANSORGID    = oSub["SrcTransOrgId_Id"], | 
|                             HGROUPBYOWNERID   = oSub["GroupByOwnerId_Id"], | 
|                             HOWNERID          = oSub["OwnerID_Id"], | 
|                             HOWNERTYPEID      = oSub["OwnerTypeId"], | 
|                             HRelationQty      = Convert.ToInt32(oSub["SelPickedQty"]) - Convert.ToInt32(oSub["SelPrcdReturnQty"]), | 
|                             HMoveStockQty     = oSub["SelTranslateQty"], | 
|                             HAuxPropID        = oSub["AuxPropID_Id"], | 
|                             HBatchNO          = oSub["Lot_Text"], | 
|                             HMTONo            = oSub["MTONO"], | 
|                             HQtyScrap               = Convert.ToInt32(oSub["BaseNumerator"]) / Convert.ToInt32(oSub["BaseDenominator"]), | 
|                             HERPInterID             = _saveObj["Result"]["Result"]["Id"], | 
|                             HERPEntryID             = oSub["Id"], | 
|                             HBackRelationQty        = oSub["WipQty"], | 
|                             HNumerator              = oSub["Numerator"], | 
|                             HDenominator             = oSub["Denominator"], | 
|                             HBASEUNITID             = oSub["BaseUnitID_Id"], | 
|                             HProcessID              = oSub["ProcessID_Id"], | 
|                             HICMOENTRYSEQ           = oSub["MoEntrySeq"], | 
|                             HPROJECTNO              = oSub["ProjectNO"], | 
|                             HOPERID                 = oSub["OperID"], | 
|                             HSEQ                    = oSub["Seq"], | 
|                             HSTOCKSTATUSID          = oSub["StockStatusId_Id"], | 
|                             HLOT                    = oSub["Lot_Id"], | 
|                             HOPTQUEUE               = oSub["OptQueue"], | 
|                             HRESERVETYPE            = oSub["ReserveType"], | 
|                             HSelPickedQty           = oSub["SelPickedQty"], | 
|                             HSELPRCDRETURNQTY = oSub["SelPrcdReturnQty"], | 
|                         }; | 
|                         #endregion                        | 
|   | 
|                         //插入子表 | 
|                         sql = $@" | 
|                  insert into Sc_PPBomBillSub | 
|                  (HInterID,HEntryID,HMaterID,HUnitID,HQty,HQtyMust,HWHID,HRemark | 
|                 ,HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HICMOInterID,HICMOEntryID,HICMOBillNo | 
|                 ,HCHILDSUPPLYORGID,HSUPPLYORGID,HENTRUSTPICKORGID,HSRCTRANSORGID,HGROUPBYOWNERID,HOWNERID,HOWNERTYPEID | 
|                 ,HRelationQty,HMoveStockQty,HAuxPropID,HBatchNO,HMTONo,HQtyScrap,HERPInterID,HERPEntryID | 
|                 ,HBackRelationQty,HNumerator,HDenominator | 
|                 ,HBASEUNITID,HProcessID,HICMOENTRYSEQ,HPROJECTNO,HOPERID,HSEQ,HSTOCKSTATUSID | 
|                 ,HLOT,HOPTQUEUE,HRESERVETYPE,HSelPickedQty,HSELPRCDRETURNQTY | 
|                  ) | 
|                  values | 
|                  ({subData.HInterID},{subData.HEntryID},{subData.HMaterID},{subData.HUnitID},{subData.HQty},{subData.HQtyMust},{subData.HWHID},'{subData.HRemark}',{subData.HSourceInterID},{subData.HSourceEntryID},'{subData.HSourceBillNo}','{subData.HSourceBillType}',{subData.HICMOInterID},{subData.HICMOEntryID},'{subData.HICMOBillNo}',{subData.HCHILDSUPPLYORGID},{subData.HSUPPLYORGID},{subData.HENTRUSTPICKORGID},{subData.HSRCTRANSORGID},{subData.HGROUPBYOWNERID},{subData.HOWNERID},'{subData.HOWNERTYPEID}',{subData.HRelationQty},{subData.HMoveStockQty},{subData.HAuxPropID},'{subData.HBatchNO}','{subData.HMTONo}',{subData.HQtyScrap},{subData.HERPInterID},{subData.HERPEntryID},{subData.HBackRelationQty},'{subData.HNumerator}','{subData.HDenominator}',{subData.HBASEUNITID},{subData.HProcessID},{subData.HICMOENTRYSEQ},'{subData.HPROJECTNO}',{subData.HOPERID},{subData.HSEQ},{subData.HSTOCKSTATUSID},{subData.HLOT},{subData.HOPTQUEUE},'{subData.HRESERVETYPE}',{subData.HSelPickedQty},{subData.HSELPRCDRETURNQTY} | 
|                   )"; | 
|   | 
|                         oCN.RunProc(sql); | 
|                     } | 
|                     objJsonResult.code = "1"; | 
|                     objJsonResult.count = 1; | 
|                     objJsonResult.Message = "单据同步成功!"; | 
|                     objJsonResult.data = null; | 
|                     return objJsonResult; | 
|   | 
|                     #endregion | 
|                 } | 
|             } | 
|             else | 
|             { | 
|                 objJsonResult.code = "0"; | 
|                 objJsonResult.count = 0; | 
|                 objJsonResult.Message = "单据读取失败!"; | 
|                 objJsonResult.data = null; | 
|                 return objJsonResult; | 
|             } | 
|         } | 
|         #endregion | 
|   | 
|     } | 
| } |