chenhaozhe
2026-03-05 524bfe49ec8a96d2762b1d29536fe97190f78644
WebAPI/Controllers/MJGL/Sc_MouldUpperBillController.cs
@@ -9,6 +9,7 @@
using Newtonsoft.Json;
using Model;
using DBUtility;
using SyntacticSugar.constant;
namespace WebAPI.Controllers.MJGL
{
@@ -39,7 +40,7 @@
                    return objJsonResult;
                }
                ds = oCN.RunProcReturn("select * from  h_v_Qj_Sc_MouldUpperBillList where 1=1" + sWhere + "order by hmainid desc ", "h_v_Qj_Sc_MouldUpperBillList");
                ds = oCN.RunProcReturn("select * from  h_v_Qj_Sc_MouldUpperBill_Edit where 1=1" + sWhere + "order by hmainid desc ", "h_v_Qj_Sc_MouldUpperBill_Edit");
                //添加列名
                foreach (DataColumn col in ds.Tables[0].Columns)
@@ -61,6 +62,55 @@
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "Exception!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
        #region 上模单 列表分页查询
        [Route("Sc_MouldUpperBill/Sc_MouldUpperBillListPage")]
        [HttpGet]
        public object Sc_MouldUpperBillListPage(string sWhere, string user, int page, int size)
        {
            try
            {
                List<object> columnNameList = new List<object>();
                //查看权限
                if (!DBUtility.ClsPub.Security_Log("Sc_MouldUpperBill_Query", 1, false, user))
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "无查看权限!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                sWhere = sWhere.Replace("'", "''");
                ds = oCN.RunProcReturn("exec h_p_Sc_MouldUpperBillList " + page + "," + size + ",'" + sWhere + "'", "h_p_Sc_MouldUpperBillList");
                //添加列名
                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 = CodeConstant.SUCCEED;
                objJsonResult.count = int.Parse(ds.Tables[1].Rows[0]["count"].ToString());
                objJsonResult.Message = "Sucess!";
                objJsonResult.data = ds.Tables[0];
                objJsonResult.list = columnNameList;
                return objJsonResult;
            }
            catch (Exception ex)
            {
                objJsonResult.code = CodeConstant.FAIL;
                objJsonResult.count = CountConstant.FAIL;
                objJsonResult.Message = "没有返回任何记录!" + ex.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
@@ -278,10 +328,10 @@
                oCN.RunProc(@"Insert Into Sc_MouldUpperBillSub   
                   (HInterID, HBillNo_bak, HEntryID, HMouldID, HQty
                   , HSourceID, HICMOInterID, HICMOEntryID, HICMOBillNo)
                   , HSourceID, HICMOInterID, HICMOEntryID, HICMOBillNo,HScanDate,HBarCode)
                    values("
                     + HInterID + ",'"+ HBillNo + "'," + i + "," + oSub.HMouldID.ToString() + ",'" + oSub.HQty 
                     + "'," + oSub.HSourceID.ToString() + "," + oSub.HICMOInterID.ToString() + "," + oSub.HICMOEntryID.ToString()+",'"+ oSub.HICMOBillNo.ToString() +
                     + "'," + oSub.HSourceID.ToString() + "," + oSub.HICMOInterID.ToString() + "," + oSub.HICMOEntryID.ToString()+",'"+ oSub.HICMOBillNo.ToString() + "',getdate(),'" + oSub.HBarCode.ToString() +
                     "') ");
            }
@@ -389,11 +439,59 @@
                        return objJsonResult;
                    }
                    BillOld.MvarItemKey = "Sc_MouldUpperBillMain";
                    //删除前控制=========================================
                    DataSet ds2;
                    string sql1 = "exec h_p_Sc_MouldUpperBill_BeforeDelCtrl " + Convert.ToInt32(hmainid) + ",'" + ds.Tables[0].Rows[0]["HBillNo"] + "','" + user + "'";
                    ds2 = oCN.RunProcReturn(sql1, "h_p_Sc_MouldUpperBill_BeforeDelCtrl");
                    if (ds2 == null || ds2.Tables.Count == 0 || ds2.Tables[0].Rows.Count == 0)
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 1;
                        objJsonResult.Message = "删除失败!原因:删除前判断失败,请与网络管理人员联系";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                    if (ds2.Tables[0].Rows[0]["HBack"].ToString() != "0")
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 1;
                        objJsonResult.Message = "删除失败!原因:" + ds2.Tables[0].Rows[0]["HRemark"].ToString(); ;
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                    //==================================================================================
                    if (ds.Tables[0].Rows.Count == 1) {
                        oCN.RunProc("delete from Sc_MouldUpperBillMain where HInterID=" + hmainid);
                    }
                    oCN.RunProc("delete from Sc_MouldUpperBillSub where HInterID=" + hmainid + " and HEntryID=" + hsubid);
                    //删除后控制=========================================
                    string sql2 = "exec h_p_Sc_MouldUpperBill_AfterDelCtrl " + Convert.ToInt32(hmainid) + ",'" + ds.Tables[0].Rows[0]["HBillNo"] + "','" + user + "'";
                    ds2 = oCN.RunProcReturn(sql2, "h_p_Sc_MouldUpperBill_AfterDelCtrl");
                    if (ds2 == null || ds2.Tables.Count == 0 || ds2.Tables[0].Rows.Count == 0)
                    {
                        oCN.RollBack();
                        objJsonResult.code = "0";
                        objJsonResult.count = 1;
                        objJsonResult.Message = "删除失败!原因:删除后判断失败,请与网络管理人员联系";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                    if (ds2.Tables[0].Rows[0]["HBack"].ToString() != "0")
                    {
                        oCN.RollBack();
                        objJsonResult.code = "0";
                        objJsonResult.count = 1;
                        objJsonResult.Message = "删除失败!原因:" + ds2.Tables[0].Rows[0]["HRemark"].ToString(); ;
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                    //==================================================================================
                    oCN.Commit();
                }
@@ -451,6 +549,7 @@
                {
                    //判断单据是否已经审核
                    DataSet ds;
                    DataSet ds2;
                    string sql = "select * from " + BillOld.MvarItemKey + " where HinterID = " + HInterID;
                    ds = oCN.RunProcReturn(sql, BillOld.MvarItemKey);
                    if (ds.Tables[0] != null && ds.Tables[0].Rows.Count > 0)
@@ -464,15 +563,38 @@
                            return objJsonResult;
                        }
                        //审核单据
                        if (!BillOld.CheckBill(Int64.Parse(HInterID), ref ClsPub.sExeReturnInfo))
                        //审核前控制=========================================
                        string sql1 = "exec h_p_Sc_MouldUpperBill_BeforeCheckCtrl " + HInterID + ",'" + ds.Tables[0].Rows[0]["HBillNo"] + "','" + user + "'";
                        ds2 = oCN.RunProcReturn(sql1, "h_p_Sc_MouldUpperBill_BeforeCheckCtrl");
                        if (ds2 == null || ds2.Tables.Count == 0 || ds2.Tables[0].Rows.Count == 0)
                        {
                            objJsonResult.code = "0";
                            objJsonResult.count = 1;
                            objJsonResult.Message = "审核失败!原因:审核前判断失败,请与网络管理人员联系";
                            objJsonResult.data = null;
                            oCN.RollBack();
                            return objJsonResult;
                        }
                        if (ds2.Tables[0].Rows[0]["HBack"].ToString() != "0")
                        {
                            objJsonResult.code = "0";
                            objJsonResult.count = 1;
                            objJsonResult.Message = "审核失败!原因:" + ds2.Tables[0].Rows[0]["HRemark"].ToString(); ;
                            objJsonResult.data = null;
                            oCN.RollBack();
                            return objJsonResult;
                        }
                        //==================================================================================
                        if (!BillOld.CheckBill(int.Parse(HInterID), ds.Tables[0].Rows[0]["HBillNo"].ToString(), "h_p_Sc_MouldUpperBill_AfterCheckCtrl", user, ref ClsPub.sExeReturnInfo))
                        {
                            objJsonResult.code = "0";
                            objJsonResult.count = 1;
                            objJsonResult.Message = "审核失败!原因:" + ClsPub.sExeReturnInfo;
                            objJsonResult.data = null;
                            return objJsonResult;
                        }
                        }
                    }
                    else
                    {
@@ -482,13 +604,12 @@
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                }
                else
                {
                    //判断单据是否已经反审核
                    DataSet ds;
                    DataSet ds2;
                    string sql = "select * from " + BillOld.MvarItemKey + " where HinterID = " + HInterID;
                    ds = oCN.RunProcReturn(sql, BillOld.MvarItemKey);
                    if (ds.Tables[0] != null && ds.Tables[0].Rows.Count > 0)
@@ -502,19 +623,36 @@
                            return objJsonResult;
                        }
                        //反审核单据
                        if (BillOld.AbandonCheck(Int64.Parse(HInterID), ref ClsPub.sExeReturnInfo))
                        //反审核前控制=========================================
                        string sql1 = "exec h_p_Sc_MouldUpperBill_BeforeUnCheckCtrl " + HInterID + ",'" + ds.Tables[0].Rows[0]["HBillNo"] + "','" + user + "'";
                        ds2 = oCN.RunProcReturn(sql1, "h_p_Sc_MouldUpperBill_BeforeUnCheckCtrl");
                        if (ds2 == null || ds2.Tables.Count == 0 || ds2.Tables[0].Rows.Count == 0)
                        {
                            objJsonResult.code = "0";
                            objJsonResult.count = 1;
                            objJsonResult.Message = "反审核失败!原因:反审核前判断失败,请与网络管理人员联系";
                            objJsonResult.data = null;
                            return objJsonResult;
                        }
                        else
                        if (ds2.Tables[0].Rows[0]["HBack"].ToString() != "0")
                        {
                            objJsonResult.code = "0";
                            objJsonResult.count = 1;
                            objJsonResult.Message = "反审核失败!原因:" + ds2.Tables[0].Rows[0]["HRemark"].ToString(); ;
                            objJsonResult.data = null;
                            return objJsonResult;
                        }
                        //===========================================================
                        if (!BillOld.AbandonCheck(int.Parse(HInterID), ds.Tables[0].Rows[0]["HBillNo"].ToString(), "h_p_Sc_MouldUpperBill_AfterUnCheckCtrl", user, ref ClsPub.sExeReturnInfo))
                        {
                            objJsonResult.code = "0";
                            objJsonResult.count = 1;
                            objJsonResult.Message = "审核失败!原因:" + ClsPub.sExeReturnInfo;
                            objJsonResult.data = null;
                            return objJsonResult;
                        }
                        }
                    }
                    else
