WebAPI/Controllers/Sc_MouldRepairInBillListController.cs
@@ -4,6 +4,8 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Web;
using System.Web.Http;
using ViewAPI;
using WebAPI.Models;
@@ -22,9 +24,11 @@
        public SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();
        public DAL.ClsSc_ICMOBill BillOld = new DAL.ClsSc_ICMOBill();
        SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
        Pub_Class.ClsXt_SystemParameter oSystemParameter = new Pub_Class.ClsXt_SystemParameter();
        public DAL.ClsSc_MouldScrapInBill BillNew0 = new DAL.ClsSc_MouldScrapInBill();   //模具报废入库对应单据类
        public DAL.ClsSc_MouldScrapInBill BillOld0 = new DAL.ClsSc_MouldScrapInBill();   //模具报废入库对应单据类
        string fileip = System.Configuration.ConfigurationManager.AppSettings["FileIP"];
        /// <summary>
@@ -602,6 +606,49 @@
        }
        #endregion
        #region 器具寿命耗用分析报表
        [Route("Sc_MouldRepairInBillList/Get_Sc_MouldLifeUsePicReport")]
        [HttpGet]
        public object Get_Sc_MouldLifeUsePicReport(string sWhere)
        {
            try
            {
                List<object> columnNameList = new List<object>();
                if (sWhere == null || sWhere.Equals(""))
                {
                    ds = oCN.RunProcReturn("select * from h_v_Sc_MouldLifeUsePicReport order by 月份 desc", "h_v_Sc_MouldLifeUsePicReport");
                }
                else
                {
                    string sql1 = "select * from h_v_Sc_MouldLifeUsePicReport where 1 = 1 ";
                    string sql = sql1 + sWhere + " order by 日期 ";
                    ds = oCN.RunProcReturn(sql, "h_v_Sc_MouldLifeUsePicReport");
                }
                //添加列名
                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 = 1;
                objJsonResult.Message = "Sucess!";
                objJsonResult.data = ds.Tables[0];
                objJsonResult.list = columnNameList;
                return objJsonResult;
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "Exception!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
        /// <summary>
@@ -1296,7 +1343,6 @@
                    }
                    //===========================================================          
                    //反审核单据
                    if (oBill.AbandonCheck(oBill.omodel.HInterID, oBill.omodel.HBillNo, "h_p_Kf_MoveStockBill_AfterUnCheckCtrl", user, ref DBUtility.ClsPub.sExeReturnInfo) == true)
                    {
@@ -1579,6 +1625,7 @@
        {
            try
            {
                List<object> columnNameList = new List<object>();  //定义声明变量 ,把通过 new List<object>()创建的 实例,赋值给变量
                //判断是否有查询权限
                if (!DBUtility.ClsPub.Security_Log("Kf_MoveStockBillQuery", 1, false, user))
                {
@@ -1598,11 +1645,18 @@
                    string sql = "select * from h_v_IF_MoveStockBillList where 1=1 " + sWhere+ "order by hmainid desc";
                    ds = oCN.RunProcReturn(sql, "h_v_IF_MoveStockBillList");
                }
                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格式的字符串
                    columnNameList.Add(JsonConvert.DeserializeObject(ColmString));//获取到DataColumn列对象的列名
                }
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "Sucess!";
                objJsonResult.data = ds.Tables[0];
                objJsonResult.list = columnNameList;
                return objJsonResult;
              
            }
@@ -1771,6 +1825,7 @@
        {
            try
            {
                List<object> columnNameList = new List<object>();  //定义声明变量 ,把通过 new List<object>()创建的 实例,赋值给变量
                //判断是否有查询权限
                if (!DBUtility.ClsPub.Security_Log("Kf_SellOutBillQuery", 1, false, user))
                {
@@ -1782,6 +1837,12 @@
                }
                ds = Sc_GetSellOutBillList(sWhere);
                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格式的字符串
                    columnNameList.Add(JsonConvert.DeserializeObject(ColmString));//获取到DataColumn列对象的列名
                }
                //if (ds.Tables[0].Rows.Count != 0 || ds != null)
                //{
@@ -1789,6 +1850,7 @@
                objJsonResult.count = 1;
                objJsonResult.Message = "Sucess!";
                objJsonResult.data = ds.Tables[0];
                objJsonResult.list = columnNameList;
                return objJsonResult;
                //}
                //else
@@ -1856,7 +1918,7 @@
                if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 1;
                    objJsonResult.count = 0;
                    objJsonResult.Message = "删除失败!原因:删除前判断失败,请与网络管理人员联系";
                    objJsonResult.data = null;
                    return objJsonResult;
@@ -1865,7 +1927,7 @@
                if (ds.Tables[0].Rows[0]["HBack"].ToString() != "0")
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 1;
                    objJsonResult.count = 0;
                    objJsonResult.Message = "删除失败!原因:" + ds.Tables[0].Rows[0]["HRemark"].ToString(); ;
                    objJsonResult.data = null;
                    return objJsonResult;
@@ -1890,11 +1952,11 @@
                oCN.RunProc("exec h_p_Xs_UpDateRelation_SeOutStockToPOStockIn_Delete " + HInterID);
                //oCN.RunProc("Delete From Kf_ICStockBillMain where HInterID = " + HInterID);
                //oCN.RunProc("Delete From Kf_ICStockBillSub where HInterID = " + HInterID);
                oCN.RunProc("Delete From Kf_ICStockBillMain where HInterID = " + HInterID);
                oCN.RunProc("Delete From Kf_ICStockBillSub where HInterID = " + HInterID);
                string sql = "exec h_p_WMS_ICStockBillAndWMS_Delete " + BillOld.omodel.HInterID + ",'" + BillOld.omodel.HBillNo + "','1205'";
                oCn.RunProc(sql);
                //string sql = "exec h_p_WMS_ICStockBillAndWMS_Delete " + BillOld.omodel.HInterID + ",'" + BillOld.omodel.HBillNo + "','1205'";
                //oCn.RunProc(sql);
                //删除后控制==================================================================================      
                string sql2 = "exec h_p_Kf_SellOutBill_AfterDelCtrl " + BillOld.omodel.HInterID + ",'" + BillOld.omodel.HBillNo + "','" + user + "'";
@@ -1903,7 +1965,7 @@
                {
                    s = "删除后判断失败,请与网络管理人员联系";
                    objJsonResult.code = "0";
                    objJsonResult.count = 1;
                    objJsonResult.count = 0;
                    objJsonResult.Message = "删除失败!原因:" + s;
                    objJsonResult.data = null;
                    oCN.RollBack();
@@ -1913,7 +1975,7 @@
                {
                    s = ds.Tables[0].Rows[0]["HRemark"].ToString();
                    objJsonResult.code = "0";
                    objJsonResult.count = 1;
                    objJsonResult.count = 0;
                    objJsonResult.Message = "删除失败!原因:" + s;
                    objJsonResult.data = null;
                    oCN.RollBack();
@@ -2196,6 +2258,7 @@
        {
            try
            {
                List<object> columnNameList = new List<object>();  //定义声明变量 ,把通过 new List<object>()创建的 实例,赋值给变量
                //判断是否有查询权限
                if (!DBUtility.ClsPub.Security_Log("Kf_OtherOutBillQuery", 1, false, user))
                {
@@ -2215,13 +2278,21 @@
                    string sql = "select * from h_v_Kf_OtherOutBillList where 1 = 1 " + sWhere+ " order by hmainid desc";
                    ds = oCN.RunProcReturn(sql, "h_v_Kf_OtherOutBillList");
                }
                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格式的字符串
                    columnNameList.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.data = ds.Tables[0];//代码将第一个DataTable(索引为0)赋值给objJsonResult的data属性
                objJsonResult.list = columnNameList;//将columnNameList赋值给objJsonResult的list属性
                return objJsonResult;
                //}
                //else
@@ -3296,7 +3367,6 @@
                    }
                    //================================================================================== 
                    //审核单据
                    if (!oBill.CheckBill(oBill.omodel.HInterID, oBill.omodel.HBillNo, "h_p_Kf_ICStockBill_AfterCheckCtrl", user, ref DBUtility.ClsPub.sExeReturnInfo) == true)
                    {
@@ -3347,7 +3417,6 @@
                        return objJsonResult;
                    }
                    //===========================================================          
                    //反审核单据
                    if (oBill.AbandonCheck(oBill.omodel.HInterID, oBill.omodel.HBillNo, "h_p_Kf_ICStockBill_AfterUnCheckCtrl", user, ref DBUtility.ClsPub.sExeReturnInfo) == true)
@@ -3640,6 +3709,7 @@
        {
            try
            {
                List<object> columnNameList = new List<object>();  //定义声明变量 ,把通过 new List<object>()创建的 实例,赋值给变量
                //判断是否有查询权限
                if (!DBUtility.ClsPub.Security_Log("Kf_OtherInBillQuery", 1, false, user))
                {
@@ -3659,13 +3729,19 @@
                    string sql = "select * from h_v_Kf_OtherInBillList where 1 = 1 " + sWhere+ " order by hmainid desc";
                    ds = oCN.RunProcReturn(sql, "h_v_Kf_OtherInBillList");
                }
                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格式的字符串
                    columnNameList.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.data = ds.Tables[0];//代码将第一个DataTable(索引为0)赋值给objJsonResult的data属性
                objJsonResult.list = columnNameList;//将columnNameList赋值给objJsonResult的list属性
                return objJsonResult;
                //}
                //else
@@ -3832,6 +3908,7 @@
        {
            try
            {
                List<object> columnNameList = new List<object>();  //定义声明变量 ,把通过 new List<object>()创建的 实例,赋值给变量
                //判断是否有查询权限
                if (!DBUtility.ClsPub.Security_Log("Kf_EntrustInBillQuery", 1, false, user))
                {
@@ -3850,13 +3927,20 @@
                    string sql = "select * from h_v_Kf_EntrustInBillList where 1 = 1 " + sWhere+ " order by hmainid desc";
                    ds = oCN.RunProcReturn(sql, "h_v_Kf_EntrustInBillList");
                }
                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格式的字符串
                    columnNameList.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.data = ds.Tables[0];//代码将第一个DataTable(索引为0)赋值给objJsonResult的data属性
                objJsonResult.list = columnNameList;//将columnNameList赋值给objJsonResult的list属性
                return objJsonResult;
                //}
                //else
@@ -4596,7 +4680,7 @@
                {
                    //ds = oCN.RunProcReturn("select HRepairCheckID,HRepairCheckContent,HManagerID,HRemark   from Sc_MouldRepairCheckBillSub", "Sc_MouldRepairCheckBillSub");
                    ds = oCN.RunProcReturn("select  HRepairCheckID,验收项目代码 HRepairCheckCode,验收项目 HRepairCheckName,验收内容 HRepairCheckContent,HManagerSonID HManagerID,子负责人代码 HManagerCode,子负责人 HManagerName,备注 HRemark from h_v_Sc_MouldRepairCheckBillList_Edit", "h_v_Sc_MouldRepairCheckBillList_Edit");
                    ds = oCN.RunProcReturn("select * from h_v_Sc_MouldRepairCheckBillList_Edit", "h_v_Sc_MouldRepairCheckBillList_Edit");
                    objJsonResult.code = "0";
                    objJsonResult.count = 1;
@@ -4607,7 +4691,7 @@
                {
                    //string sql1 = "select HRepairCheckID,HRepairCheckContent,HManagerID,HRemark  from Sc_MouldRepairCheckBillSub where 1 = 1 ";
                    string sql1 = "select  HRepairCheckID,验收项目代码 HRepairCheckCode,验收项目 HRepairCheckName,验收内容 HRepairCheckContent,HManagerSonID HManagerID,子负责人代码 HManagerCode,子负责人 HManagerName,备注 HRemark from h_v_Sc_MouldRepairCheckBillList_Edit where 1 = 1 ";
                    string sql1 = "select * from h_v_Sc_MouldRepairCheckBillList_Edit where 1 = 1 ";
                    string sql = sql1 + sqlWhere;
                    ds = oCN.RunProcReturn(sql, "h_v_Sc_MouldRepairCheckBillList_Edit");
@@ -5035,6 +5119,7 @@
                DAL.ClsSc_MouldMaintainPlanBill oBill = new DAL.ClsSc_MouldMaintainPlanBill();
                List<Model.ClsSc_MouldMaintainPlanBillMain> lsmain = new List<Model.ClsSc_MouldMaintainPlanBillMain>();
                msg2 = msg2.Replace("\\", "");
                msg2 = msg2.Replace("\n", "");  //\n
                lsmain = oListModels.getObjectByJson_Gy_MouldMaintainPlanBillMain(msg2);
@@ -5044,11 +5129,14 @@
                    UserName = oItem.HMaker;  //制单人
                    oItem.HBillType = "3818";
                    oItem.HBillSubType = "3818";
                    oItem.HMainSourceInterID = oItem.HMouldMaintainRuleID;
                    oItem.HMainSourceBillNo = oItem.HMouldMaintainRuleNo;
                    //oItem.HInterID =0;
                    //oItem.HBillNo = "";
                    oItem.HDate = DBUtility.ClsPub.isDate(DateTime.Now.ToString("yyyy-MM-dd"));//  --日期
                    oItem.HYear = DBUtility.ClsPub.isLong(DateTime.Now.Year);
                    oItem.HPeriod = DBUtility.ClsPub.isLong(DateTime.Now.Month);
                    //oItem.HMakeDate = "";
                    //oItem.HYear = "";
                    //oItem.HPeriod = "";
@@ -5201,7 +5289,7 @@
            {
                SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
                //获取保养项目编辑数据
                string sql = "select 保养项目ID HMaintainItemID, 保养项目代码 HMaintainItemNumber,保养项目 HMaintainItem,保养部位 HMaintainPart,具体要求 HClaim,负责人ID,负责人代码 HManagerNumber,负责人名称 HManagerName,子备注2 HRemark,HMouldMaintainRuleID,HEquipDotCheckNo  from h_v_Sc_MouldMaintainPlanBillSub_Item where 1 = 1 " + sqlWhere + "";
                string sql = "select 保养项目ID HMaintainItemID, 保养项目代码 HMaintainItemNumber,保养项目 HMaintainItem,保养部位 HMaintainPart,具体要求 HClaim,负责人ID HManagerID,负责人代码 HManagerNumber,负责人名称 HManagerName,子备注2 HRemark,HMouldMaintainRuleID,HEquipDotCheckNo  from h_v_Sc_MouldMaintainPlanBillSub_Item where 1 = 1 " + sqlWhere + "";
                ds = oCN.RunProcReturn(sql, "h_v_Sc_MouldMaintainPlanBillSub_Item");
                //获取配件项目编辑数据
@@ -5580,6 +5668,142 @@
        }
        #endregion
        #region 模具保养记录表 保存/编辑PDA
        /// <summary>
        /// 保存模具维修单
        /// </summary>
        /// <param name="msg"></param>
        /// <returns></returns>
        [Route("Sc_MouldMaintainBill/SaveGetMouldMaintainBillListPDA")]
        [HttpPost]
        public object SaveGetMouldMaintainBillListPDA([FromBody] JObject msg)
        {
            var _value = msg["msg"].ToString();
            string msg1 = _value.ToString();
            string[] sArray = msg1.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
            string msg2 = sArray[0].ToString();
            string msg3 = sArray[1].ToString();
            string msg5 = sArray[2].ToString();
            string UserName = "";
            ListModels oListModels = new ListModels();
            try
            {
                if (!DBUtility.ClsPub.Security_Log("Sc_MouldMaintainBill_Edit", 1, false, msg5))
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "无保存权限!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                DAL.ClsSc_MouldMaintainBill oBill = new DAL.ClsSc_MouldMaintainBill();
                List<Model.ClsSc_MouldMaintainBillMain> lsmain = new List<Model.ClsSc_MouldMaintainBillMain>();
                msg2 = msg2.Replace("\\", "");
                msg2 = msg2.Replace("\n", "");  //\n
                lsmain = oListModels.getObjectByJson_Sc_MouldMaintainBillMain(msg2);
                foreach (Model.ClsSc_MouldMaintainBillMain oItem in lsmain)
                {
                    UserName = oItem.HMaker;  //制单人
                    DBUtility.ClsPub.CurUserName = UserName;
                    oItem.HBillType = "3819";
                    oItem.HBillSubType = "3819";
                    //oItem.HInterID =0;
                    //oItem.HBillNo = "";
                    oItem.HDate = DBUtility.ClsPub.isDate(DateTime.Now.ToString("yyyy-MM-dd"));//  --日期
                    oItem.HYear = DBUtility.ClsPub.isLong(DateTime.Now.Year);
                    //oItem.HMakeDate = "";
                    //oItem.HYear = "";
                    //oItem.HPeriod = "";
                    //oItem.HRemark = "";
                    //oItem.HCycleUnit = "";
                    //oItem.HCheckCycle = "";
                    //oItem.HBeginDate = "";
                    //oItem.HEndDate = "";
                    //oItem.HInnerBillNo = "";
                    //oItem.HExplanation = "";
                    //oItem.HInterID = DBUtility.ClsPub.CreateBillID_SRMProd("1103", ref DBUtility.ClsPub.sExeReturnInfo);
                    if (DBUtility.ClsPub.isStrNull(oItem.HDate) == "")
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "保存失败!没有单据日期,无法保存!";
                        objJsonResult.data = 1;
                        return objJsonResult;
                    }
                    oBill.omodel = oItem;
                }
                //保养项表体数据
                //按 },{来拆分数组 //去掉【和】
                msg3 = msg3.Substring(1, msg3.Length - 2);
                msg3 = msg3.Replace("\\", "");
                msg3 = msg3.Replace("\n", "");  //\n
                //msg2 = msg2.Replace("'", "’");
                List<Model.ClsSc_MouldMaintainRuleBillSub_Item> ls = new List<Model.ClsSc_MouldMaintainRuleBillSub_Item>();
                ls = oListModels.getObjectByJson_Sc_MouldMaintainRuleBillSub_Item(msg3);
                int i = 0;
                foreach (Model.ClsSc_MouldMaintainRuleBillSub_Item oItemSub in ls)
                {
                    i++;
                    oItemSub.HEntryID = i;
                    //oItemSub.HCloseMan = "";       //行关闭
                    oItemSub.HEntryCloseDate = DBUtility.ClsPub.isDate(DateTime.Now);
                    oItemSub.HCloseType = false;   //关闭类型
                    //oItemSub.HRemark = "";         //备注
                    oItemSub.HSourceInterID = 0;     // 源单主内码
                    oItemSub.HSourceEntryID = 0;   //源单子内码
                    //oItemSub.HSourceBillNo = "";  //源单单号
                    //oItemSub.HSourceBillType = ""; //源单类型
                    oItemSub.HRelationQty = 0;     //关联数量
                    oBill.DetailCol.Add(oItemSub);
                }
                //保存
                //保存完毕后处理
                bool bResult;
                if (oBill.omodel.HInterID == 0)
                {
                    // bResult = oBill.AddBill(ref DBUtility.ClsPub.sExeReturnInfo);
                    bResult = oBill.AddBill(ref DBUtility.ClsPub.sExeReturnInfo);
                }
                else
                {
                    bResult = oBill.ModifyBill(oBill.omodel.HInterID, ref DBUtility.ClsPub.sExeReturnInfo);
                }
                if (bResult)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "保存成功!";
                    //WebAPIController.Add_Log("送货单下推", UserName, "生成送货单");
                    objJsonResult.data = 1;
                    return objJsonResult;
                }
                else
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "保存失败!" + DBUtility.ClsPub.sExeReturnInfo;
                    objJsonResult.data = 1;
                    return objJsonResult;
                }
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "保存失败!" + e.ToString();
                objJsonResult.data = 1;
                return objJsonResult;
            }
        }
        #endregion
        #region[模具保养记录表编辑时获取表头数据]
        [Route("Sc_MouldMaintainBill/Sc_MouldMaintainBillListCheckDetai")]
        [HttpGet]
@@ -5655,7 +5879,7 @@
                }
                SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
                //获取保养项目编辑数据
                string sql = "select HMaintainItemID, 保养项目代码 HMaintainItemNumber,保养项目名称 HMaintainItem,保养部位 HMaintainPart,具体要求 HClaim,HManagerID,负责人代码 HManagerNumber,负责人 HManagerName,表体备注 HRemark  from h_v_Sc_MouldMaintainBillListItem where 1 = 1 " + Swhere + "";
                string sql = "select HMaintainItemID, 保养项目代码 HMaintainItemNumber,保养项目名称 HMaintainItem,保养部位 HMaintainPart,具体要求 HClaim,HManagerID,负责人代码 HManagerNumber,负责人 HManagerName,表体备注 HRemark,保养结果 HMaintainResult  from h_v_Sc_MouldMaintainBillListItem where 1 = 1 " + Swhere + "";
                ds = oCN.RunProcReturn(sql, "h_v_Sc_MouldMaintainBillListItem");
                //获取配件项目编辑数据
                string sql1 = "select HMaterID, 配件代码 HMaterNumber,配件名称 HMaterName,规格型号 HMaterSpec,HUnitID,单位代码 HUnitNumber,单位名称 HUnitName,实际用量 HQty,标准用量 HQtyMust,HManagerID,负责人代码 HManagerNumber,负责人 HManagerName,表体备注 HRemark  from h_v_Sc_MouldMaintainBillList where 1 = 1 " + Swhere + "";
@@ -6310,8 +6534,6 @@
            string msg2 = sArray[0].ToString();
            string msg3 = sArray[1].ToString();
            string msg4 = sArray[2].ToString();
            //string msg5 = sArray[3].ToString();
            string UserName = "";
            ListModels oListModels = new ListModels();
@@ -6332,28 +6554,14 @@
                msg2 = msg2.Replace("\n", "");  //\n
                lsmain = oListModels.getObjectByJson_Sc_MouldDotCheckPlanBillMain(msg2);
                foreach (Model.ClsSc_MouldDotCheckPlanBillMain oItem in lsmain)
                {
                    //oItem.HMaker = "";
                {
                    UserName = oItem.HMaker;  //制单人
                    oItem.HBillType = "3820";
                    oItem.HBillSubType = "3820";
                    //oItem.HInterID =0;
                    //oItem.HBillNo = "";
                    oItem.HDate = DBUtility.ClsPub.isDate(DateTime.Now.ToString("yyyy-MM-dd"));//  --日期
                    oItem.HYear = DBUtility.ClsPub.isLong(DateTime.Now.Year);
                    //oItem.HMakeDate = "";
                    //oItem.HYear = "";
                    //oItem.HPeriod = "";
                    //oItem.HRemark = "";
                    //oItem.HCycleUnit = "";
                    //oItem.HCheckCycle = "";
                    //oItem.HBeginDate = "";
                    //oItem.HEndDate = "";
                    //oItem.HInnerBillNo = "";
                    //oItem.HExplanation = "";
                    //oItem.HInterID = DBUtility.ClsPub.CreateBillID_SRMProd("1103", ref DBUtility.ClsPub.sExeReturnInfo);
                    oItem.HYear = DBUtility.ClsPub.isLong(DateTime.Now.Year);
                    if (DBUtility.ClsPub.isStrNull(oItem.HDate) == "")
                    {
                        objJsonResult.code = "0";
@@ -6378,7 +6586,7 @@
                    i++;
                    oItemSub.HEntryID = i;
                    //oItemSub.HCloseMan = "";       //行关闭
                    oItemSub.HEntryCloseDate = DBUtility.ClsPub.isDate(DateTime.Now);
                    oItemSub.HCloseType = false;   //关闭类型
                    //oItemSub.HRemark = "";         //备注
@@ -6386,43 +6594,10 @@
                    oItemSub.HSourceEntryID = 0;   //源单子内码
                    //oItemSub.HSourceBillNo = "";  //源单单号
                    //oItemSub.HSourceBillType = ""; //源单类型
                    oItemSub.HRelationQty = 0;     //关联数量
                                                   //oItemSub.HRelationMoney = 0;   //关联金额
                                                   //HMaterID = "";//配件代码
                                                   //HUnitID = "";//单位代码
                                                   //HQty = "";//实际用量
                                                   //HQtyMust = "";//单位用量
                                                   //HRemark = "";//备注
                    oItemSub.HRelationQty = 0;     //关联数量
                    oBill.DetailColl.Add(oItemSub);
                }
                ////配件项表体数据
                ////按 },{来拆分数组 //去掉【和】
                //msg5 = msg5.Substring(1, msg5.Length - 2);
                //msg5 = msg5.Replace("\\", "");
                //msg5 = msg5.Replace("\n", "");  //\n
                //                                //msg2 = msg2.Replace("'", "’");
                //List<Model.ClsSc_MouldDotCheckPlanBillSub_Item> ls1 = new List<Model.ClsSc_MouldDotCheckPlanBillSub_Item>();
                //ls1 = oListModels.getObjectByJson_Sc_MouldDotCheckPlanBillSub_Item(msg5);
                //int j = 0;
                //foreach (Model.ClsSc_MouldDotCheckPlanBillSub_Item oItemSub in ls1)
                //{
                //    j++;
                //    oItemSub.HEntryID = j;
                //    //oItemSub.HCloseMan = "";       //行关闭
                //    oItemSub.HEntryCloseDate = DBUtility.ClsPub.isDate(DateTime.Now);
                //    oItemSub.HCloseType = false;   //关闭类型
                //    oItemSub.HSourceInterID = 0;     // 源单主内码
                //    oItemSub.HSourceEntryID = 0;   //源单子内码
                //    oItemSub.HRelationQty = 0;     //关联数量
                //    oBill.DetailCol.Add(oItemSub);
                //}
                }
                //保存
                //保存完毕后处理
                bool bResult;
@@ -6599,6 +6774,124 @@
        }
        #endregion
        #region 器具点检计划单审核/反审核功能
        [Route("Sc_MouldDotCheckPlanBill/CheckSc_MouldDotCheckPlanBill")]
        [HttpGet]
        public object CheckSc_MouldDotCheckPlanBill(string HInterID, int Type, string user)
        {
            DAL.ClsSc_MouldDotCheckPlanBill BillOld = new DAL.ClsSc_MouldDotCheckPlanBill();
            try
            {
                //判断是否有审核权限
                if (!DBUtility.ClsPub.Security_Log("Sc_MouldDotCheckPlanBill_Check", 1, false, user))
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "无权限审核!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                if (string.IsNullOrWhiteSpace(HInterID))
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "HInterID为空!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                ClsPub.CurUserName = user;
                oCN.BeginTran();//开始事务
                //Type 1 审核  2  反审核
                if (Type == 1)
                {
                    if (!BillOld.CheckBill(int.Parse(HInterID), ref ClsPub.sExeReturnInfo))
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 1;
                        objJsonResult.Message = "审核失败!原因:" + ClsPub.sExeReturnInfo;
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                    //自动生成点检计划单
                    oCN.RunProc("exec h_p_Sc_MouldDotCheckPlan_Auto " + HInterID);
                }
                else
                {
                    if (BillOld.AbandonCheck(int.Parse(HInterID), ref ClsPub.sExeReturnInfo))
                    {
                        SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();
                    }
                    else
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 1;
                        objJsonResult.Message = "审核失败!原因:" + ClsPub.sExeReturnInfo;
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                }
                oCN.Commit();//提交事务
                objJsonResult.code = "0";
                objJsonResult.count = 1;
                objJsonResult.Message = "执行成功!";
                objJsonResult.data = null;
                return objJsonResult; ;
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "执行失败!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
        #region[器具点检计划表编辑时获取表体数据--保养计划]
        [Route("Sc_MouldDotCheckPlanBill/GetPlanList")]
        [HttpGet]
        public object GetPlanList_Check(string sqlWhere)
        {
            DataSet ds;
            try
            {
                SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
                if (sqlWhere == null || sqlWhere.Equals(""))
                {
                    ds = oCN.RunProcReturn("select * from h_v_Sc_MouldDotCheckPlanList", "h_v_Sc_MouldDotCheckPlanList");
                    objJsonResult.code = "0";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "获取信息成功!";
                    objJsonResult.data = ds.Tables[0];
                }
                else
                {
                    string sql1 = "select * from h_v_Sc_MouldDotCheckPlanList where 1 = 1 ";
                    string sql = sql1 + sqlWhere;
                    ds = oCN.RunProcReturn(sql, "h_v_Sc_MouldDotCheckPlanList");
                    objJsonResult.code = "0";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "获取信息成功!";
                    objJsonResult.data = ds.Tables[0];
                }
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "没有返回任何计划!" + e.ToString();
                objJsonResult.data = null;
            }
            return objJsonResult;
        }
        #endregion
        #endregion
@@ -6618,7 +6911,7 @@
                    return objJsonResult;
                }
                //得到信息
                ds = oCN.RunProcReturn("select top 1 * from Gy_MouldFileMain  where HNumber= '" + HBarCode + "'", "Gy_MouldFileMain");
                ds = oCN.RunProcReturn("select top 1 * from Gy_MouldFileMain  where HBarCode= '" + HBarCode + "'", "Gy_MouldFileMain");
                //写入信息
                if (ds == null || ds.Tables[0].Rows.Count == 0)
                {
@@ -6720,7 +7013,208 @@
        }
        #endregion
        #region 模具报废入库单保存/编辑
        #region 模具报废入库单保存/编辑    20240702作废
        /// <summary>
        /// 保存模具报废入库单
        /// </summary>
        /// <param name="msg"></param>
        /// <returns></returns>
        //[Route("Sc_MouldScrapInHouseBill/SaveGetMouldScrapInHouseBillList")]
        //[HttpPost]
        //public object SaveGetMouldScrapInHouseBillList([FromBody] JObject msg)
        //{
        //    var _value = msg["msg"].ToString();
        //    string msg1 = _value.ToString();
        //    string[] sArray = msg1.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
        //    string msg2 = sArray[0].ToString();
        //    string msg3 = sArray[1].ToString();
        //    string refSav = sArray[2].ToString();
        //    string msg4 = sArray[3].ToString();
        //    string UserName = "";
        //    string s = "";
        //    ListModels oListModels = new ListModels();
        //    try
        //    {
        //        //编辑权限
        //        if (!DBUtility.ClsPub.Security_Log("Sc_MouldScrapRequestBill_Edit", 1, false, msg4))
        //        {
        //            objJsonResult.code = "0";
        //            objJsonResult.count = 0;
        //            objJsonResult.Message = "无保存权限!";
        //            objJsonResult.data = null;
        //            return objJsonResult;
        //        }
        //        DLL.ClsSc_MouldScrapInBill oBill = new DLL.ClsSc_MouldScrapInBill();
        //        List<Models.ClsSc_MouldStockBillMain> lsmain = new List<Models.ClsSc_MouldStockBillMain>();
        //        msg2 = msg2.Replace("\\", "");
        //        msg2 = msg2.Replace("\n", "");  //\n
        //        lsmain = oListModels.getObjectByJson_Gy_MouldScrapInHouseBillMain(msg2);
        //        foreach (Models.ClsSc_MouldStockBillMain oItem in lsmain)
        //        {
        //            if (refSav == "Add")
        //            {
        //                //单据号是否重复
        //                if (BillNew0.IsExistBillNo(ref ClsPub.sExeReturnInfo, oItem.HBillNo, BillStatus, BillOld0.omodel.HInterID))
        //                {
        //                    objJsonResult.code = "0";
        //                    objJsonResult.count = 0;
        //                    objJsonResult.Message = "单据号重复!不允许保存!";
        //                    objJsonResult.data = 1;
        //                    return objJsonResult;
        //                }
        //            }
        //            if (refSav == "Update")
        //            {
        //                if (BillOld0.ShowBill(oItem.HInterID, ref s) == false)
        //                {
        //                    objJsonResult.code = "0";
        //                    objJsonResult.count = 0;
        //                    objJsonResult.Message = "此单据有误!";
        //                    objJsonResult.data = 1;
        //                    return objJsonResult;
        //                }
        //                //判断是否可编辑
        //                if (BillOld0.omodel.HChecker != "" && BillOld0.omodel.HChecker != null)
        //                {
        //                    objJsonResult.code = "0";
        //                    objJsonResult.count = 0;
        //                    objJsonResult.Message = "此单据已经被审核,不允许修改!";
        //                    objJsonResult.data = 1;
        //                    return objJsonResult;
        //                }
        //                if (BillOld0.omodel.HBillStatus > 1)
        //                {
        //                    objJsonResult.code = "0";
        //                    objJsonResult.count = 0;
        //                    objJsonResult.Message = "此单据处于不可编辑状态,不允许修改!";
        //                    objJsonResult.data = 1;
        //                    return objJsonResult;
        //                }
        //                if (!DBUtility.Xt_BaseBillFun.Fun_AllowEditBill(BillOld0, ref s))
        //                {
        //                    objJsonResult.code = "0";
        //                    objJsonResult.count = 0;
        //                    objJsonResult.Message = s + ",不允许修改";
        //                    objJsonResult.data = 1;
        //                    return objJsonResult;
        //                }
        //            }
        //            //oItem.HMaker = "";
        //            UserName = oItem.HMaker;  //制单人
        //            oItem.HBillType = "3831";
        //            oItem.HBillSubType = "3831";
        //            //oItem.HBillNo = "";    //单据号
        //            //oItem.HDate = DBUtility.ClsPub.isDate(DateTime.Now.ToString("yyyy-MM-dd"));//  --日期
        //            //oItem.HInnerBillNo = "";  //  --内部单据号
        //            oItem.HYear = DBUtility.ClsPub.isLong(DateTime.Now.Year);
        //            oItem.HMakeDate = DBUtility.ClsPub.isStrNull(DateTime.Now.ToString("yyyy-MM-dd"));
        //            //oItem.HEquipID = 0;    //设备ID(Gy_EquipMent)
        //            //oItem.HPeriod = 0;
        //            //oItem.HCheckBeginDate = DBUtility.ClsPub.isDate(DateTime.Now.ToString("yyyy-MM-dd"));  //  --维修日期
        //            //oItem.HCheckResult = "";     //验收结论--(正常,异常)
        //            //oItem.HEmpID = 0;           //验收人(Gy_Employee)
        //            //oItem.HManagerID = 0;      //负责人(Gy_Employee)
        //            //oItem.HDeptID = 0;        //验收部门(Gy_Department)
        //            //oItem.HExplanation = "";  //摘要(故障描述)
        //            //oItem.HRemark = "";       //备注
        //            //oItem.HMainSourceInterID = oItem.HInterID;
        //            //oItem.HInterID = DBUtility.ClsPub.CreateBillID_SRMProd("1103", ref DBUtility.ClsPub.sExeReturnInfo);
        //            if (DBUtility.ClsPub.isStrNull(oItem.HDate) == "")
        //            {
        //                objJsonResult.code = "0";
        //                objJsonResult.count = 0;
        //                objJsonResult.Message = "保存失败!没有单据日期,无法保存!";
        //                objJsonResult.data = 1;
        //                return objJsonResult;
        //            }
        //            oBill.omodel = oItem;
        //        }
        //        //表体数据
        //        //按 },{来拆分数组 //去掉【和】
        //        msg3 = msg3.Substring(1, msg3.Length - 2);
        //        msg3 = msg3.Replace("\\", "");
        //        msg3 = msg3.Replace("\n", "");  //\n
        //        //msg2 = msg2.Replace("'", "’");
        //        List<Models.ClsSc_MouldStockBillSub> ls = new List<Models.ClsSc_MouldStockBillSub>();
        //        ls = oListModels.getObjectByJson_Gy_MouldScrapInHouseBillSub(msg3);
        //        int i = 0;
        //        foreach (Models.ClsSc_MouldStockBillSub oItemSub in ls)
        //        {
        //            i++;
        //            oItemSub.HEntryID = i;
        //            //oItemSub.HRepairCheckID = 0;   //验收项目ID
        //            //oItemSub.HRepairCheckContent = ""; //验收内容
        //            //oItemSub.HManagerID = 0;   //负责人ID
        //            //oItemSub.HCloseMan = "";       //行关闭
        //            oItemSub.HEntryCloseDate = DBUtility.ClsPub.isDate(DateTime.Now);
        //            oItemSub.HCloseType = false;   //关闭类型
        //            //oItemSub.HRemark = "";         //备注
        //            oItemSub.HSourceInterID = 0;     // 源单主内码
        //            oItemSub.HSourceEntryID = 0;   //源单子内码
        //            //oItemSub.HSourceBillNo = "";  //源单单号
        //            //oItemSub.HSourceBillType = ""; //源单类型
        //            //oItemSub.HRelationQty = 0;     //关联数量
        //            //oItemSub.HRelationMoney = 0;   //关联金额
        //            //oItemSub.HRepairID = 0;       //维修项目
        //            //oItemSub.HRepairExplanation ="";   //维修要求
        //            //oItemSub.HMoney = 0;        //维修费用
        //            oBill.DetailColl.Add(oItemSub);
        //        }
        //        //保存
        //        //保存完毕后处理
        //        bool bResult;
        //        if (oBill.omodel.HInterID == 0)
        //        {
        //            // bResult = oBill.AddBill(ref DBUtility.ClsPub.sExeReturnInfo);
        //            bResult = oBill.AddBill(ref DBUtility.ClsPub.sExeReturnInfo);
        //            string sql = string.Format($"exec h_p_Sc_MouldChangeFileStatus  'in','{oBill.omodel.HInterID.ToString()}' ");
        //            oCn.RunProc(sql);
        //        }
        //        else
        //        {
        //            bResult = oBill.ModifyBill(oBill.omodel.HInterID, ref DBUtility.ClsPub.sExeReturnInfo);
        //            //修改成功
        //            //string sql = string.Format($"exec h_p_Sc_MouldChangeNowWHID  1,{oBill.omodel.HInterID.ToString()},' ' ");
        //            string sql = string.Format($"exec h_p_Sc_MouldChangeNowWHID ");
        //            oCn.RunProc(sql);
        //        }
        //        if (bResult)
        //        {
        //            objJsonResult.code = "0";
        //            objJsonResult.count = 1;
        //            objJsonResult.Message = "保存成功!";
        //            //WebAPIController.Add_Log("送货单下推", UserName, "生成送货单");
        //            objJsonResult.data = 1;
        //            return objJsonResult;
        //        }
        //        else
        //        {
        //            objJsonResult.code = "0";
        //            objJsonResult.count = 0;
        //            objJsonResult.Message = "保存失败!" + DBUtility.ClsPub.sExeReturnInfo;
        //            objJsonResult.data = 1;
        //            return objJsonResult;
        //        }
        //    }
        //    catch (Exception e)
        //    {
        //        objJsonResult.code = "0";
        //        objJsonResult.count = 0;
        //        objJsonResult.Message = "保存失败!" + e.ToString();
        //        objJsonResult.data = 1;
        //        return objJsonResult;
        //    }
        //}
        #endregion
        #region 模具报废入库单保存/编辑    20240702
        /// <summary>
        /// 保存模具报废入库单
        /// </summary>
@@ -6730,175 +7224,137 @@
        [HttpPost]
        public object SaveGetMouldScrapInHouseBillList([FromBody] JObject msg)
        {
            DAL.ClsSc_MouldScrapInBill oBill = new DAL.ClsSc_MouldScrapInBill();
            var _value = msg["msg"].ToString();
            string msg1 = _value.ToString();
            string[] sArray = msg1.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
            string msg2 = sArray[0].ToString();
            string msg3 = sArray[1].ToString();
            string refSav = sArray[2].ToString();
            string msg4 = sArray[3].ToString();
            string UserName = "";
            string s = "";
            ListModels oListModels = new ListModels();
            string sMainStr = sArray[0].ToString();         //主表数据
            string sSubStr = sArray[1].ToString();          //子表数据
            string OperationType = sArray[2].ToString();    //操作类型(Add新增、Update编辑)
            string HMaker = sArray[3].ToString();           //制单人
            try
            {
                //编辑权限
                if (!DBUtility.ClsPub.Security_Log("Sc_MouldScrapRequestBill_Edit", 1, false, msg4))
                //判断权限
                if (OperationType == "Add")
                {
                    BillStatus = DBUtility.ClsPub.Enum_BillStatus.BillStatus_AddNew;
                    //判断新增权限
                    if (!DBUtility.ClsPub.Security_Log("Sc_MouldScrapRequestBill", 1, false, HMaker))
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "您没有该模块新增权限,请与管理员联系!";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                }
                else
                {
                    BillStatus = DBUtility.ClsPub.Enum_BillStatus.BillStatus_Modify;
                    //判断编辑权限
                    if (!DBUtility.ClsPub.Security_Log("Sc_MouldScrapRequestBill_Edit", 1, false, HMaker))
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "您没有该模块编辑权限,请与管理员联系!";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                }
                //表头赋值
                sMainStr = sMainStr.Replace("\\", "");
                sMainStr = sMainStr.Replace("\n", "");
                sMainStr = "[" + sMainStr.ToString() + "]";
                List<Model.ClsSc_MouldStockBillMain> lsmain = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Model.ClsSc_MouldStockBillMain>>(sMainStr);
                foreach (Model.ClsSc_MouldStockBillMain oItem in lsmain)
                {
                    //单据号是否重复
                    if (oBill.IsExistBillNo(ref ClsPub.sExeReturnInfo, oItem.HBillNo, BillStatus, oItem.HInterID))
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "单据号重复!不允许保存!";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                    //判断会计期是否合理
                    string s = "";
                    int sYear = 0;
                    int sPeriod = 0;
                    if (DBUtility.Xt_BaseBillFun.Fun_AllowYearPeriod(oItem.HDate, ref sYear, ref sPeriod, ref s) == false)
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = s;
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                    oItem.HYear = sYear;
                    oItem.HPeriod = sPeriod;
                    DBUtility.ClsPub.CurUserName = oItem.HMaker;
                    oBill.omodel = oItem;
                }
                //表体赋值
                //按 },{来拆分数组 //去掉【和】
                sSubStr = sSubStr.Substring(1, sSubStr.Length - 2);
                sSubStr = sSubStr.Replace("\\", "");
                sSubStr = sSubStr.Replace("\n", "");
                sSubStr = "[" + sSubStr.ToString() + "]";
                List<Model.ClsSc_MouldStockBillSub> ls = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Model.ClsSc_MouldStockBillSub>>(sSubStr);
                int i = 0;
                foreach (Model.ClsSc_MouldStockBillSub oItemSub in ls)
                {
                    i++;
                    oItemSub.HEntryID = i;
                    oBill.DetailColl.Add(oItemSub);
                }
                string sErrMsg = "";
                bool bResult;
                //获取系统参数
                if (oSystemParameter.ShowBill(ref sErrMsg) == true)
                {
                    //保存
                    if (OperationType == "Add")   //新增保存
                    {
                        bResult = oBill.AddBill(ref DBUtility.ClsPub.sExeReturnInfo);
                        if (oSystemParameter.omodel.WMS_CampanyName == "四维尔") //系统参数  客户定制化名称     空白为通用
                        {
                            //修改器具档案位置
                            string sql = string.Format($"exec h_p_Sc_MouldChangeFileStatus  'in','{oBill.omodel.HInterID.ToString()}' ");
                            oCn.RunProc(sql);
                        }
                    }
                    else                        //编辑保存
                    {
                        bResult = oBill.ModifyBill(oBill.omodel.HInterID, ref DBUtility.ClsPub.sExeReturnInfo);
                        if (oSystemParameter.omodel.WMS_CampanyName == "四维尔") //系统参数  客户定制化名称     空白为通用
                        {
                            //修改器具档案位置
                            string sql = string.Format($"exec h_p_Sc_MouldChangeNowWHID ");
                            oCn.RunProc(sql);
                        }
                    }
                }
                else
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "无保存权限!";
                    objJsonResult.Message = "获取系统参数失败! " + sErrMsg;
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                DLL.ClsSc_MouldScrapInBill oBill = new DLL.ClsSc_MouldScrapInBill();
                List<Models.ClsSc_MouldStockBillMain> lsmain = new List<Models.ClsSc_MouldStockBillMain>();
                msg2 = msg2.Replace("\\", "");
                msg2 = msg2.Replace("\n", "");  //\n
                lsmain = oListModels.getObjectByJson_Gy_MouldScrapInHouseBillMain(msg2);
                foreach (Models.ClsSc_MouldStockBillMain oItem in lsmain)
                {
                    if (refSav == "Add")
                    {
                        //单据号是否重复
                        if (BillNew0.IsExistBillNo(ref ClsPub.sExeReturnInfo, oItem.HBillNo, BillStatus, BillOld0.omodel.HInterID))
                        {
                            objJsonResult.code = "0";
                            objJsonResult.count = 0;
                            objJsonResult.Message = "单据号重复!不允许保存!";
                            objJsonResult.data = 1;
                            return objJsonResult;
                        }
                    }
                    if (refSav == "Update")
                    {
                        if (BillOld0.ShowBill(oItem.HInterID, ref s) == false)
                        {
                            objJsonResult.code = "0";
                            objJsonResult.count = 0;
                            objJsonResult.Message = "此单据有误!";
                            objJsonResult.data = 1;
                            return objJsonResult;
                        }
                        //判断是否可编辑
                        if (BillOld0.omodel.HChecker != "" && BillOld0.omodel.HChecker != null)
                        {
                            objJsonResult.code = "0";
                            objJsonResult.count = 0;
                            objJsonResult.Message = "此单据已经被审核,不允许修改!";
                            objJsonResult.data = 1;
                            return objJsonResult;
                        }
                        if (BillOld0.omodel.HBillStatus > 1)
                        {
                            objJsonResult.code = "0";
                            objJsonResult.count = 0;
                            objJsonResult.Message = "此单据处于不可编辑状态,不允许修改!";
                            objJsonResult.data = 1;
                            return objJsonResult;
                        }
                        if (!DBUtility.Xt_BaseBillFun.Fun_AllowEditBill(BillOld0, ref s))
                        {
                            objJsonResult.code = "0";
                            objJsonResult.count = 0;
                            objJsonResult.Message = s + ",不允许修改";
                            objJsonResult.data = 1;
                            return objJsonResult;
                        }
                    }
                    //oItem.HMaker = "";
                    UserName = oItem.HMaker;  //制单人
                    oItem.HBillType = "3831";
                    oItem.HBillSubType = "3831";
                    //oItem.HBillNo = "";    //单据号
                    //oItem.HDate = DBUtility.ClsPub.isDate(DateTime.Now.ToString("yyyy-MM-dd"));//  --日期
                    //oItem.HInnerBillNo = "";  //  --内部单据号
                    oItem.HYear = DBUtility.ClsPub.isLong(DateTime.Now.Year);
                    oItem.HMakeDate = DBUtility.ClsPub.isStrNull(DateTime.Now.ToString("yyyy-MM-dd"));
                    //oItem.HEquipID = 0;    //设备ID(Gy_EquipMent)
                    //oItem.HPeriod = 0;
                    //oItem.HCheckBeginDate = DBUtility.ClsPub.isDate(DateTime.Now.ToString("yyyy-MM-dd"));  //  --维修日期
                    //oItem.HCheckResult = "";     //验收结论--(正常,异常)
                    //oItem.HEmpID = 0;           //验收人(Gy_Employee)
                    //oItem.HManagerID = 0;      //负责人(Gy_Employee)
                    //oItem.HDeptID = 0;        //验收部门(Gy_Department)
                    //oItem.HExplanation = "";  //摘要(故障描述)
                    //oItem.HRemark = "";       //备注
                    //oItem.HMainSourceInterID = oItem.HInterID;
                    //oItem.HInterID = DBUtility.ClsPub.CreateBillID_SRMProd("1103", ref DBUtility.ClsPub.sExeReturnInfo);
                    if (DBUtility.ClsPub.isStrNull(oItem.HDate) == "")
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "保存失败!没有单据日期,无法保存!";
                        objJsonResult.data = 1;
                        return objJsonResult;
                    }
                    oBill.omodel = oItem;
                }
                //表体数据
                //按 },{来拆分数组 //去掉【和】
                msg3 = msg3.Substring(1, msg3.Length - 2);
                msg3 = msg3.Replace("\\", "");
                msg3 = msg3.Replace("\n", "");  //\n
                //msg2 = msg2.Replace("'", "’");
                List<Models.ClsSc_MouldStockBillSub> ls = new List<Models.ClsSc_MouldStockBillSub>();
                ls = oListModels.getObjectByJson_Gy_MouldScrapInHouseBillSub(msg3);
                int i = 0;
                foreach (Models.ClsSc_MouldStockBillSub oItemSub in ls)
                {
                    i++;
                    oItemSub.HEntryID = i;
                    //oItemSub.HRepairCheckID = 0;   //验收项目ID
                    //oItemSub.HRepairCheckContent = ""; //验收内容
                    //oItemSub.HManagerID = 0;   //负责人ID
                    //oItemSub.HCloseMan = "";       //行关闭
                    oItemSub.HEntryCloseDate = DBUtility.ClsPub.isDate(DateTime.Now);
                    oItemSub.HCloseType = false;   //关闭类型
                    //oItemSub.HRemark = "";         //备注
                    oItemSub.HSourceInterID = 0;     // 源单主内码
                    oItemSub.HSourceEntryID = 0;   //源单子内码
                    //oItemSub.HSourceBillNo = "";  //源单单号
                    //oItemSub.HSourceBillType = ""; //源单类型
                    //oItemSub.HRelationQty = 0;     //关联数量
                    //oItemSub.HRelationMoney = 0;   //关联金额
                    //oItemSub.HRepairID = 0;       //维修项目
                    //oItemSub.HRepairExplanation ="";   //维修要求
                    //oItemSub.HMoney = 0;        //维修费用
                    oBill.DetailColl.Add(oItemSub);
                }
                //保存
                //保存完毕后处理
                bool bResult;
                if (oBill.omodel.HInterID == 0)
                {
                    // bResult = oBill.AddBill(ref DBUtility.ClsPub.sExeReturnInfo);
                    bResult = oBill.AddBill(ref DBUtility.ClsPub.sExeReturnInfo);
                    string sql = string.Format($"exec h_p_Sc_MouldChangeFileStatus  'in','{oBill.omodel.HInterID.ToString()}' ");
                    oCn.RunProc(sql);
                }
                else
                {
                    bResult = oBill.ModifyBill(oBill.omodel.HInterID, ref DBUtility.ClsPub.sExeReturnInfo);
                    //修改成功
                    //string sql = string.Format($"exec h_p_Sc_MouldChangeNowWHID  1,{oBill.omodel.HInterID.ToString()},' ' ");
                    string sql = string.Format($"exec h_p_Sc_MouldChangeNowWHID ");
                    oCn.RunProc(sql);
                }
                if (bResult)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "保存成功!";
                    //WebAPIController.Add_Log("送货单下推", UserName, "生成送货单");
                    objJsonResult.data = 1;
                    objJsonResult.Message = DBUtility.ClsPub.sExeReturnInfo;  //成功!
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                else
@@ -6906,7 +7362,7 @@
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "保存失败!" + DBUtility.ClsPub.sExeReturnInfo;
                    objJsonResult.data = 1;
                    objJsonResult.data = null;
                    return objJsonResult;
                }
            }
@@ -6914,8 +7370,8 @@
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "保存失败!" + e.ToString();
                objJsonResult.data = 1;
                objJsonResult.Message = "保存失败!" + e.Message;
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
@@ -7184,7 +7640,158 @@
        }
        #endregion
        #region 模具处理出库单保存/编辑
        #region 模具处理出库单保存/编辑    20240702作废
        /// <summary>
        /// 保存模具处理出库单
        /// </summary>
        /// <param name="msg"></param>
        /// <returns></returns>
        //[Route("Sc_MouldScrapOutHouseBill/SaveGetMouldScrapOutHouseBillList")]
        //[HttpPost]
        //public object SaveGetMouldScrapOutHouseBillList([FromBody] JObject msg)
        //{
        //    var _value = msg["msg"].ToString();
        //    string msg1 = _value.ToString();
        //    string[] sArray = msg1.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
        //    string msg2 = sArray[0].ToString();
        //    string msg3 = sArray[1].ToString();
        //    string msg4 = sArray[2].ToString();
        //    string UserName = "";
        //    ListModels oListModels = new ListModels();
        //    try
        //    {
        //        //编辑权限
        //        if (!DBUtility.ClsPub.Security_Log("Sc_MouldScrapOutBill_Edit", 1, false, msg4))
        //        {
        //            objJsonResult.code = "0";
        //            objJsonResult.count = 0;
        //            objJsonResult.Message = "无保存权限!";
        //            objJsonResult.data = null;
        //            return objJsonResult;
        //        }
        //        DLL.ClsSc_MouldScrapOutBill oBill = new DLL.ClsSc_MouldScrapOutBill();
        //        List<Model.ClsSc_MouldStockBillMain> lsmain = new List<Model.ClsSc_MouldStockBillMain>();
        //        msg2 = msg2.Replace("\\", "");
        //        msg2 = msg2.Replace("\n", "");  //\n
        //        lsmain = oListModels.getObjectByJson_Gy_MouldScrapOutHouseBillMain(msg2);
        //        foreach (Model.ClsSc_MouldStockBillMain oItem in lsmain)
        //        {
        //            //oItem.HMaker = "";
        //            UserName = oItem.HMaker;  //制单人
        //            oItem.HBillType = "3832";
        //            oItem.HBillSubType = "3832";
        //            //oItem.HBillNo = "";    //单据号
        //            //oItem.HDate = DBUtility.ClsPub.isDate(DateTime.Now.ToString("yyyy-MM-dd"));//  --日期
        //            //oItem.HInnerBillNo = "";  //  --内部单据号
        //            oItem.HYear = DBUtility.ClsPub.isLong(DateTime.Now.Year);
        //            oItem.HMakeDate = DBUtility.ClsPub.isStrNull(DateTime.Now.ToString("yyyy-MM-dd"));
        //            //oItem.HEquipID = 0;    //设备ID(Gy_EquipMent)
        //            //oItem.HPeriod = 0;
        //            //oItem.HCheckBeginDate = DBUtility.ClsPub.isDate(DateTime.Now.ToString("yyyy-MM-dd"));  //  --维修日期
        //            //oItem.HCheckResult = "";     //验收结论--(正常,异常)
        //            //oItem.HEmpID = 0;           //验收人(Gy_Employee)
        //            //oItem.HManagerID = 0;      //负责人(Gy_Employee)
        //            //oItem.HDeptID = 0;        //验收部门(Gy_Department)
        //            //oItem.HExplanation = "";  //摘要(故障描述)
        //            //oItem.HRemark = "";       //备注
        //            //oItem.HMainSourceInterID = oItem.HInterID;
        //            //oItem.HInterID = DBUtility.ClsPub.CreateBillID_SRMProd("1103", ref DBUtility.ClsPub.sExeReturnInfo);
        //            if (DBUtility.ClsPub.isStrNull(oItem.HDate) == "")
        //            {
        //                objJsonResult.code = "0";
        //                objJsonResult.count = 0;
        //                objJsonResult.Message = "保存失败!没有单据日期,无法保存!";
        //                objJsonResult.data = 1;
        //                return objJsonResult;
        //            }
        //            oBill.omodel = oItem;
        //        }
        //        //表体数据
        //        //按 },{来拆分数组 //去掉【和】
        //        msg3 = msg3.Substring(1, msg3.Length - 2);
        //        msg3 = msg3.Replace("\\", "");
        //        msg3 = msg3.Replace("\n", "");  //\n
        //        //msg2 = msg2.Replace("'", "’");
        //        List<Model.ClsSc_MouldStockBillSub> ls = new List<Model.ClsSc_MouldStockBillSub>();
        //        ls = oListModels.getObjectByJson_Gy_MouldScrapOutHouseBillSub(msg3);
        //        int i = 0;
        //        foreach (Model.ClsSc_MouldStockBillSub oItemSub in ls)
        //        {
        //            i++;
        //            oItemSub.HEntryID = i;
        //            //oItemSub.HRepairCheckID = 0;   //验收项目ID
        //            //oItemSub.HRepairCheckContent = ""; //验收内容
        //            //oItemSub.HManagerID = 0;   //负责人ID
        //            //oItemSub.HCloseMan = "";       //行关闭
        //            oItemSub.HEntryCloseDate = DBUtility.ClsPub.isDate(DateTime.Now);
        //            oItemSub.HCloseType = false;   //关闭类型
        //            //oItemSub.HRemark = "";         //备注
        //            oItemSub.HSourceInterID = 0;     // 源单主内码
        //            oItemSub.HSourceEntryID = 0;   //源单子内码
        //            //oItemSub.HSourceBillNo = "";  //源单单号
        //            //oItemSub.HSourceBillType = ""; //源单类型
        //            //oItemSub.HRelationQty = 0;     //关联数量
        //            //oItemSub.HRelationMoney = 0;   //关联金额
        //            //oItemSub.HRepairID = 0;       //维修项目
        //            //oItemSub.HRepairExplanation ="";   //维修要求
        //            //oItemSub.HMoney = 0;        //维修费用
        //            oBill.DetailColl.Add(oItemSub);
        //        }
        //        //保存
        //        //保存完毕后处理
        //        bool bResult;
        //        if (oBill.omodel.HInterID == 0)
        //        {
        //            // bResult = oBill.AddBill(ref DBUtility.ClsPub.sExeReturnInfo);
        //            bResult = oBill.AddBill(ref DBUtility.ClsPub.sExeReturnInfo);
        //            string sql = string.Format($"exec h_p_Sc_MouldChangeFileStatus  'out','{oBill.omodel.HInterID.ToString()}' ");
        //            oCn.RunProc(sql);
        //        }
        //        else
        //        {
        //            bResult = oBill.ModifyBill(oBill.omodel.HInterID, ref DBUtility.ClsPub.sExeReturnInfo);
        //            //修改成功
        //            //string sql = string.Format($"exec h_p_Sc_MouldChangeNowWHID  1,{oBill.omodel.HInterID.ToString()},' ' ");
        //            string sql = string.Format($"exec h_p_Sc_MouldChangeNowWHID ");
        //            oCn.RunProc(sql);
        //        }
        //        if (bResult)
        //        {
        //            objJsonResult.code = "0";
        //            objJsonResult.count = 1;
        //            objJsonResult.Message = "保存成功!";
        //            //WebAPIController.Add_Log("送货单下推", UserName, "生成送货单");
        //            objJsonResult.data = 1;
        //            return objJsonResult;
        //        }
        //        else
        //        {
        //            objJsonResult.code = "0";
        //            objJsonResult.count = 0;
        //            objJsonResult.Message = "保存失败!" + DBUtility.ClsPub.sExeReturnInfo;
        //            objJsonResult.data = 1;
        //            return objJsonResult;
        //        }
        //    }
        //    catch (Exception e)
        //    {
        //        objJsonResult.code = "0";
        //        objJsonResult.count = 0;
        //        objJsonResult.Message = "保存失败!" + e.ToString();
        //        objJsonResult.data = 1;
        //        return objJsonResult;
        //    }
        //}
        #endregion
        #region 模具处理出库单保存/编辑    20240702
        /// <summary>
        /// 保存模具处理出库单
        /// </summary>
@@ -7194,125 +7801,126 @@
        [HttpPost]
        public object SaveGetMouldScrapOutHouseBillList([FromBody] JObject msg)
        {
            DAL.ClsSc_MouldScrapOutBill oBill = new DAL.ClsSc_MouldScrapOutBill();
            var _value = msg["msg"].ToString();
            string msg1 = _value.ToString();
            string[] sArray = msg1.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
            string msg2 = sArray[0].ToString();
            string msg3 = sArray[1].ToString();
            string msg4 = sArray[2].ToString();
            string UserName = "";
            ListModels oListModels = new ListModels();
            string sMainStr = sArray[0].ToString();         //主表数据
            string sSubStr = sArray[1].ToString();          //子表数据
            string HMaker = sArray[2].ToString();           //制单人
            try
            {
                //编辑权限
                if (!DBUtility.ClsPub.Security_Log("Sc_MouldScrapOutBill_Edit", 1, false, msg4))
                if (!DBUtility.ClsPub.Security_Log("Sc_MouldScrapOutBill_Edit", 1, false, HMaker))
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "无保存权限!";
                    objJsonResult.Message = "您没有该模块新增/编辑权限,请与管理员联系!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                //表头赋值
                sMainStr = sMainStr.Replace("\\", "");
                sMainStr = sMainStr.Replace("\n", "");
                sMainStr = "[" + sMainStr.ToString() + "]";
                List<Model.ClsSc_MouldStockBillMain> lsmain = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Model.ClsSc_MouldStockBillMain>>(sMainStr);
                foreach (Model.ClsSc_MouldStockBillMain oItem in lsmain)
                {
                    if (oItem.HInterID == 0)
                    {
                        BillStatus = DBUtility.ClsPub.Enum_BillStatus.BillStatus_AddNew;
                    }
                    else
                    {
                        BillStatus = DBUtility.ClsPub.Enum_BillStatus.BillStatus_Modify;
                    }
                    //单据号是否重复
                    if (oBill.IsExistBillNo(ref ClsPub.sExeReturnInfo, oItem.HBillNo, BillStatus, oItem.HInterID))
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "单据号重复!不允许保存!";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                    //判断会计期是否合理
                    string s = "";
                    int sYear = 0;
                    int sPeriod = 0;
                    if (DBUtility.Xt_BaseBillFun.Fun_AllowYearPeriod(oItem.HDate, ref sYear, ref sPeriod, ref s) == false)
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = s;
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                    oItem.HYear = sYear;
                    oItem.HPeriod = sPeriod;
                    DBUtility.ClsPub.CurUserName = oItem.HMaker;
                    oBill.omodel = oItem;
                }
                //表体赋值
                //按 },{来拆分数组 //去掉【和】
                sSubStr = sSubStr.Substring(1, sSubStr.Length - 2);
                sSubStr = sSubStr.Replace("\\", "");
                sSubStr = sSubStr.Replace("\n", "");
                sSubStr = "[" + sSubStr.ToString() + "]";
                List<Model.ClsSc_MouldStockBillSub> ls = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Model.ClsSc_MouldStockBillSub>>(sSubStr);
                int i = 0;
                foreach (Model.ClsSc_MouldStockBillSub oItemSub in ls)
                {
                    i++;
                    oItemSub.HEntryID = i;
                    oBill.DetailColl.Add(oItemSub);
                }
                string sErrMsg = "";
                bool bResult;
                //获取系统参数
                if (oSystemParameter.ShowBill(ref sErrMsg) == true)
                {
                    //保存
                    if (oBill.omodel.HInterID == 0)   //新增保存
                    {
                        bResult = oBill.AddBill(ref DBUtility.ClsPub.sExeReturnInfo);
                        if (oSystemParameter.omodel.WMS_CampanyName == "四维尔") //系统参数  客户定制化名称     空白为通用
                        {
                            //修改器具档案位置
                            string sql = string.Format($"exec h_p_Sc_MouldChangeFileStatus  'out','{oBill.omodel.HInterID.ToString()}' ");
                            oCn.RunProc(sql);
                        }
                    }
                    else                        //编辑保存
                    {
                        bResult = oBill.ModifyBill(oBill.omodel.HInterID, ref DBUtility.ClsPub.sExeReturnInfo);
                        if (oSystemParameter.omodel.WMS_CampanyName == "四维尔") //系统参数  客户定制化名称     空白为通用
                        {
                            //修改器具档案位置
                            string sql = string.Format($"exec h_p_Sc_MouldChangeNowWHID ");
                            oCn.RunProc(sql);
                        }
                    }
                }
                else
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "获取系统参数失败! " + sErrMsg;
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                DLL.ClsSc_MouldScrapOutBill oBill = new DLL.ClsSc_MouldScrapOutBill();
                List<Model.ClsSc_MouldStockBillMain> lsmain = new List<Model.ClsSc_MouldStockBillMain>();
                msg2 = msg2.Replace("\\", "");
                msg2 = msg2.Replace("\n", "");  //\n
                lsmain = oListModels.getObjectByJson_Gy_MouldScrapOutHouseBillMain(msg2);
                foreach (Model.ClsSc_MouldStockBillMain oItem in lsmain)
                {
                    //oItem.HMaker = "";
                    UserName = oItem.HMaker;  //制单人
                    oItem.HBillType = "3832";
                    oItem.HBillSubType = "3832";
                    //oItem.HBillNo = "";    //单据号
                    //oItem.HDate = DBUtility.ClsPub.isDate(DateTime.Now.ToString("yyyy-MM-dd"));//  --日期
                    //oItem.HInnerBillNo = "";  //  --内部单据号
                    oItem.HYear = DBUtility.ClsPub.isLong(DateTime.Now.Year);
                    oItem.HMakeDate = DBUtility.ClsPub.isStrNull(DateTime.Now.ToString("yyyy-MM-dd"));
                    //oItem.HEquipID = 0;    //设备ID(Gy_EquipMent)
                    //oItem.HPeriod = 0;
                    //oItem.HCheckBeginDate = DBUtility.ClsPub.isDate(DateTime.Now.ToString("yyyy-MM-dd"));  //  --维修日期
                    //oItem.HCheckResult = "";     //验收结论--(正常,异常)
                    //oItem.HEmpID = 0;           //验收人(Gy_Employee)
                    //oItem.HManagerID = 0;      //负责人(Gy_Employee)
                    //oItem.HDeptID = 0;        //验收部门(Gy_Department)
                    //oItem.HExplanation = "";  //摘要(故障描述)
                    //oItem.HRemark = "";       //备注
                    //oItem.HMainSourceInterID = oItem.HInterID;
                    //oItem.HInterID = DBUtility.ClsPub.CreateBillID_SRMProd("1103", ref DBUtility.ClsPub.sExeReturnInfo);
                    if (DBUtility.ClsPub.isStrNull(oItem.HDate) == "")
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "保存失败!没有单据日期,无法保存!";
                        objJsonResult.data = 1;
                        return objJsonResult;
                    }
                    oBill.omodel = oItem;
                }
                //表体数据
                //按 },{来拆分数组 //去掉【和】
                msg3 = msg3.Substring(1, msg3.Length - 2);
                msg3 = msg3.Replace("\\", "");
                msg3 = msg3.Replace("\n", "");  //\n
                //msg2 = msg2.Replace("'", "’");
                List<Model.ClsSc_MouldStockBillSub> ls = new List<Model.ClsSc_MouldStockBillSub>();
                ls = oListModels.getObjectByJson_Gy_MouldScrapOutHouseBillSub(msg3);
                int i = 0;
                foreach (Model.ClsSc_MouldStockBillSub oItemSub in ls)
                {
                    i++;
                    oItemSub.HEntryID = i;
                    //oItemSub.HRepairCheckID = 0;   //验收项目ID
                    //oItemSub.HRepairCheckContent = ""; //验收内容
                    //oItemSub.HManagerID = 0;   //负责人ID
                    //oItemSub.HCloseMan = "";       //行关闭
                    oItemSub.HEntryCloseDate = DBUtility.ClsPub.isDate(DateTime.Now);
                    oItemSub.HCloseType = false;   //关闭类型
                    //oItemSub.HRemark = "";         //备注
                    oItemSub.HSourceInterID = 0;     // 源单主内码
                    oItemSub.HSourceEntryID = 0;   //源单子内码
                    //oItemSub.HSourceBillNo = "";  //源单单号
                    //oItemSub.HSourceBillType = ""; //源单类型
                    //oItemSub.HRelationQty = 0;     //关联数量
                    //oItemSub.HRelationMoney = 0;   //关联金额
                    //oItemSub.HRepairID = 0;       //维修项目
                    //oItemSub.HRepairExplanation ="";   //维修要求
                    //oItemSub.HMoney = 0;        //维修费用
                    oBill.DetailColl.Add(oItemSub);
                }
                //保存
                //保存完毕后处理
                bool bResult;
                if (oBill.omodel.HInterID == 0)
                {
                    // bResult = oBill.AddBill(ref DBUtility.ClsPub.sExeReturnInfo);
                    bResult = oBill.AddBill(ref DBUtility.ClsPub.sExeReturnInfo);
                    string sql = string.Format($"exec h_p_Sc_MouldChangeFileStatus  'out','{oBill.omodel.HInterID.ToString()}' ");
                    oCn.RunProc(sql);
                }
                else
                {
                    bResult = oBill.ModifyBill(oBill.omodel.HInterID, ref DBUtility.ClsPub.sExeReturnInfo);
                    //修改成功
                    //string sql = string.Format($"exec h_p_Sc_MouldChangeNowWHID  1,{oBill.omodel.HInterID.ToString()},' ' ");
                    string sql = string.Format($"exec h_p_Sc_MouldChangeNowWHID ");
                    oCn.RunProc(sql);
                }
                if (bResult)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "保存成功!";
                    //WebAPIController.Add_Log("送货单下推", UserName, "生成送货单");
                    objJsonResult.data = 1;
                    objJsonResult.Message = DBUtility.ClsPub.sExeReturnInfo;  //成功!
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                else
@@ -7320,7 +7928,7 @@
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "保存失败!" + DBUtility.ClsPub.sExeReturnInfo;
                    objJsonResult.data = 1;
                    objJsonResult.data = null;
                    return objJsonResult;
                }
            }
@@ -7328,8 +7936,8 @@
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "保存失败!" + e.ToString();
                objJsonResult.data = 1;
                objJsonResult.Message = "保存失败!" + e.Message;
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
@@ -7776,7 +8384,159 @@
        }
        #endregion
        #region 模具退库单保存/编辑
        #region 模具退库单保存/编辑    20240702作废
        /// <summary>
        /// 保存模具退库单
        /// </summary>
        /// <param name="msg"></param>
        /// <returns></returns>
        //[Route("Sc_MouldProdBackBill/SaveGetMouldProdBackBillList")]
        //[HttpPost]
        //public object SaveGetMouldProdBackBillList([FromBody] JObject msg)
        //{
        //    var _value = msg["msg"].ToString();
        //    string msg1 = _value.ToString();
        //    string[] sArray = msg1.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
        //    string msg2 = sArray[0].ToString();
        //    string msg3 = sArray[1].ToString();
        //    string msg4 = sArray[2].ToString();
        //    string UserName = "";
        //    ListModels oListModels = new ListModels();
        //    try
        //    {
        //        if (!DBUtility.ClsPub.Security_Log("Sc_MouldProdBackBill_Edit", 1, false, msg4))
        //        {
        //            objJsonResult.code = "0";
        //            objJsonResult.count = 0;
        //            objJsonResult.Message = "没有保存权限";
        //            objJsonResult.data = null;
        //            return objJsonResult;
        //        }
        //        DLL.ClsSc_MouldProdBackBill oBill = new DLL.ClsSc_MouldProdBackBill();
        //        List<Model.ClsSc_MouldProdBackBillMain> lsmain = new List<Model.ClsSc_MouldProdBackBillMain>();
        //        msg2 = msg2.Replace("\\", "");
        //        msg2 = msg2.Replace("\n", "");  //\n
        //        lsmain = oListModels.getObjectByJson_Gy_MouldProdBackBillMain(msg2);
        //        foreach (Model.ClsSc_MouldProdBackBillMain oItem in lsmain)
        //        {
        //             //oItem.HMaker = "";
        //            UserName = oItem.HMaker;  //制单人
        //            oItem.HBillType = "3803";
        //            oItem.HBillSubType = "3803";
        //            //oItem.HBillNo = "";    //单据号
        //            //oItem.HDate = DBUtility.ClsPub.isDate(DateTime.Now.ToString("yyyy-MM-dd"));//  --日期
        //            //oItem.HInnerBillNo = "";  //  --内部单据号
        //            oItem.HYear = DBUtility.ClsPub.isLong(DateTime.Now.Year);
        //            oItem.HMakeDate = DBUtility.ClsPub.isStrNull(DateTime.Now.ToString("yyyy-MM-dd"));
        //            //oItem.HEquipID = 0;    //设备ID(Gy_EquipMent)
        //            //oItem.HPeriod = 0;
        //            //oItem.HCheckBeginDate = DBUtility.ClsPub.isDate(DateTime.Now.ToString("yyyy-MM-dd"));  //  --维修日期
        //            //oItem.HCheckResult = "";     //验收结论--(正常,异常)
        //            //oItem.HEmpID = 0;           //验收人(Gy_Employee)
        //            //oItem.HManagerID = 0;      //负责人(Gy_Employee)
        //            //oItem.HDeptID = 0;        //验收部门(Gy_Department)
        //            //oItem.HExplanation = "";  //摘要(故障描述)
        //            //oItem.HRemark = "";       //备注
        //            //oItem.HMainSourceInterID = oItem.HInterID;
        //            //oItem.HInterID = DBUtility.ClsPub.CreateBillID_SRMProd("1103", ref DBUtility.ClsPub.sExeReturnInfo);
        //            if (DBUtility.ClsPub.isStrNull(oItem.HDate) == "")
        //            {
        //                objJsonResult.code = "0";
        //                objJsonResult.count = 0;
        //                objJsonResult.Message = "保存失败!没有单据日期,无法保存!";
        //                objJsonResult.data = 1;
        //                return objJsonResult;
        //            }
        //            oBill.omodel = oItem;
        //        }
        //        //表体数据
        //        //按 },{来拆分数组 //去掉【和】
        //        msg3 = msg3.Substring(1, msg3.Length - 2);
        //        msg3 = msg3.Replace("\\", "");
        //        msg3 = msg3.Replace("\n", "");  //\n
        //        //msg2 = msg2.Replace("'", "’");
        //        List<Model.ClsSc_MouldProdBackBillSub> ls = new List<Model.ClsSc_MouldProdBackBillSub>();
        //        ls = oListModels.getObjectByJson_Gy_MouldProdBackBillSub(msg3);
        //        int i = 0;
        //        foreach (Model.ClsSc_MouldProdBackBillSub oItemSub in ls)
        //        {
        //            i++;
        //            oItemSub.HEntryID = i;
        //            //oItemSub.HRepairCheckID = 0;   //验收项目ID
        //            //oItemSub.HRepairCheckContent = ""; //验收内容
        //            //oItemSub.HManagerID = 0;   //负责人ID
        //            //oItemSub.HCloseMan = "";       //行关闭
        //            oItemSub.HEntryCloseDate = DBUtility.ClsPub.isDate(DateTime.Now);
        //            oItemSub.HCloseType = false;   //关闭类型
        //            //oItemSub.HRemark = "";         //备注
        //            oItemSub.HSourceInterID = 0;     // 源单主内码
        //            oItemSub.HSourceEntryID = 0;   //源单子内码
        //            //oItemSub.HSourceBillNo = "";  //源单单号
        //            //oItemSub.HSourceBillType = ""; //源单类型
        //            //oItemSub.HRelationQty = 0;     //关联数量
        //            //oItemSub.HRelationMoney = 0;   //关联金额
        //            //oItemSub.HRepairID = 0;       //维修项目
        //            //oItemSub.HRepairExplanation ="";   //维修要求
        //            //oItemSub.HMoney = 0;        //维修费用
        //            oBill.DetailColl.Add(oItemSub);
        //        }
        //        //保存
        //        //保存完毕后处理
        //        bool bResult;
        //        if (oBill.omodel.HInterID == 0)
        //        {
        //            // bResult = oBill.AddBill(ref DBUtility.ClsPub.sExeReturnInfo);
        //            bResult = oBill.AddBill(ref DBUtility.ClsPub.sExeReturnInfo);
        //            string sql1 = string.Format($"exec h_p_Sc_MouldChangeFileStatus  'in','{oBill.omodel.HInterID.ToString()}' ");
        //            oCn.RunProc(sql1);
        //        }
        //        else
        //        {
        //            bResult = oBill.ModifyBill(oBill.omodel.HInterID, ref DBUtility.ClsPub.sExeReturnInfo);
        //            //修改成功
        //            //string sql = string.Format($"exec h_p_Sc_MouldChangeNowWHID  1,{oBill.omodel.HInterID.ToString()},' ' ");
        //            string sql = string.Format($"exec h_p_Sc_MouldChangeNowWHID ");
        //            oCn.RunProc(sql);
        //        }
        //        if (bResult)
        //        {
        //            string sql =string.Format($"exec h_p_Sc_MouldProdBackBillList '{oBill.omodel.HBillNo}' ") ;
        //            oCn.RunProc(sql);
        //            objJsonResult.code = "0";
        //            objJsonResult.count = 1;
        //            objJsonResult.Message = "保存成功!";
        //            //WebAPIController.Add_Log("送货单下推", UserName, "生成送货单");
        //            objJsonResult.data = 1;
        //            return objJsonResult;
        //        }
        //        else
        //        {
        //            objJsonResult.code = "0";
        //            objJsonResult.count = 0;
        //            objJsonResult.Message = "保存失败!" + DBUtility.ClsPub.sExeReturnInfo;
        //            objJsonResult.data = 1;
        //            return objJsonResult;
        //        }
        //    }
        //    catch (Exception e)
        //    {
        //        objJsonResult.code = "0";
        //        objJsonResult.count = 0;
        //        objJsonResult.Message = "保存失败!" + e.ToString();
        //        objJsonResult.data = 1;
        //        return objJsonResult;
        //    }
        //}
        #endregion
        #region 模具退库单保存/编辑    20240702
        /// <summary>
        /// 保存模具退库单
        /// </summary>
@@ -7786,126 +8546,127 @@
        [HttpPost]
        public object SaveGetMouldProdBackBillList([FromBody] JObject msg)
        {
            DAL.ClsSc_MouldProdBackBill oBill = new DAL.ClsSc_MouldProdBackBill();
            var _value = msg["msg"].ToString();
            string msg1 = _value.ToString();
            string[] sArray = msg1.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
            string msg2 = sArray[0].ToString();
            string msg3 = sArray[1].ToString();
            string msg4 = sArray[2].ToString();
            string UserName = "";
            ListModels oListModels = new ListModels();
            string sMainStr = sArray[0].ToString();         //主表数据
            string sSubStr = sArray[1].ToString();          //子表数据
            string HMaker = sArray[2].ToString();           //制单人
            try
            {
                if (!DBUtility.ClsPub.Security_Log("Sc_MouldProdBackBill_Edit", 1, false, msg4))
                //判断权限
                if (!DBUtility.ClsPub.Security_Log("Sc_MouldProdBackBill_Edit", 1, false, HMaker))
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "没有保存权限";
                    objJsonResult.Message = "您没有该模块新增/编辑权限,请与管理员联系!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                //表头赋值
                sMainStr = sMainStr.Replace("\\", "");
                sMainStr = sMainStr.Replace("\n", "");
                sMainStr = "[" + sMainStr.ToString() + "]";
                List<Model.ClsSc_MouldProdBackBillMain> lsmain = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Model.ClsSc_MouldProdBackBillMain>>(sMainStr);
                foreach (Model.ClsSc_MouldProdBackBillMain oItem in lsmain)
                {
                    if (oItem.HInterID == 0)
                    {
                        BillStatus = DBUtility.ClsPub.Enum_BillStatus.BillStatus_AddNew;
                    }
                    else
                    {
                        BillStatus = DBUtility.ClsPub.Enum_BillStatus.BillStatus_Modify;
                    }
                    //单据号是否重复
                    if (oBill.IsExistBillNo(ref ClsPub.sExeReturnInfo, oItem.HBillNo, BillStatus, oItem.HInterID))
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "单据号重复!不允许保存!";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                    //判断会计期是否合理
                    string s = "";
                    int sYear = 0;
                    int sPeriod = 0;
                    if (DBUtility.Xt_BaseBillFun.Fun_AllowYearPeriod(oItem.HDate, ref sYear, ref sPeriod, ref s) == false)
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = s;
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                    oItem.HYear = sYear;
                    oItem.HPeriod = sPeriod;
                    DBUtility.ClsPub.CurUserName = oItem.HMaker;
                    oBill.omodel = oItem;
                }
                //表体赋值
                //按 },{来拆分数组 //去掉【和】
                sSubStr = sSubStr.Substring(1, sSubStr.Length - 2);
                sSubStr = sSubStr.Replace("\\", "");
                sSubStr = sSubStr.Replace("\n", "");
                sSubStr = "[" + sSubStr.ToString() + "]";
                List<Model.ClsSc_MouldStockBillSub> ls = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Model.ClsSc_MouldStockBillSub>>(sSubStr);
                int i = 0;
                foreach (Model.ClsSc_MouldStockBillSub oItemSub in ls)
                {
                    i++;
                    oItemSub.HEntryID = i;
                    oBill.DetailColl.Add(oItemSub);
                }
                string sErrMsg = "";
                bool bResult;
                //获取系统参数
                if (oSystemParameter.ShowBill(ref sErrMsg) == true)
                {
                    //保存
                    if (oBill.omodel.HInterID == 0)   //新增保存
                    {
                        bResult = oBill.AddBill(ref DBUtility.ClsPub.sExeReturnInfo);
                        if (oSystemParameter.omodel.WMS_CampanyName == "四维尔") //系统参数  客户定制化名称     空白为通用
                        {
                            //修改器具档案位置
                            string sql1 = string.Format($"exec h_p_Sc_MouldChangeFileStatus  'in','{oBill.omodel.HInterID.ToString()}' ");
                            oCn.RunProc(sql1);
                        }
                    }
                    else                        //编辑保存
                    {
                        bResult = oBill.ModifyBill(oBill.omodel.HInterID, ref DBUtility.ClsPub.sExeReturnInfo);
                        if (oSystemParameter.omodel.WMS_CampanyName == "四维尔") //系统参数  客户定制化名称     空白为通用
                        {
                            //修改器具档案位置
                            string sql = string.Format($"exec h_p_Sc_MouldChangeNowWHID ");
                            oCn.RunProc(sql);
                        }
                    }
                }
                else
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "获取系统参数失败! " + sErrMsg;
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                DLL.ClsSc_MouldProdBackBill oBill = new DLL.ClsSc_MouldProdBackBill();
                List<Model.ClsSc_MouldProdBackBillMain> lsmain = new List<Model.ClsSc_MouldProdBackBillMain>();
                msg2 = msg2.Replace("\\", "");
                msg2 = msg2.Replace("\n", "");  //\n
                lsmain = oListModels.getObjectByJson_Gy_MouldProdBackBillMain(msg2);
                foreach (Model.ClsSc_MouldProdBackBillMain oItem in lsmain)
                {
                     //oItem.HMaker = "";
                    UserName = oItem.HMaker;  //制单人
                    oItem.HBillType = "3803";
                    oItem.HBillSubType = "3803";
                    //oItem.HBillNo = "";    //单据号
                    //oItem.HDate = DBUtility.ClsPub.isDate(DateTime.Now.ToString("yyyy-MM-dd"));//  --日期
                    //oItem.HInnerBillNo = "";  //  --内部单据号
                    oItem.HYear = DBUtility.ClsPub.isLong(DateTime.Now.Year);
                    oItem.HMakeDate = DBUtility.ClsPub.isStrNull(DateTime.Now.ToString("yyyy-MM-dd"));
                    //oItem.HEquipID = 0;    //设备ID(Gy_EquipMent)
                    //oItem.HPeriod = 0;
                    //oItem.HCheckBeginDate = DBUtility.ClsPub.isDate(DateTime.Now.ToString("yyyy-MM-dd"));  //  --维修日期
                    //oItem.HCheckResult = "";     //验收结论--(正常,异常)
                    //oItem.HEmpID = 0;           //验收人(Gy_Employee)
                    //oItem.HManagerID = 0;      //负责人(Gy_Employee)
                    //oItem.HDeptID = 0;        //验收部门(Gy_Department)
                    //oItem.HExplanation = "";  //摘要(故障描述)
                    //oItem.HRemark = "";       //备注
                    //oItem.HMainSourceInterID = oItem.HInterID;
                    //oItem.HInterID = DBUtility.ClsPub.CreateBillID_SRMProd("1103", ref DBUtility.ClsPub.sExeReturnInfo);
                    if (DBUtility.ClsPub.isStrNull(oItem.HDate) == "")
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "保存失败!没有单据日期,无法保存!";
                        objJsonResult.data = 1;
                        return objJsonResult;
                    }
                    oBill.omodel = oItem;
                }
                //表体数据
                //按 },{来拆分数组 //去掉【和】
                msg3 = msg3.Substring(1, msg3.Length - 2);
                msg3 = msg3.Replace("\\", "");
                msg3 = msg3.Replace("\n", "");  //\n
                //msg2 = msg2.Replace("'", "’");
                List<Model.ClsSc_MouldProdBackBillSub> ls = new List<Model.ClsSc_MouldProdBackBillSub>();
                ls = oListModels.getObjectByJson_Gy_MouldProdBackBillSub(msg3);
                int i = 0;
                foreach (Model.ClsSc_MouldProdBackBillSub oItemSub in ls)
                {
                    i++;
                    oItemSub.HEntryID = i;
                    //oItemSub.HRepairCheckID = 0;   //验收项目ID
                    //oItemSub.HRepairCheckContent = ""; //验收内容
                    //oItemSub.HManagerID = 0;   //负责人ID
                    //oItemSub.HCloseMan = "";       //行关闭
                    oItemSub.HEntryCloseDate = DBUtility.ClsPub.isDate(DateTime.Now);
                    oItemSub.HCloseType = false;   //关闭类型
                    //oItemSub.HRemark = "";         //备注
                    oItemSub.HSourceInterID = 0;     // 源单主内码
                    oItemSub.HSourceEntryID = 0;   //源单子内码
                    //oItemSub.HSourceBillNo = "";  //源单单号
                    //oItemSub.HSourceBillType = ""; //源单类型
                    //oItemSub.HRelationQty = 0;     //关联数量
                    //oItemSub.HRelationMoney = 0;   //关联金额
                    //oItemSub.HRepairID = 0;       //维修项目
                    //oItemSub.HRepairExplanation ="";   //维修要求
                    //oItemSub.HMoney = 0;        //维修费用
                    oBill.DetailColl.Add(oItemSub);
                }
                //保存
                //保存完毕后处理
                bool bResult;
                if (oBill.omodel.HInterID == 0)
                {
                    // bResult = oBill.AddBill(ref DBUtility.ClsPub.sExeReturnInfo);
                    bResult = oBill.AddBill(ref DBUtility.ClsPub.sExeReturnInfo);
                    string sql1 = string.Format($"exec h_p_Sc_MouldChangeFileStatus  'in','{oBill.omodel.HInterID.ToString()}' ");
                    oCn.RunProc(sql1);
                }
                else
                {
                    bResult = oBill.ModifyBill(oBill.omodel.HInterID, ref DBUtility.ClsPub.sExeReturnInfo);
                    //修改成功
                    //string sql = string.Format($"exec h_p_Sc_MouldChangeNowWHID  1,{oBill.omodel.HInterID.ToString()},' ' ");
                    string sql = string.Format($"exec h_p_Sc_MouldChangeNowWHID ");
                    oCn.RunProc(sql);
                }
                if (bResult)
                {
                    string sql =string.Format($"exec h_p_Sc_MouldProdBackBillList '{oBill.omodel.HBillNo}' ") ;
                    oCn.RunProc(sql);
                    string sql = string.Format($"exec h_p_Sc_MouldProdBackBillList '{oBill.omodel.HBillNo}' ");
                    objJsonResult.code = "0";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "保存成功!";
                    //WebAPIController.Add_Log("送货单下推", UserName, "生成送货单");
                    objJsonResult.data = 1;
                    objJsonResult.Message = DBUtility.ClsPub.sExeReturnInfo;  //成功!
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                else
@@ -7913,7 +8674,7 @@
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "保存失败!" + DBUtility.ClsPub.sExeReturnInfo;
                    objJsonResult.data = 1;
                    objJsonResult.data = null;
                    return objJsonResult;
                }
            }
@@ -7921,8 +8682,8 @@
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "保存失败!" + e.ToString();
                objJsonResult.data = 1;
                objJsonResult.Message = "保存失败!" + e.Message;
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
@@ -8229,7 +8990,158 @@
        }
        #endregion
        #region 模具领用单保存/编辑
        #region 模具领用单保存/编辑    20240702作废
        /// <summary>
        /// 保存模具领用单
        /// </summary>
        /// <param name="msg"></param>
        /// <returns></returns>
        //[Route("Sc_MouldProdOutBill/SaveGetMouldProdOutBillList")]
        //[HttpPost]
        //public object SaveGetMouldProdOutBillList([FromBody] JObject msg)
        //{
        //    var _value = msg["msg"].ToString();
        //    string msg1 = _value.ToString();
        //    string[] sArray = msg1.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
        //    string msg2 = sArray[0].ToString();
        //    string msg3 = sArray[1].ToString();
        //    string msg4 = sArray[2].ToString();
        //    string UserName = "";
        //    ListModels oListModels = new ListModels();
        //    try
        //    {
        //        //模块名,写入日志,报错框,用户名
        //        if (!DBUtility.ClsPub.Security_Log("Sc_MouldProdOutBill_Edit", 1, false, msg4))
        //        {
        //            objJsonResult.code = "0";
        //            objJsonResult.count = 0;
        //            objJsonResult.Message = "没有保存权限";
        //            objJsonResult.data = null;
        //            return objJsonResult;
        //        }
        //        DLL.ClsSc_MouldProdOutBill oBill = new DLL.ClsSc_MouldProdOutBill();
        //        List<Model.ClsSc_MouldProdOutBillMain> lsmain = new List<Model.ClsSc_MouldProdOutBillMain>();
        //        msg2 = msg2.Replace("\\", "");
        //        msg2 = msg2.Replace("\n", "");  //\n
        //        lsmain = oListModels.getObjectByJson_Gy_MouldProdOutBillMain(msg2);
        //        foreach (Model.ClsSc_MouldProdOutBillMain oItem in lsmain)
        //        {
        //            //oItem.HMaker = "";
        //            UserName = oItem.HMaker;  //制单人
        //            oItem.HBillType = "3802";
        //            oItem.HBillSubType = "3802";
        //            //oItem.HBillNo = "";    //单据号
        //            //oItem.HDate = DBUtility.ClsPub.isDate(DateTime.Now.ToString("yyyy-MM-dd"));//  --日期
        //            //oItem.HInnerBillNo = "";  //  --内部单据号
        //            oItem.HYear = DBUtility.ClsPub.isLong(DateTime.Now.Year);
        //            oItem.HMakeDate = DBUtility.ClsPub.isStrNull(DateTime.Now.ToString("yyyy-MM-dd"));
        //            //oItem.HEquipID = 0;    //设备ID(Gy_EquipMent)
        //            //oItem.HPeriod = 0;
        //            //oItem.HCheckBeginDate = DBUtility.ClsPub.isDate(DateTime.Now.ToString("yyyy-MM-dd"));  //  --维修日期
        //            //oItem.HCheckResult = "";     //验收结论--(正常,异常)
        //            //oItem.HEmpID = 0;           //验收人(Gy_Employee)
        //            //oItem.HManagerID = 0;      //负责人(Gy_Employee)
        //            //oItem.HDeptID = 0;        //验收部门(Gy_Department)
        //            //oItem.HExplanation = "";  //摘要(故障描述)
        //            //oItem.HRemark = "";       //备注
        //            //oItem.HMainSourceInterID = oItem.HInterID;
        //            //oItem.HInterID = DBUtility.ClsPub.CreateBillID_SRMProd("1103", ref DBUtility.ClsPub.sExeReturnInfo);
        //            if (DBUtility.ClsPub.isStrNull(oItem.HDate) == "")
        //            {
        //                objJsonResult.code = "0";
        //                objJsonResult.count = 0;
        //                objJsonResult.Message = "保存失败!没有单据日期,无法保存!";
        //                objJsonResult.data = 1;
        //                return objJsonResult;
        //            }
        //            oBill.omodel = oItem;
        //        }
        //        //表体数据
        //        //按 },{来拆分数组 //去掉【和】
        //        msg3 = msg3.Substring(1, msg3.Length - 2);
        //        msg3 = msg3.Replace("\\", "");
        //        msg3 = msg3.Replace("\n", "");  //\n
        //        //msg2 = msg2.Replace("'", "’");
        //        List<Model.ClsSc_MouldStockBillSub> ls = new List<Model.ClsSc_MouldStockBillSub>();
        //        ls = oListModels.getObjectByJson_Gy_MouldStockBillSub(msg3);
        //        int i = 0;
        //        foreach (Model.ClsSc_MouldStockBillSub oItemSub in ls)
        //        {
        //            i++;
        //            oItemSub.HEntryID = i;
        //            //oItemSub.HRepairCheckID = 0;   //验收项目ID
        //            //oItemSub.HRepairCheckContent = ""; //验收内容
        //            //oItemSub.HManagerID = 0;   //负责人ID
        //            //oItemSub.HCloseMan = "";       //行关闭
        //            oItemSub.HEntryCloseDate = DBUtility.ClsPub.isDate(DateTime.Now);
        //            oItemSub.HCloseType = false;   //关闭类型
        //            //oItemSub.HRemark = "";         //备注
        //            oItemSub.HSourceInterID = 0;     // 源单主内码
        //            oItemSub.HSourceEntryID = 0;   //源单子内码
        //            //oItemSub.HSourceBillNo = "";  //源单单号
        //            //oItemSub.HSourceBillType = ""; //源单类型
        //            //oItemSub.HRelationQty = 0;     //关联数量
        //            //oItemSub.HRelationMoney = 0;   //关联金额
        //            //oItemSub.HRepairID = 0;       //维修项目
        //            //oItemSub.HRepairExplanation ="";   //维修要求
        //            //oItemSub.HMoney = 0;        //维修费用
        //            oBill.DetailColl.Add(oItemSub);
        //        }
        //        //保存
        //        //保存完毕后处理
        //        bool bResult;
        //        if (oBill.omodel.HInterID == 0)
        //        {
        //            // bResult = oBill.AddBill(ref DBUtility.ClsPub.sExeReturnInfo);
        //            bResult = oBill.AddBill(ref DBUtility.ClsPub.sExeReturnInfo);
        //            string sql = string.Format($"exec h_p_Sc_MouldChangeFileStatus  'out','{oBill.omodel.HInterID.ToString()}' ");
        //            oCn.RunProc(sql);
        //        }
        //        else
        //        {
        //            bResult = oBill.ModifyBill(oBill.omodel.HInterID, ref DBUtility.ClsPub.sExeReturnInfo);
        //            //修改成功
        //            //string sql = string.Format($"exec h_p_Sc_MouldChangeNowWHID  1,{oBill.omodel.HInterID.ToString()},' ' ");
        //            string sql = string.Format($"exec h_p_Sc_MouldChangeNowWHID ");
        //            oCn.RunProc(sql);
        //        }
        //        if (bResult)
        //        {
        //            objJsonResult.code = "0";
        //            objJsonResult.count = 1;
        //            objJsonResult.Message = "保存成功!";
        //            //WebAPIController.Add_Log("送货单下推", UserName, "生成送货单");
        //            objJsonResult.data = 1;
        //            return objJsonResult;
        //        }
        //        else
        //        {
        //            objJsonResult.code = "0";
        //            objJsonResult.count = 0;
        //            objJsonResult.Message = "保存失败!" + DBUtility.ClsPub.sExeReturnInfo;
        //            objJsonResult.data = 1;
        //            return objJsonResult;
        //        }
        //    }
        //    catch (Exception e)
        //    {
        //        objJsonResult.code = "0";
        //        objJsonResult.count = 0;
        //        objJsonResult.Message = "保存失败!" + e.ToString();
        //        objJsonResult.data = 1;
        //        return objJsonResult;
        //    }
        //}
        #endregion
        #region 模具领用单保存/编辑    20240702
        /// <summary>
        /// 保存模具领用单
        /// </summary>
@@ -8239,125 +9151,126 @@
        [HttpPost]
        public object SaveGetMouldProdOutBillList([FromBody] JObject msg)
        {
            DAL.ClsSc_MouldProdOutBill oBill = new DAL.ClsSc_MouldProdOutBill();
            var _value = msg["msg"].ToString();
            string msg1 = _value.ToString();
            string[] sArray = msg1.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
            string msg2 = sArray[0].ToString();
            string msg3 = sArray[1].ToString();
            string msg4 = sArray[2].ToString();
            string UserName = "";
            ListModels oListModels = new ListModels();
            string sMainStr = sArray[0].ToString();         //主表数据
            string sSubStr = sArray[1].ToString();          //子表数据
            string HMaker = sArray[2].ToString();           //制单人
            try
            {
                //模块名,写入日志,报错框,用户名
                if (!DBUtility.ClsPub.Security_Log("Sc_MouldProdOutBill_Edit", 1, false, msg4))
                if (!DBUtility.ClsPub.Security_Log("Sc_MouldProdOutBill_Edit", 1, false, HMaker))
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "没有保存权限";
                    objJsonResult.Message = "您没有该模块新增/编辑权限,请与管理员联系!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                DLL.ClsSc_MouldProdOutBill oBill = new DLL.ClsSc_MouldProdOutBill();
                List<Model.ClsSc_MouldProdOutBillMain> lsmain = new List<Model.ClsSc_MouldProdOutBillMain>();
                msg2 = msg2.Replace("\\", "");
                msg2 = msg2.Replace("\n", "");  //\n
                lsmain = oListModels.getObjectByJson_Gy_MouldProdOutBillMain(msg2);
                //表头赋值
                sMainStr = sMainStr.Replace("\\", "");
                sMainStr = sMainStr.Replace("\n", "");
                sMainStr = "[" + sMainStr.ToString() + "]";
                List<Model.ClsSc_MouldProdOutBillMain> lsmain = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Model.ClsSc_MouldProdOutBillMain>>(sMainStr);
                foreach (Model.ClsSc_MouldProdOutBillMain oItem in lsmain)
                {
                    //oItem.HMaker = "";
                    UserName = oItem.HMaker;  //制单人
                    oItem.HBillType = "3802";
                    oItem.HBillSubType = "3802";
                    //oItem.HBillNo = "";    //单据号
                    //oItem.HDate = DBUtility.ClsPub.isDate(DateTime.Now.ToString("yyyy-MM-dd"));//  --日期
                    //oItem.HInnerBillNo = "";  //  --内部单据号
                    oItem.HYear = DBUtility.ClsPub.isLong(DateTime.Now.Year);
                    oItem.HMakeDate = DBUtility.ClsPub.isStrNull(DateTime.Now.ToString("yyyy-MM-dd"));
                    //oItem.HEquipID = 0;    //设备ID(Gy_EquipMent)
                    //oItem.HPeriod = 0;
                    //oItem.HCheckBeginDate = DBUtility.ClsPub.isDate(DateTime.Now.ToString("yyyy-MM-dd"));  //  --维修日期
                    //oItem.HCheckResult = "";     //验收结论--(正常,异常)
                    //oItem.HEmpID = 0;           //验收人(Gy_Employee)
                    //oItem.HManagerID = 0;      //负责人(Gy_Employee)
                    //oItem.HDeptID = 0;        //验收部门(Gy_Department)
                    //oItem.HExplanation = "";  //摘要(故障描述)
                    //oItem.HRemark = "";       //备注
                    //oItem.HMainSourceInterID = oItem.HInterID;
                    //oItem.HInterID = DBUtility.ClsPub.CreateBillID_SRMProd("1103", ref DBUtility.ClsPub.sExeReturnInfo);
                    if (DBUtility.ClsPub.isStrNull(oItem.HDate) == "")
                    if (oItem.HInterID == 0)
                    {
                        BillStatus = DBUtility.ClsPub.Enum_BillStatus.BillStatus_AddNew;
                    }
                    else
                    {
                        BillStatus = DBUtility.ClsPub.Enum_BillStatus.BillStatus_Modify;
                    }
                    //单据号是否重复
                    if (oBill.IsExistBillNo(ref ClsPub.sExeReturnInfo, oItem.HBillNo, BillStatus, oItem.HInterID))
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "保存失败!没有单据日期,无法保存!";
                        objJsonResult.data = 1;
                        objJsonResult.Message = "单据号重复!不允许保存!";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                    //判断会计期是否合理
                    string s = "";
                    int sYear = 0;
                    int sPeriod = 0;
                    if (DBUtility.Xt_BaseBillFun.Fun_AllowYearPeriod(oItem.HDate, ref sYear, ref sPeriod, ref s) == false)
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = s;
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                    oItem.HYear = sYear;
                    oItem.HPeriod = sPeriod;
                    DBUtility.ClsPub.CurUserName = oItem.HMaker;
                    oBill.omodel = oItem;
                }
                //表体数据
                //表体赋值
                //按 },{来拆分数组 //去掉【和】
                msg3 = msg3.Substring(1, msg3.Length - 2);
                msg3 = msg3.Replace("\\", "");
                msg3 = msg3.Replace("\n", "");  //\n
                //msg2 = msg2.Replace("'", "’");
                List<Model.ClsSc_MouldStockBillSub> ls = new List<Model.ClsSc_MouldStockBillSub>();
                ls = oListModels.getObjectByJson_Gy_MouldStockBillSub(msg3);
                sSubStr = sSubStr.Substring(1, sSubStr.Length - 2);
                sSubStr = sSubStr.Replace("\\", "");
                sSubStr = sSubStr.Replace("\n", "");
                sSubStr = "[" + sSubStr.ToString() + "]";
                List<Model.ClsSc_MouldStockBillSub> ls = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Model.ClsSc_MouldStockBillSub>>(sSubStr);
                int i = 0;
                foreach (Model.ClsSc_MouldStockBillSub oItemSub in ls)
                {
                    i++;
                    oItemSub.HEntryID = i;
                    //oItemSub.HRepairCheckID = 0;   //验收项目ID
                    //oItemSub.HRepairCheckContent = ""; //验收内容
                    //oItemSub.HManagerID = 0;   //负责人ID
                    //oItemSub.HCloseMan = "";       //行关闭
                    oItemSub.HEntryCloseDate = DBUtility.ClsPub.isDate(DateTime.Now);
                    oItemSub.HCloseType = false;   //关闭类型
                    //oItemSub.HRemark = "";         //备注
                    oItemSub.HSourceInterID = 0;     // 源单主内码
                    oItemSub.HSourceEntryID = 0;   //源单子内码
                    //oItemSub.HSourceBillNo = "";  //源单单号
                    //oItemSub.HSourceBillType = ""; //源单类型
                    //oItemSub.HRelationQty = 0;     //关联数量
                    //oItemSub.HRelationMoney = 0;   //关联金额
                    //oItemSub.HRepairID = 0;       //维修项目
                    //oItemSub.HRepairExplanation ="";   //维修要求
                    //oItemSub.HMoney = 0;        //维修费用
                    oBill.DetailColl.Add(oItemSub);
                }
                //保存
                //保存完毕后处理
                string sErrMsg = "";
                bool bResult;
                if (oBill.omodel.HInterID == 0)
                //获取系统参数
                if (oSystemParameter.ShowBill(ref sErrMsg) == true)
                {
                    // bResult = oBill.AddBill(ref DBUtility.ClsPub.sExeReturnInfo);
                    bResult = oBill.AddBill(ref DBUtility.ClsPub.sExeReturnInfo);
                    string sql = string.Format($"exec h_p_Sc_MouldChangeFileStatus  'out','{oBill.omodel.HInterID.ToString()}' ");
                    oCn.RunProc(sql);
                    //保存
                    if (oBill.omodel.HInterID == 0)   //新增保存
                    {
                        bResult = oBill.AddBill(ref DBUtility.ClsPub.sExeReturnInfo);
                        if (oSystemParameter.omodel.WMS_CampanyName == "四维尔") //系统参数  客户定制化名称     空白为通用
                        {
                            //修改器具档案位置
                            string sql = string.Format($"exec h_p_Sc_MouldChangeFileStatus  'out','{oBill.omodel.HInterID.ToString()}' ");
                            oCn.RunProc(sql);
                        }
                    }
                    else                        //编辑保存
                    {
                        bResult = oBill.ModifyBill(oBill.omodel.HInterID, ref DBUtility.ClsPub.sExeReturnInfo);
                        if (oSystemParameter.omodel.WMS_CampanyName == "四维尔") //系统参数  客户定制化名称     空白为通用
                        {
                            //修改器具档案位置
                            string sql = string.Format($"exec h_p_Sc_MouldChangeNowWHID ");
                            oCn.RunProc(sql);
                        }
                    }
                }
                else
                {
                    bResult = oBill.ModifyBill(oBill.omodel.HInterID, ref DBUtility.ClsPub.sExeReturnInfo);
                    //修改成功
                    //string sql = string.Format($"exec h_p_Sc_MouldChangeNowWHID  1,{oBill.omodel.HInterID.ToString()},' ' ");
                    string sql = string.Format($"exec h_p_Sc_MouldChangeNowWHID ");
                    oCn.RunProc(sql);
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "获取系统参数失败! " + sErrMsg;
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                if (bResult)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "保存成功!";
                    //WebAPIController.Add_Log("送货单下推", UserName, "生成送货单");
                    objJsonResult.data = 1;
                    objJsonResult.Message = DBUtility.ClsPub.sExeReturnInfo;  //成功!
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                else
@@ -8365,7 +9278,7 @@
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "保存失败!" + DBUtility.ClsPub.sExeReturnInfo;
                    objJsonResult.data = 1;
                    objJsonResult.data = null;
                    return objJsonResult;
                }
            }
@@ -8373,8 +9286,8 @@
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "保存失败!" + e.ToString();
                objJsonResult.data = 1;
                objJsonResult.Message = "保存失败!" + e.Message;
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
@@ -9313,5 +10226,366 @@
            return objJsonResult;
        }
        #endregion
        #region 器具点检记录拍照上传
        [Route("Sc_MouldDotCheckBill/UploadFile")]
        [HttpPost]
        public object UploadFile()
        {
            string HBillNo = HttpContext.Current.Request.Params["HBillNo"];  //单据号
            string HRemark = HttpContext.Current.Request.Params["HRemark"];  //备注
            string HUserName = HttpContext.Current.Request.Params["HUserName"];  //创建人
            HttpPostedFile files = HttpContext.Current.Request.Files["file"];
            string path = HttpContext.Current.Server.MapPath("~/../Files/MouldFolder/" + HBillNo);
            //string path = @"D:\\Files\\"+ HBillNo;
            dynamic dyResult = UpLoadFile(files, path, HBillNo, HRemark, HUserName);
            if (dyResult != null && dyResult.result == 1)
            {
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "上传成功!";
                objJsonResult.data = null;
                return objJsonResult;
            }
            else
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = dyResult.returnval;
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        public dynamic UpLoadFile(HttpPostedFile files, string path, string HBillNo, string HRemark, string HUserName)
        {
            dynamic Result_Ob = new { result = 1, returnval = "上传成功!" };
            string filePath = Path.GetFullPath(files.FileName);//文件上传路径
            string fileExtension = Path.GetExtension(files.FileName);// 文件扩展名
            string filename = files.FileName;//文件名
            string fileSavePath = path;// 上传保存路径
            int filesize = files.ContentLength;//获取上传文件的大小单位为字节byte
            int Maxsize = 40000 * 1024;//定义上传文件的最大空间大小为40M
            try
            {
                if (files == null || files.ContentLength <= 0)
                {
                    Result_Ob = new { result = 0, returnval = "文件不能为空!" };
                    return Result_Ob;
                }
                if (filesize >= Maxsize)
                {
                    Result_Ob = new { result = 0, returnval = "上传文件超过40M,不能上传!" };
                    return Result_Ob;
                }
                string fileurl = Path.Combine(fileSavePath, filename);
                if (Directory.Exists(fileurl) == true)  //如果存在重名文件就提示
                {
                    Result_Ob = new { result = 0, returnval = "存在同名文件!" };
                    return Result_Ob;
                }
                //删除数据表数据
                ds = oCN.RunProcReturn("delete from MES_AccessoriesList where HSourceBillNo ='" + HBillNo + "' and HFileName='" + filename + "'", "MES_AccessoriesList");
                if (Directory.Exists(path))
                {
                    File.Delete(fileurl);      //删除指定文件
                    files.SaveAs(fileurl);
                    string StrPath = "/files/MouldFolder/" + HBillNo + "/" + filename;
                    if (File.Exists(fileurl))
                    {
                        //这里可以执行一些其它的操作,比如更新数据库
                        //写入数据表
                        oCN.RunProc("Insert into MES_AccessoriesList (HFileName,HFilePath,HFilePath_Cus,HFileType" +
                                    ",HLoadMan,HLoadDate,HRemark,HVerNum,HFileSize" +
                                    ",HFileClsID,HSourceBillNo" +
                                   ") values('"
                                    + filename.ToString() + "','" + StrPath.ToString() + "','" + filePath.ToString() + "','" + fileExtension.ToString() + "'" +
                                    ",'" + HUserName + "',getdate(),'" + HRemark + "','V1','" + filesize +
                                    "','" + 0 + "','" + HBillNo +
                                   "') ");
                    }
                    else
                    {
                        Result_Ob = new { result = 0, returnval = "上传失败!此文件为恶意文件" };
                    }
                }
                else
                {
                    Directory.CreateDirectory(fileSavePath); //添加文件夹
                    files.SaveAs(fileurl);
                    string StrPath = "/files/MouldFolder/" + HBillNo + "/" + filename;
                    if (File.Exists(fileurl))
                    {
                        //这里可以执行一些其它的操作,比如更新数据库
                        //写入数据表
                        oCN.RunProc("Insert into MES_AccessoriesList (HFileName,HFilePath,HFilePath_Cus,HFileType" +
                                    ",HLoadMan,HLoadDate,HRemark,HVerNum,HFileSize" +
                                    ",HFileClsID,HSourceBillNo" +
                                   ") values('"
                                    + filename.ToString() + "','" + StrPath.ToString() + "','" + filePath.ToString() + "','" + fileExtension.ToString() + "'" +
                                    ",'" + HUserName + "',getdate(),'" + HRemark + "','V1','" + filesize +
                                    "','" + 0 + "','" + HBillNo +
                                   "') ");
                    }
                    else
                    {
                        Result_Ob = new { result = 0, returnval = "上传失败!此文件为恶意文件" };
                    }
                }
            }
            catch (Exception e)
            {
                Result_Ob = new { result = 0, returnval = e.Message };
            }
            return Result_Ob;
        }
        /// <summary>
        /// 根据单据号查找上传文件列表
        /// </summary>
        /// <param name="sWhere"></param>
        /// <returns></returns>
        [Route("Sc_MouldDotCheckBill/Filelist")]
        [HttpGet]
        public object Filelist(string HBillNo)
        {
            var url = fileip + "/files/MouldFolder/" + HBillNo + "/";
            //@"C:\\files\\"
            try
            {
                ds = oCN.RunProcReturn("select *,'" + url + "'+CAST(HFileName as varchar(200))as url  from MES_AccessoriesList where HSourceBillNo='" + HBillNo + "'", "MES_AccessoriesList");
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "Sucess!";
                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;
            }
        }
        /// <summary>
        /// 根据ID,单据号,文件名 删除文件
        /// </summary>
        /// <param name="sWhere"></param>
        /// <returns></returns>
        [Route("Sc_MouldDotCheckBill/DeleteFilelist")]
        [HttpGet]
        public object DeleteFilelist(string HItemID, string HSourceBillNo, string HFileName)
        {
            try
            {
                oCN.RunProc("delete from MES_AccessoriesList where HItemID =" + HItemID);
                string fileurl = Path.Combine(HttpContext.Current.Server.MapPath("~/../Files/MouldFolder/" + HSourceBillNo), HFileName);
                File.Delete(fileurl);      //删除指定文件
                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
        #region 器具保养记录拍照上传
        [Route("Sc_MouldMaintainBill/UploadFile")]
        [HttpPost]
        public object UploadFile_Maintain()
        {
            string HBillNo = HttpContext.Current.Request.Params["HBillNo"];  //单据号
            string HRemark = HttpContext.Current.Request.Params["HRemark"];  //备注
            string HUserName = HttpContext.Current.Request.Params["HUserName"];  //创建人
            HttpPostedFile files = HttpContext.Current.Request.Files["file"];
            string path = HttpContext.Current.Server.MapPath("~/../Files/MouldFolder/" + HBillNo);
            //string path = @"D:\\Files\\"+ HBillNo;
            dynamic dyResult = UpLoadFile_Maintain(files, path, HBillNo, HRemark, HUserName);
            if (dyResult != null && dyResult.result == 1)
            {
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "上传成功!";
                objJsonResult.data = null;
                return objJsonResult;
            }
            else
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = dyResult.returnval;
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        public dynamic UpLoadFile_Maintain(HttpPostedFile files, string path, string HBillNo, string HRemark, string HUserName)
        {
            dynamic Result_Ob = new { result = 1, returnval = "上传成功!" };
            string filePath = Path.GetFullPath(files.FileName);//文件上传路径
            string fileExtension = Path.GetExtension(files.FileName);// 文件扩展名
            string filename = files.FileName;//文件名
            string fileSavePath = path;// 上传保存路径
            int filesize = files.ContentLength;//获取上传文件的大小单位为字节byte
            int Maxsize = 40000 * 1024;//定义上传文件的最大空间大小为40M
            try
            {
                if (files == null || files.ContentLength <= 0)
                {
                    Result_Ob = new { result = 0, returnval = "文件不能为空!" };
                    return Result_Ob;
                }
                if (filesize >= Maxsize)
                {
                    Result_Ob = new { result = 0, returnval = "上传文件超过40M,不能上传!" };
                    return Result_Ob;
                }
                string fileurl = Path.Combine(fileSavePath, filename);
                if (Directory.Exists(fileurl) == true)  //如果存在重名文件就提示
                {
                    Result_Ob = new { result = 0, returnval = "存在同名文件!" };
                    return Result_Ob;
                }
                //删除数据表数据
                ds = oCN.RunProcReturn("delete from MES_AccessoriesList where HSourceBillNo ='" + HBillNo + "' and HFileName='" + filename + "'", "MES_AccessoriesList");
                if (Directory.Exists(path))
                {
                    File.Delete(fileurl);      //删除指定文件
                    files.SaveAs(fileurl);
                    string StrPath = "/files/MouldFolder/" + HBillNo + "/" + filename;
                    if (File.Exists(fileurl))
                    {
                        //这里可以执行一些其它的操作,比如更新数据库
                        //写入数据表
                        oCN.RunProc("Insert into MES_AccessoriesList (HFileName,HFilePath,HFilePath_Cus,HFileType" +
                                    ",HLoadMan,HLoadDate,HRemark,HVerNum,HFileSize" +
                                    ",HFileClsID,HSourceBillNo" +
                                   ") values('"
                                    + filename.ToString() + "','" + StrPath.ToString() + "','" + filePath.ToString() + "','" + fileExtension.ToString() + "'" +
                                    ",'" + HUserName + "',getdate(),'" + HRemark + "','V1','" + filesize +
                                    "','" + 0 + "','" + HBillNo +
                                   "') ");
                    }
                    else
                    {
                        Result_Ob = new { result = 0, returnval = "上传失败!此文件为恶意文件" };
                    }
                }
                else
                {
                    Directory.CreateDirectory(fileSavePath); //添加文件夹
                    files.SaveAs(fileurl);
                    string StrPath = "/files/MouldFolder/" + HBillNo + "/" + filename;
                    if (File.Exists(fileurl))
                    {
                        //这里可以执行一些其它的操作,比如更新数据库
                        //写入数据表
                        oCN.RunProc("Insert into MES_AccessoriesList (HFileName,HFilePath,HFilePath_Cus,HFileType" +
                                    ",HLoadMan,HLoadDate,HRemark,HVerNum,HFileSize" +
                                    ",HFileClsID,HSourceBillNo" +
                                   ") values('"
                                    + filename.ToString() + "','" + StrPath.ToString() + "','" + filePath.ToString() + "','" + fileExtension.ToString() + "'" +
                                    ",'" + HUserName + "',getdate(),'" + HRemark + "','V1','" + filesize +
                                    "','" + 0 + "','" + HBillNo +
                                   "') ");
                    }
                    else
                    {
                        Result_Ob = new { result = 0, returnval = "上传失败!此文件为恶意文件" };
                    }
                }
            }
            catch (Exception e)
            {
                Result_Ob = new { result = 0, returnval = e.Message };
            }
            return Result_Ob;
        }
        /// <summary>
        /// 根据单据号查找上传文件列表
        /// </summary>
        /// <param name="sWhere"></param>
        /// <returns></returns>
        [Route("Sc_MouldMaintainBill/Filelist")]
        [HttpGet]
        public object Filelist_Maintain(string HBillNo)
        {
            var url = fileip + "/files/MouldFolder/" + HBillNo + "/";
            //@"C:\\files\\"
            try
            {
                ds = oCN.RunProcReturn("select *,'" + url + "'+CAST(HFileName as varchar(200))as url  from MES_AccessoriesList where HSourceBillNo='" + HBillNo + "'", "MES_AccessoriesList");
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "Sucess!";
                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;
            }
        }
        /// <summary>
        /// 根据ID,单据号,文件名 删除文件
        /// </summary>
        /// <param name="sWhere"></param>
        /// <returns></returns>
        [Route("Sc_MouldMaintainBill/DeleteFilelist")]
        [HttpGet]
        public object DeleteFilelist_Maintain(string HItemID, string HSourceBillNo, string HFileName)
        {
            try
            {
                oCN.RunProc("delete from MES_AccessoriesList where HItemID =" + HItemID);
                string fileurl = Path.Combine(HttpContext.Current.Server.MapPath("~/../Files/MouldFolder/" + HSourceBillNo), HFileName);
                File.Delete(fileurl);      //删除指定文件
                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
    }
}