@@ -582,6 +720,7 @@
                {
                    //判断单据是否已经关闭
                    DataSet ds;
                    DataSet ds2;
                    string sql = "select * from " + BillOld.MvarItemKey + " where HinterID = " + HInterID;
                    ds = oCN.RunProcReturn(sql, BillOld.MvarItemKey);
                    if (ds == null || ds.Tables[0].Rows.Count == 0)
@@ -603,7 +742,6 @@
                            return objJsonResult;
                        }
                        if (ds.Tables[0].Rows[0]["HCloseMan"] != null && ds.Tables[0].Rows[0]["HCloseMan"].ToString() != "")
                        {
                            objJsonResult.code = "0";
@@ -612,12 +750,43 @@
                            objJsonResult.data = null;
                            return objJsonResult;
                        }
                        //关闭单据
                        if (!BillOld.CloseBill(Int64.Parse(HInterID), ref ClsPub.sExeReturnInfo))
                        //关闭前控制===============================================Begin===================================================================
                        sql = "exec h_p_Sc_MouldUpperBill_BeforeCloseCtrl " + HInterID + ",'" + ds.Tables[0].Rows[0]["HBillNo"] + "','" + user + "'";
                        ds2 = oCN.RunProcReturn(sql, "h_p_Sc_MouldUpperBill_BeforeCloseCtrl");
                        if (ds2 == null || ds2.Tables.Count == 0 || ds2.Tables[0].Rows.Count == 0)
                        {
                            objJsonResult.code = "0";
                            objJsonResult.count = 0;
                            objJsonResult.Message = "关闭失败!原因:关闭前前判断失败,无返回信息,请与网络管理人员联系";
                            objJsonResult.data = null;
                            return objJsonResult;
                        }
                        if (ds2.Tables[0].Rows[0]["HBack"].ToString() != "0")
                        {
                            objJsonResult.code = "0";
                            objJsonResult.count = 0;
                            objJsonResult.Message = "关闭失败!原因:" + ds2.Tables[0].Rows[0]["HRemark"].ToString(); ;
                            objJsonResult.data = null;
                            return objJsonResult;
                        }
                        //关闭前控制===============================================End===================================================================
                        //关闭提交
                        if (BillOld.CloseBill(Convert.ToInt32(HInterID), ds.Tables[0].Rows[0]["HBillNo"].ToString(), "h_p_Sc_MouldUpperBill_AfterCloseCtrl", user, ref DBUtility.ClsPub.sExeReturnInfo) == true)
                        {
                            objJsonResult.code = "1";
                            objJsonResult.count = 1;
                            objJsonResult.Message = "关闭失败!原因:" + ClsPub.sExeReturnInfo;
                            objJsonResult.Message = "关闭成功";
                            objJsonResult.data = null;
                            return objJsonResult;
                        }
                        else
                        {
                            objJsonResult.code = "0";
                            objJsonResult.count = 0;
                            objJsonResult.Message = "关闭失败!原因:" + DBUtility.ClsPub.sExeReturnInfo;
                            objJsonResult.data = null;
                            return objJsonResult;
                        }
@@ -627,6 +796,7 @@
                {
                    //判断单据是否已经反关闭
                    DataSet ds;
                    DataSet ds2;
                    string sql = "select * from " + BillOld.MvarItemKey + " where HinterID = " + HInterID;
                    ds = oCN.RunProcReturn(sql, BillOld.MvarItemKey);
                    if (ds.Tables[0] != null && ds.Tables[0].Rows.Count > 0)
@@ -648,15 +818,46 @@
                            objJsonResult.data = null;
                            return objJsonResult;
                        }
                        //反关闭单据
                        if (!BillOld.CancelClose(Int64.Parse(HInterID), ref ClsPub.sExeReturnInfo))
                        //反关闭前控制===============================================Begin===================================================================
                        sql = "exec h_p_Sc_MouldUpperBill_BeforeUnCloseCtrl " + HInterID + ",'" + ds.Tables[0].Rows[0]["HBillNo"] + "','" + user + "'";
                        ds2 = oCN.RunProcReturn(sql, "h_p_Sc_MouldUpperBill_BeforeUnCloseCtrl");
                        if (ds2 == null || ds2.Tables.Count == 0 || ds2.Tables[0].Rows.Count == 0)
                        {
                            objJsonResult.code = "0";
                            objJsonResult.count = 1;
                            objJsonResult.Message = "反关闭失败!原因:" + ClsPub.sExeReturnInfo;
                            objJsonResult.count = 0;
                            objJsonResult.Message = "反关闭失败!原因:反关闭前前判断失败,无返回信息,请与网络管理人员联系";
                            objJsonResult.data = null;
                            return objJsonResult;
                        }
                        if (ds2.Tables[0].Rows[0]["HBack"].ToString() != "0")
                        {
                            objJsonResult.code = "0";
                            objJsonResult.count = 0;
                            objJsonResult.Message = "反关闭失败!原因:" + ds2.Tables[0].Rows[0]["HRemark"].ToString(); ;
                            objJsonResult.data = null;
                            return objJsonResult;
                        }
                        //反关闭前控制===============================================End===================================================================
                        //反关闭提交
                        if (BillOld.CancelClose(Convert.ToInt32(HInterID), ds.Tables[0].Rows[0]["HBillNo"].ToString(), "h_p_Sc_MouldUpperBill_AfterUnCloseCtrl", user, ref DBUtility.ClsPub.sExeReturnInfo) == true)
                        {
                            objJsonResult.code = "1";
                            objJsonResult.count = 1;
                            objJsonResult.Message = "反关闭成功";
                            objJsonResult.data = null;
                            return objJsonResult;
                        }
                        else
                        {
                            objJsonResult.code = "0";
                            objJsonResult.count = 0;
                            objJsonResult.Message = "反关闭失败!原因:" + DBUtility.ClsPub.sExeReturnInfo;
                            objJsonResult.data = null;
                            return objJsonResult;
                        }
                    }
                }
@@ -829,7 +1030,7 @@
                    return objJsonResult;
                }
                ds = oCN.RunProcReturn("select * from  h_v_Qj_Sc_MouldLowerBillList where 1=1" + sWhere + "order by hmainid desc ", "h_v_Qj_Sc_MouldLowerBillList");
                ds = oCN.RunProcReturn("select * from  h_v_Qj_Sc_MouldLowerBill_Edit where 1=1" + sWhere + "order by hmainid desc ", "h_v_Qj_Sc_MouldLowerBill_Edit");
                //添加列名
                foreach (DataColumn col in ds.Tables[0].Columns)
@@ -851,6 +1052,55 @@
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "Exception!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
        #region 下模单 列表分页查询
        [Route("Sc_MouldUpperBill/Sc_MouldLowerBillListPage")]
        [HttpGet]
        public object Sc_MouldLowerBillListPage(string sWhere, string user, int page, int size)
        {
            try
            {
                List<object> columnNameList = new List<object>();
                //查看权限
                if (!DBUtility.ClsPub.Security_Log("Sc_MouldLowerBill_Query", 1, false, user))
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "无查看权限!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                sWhere = sWhere.Replace("'", "''");
                ds = oCN.RunProcReturn("exec h_p_Sc_MouldLowerBillList " + page + "," + size + ",'" + sWhere + "'", "h_p_Sc_MouldLowerBillList");
                //添加列名
                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 = CodeConstant.SUCCEED;
                objJsonResult.count = int.Parse(ds.Tables[1].Rows[0]["count"].ToString());
                objJsonResult.Message = "Sucess!";
                objJsonResult.data = ds.Tables[0];
                objJsonResult.list = columnNameList;
                return objJsonResult;
            }
            catch (Exception ex)
            {
                objJsonResult.code = CodeConstant.FAIL;
                objJsonResult.count = CountConstant.FAIL;
                objJsonResult.Message = "没有返回任何记录!" + ex.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
@@ -1179,12 +1429,60 @@
                        return objJsonResult;
                    }
                    BillOld.MvarItemKey = "Sc_MouldLowerBillMain";
                    //删除前控制=========================================
                    DataSet ds2;
                    string sql1 = "exec h_p_Sc_MouldLowerBill_BeforeDelCtrl " + Convert.ToInt32(hmainid) + ",'" + ds.Tables[0].Rows[0]["HBillNo"] + "','" + user + "'";
                    ds2 = oCN.RunProcReturn(sql1, "h_p_Sc_MouldLowerBill_BeforeDelCtrl");
                    if (ds2 == null || ds2.Tables.Count == 0 || ds2.Tables[0].Rows.Count == 0)
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 1;
                        objJsonResult.Message = "删除失败!原因:删除前判断失败,请与网络管理人员联系";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                    if (ds2.Tables[0].Rows[0]["HBack"].ToString() != "0")
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 1;
                        objJsonResult.Message = "删除失败!原因:" + ds2.Tables[0].Rows[0]["HRemark"].ToString(); ;
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                    //==================================================================================
                    if (ds.Tables[0].Rows.Count == 1)
                    {
                        oCN.RunProc("delete from Sc_MouldLowerBillMain where HInterID=" + hmainid);
                    }
                    oCN.RunProc("delete from Sc_MouldLowerBillSub where HInterID=" + hmainid + " and HEntryID=" + hsubid);
                    //删除后控制=========================================
                    string sql2 = "exec h_p_Sc_MouldLowerBill_AfterDelCtrl " + Convert.ToInt32(hmainid) + ",'" + ds.Tables[0].Rows[0]["HBillNo"] + "','" + user + "'";
                    ds2 = oCN.RunProcReturn(sql2, "h_p_Sc_MouldLowerBill_AfterDelCtrl");
                    if (ds2 == null || ds2.Tables.Count == 0 || ds2.Tables[0].Rows.Count == 0)
                    {
                        oCN.RollBack();
                        objJsonResult.code = "0";
                        objJsonResult.count = 1;
                        objJsonResult.Message = "删除失败!原因:删除后判断失败,请与网络管理人员联系";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                    if (ds2.Tables[0].Rows[0]["HBack"].ToString() != "0")
                    {
                        oCN.RollBack();
                        objJsonResult.code = "0";
                        objJsonResult.count = 1;
                        objJsonResult.Message = "删除失败!原因:" + ds2.Tables[0].Rows[0]["HRemark"].ToString(); ;
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                    //==================================================================================
                    oCN.Commit();
                }
@@ -1242,6 +1540,7 @@
                {
                    //判断单据是否已经审核
                    DataSet ds;
                    DataSet ds2;
                    string sql = "select * from " + BillOld.MvarItemKey + " where HinterID = " + HInterID;
                    ds = oCN.RunProcReturn(sql, BillOld.MvarItemKey);
                    if (ds.Tables[0] != null && ds.Tables[0].Rows.Count > 0)
@@ -1255,8 +1554,31 @@
                            return objJsonResult;
                        }
                        //审核单据
                        if (!BillOld.CheckBill(Int64.Parse(HInterID), ref ClsPub.sExeReturnInfo))
                        //审核前控制=========================================
                        string sql1 = "exec h_p_Sc_MouldLowerBill_BeforeCheckCtrl " + HInterID + ",'" + ds.Tables[0].Rows[0]["HBillNo"] + "','" + user + "'";
                        ds2 = oCN.RunProcReturn(sql1, "h_p_Sc_MouldLowerBill_BeforeCheckCtrl");
                        if (ds2 == null || ds2.Tables.Count == 0 || ds2.Tables[0].Rows.Count == 0)
                        {
                            objJsonResult.code = "0";
                            objJsonResult.count = 1;
                            objJsonResult.Message = "审核失败!原因:审核前判断失败,请与网络管理人员联系";
                            objJsonResult.data = null;
                            oCN.RollBack();
                            return objJsonResult;
                        }
                        if (ds2.Tables[0].Rows[0]["HBack"].ToString() != "0")
                        {
                            objJsonResult.code = "0";
                            objJsonResult.count = 1;
                            objJsonResult.Message = "审核失败!原因:" + ds2.Tables[0].Rows[0]["HRemark"].ToString(); ;
                            objJsonResult.data = null;
                            oCN.RollBack();
                            return objJsonResult;
                        }
                        //==================================================================================
                        if (!BillOld.CheckBill(int.Parse(HInterID), ds.Tables[0].Rows[0]["HBillNo"].ToString(), "h_p_Sc_MouldLowerBill_AfterCheckCtrl", user, ref ClsPub.sExeReturnInfo))
                        {
                            objJsonResult.code = "0";
                            objJsonResult.count = 1;
@@ -1277,6 +1599,7 @@
                {
                    //判断单据是否已经反审核
                    DataSet ds;
                    DataSet ds2;
                    string sql = "select * from " + BillOld.MvarItemKey + " where HinterID = " + HInterID;
                    ds = oCN.RunProcReturn(sql, BillOld.MvarItemKey);
                    if (ds.Tables[0] != null && ds.Tables[0].Rows.Count > 0)
@@ -1290,12 +1613,29 @@
                            return objJsonResult;
                        }
                        //反审核单据
                        if (BillOld.AbandonCheck(Int64.Parse(HInterID), ref ClsPub.sExeReturnInfo))
                        //反审核前控制=========================================
                        string sql1 = "exec h_p_Sc_MouldLowerBill_BeforeUnCheckCtrl " + HInterID + ",'" + ds.Tables[0].Rows[0]["HBillNo"] + "','" + user + "'";
                        ds2 = oCN.RunProcReturn(sql1, "h_p_Sc_MouldLowerBill_BeforeUnCheckCtrl");
                        if (ds2 == null || ds2.Tables.Count == 0 || ds2.Tables[0].Rows.Count == 0)
                        {
                            objJsonResult.code = "0";
                            objJsonResult.count = 1;
                            objJsonResult.Message = "反审核失败!原因:反审核前判断失败,请与网络管理人员联系";
                            objJsonResult.data = null;
                            return objJsonResult;
                        }
                        else
                        if (ds2.Tables[0].Rows[0]["HBack"].ToString() != "0")
                        {
                            objJsonResult.code = "0";
                            objJsonResult.count = 1;
                            objJsonResult.Message = "反审核失败!原因:" + ds2.Tables[0].Rows[0]["HRemark"].ToString(); ;
                            objJsonResult.data = null;
                            return objJsonResult;
                        }
                        //===========================================================
                        if (!BillOld.AbandonCheck(int.Parse(HInterID), ds.Tables[0].Rows[0]["HBillNo"].ToString(), "h_p_Sc_MouldLowerBill_AfterUnCheckCtrl", user, ref ClsPub.sExeReturnInfo))
                        {
                            objJsonResult.code = "0";
                            objJsonResult.count = 1;
@@ -1369,6 +1709,7 @@
                {
                    //判断单据是否已经关闭
                    DataSet ds;
                    DataSet ds2;
                    string sql = "select * from " + BillOld.MvarItemKey + " where HinterID = " + HInterID;
                    ds = oCN.RunProcReturn(sql, BillOld.MvarItemKey);
                    if (ds == null || ds.Tables[0].Rows.Count == 0)
@@ -1399,12 +1740,43 @@
                            objJsonResult.data = null;
                            return objJsonResult;
                        }
                        //关闭单据
                        if (!BillOld.CloseBill(Int64.Parse(HInterID), ref ClsPub.sExeReturnInfo))
                        //关闭前控制===============================================Begin===================================================================
                        sql = "exec h_p_Sc_MouldLowerBill_BeforeCloseCtrl " + HInterID + ",'" + ds.Tables[0].Rows[0]["HBillNo"] + "','" + user + "'";
                        ds2 = oCN.RunProcReturn(sql, "h_p_Sc_MouldLowerBill_BeforeCloseCtrl");
                        if (ds2 == null || ds2.Tables.Count == 0 || ds2.Tables[0].Rows.Count == 0)
                        {
                            objJsonResult.code = "0";
                            objJsonResult.count = 0;
                            objJsonResult.Message = "关闭失败!原因:关闭前前判断失败,无返回信息,请与网络管理人员联系";
                            objJsonResult.data = null;
                            return objJsonResult;
                        }
                        if (ds2.Tables[0].Rows[0]["HBack"].ToString() != "0")
                        {
                            objJsonResult.code = "0";
                            objJsonResult.count = 0;
                            objJsonResult.Message = "关闭失败!原因:" + ds2.Tables[0].Rows[0]["HRemark"].ToString(); ;
                            objJsonResult.data = null;
                            return objJsonResult;
                        }
                        //关闭前控制===============================================End===================================================================
                        //关闭提交
                        if (BillOld.CloseBill(Convert.ToInt32(HInterID), ds.Tables[0].Rows[0]["HBillNo"].ToString(), "h_p_Sc_MouldLowerBill_AfterCloseCtrl", user, ref DBUtility.ClsPub.sExeReturnInfo) == true)
                        {
                            objJsonResult.code = "1";
                            objJsonResult.count = 1;
                            objJsonResult.Message = "关闭失败!原因:" + ClsPub.sExeReturnInfo;
                            objJsonResult.Message = "关闭成功";
                            objJsonResult.data = null;
                            return objJsonResult;
                        }
                        else
                        {
                            objJsonResult.code = "0";
                            objJsonResult.count = 0;
                            objJsonResult.Message = "关闭失败!原因:" + DBUtility.ClsPub.sExeReturnInfo;
                            objJsonResult.data = null;
                            return objJsonResult;
                        }
@@ -1414,6 +1786,7 @@
                {
                    //判断单据是否已经反关闭
                    DataSet ds;
                    DataSet ds2;
                    string sql = "select * from " + BillOld.MvarItemKey + " where HinterID = " + HInterID;
                    ds = oCN.RunProcReturn(sql, BillOld.MvarItemKey);
                    if (ds.Tables[0] != null && ds.Tables[0].Rows.Count > 0)
@@ -1435,12 +1808,43 @@
                            objJsonResult.data = null;
                            return objJsonResult;
                        }
                        //反关闭单据
                        if (!BillOld.CancelClose(Int64.Parse(HInterID), ref ClsPub.sExeReturnInfo))
                        //反关闭前控制===============================================Begin===================================================================
                        sql = "exec h_p_Sc_MouldLowerBill_BeforeUnCloseCtrl " + HInterID + ",'" + ds.Tables[0].Rows[0]["HBillNo"] + "','" + user + "'";
                        ds2 = oCN.RunProcReturn(sql, "h_p_Sc_MouldLowerBill_BeforeUnCloseCtrl");
                        if (ds2 == null || ds2.Tables.Count == 0 || ds2.Tables[0].Rows.Count == 0)
                        {
                            objJsonResult.code = "0";
                            objJsonResult.count = 0;
                            objJsonResult.Message = "反关闭失败!原因:反关闭前前判断失败,无返回信息,请与网络管理人员联系";
                            objJsonResult.data = null;
                            return objJsonResult;
                        }
                        if (ds2.Tables[0].Rows[0]["HBack"].ToString() != "0")
                        {
                            objJsonResult.code = "0";
                            objJsonResult.count = 0;
                            objJsonResult.Message = "反关闭失败!原因:" + ds2.Tables[0].Rows[0]["HRemark"].ToString(); ;
                            objJsonResult.data = null;
                            return objJsonResult;
                        }
                        //反关闭前控制===============================================End===================================================================
                        //反关闭提交
                        if (BillOld.CancelClose(Convert.ToInt32(HInterID), ds.Tables[0].Rows[0]["HBillNo"].ToString(), "h_p_Sc_MouldLowerBill_AfterUnCloseCtrl", user, ref DBUtility.ClsPub.sExeReturnInfo) == true)
                        {
                            objJsonResult.code = "1";
                            objJsonResult.count = 1;
                            objJsonResult.Message = "反关闭失败!原因:" + ClsPub.sExeReturnInfo;
                            objJsonResult.Message = "反关闭成功";
                            objJsonResult.data = null;
                            return objJsonResult;
                        }
                        else
                        {
                            objJsonResult.code = "0";
                            objJsonResult.count = 0;
                            objJsonResult.Message = "反关闭失败!原因:" + DBUtility.ClsPub.sExeReturnInfo;
                            objJsonResult.data = null;
                            return objJsonResult;
                        }
@@ -1649,13 +2053,22 @@
                    return objJsonResult;
                }
                ds = oCN.RunProcReturn("exec h_p_Sc_AllowLoadData '" + HBarCode + "','"+ HSourceID + "'", "h_p_Sc_AllowLoadData");
                ds = oCN.RunProcReturn("exec h_p_Sc_AllowLoadData '" + HBarCode + "','"+ HSourceID + "','"+ HBillType + "'", "h_p_Sc_AllowLoadData");
                if (ds == null || ds .Tables.Count== 0 || ds.Tables[0].Rows.Count == 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "查无数据!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                if (DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[0]["HBack"]) != "0")
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "保存失败!" + DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[0]["HBackRemark"]);
                    objJsonResult.data = null;
                    return objJsonResult;
                }
@@ -1868,15 +2281,188 @@
        #endregion
        #region 下模单 PDA新增
        /// <summary>
        /// 新增单据-保存按钮
        ///参数:string sql。
        ///返回值:object。
        /// </summary>
        #region 下模单 PDA新增  新的260227   app在发信息的时候回放到事务外
        [Route("Sc_MouldUpperBill/AddSc_MouldLowerBill_PDA")]
        [HttpPost]
        public object AddSc_MouldLowerBill_PDA([FromBody] JObject oMain)
        {
            var _value = oMain["oMain"].ToString();
            string msg1 = _value.ToString();
            string[] sArray = msg1.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
            string msg2 = sArray[0].ToString();
            string user = sArray[1].ToString();                     // 用户名
            int OperationType = int.Parse(sArray[2].ToString());    // 数据类型 1添加 3修改 2复制
            // 开始事务
            oCN.BeginTran();
            try
            {
                // 权限校验
                if (!DBUtility.ClsPub.Security_Log("Sc_MouldLowerBill_Edit", 1, false, user))
                {
                    oCN.RollBack();
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "无权限编辑!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                // 处理主表 JSON(包装成数组形式)
                string mainJsonArray = "[" + msg2 + "]";
                List<ClsSc_MouldLowerBillMain> mainList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<ClsSc_MouldLowerBillMain>>(mainJsonArray);
                string HBillType = "3847";
                long HInterID = mainList[0].HInterID;
                string HBillNo = mainList[0].HBillNo;
                DateTime HDate = mainList[0].HDate;
                int HYear = DateTime.Now.Year;
                double HPeriod = DateTime.Now.Month;
                string HRemark = mainList[0].HRemark;
                string HMaker = mainList[0].HMaker;
                int HOrgID = mainList[0].HOrgID;
                Int64 HDeptID = mainList[0].HDeptID;
                Int64 HEmpID = mainList[0].HEmpID;
                Int64 HMangerID = mainList[0].HMangerID;
                // 查询主表是否存在(用于判断新增/修改)
                ds = oCN.RunProcReturn("select * from h_v_Qj_Sc_MouldLowerBillList where hmainid=" + HInterID + " and 单据号='" + HBillNo + "'", "h_v_Qj_Sc_MouldLowerBillList");
                // ----- 主表保存逻辑 -----
                if ((OperationType == 1) && ds.Tables[0].Rows.Count == 0) // 新增
                {
                    // 保存前控制
                    objJsonResult = BeforeSave_MouldLowerBill(HInterID, HBillNo, 1);
                    if (objJsonResult.count == 0)
                    {
                        oCN.RollBack();
                        objJsonResult.code = "0";
                        objJsonResult.Message = objJsonResult.Message;
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                    // 插入主表
                    oCN.RunProc(@"Insert Into Sc_MouldLowerBillMain
                   (HBillType, HBillStatus, HBillSubType, HInterID, HBillNo, HDate
                   , HYear, HPeriod, HRemark, HMaker, HMakeDate, HOrgID
                   , HDeptID, HEmpID, HMangerID) values('" + HBillType + "','1','" + HBillType + "'," + HInterID + ",'" + HBillNo + "','" + HDate + "'"
                           + "," + HYear + "," + HPeriod + ",'" + HRemark + "','" + HMaker + "',getdate()," + HOrgID
                           + "," + HDeptID + "," + HEmpID + "," + HMangerID + ") ");
                }
                else if (OperationType == 3 || ds.Tables[0].Rows.Count != 0) // 修改或已存在
                {
                    // 保存前控制
                    objJsonResult = BeforeSave_MouldLowerBill(HInterID, HBillNo, 2);
                    if (objJsonResult.count == 0)
                    {
                        oCN.RollBack();
                        objJsonResult.code = "0";
                        objJsonResult.Message = objJsonResult.Message;
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                    // 更新主表
                    oCN.RunProc("update Sc_MouldLowerBillMain set " +
                        "HDate='" + HDate +
                        "',HYear='" + HYear + "',HPeriod='" + HPeriod + "',HRemark='" + HRemark + "',hupdater='" + HMaker +
                        "',hupdatedate=getdate(),HDeptID=" + HDeptID + ",HEmpID=" + HEmpID + ",HMangerID=" + HMangerID +
                        " where HInterID='" + HInterID + "'");
                    // 删除原有子表(修改时重新插入)
                    oCN.RunProc("delete from Sc_MouldLowerBillSub where HInterID='" + HInterID + "'");
                }
                // ----- 子表保存逻辑 -----
                List<ClsSc_MouldLowerBillSub> DetailColl = Newtonsoft.Json.JsonConvert.DeserializeObject<List<ClsSc_MouldLowerBillSub>>(mainJsonArray);
                int i = 0;
                foreach (ClsSc_MouldLowerBillSub oSub in DetailColl)
                {
                    i++;
                    oCN.RunProc(@"Insert Into Sc_MouldLowerBillSub
                   (HInterID, HBillNo_bak, HEntryID, HMouldID, HQty
                   , HSourceID, HICMOInterID, HICMOEntryID, HICMOBillNo
                   , HProcExchBillNo, HProcExchInterID, HProcExchEntryID
                   , HScanDate, HBarCode)
                   values("
                             + HInterID + ",'" + HBillNo + "'," + i + "," + oSub.HMouldID.ToString() + ",'" + oSub.HQty
                             + "'," + oSub.HSourceID.ToString() + "," + oSub.HICMOInterID.ToString() + "," + oSub.HICMOEntryID.ToString() + ",'" + oSub.HICMOBillNo.ToString()
                             + "','" + oSub.HProcExchBillNo.ToString() + "'," + oSub.HProcExchInterID.ToString() + "," + oSub.HProcExchEntryID.ToString()
                             + ",'" + oSub.HScanDate.ToString() + "','" + oSub.HMouldNumber.ToString() + "') ");
                }
                // 保存后控制(根据操作类型)
                if (OperationType == 1) // 新增
                {
                    objJsonResult = AfterSave_MouldLowerBill(HInterID, HBillNo, 1);
                    if (objJsonResult.count == 0)
                    {
                        oCN.RollBack();
                        objJsonResult.code = "0";
                        objJsonResult.Message = objJsonResult.Message;
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                }
                else // 修改/复制
                {
                    objJsonResult = AfterSave_MouldLowerBill(HInterID, HBillNo, 2);
                    if (objJsonResult.count == 0)
                    {
                        oCN.RollBack();
                        objJsonResult.code = "0";
                        objJsonResult.Message = objJsonResult.Message;
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                }
                // 所有操作成功,提交事务
                oCN.Commit();
                if (OperationType == 1) // 新增
                {
                    // 自动生成工作联系单(华舟专用)
                    string sReturn = "";
                    if (oSystemParameter.ShowBill(ref sReturn) == true)
                    {
                        if (oSystemParameter.omodel.WMS_CampanyName == "华舟")
                        {
                            var ds2 = oCN.RunProcReturn("exec h_p_OA_WorkLinkBill_Create " + HInterID + "," + 3847, "h_p_OA_WorkLinkBill_Create");
                            if (ds2 != null && ds2.Tables[0].Rows.Count > 0)
                            {
                                int HInterID0 = int.Parse(ds2.Tables[0].Rows[0]["NewHInterID"].ToString());
                                LogService.Write("执行消息推送..." + HInterID0);
                                Service.GeTuiService.PubishSingle(HInterID0);
                            }
                        }
                    }
                }
                // 返回成功结果(注意原逻辑中使用了 ds.Tables[0])
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "新增单据成功!";
                objJsonResult.data = ds.Tables[0];
                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 下模单 PDA新增  老的  老的app在发信息的时候回导致表被锁住
        [Route("Sc_MouldUpperBill/AddSc_MouldLowerBill_PDA_OLD")]
        [HttpPost]
        public object AddSc_MouldLowerBill_PDA_OLD([FromBody] JObject oMain)
        {
            var _value = oMain["oMain"].ToString();
            string msg1 = _value.ToString();
@@ -2028,6 +2614,26 @@
            {
                //保存后控制
                objJsonResult = AfterSave_MouldLowerBill(HInterID, HBillNo, 1);
                string sReturn = "";
                if (oSystemParameter.ShowBill(ref sReturn) == true)
                {
                    if (oSystemParameter.omodel.WMS_CampanyName == "华舟")
                    {
                        //自动生成工作联系单
                        var ds2 = oCN.RunProcReturn("exec h_p_OA_WorkLinkBill_Create " + BillOld.omodel.HInterID + "," + 3847, "h_p_OA_WorkLinkBill_Create");
                        if (ds2 != null && ds2.Tables[0].Rows.Count > 0)
                        {
                            int HInterID0 = int.Parse(ds2.Tables[0].Rows[0]["NewHInterID"].ToString());
                            LogService.Write("执行消息推送..." + HInterID0);
                            // 触发消息推送
                            //Service.GeTuiService.PubishSingle(HInterID0);
                        }
                    }
                }
                if (objJsonResult.count == 0)
                {
                    objJsonResult.code = "0";
@@ -2058,5 +2664,278 @@
        }
        #endregion
        #region 上模单 APP新增
        /// <summary>
        /// 新增单据-保存按钮
        ///参数:string sql。
        ///返回值:object。
        /// </summary>
        [Route("Sc_MouldUpperBill/AddSc_MouldUpperBill_APP")]
        [HttpPost]
        public object AddSc_MouldUpperBill_APP([FromBody] JObject sMainSub)
        {
            var _value = sMainSub["sMainSub"].ToString();
            string msg1 = _value.ToString();
            oCN.BeginTran();
            //保存主表
            objJsonResult = AddBillMain_APP(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 = ds.Tables[0];
            return objJsonResult;
        }
        public json AddBillMain_APP(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修改 2 复制
            string user = sArray[3].ToString();//用户名
            try
            {
                if (!DBUtility.ClsPub.Security_Log("Sc_MouldUpperBill_Edit", 1, false, user))
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "无权限编辑!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                msg2 = "[" + msg2.ToString() + "]";
                List<ClsSc_MouldUpperBillMain> mainList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<ClsSc_MouldUpperBillMain>>(msg2);
                string HBillType = "3846";
                long HInterID = mainList[0].HInterID;//递入type得到的单据ID
                string HBillNo = mainList[0].HBillNo;//递入type得到的单据号
                DateTime HDate = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd"));//日期
                int HYear = DateTime.Now.Year;
                double HPeriod = DateTime.Now.Month;
                string HRemark = mainList[0].HRemark;//备注
                string HMaker = mainList[0].HMaker;//制单人
                int HOrgID = mainList[0].HOrgID;  //组织
                Int64 HDeptID = mainList[0].HDeptID;
                Int64 HEmpID = mainList[0].HEmpID;
                Int64 HMangerID = mainList[0].HMangerID;
                ds = oCN.RunProcReturn("select * from h_v_Qj_Sc_MouldUpperBillList where hmainid=" + HInterID + " and 单据号='" + HBillNo + "'", "h_v_Qj_Sc_MouldUpperBillList");
                if ((OperationType == 1) && ds.Tables[0].Rows.Count == 0)//新增
                {
                    //保存前控制
                    objJsonResult = BeforeSave_MouldUpperBill(HInterID, HBillNo, 1);
                    if (objJsonResult.count == 0)
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = objJsonResult.Message;
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                    //主表
                    oCN.RunProc(@"Insert Into Sc_MouldUpperBillMain
                   (HBillType,HBillStatus, HBillSubType, HInterID, HBillNo, HDate
                   , HYear, HPeriod, HRemark, HMaker, HMakeDate, HOrgID
                   , HDeptID, HEmpID, HMangerID)" +
                    " values('" + HBillType + "','1','" + HBillType + "'," + HInterID + ",'" + HBillNo + "','" + HDate + "'" +
                    "," + HYear + "," + HPeriod + ",'" + HRemark + "','" + HMaker + "',getdate()," + HOrgID +
                    "," + HDeptID + "," + HEmpID + "," + HMangerID + ") ");
                }
                else if (OperationType == 3 || ds.Tables[0].Rows.Count != 0)
                {
                    //保存前控制
                    objJsonResult = BeforeSave_MouldUpperBill(HInterID, HBillNo, 2);
                    if (objJsonResult.count == 0)
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = objJsonResult.Message;
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                    //修改
                    oCN.RunProc("update Sc_MouldUpperBillMain  set " +
                       "HDate='" + HDate +
                       "',HYear='" + HYear + "',HPeriod='" + HPeriod + "',HRemark='" + HRemark + "',hupdater='" + HMaker +
                       "',hupdatedate=getdate(),HDeptID=" + HDeptID + ",HEmpID=" + HEmpID + ",HMangerID=" + HMangerID + " where HInterID='" + HInterID + "'");
                    //删除子表
                    oCN.RunProc("delete from Sc_MouldUpperBillSub where HInterID='" + HInterID + "'");
                }
                //保存子表
                objJsonResult = AddBillSub_APP(msg3, HInterID, HBillNo, 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_APP(string msg3, long HInterID, string HBillNo, Int64 OperationType)
        {
            List<ClsSc_MouldUpperBillSub> DetailColl = Newtonsoft.Json.JsonConvert.DeserializeObject<List<ClsSc_MouldUpperBillSub>>(msg3);
            int i = 0;
            foreach (ClsSc_MouldUpperBillSub oSub in DetailColl)
            {
                i++;
                oCN.RunProc(@"Insert Into Sc_MouldUpperBillSub
                   (HInterID, HBillNo_bak, HEntryID, HMouldID, HQty
                   , HSourceID, HICMOInterID, HICMOEntryID, HICMOBillNo,HScanDate,HBarCode)
                    values("
                     + HInterID + ",'" + HBillNo + "'," + i + "," + oSub.HMouldID.ToString() + ",'" + oSub.HQty
                     + "'," + oSub.HSourceID.ToString() + "," + oSub.HICMOInterID.ToString() + "," + oSub.HICMOEntryID.ToString() + ",'" + oSub.HICMOBillNo.ToString() + "',getdate(),'" + oSub.HBarCode.ToString() +
                     "') ");
            }
            if (OperationType == 1)//新增
            {
                //保存后控制
                objJsonResult = AfterSave_MouldUpperBill(HInterID, HBillNo, 1);
                if (objJsonResult.count == 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = objJsonResult.Message;
                    objJsonResult.data = null;
                    return objJsonResult;
                }
            }
            else
            {
                //保存后控制
                objJsonResult = AfterSave_MouldUpperBill(HInterID, HBillNo, 2);
                if (objJsonResult.count == 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;
        }
        #endregion
        #region 上模单扫描条码查询是否存在 并校验产品防错信息
        [Route("Sc_MouldUpperBill/GetBarCode_FC")]
        [HttpGet]
        public object GetBarCode_FC(string HBarCode, int HMaterID)
        {
            try
            {
                ds = oCN.RunProcReturn("exec h_p_Sc_MouldFill_Verification '" + HBarCode + "','" + HMaterID + "'", "h_p_Sc_MouldFill_Verification");
                if (ds == null || ds.Tables[0].Rows.Count == 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "查无数据!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                else if (DBUtility.ClsPub.isLong(ds.Tables[0].Rows[0]["HBack"]) == 1)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;  //失败!
                    objJsonResult.Message = DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[0]["HRemark"]);
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                else
                {
                    objJsonResult.code = "1";
                    objJsonResult.count = 1;  //成功!
                    objJsonResult.Message = DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[0]["HRemark"]);
                    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
        #region 上模单扫描工单条码查询对应的器具清单
        [Route("Sc_MouldUpperBill/GetMaterialMouldList")]
        [HttpGet]
        public object GetMaterialMouldList(string sWhere, string user)
        {
            try
            {
                ds = oCN.RunProcReturn("select * from h_v_Gy_MaterialMouldBillMainList_APP where 1 = 1"+sWhere, "h_v_Gy_MaterialMouldBillMainList_APP");
                if (ds == null || ds.Tables[0].Rows.Count == 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "未找到当前物料对应的检具清单!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                else
                {
                    objJsonResult.code = "1";
                    objJsonResult.count = 1;  //成功!
                    objJsonResult.Message = "查询成功";
                    objJsonResult.data = ds.Tables[0];
                    return objJsonResult;
                }
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "Exception!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
    }
}