WebAPI/Controllers/WebAPIController.cs
@@ -18,9 +18,6 @@
using WebAPI.Controllers.SCGL.日计划管理;
using WebAPI.Models;
using WebAPI.Service;
using System.Web;
using WebAPI.Controllers.SCGL.日计划管理;
using System.IO;
using SyntacticSugar.constant;
namespace WebAPI.Controllers
@@ -40,7 +37,7 @@
        string fileip = System.Configuration.ConfigurationManager.AppSettings["FileIP"];
        /// <summary>
        /// 送货单表头信息
        /// 获取单据号与单据内码
        /// </summary>
        /// <param name="sMsg"></param>
        /// <returns></returns>
@@ -355,6 +352,16 @@
                    objjson.code = "0";
                    objjson.count = 0;
                    objjson.Message = "密码错误!";
                    objjson.data = null;
                    return objjson;
                }
                //判断用户数是否大于客户账号数
                DataSet ds1 = oCN.RunProcReturn("Exec h_p_Xt_BaseInfo ", "h_p_Xt_BaseInfo");
                if (DBUtility.ClsPub.isStrNull(ds1.Tables[0].Rows[0]["HBack"]) != "0")
                {
                    objjson.code = "0";
                    objjson.count = 0;
                    objjson.Message = ds1.Tables[0].Rows[0]["HBackRemark"].ToString();
                    objjson.data = null;
                    return objjson;
                }
@@ -2607,7 +2614,6 @@
            DataSet Maxds = oCN.RunProcReturn("select MAX(HItemID) HItemID from Gy_BadReason ", "Gy_BadReason");
            if (Maxds != null || Maxds.Tables[0].Rows.Count > 0)
            {
                //HItemID= Maxds.Tables[0].Rows[0]["HItemID"]
                var maxid = Convert.ToInt32(Maxds.Tables[0].Rows[0]["HItemID"]);
                maxid += 1;
                HItemID = maxid;
@@ -2734,7 +2740,7 @@
                    oItem.HShortNumber = sShortNumber;//短代码
                    oItem.HEndFlag = true;//末级标志
                    oItem.HLevel = DBUtility.ClsPub.GetLevel(oItem.HNumber.Trim()); //等级
                    oItem.HMakeEmp = msg2;
                    oBill.oModel = oItem;
                }
@@ -2743,19 +2749,17 @@
                bool bResult;
                if (oBill.oModel.HItemID == 0)
                {
                    // bResult = oBill.AddBill(ref DBUtility.ClsPub.sExeReturnInfo);
                    bResult = oBill.AddNew();
                    bResult = oBill.AddNew(ref DBUtility.ClsPub.sExeReturnInfo);
                }
                else
                {
                    bResult = oBill.ModifyByID(oBill.oModel.HItemID);
                    bResult = oBill.ModifyByID(oBill.oModel.HItemID, ref DBUtility.ClsPub.sExeReturnInfo);
                }
                if (bResult)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "保存成功!";
                    //WebAPIController.Add_Log("送货单下推", UserName, "生成送货单");
                    objJsonResult.Message = "保存成功!";;
                    objJsonResult.data = 1;
                    return objJsonResult;
                }
@@ -2778,6 +2782,480 @@
            }
        }
        /// <summary>
        /// 不良原因获取信息
        /// </summary>
        /// <returns></returns>
        [Route("GetGy_BadReasonDetail")]
        [HttpGet]
        public ApiResult<DataSet> GetGy_BadReasonDetail(string HID)
        {
            var model = LuBaoSevice.GetGy_BadReasonBillDetail(HID);
            return model;
        }
        /// <summary>
        /// 不良原因删除功能
        /// </summary>
        /// <returns></returns>
        [Route("DeltetGy_BadReason")]
        [HttpGet]
        public object DeltetGy_BadReason(string HItemID, string user)
        {
            DataSet ds;
            //string ModRightNameCheck = "Sc_ProcessReport_check";
            try
            {
                //删除权限
                if (!DBUtility.ClsPub.Security_Log("Gy_BadReason_Delete", 1, false, user))
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "无删除权限!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
                if (string.IsNullOrWhiteSpace(HItemID))
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "HItemID为空!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                oCN.BeginTran();//开始事务
                ds = oCN.RunProcReturn("select * from Gy_BadReason where HItemID=" + HItemID, "Gy_BadReason");
                if (ds == null || ds.Tables[0].Rows.Count == 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "没有数据,无法删除!";
                    objJsonResult.data = null;
                    return objJsonResult; ;
                }
                //var HStopflag = Convert.ToBoolean(ds.Tables[0].Rows[0]["HStopflag"]);
                //if (HStopflag)
                //{
                //    oCN.RollBack();//回滚事务
                //    objJsonResult.code = "0";
                //    objJsonResult.count = 0;
                //    objJsonResult.Message = "数据已删除无法再次删除!";
                //    objJsonResult.data = null;
                //    return objJsonResult;
                //}
                //删除前控制=========================================
                string sql1 = "exec h_p_Gy_BadReason_BeforeDelCtrl " + HItemID + ",'" + user + "'";
                ds = oCN.RunProcReturn(sql1, "h_p_Gy_BadReason_BeforeDelCtrl");
                if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "删除失败!原因:删除前判断失败,请与网络管理人员联系";
                    objJsonResult.data = null;
                    oCN.RollBack();
                    return objJsonResult;
                }
                if (ds.Tables[0].Rows[0]["HBack"].ToString() != "0")
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "删除失败!原因:" + ds.Tables[0].Rows[0]["HRemark"].ToString(); ;
                    objJsonResult.data = null;
                    oCN.RollBack();
                    return objJsonResult;
                }
                //==================================================================================
                oCN.RunProc("delete Gy_BadReason where HItemID=" + HItemID);
                //删除后控制=========================================
                string sql2 = "exec h_p_Gy_BadReason_AfterDelCtrl " + HItemID + ",'" + user + "'";
                ds = oCN.RunProcReturn(sql2, "h_p_Gy_BadReason_AfterDelCtrl");
                if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "删除失败!原因:删除后判断失败,请与网络管理人员联系";
                    objJsonResult.data = null;
                    oCN.RollBack();
                    return objJsonResult;
                }
                if (ds.Tables[0].Rows[0]["HBack"].ToString() != "0")
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "删除失败!原因:" + ds.Tables[0].Rows[0]["HRemark"].ToString(); ;
                    objJsonResult.data = null;
                    oCN.RollBack();
                    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;
            }
        }
        #region 不良原因 文件导入保存
        #region 不良原因 文件上传
        [Route("Gy_BadReason/Gy_BadReason_Excel")]
        [HttpPost]
        public object Gy_BadReason_Excel()
        {
            try
            {
                //获取文件名称
                var file = HttpContext.Current.Request.Files[0];
                //获取文件物理路径
                string ExcelPath = HttpContext.Current.Server.MapPath("~/" + file.FileName);
                //保存文件
                file.SaveAs(ExcelPath);
                NpoiHelper np = new NpoiHelper();
                DataSet ExcelDs = np.ReadExcel(ExcelPath, 1, 1, "0");
                //删除文件
                File.Delete(ExcelPath);
                //创建临时表
                DataTable tb2 = new DataTable("dt2");
                //添加列名
                for (int i = 0; i < ExcelDs.Tables[0].Columns.Count; i++)
                {
                    tb2.Columns.Add(ExcelDs.Tables[0].Rows[0][i].ToString());
                }
                //模板缺少列 但需要从数据库中查询出来显示在页面的字段
                tb2.Columns.Add("HOrgID", typeof(Int32));//组织ID
                tb2.Columns.Add("HDeptID", typeof(Int32));//部门ID
                tb2.Columns.Add("HProcID", typeof(Int32));//工序ID
                //添加数据
                for (int i = 1; i < ExcelDs.Tables[0].Rows.Count; i++)
                {
                    DataRow row = tb2.NewRow();
                    for (int j = 0; j < ExcelDs.Tables[0].Columns.Count; j++)
                    {
                        row[j] = ExcelDs.Tables[0].Rows[i][j].ToString();
                    }
                    tb2.Rows.Add(row);
                }
                var error = "";
                //查询没有的列
                if (!tb2.Columns.Contains("组织代码"))
                    error += "没有找到【组织代码】的标题,";
                if (!tb2.Columns.Contains("组织名称"))
                    error += "没有找到【组织名称】的标题,";
                if (!tb2.Columns.Contains("不良原因代码"))
                    error += "没有找到【不良原因代码】的标题,";
                if (!tb2.Columns.Contains("不良原因"))
                    error += "没有找到【不良原因】的标题,";
                if (!tb2.Columns.Contains("默认部门代码"))
                    error += "没有找到【默认部门代码】的标题,";
                if (!tb2.Columns.Contains("默认部门"))
                    error += "没有找到【默认部门】的标题,";
                if (!tb2.Columns.Contains("默认工序代码"))
                    error += "没有找到【默认工序代码】的标题,";
                if (!tb2.Columns.Contains("默认工序"))
                    error += "没有找到【默认工序】的标题,";
                if (!tb2.Columns.Contains("备注"))
                    error += "没有找到【备注】的标题,";
                if (!tb2.Columns.Contains("助记码"))
                    error += "没有找到【助记码】的标题,";
                if (error.Length > 0)
                {
                    objJsonResult.code = CodeConstant.FAIL;
                    objJsonResult.count = CountConstant.FAIL;
                    objJsonResult.Message = $"Excel模板存在错误,{error}\r\n";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                for (int i = 0; i <= tb2.Rows.Count - 1; i++)
                {
                    string HName = "";
                    string HNum = "";
                    string HORGNumber = "";
                    string HORGName = "";
                    string HDeptNumber = "";
                    string HDeptName = "";
                    string HProcNumber = "";
                    string HProcName = "";
                    HName = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["不良原因"].ToString());
                    HNum = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["不良原因代码"].ToString());
                    HORGNumber = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["组织代码"].ToString());
                    HORGName = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["组织名称"].ToString());
                    HDeptNumber = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["默认部门代码"].ToString());
                    HDeptName = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["默认部门"].ToString());
                    HProcNumber = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["默认工序代码"].ToString());
                    HProcName = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["默认工序"].ToString());
                    //检查物料
                    int index = i + 1;
                    if (HORGNumber != "")
                    {
                        //查询组织
                        ds = oCN.RunProcReturn("select * from Xt_ORGANIZATIONS where  HNumber='" + HORGNumber + "' and Hname='" + HORGName + "'", "Xt_ORGANIZATIONS");
                        if (ds.Tables[0].Rows.Count == 0)
                        {
                            objJsonResult.code = CodeConstant.FAIL;
                            objJsonResult.count = CountConstant.FAIL;
                            objJsonResult.Message = "第" + index + "行,组织不存在!";
                            objJsonResult.data = null;
                            return objJsonResult;
                        }
                        else
                        {
                            tb2.Rows[i]["HOrgID"] = ds.Tables[0].Rows[0]["HItemID"].ToString();
                        }
                        if (HDeptNumber != "")
                        {
                            //查询部门
                            ds = oCN.RunProcReturn("select * from Gy_Department where  HNumber='" + HDeptNumber + "' and Hname='" + HDeptName + "'", "Gy_Department");
                            if (ds.Tables[0].Rows.Count == 0)
                            {
                                objJsonResult.code = CodeConstant.FAIL;
                                objJsonResult.count = CountConstant.FAIL;
                                objJsonResult.Message = "第" + index + "行,部门不存在!";
                                objJsonResult.data = null;
                                return objJsonResult;
                            }
                            else
                            {
                                tb2.Rows[i]["HDeptID"] = ds.Tables[0].Rows[0]["HItemID"].ToString();
                            }
                        }
                        else
                        {
                            tb2.Rows[i]["HDeptID"] = 0;
                        }
                        if (HProcNumber != "")
                        {
                            //查询部门
                            ds = oCN.RunProcReturn("select * from Gy_Process where  HNumber='" + HProcNumber + "' and Hname='" + HProcName + "'", "Gy_Process");
                            if (ds.Tables[0].Rows.Count == 0)
                            {
                                objJsonResult.code = CodeConstant.FAIL;
                                objJsonResult.count = CountConstant.FAIL;
                                objJsonResult.Message = "第" + index + "行,工序不存在!";
                                objJsonResult.data = null;
                                return objJsonResult;
                            }
                            else
                            {
                                tb2.Rows[i]["HProcID"] = ds.Tables[0].Rows[0]["HItemID"].ToString();
                            }
                        }
                        else
                        {
                            tb2.Rows[i]["HProcID"] = 0;
                        }
                        //不良原因名称
                        if (HName == "")
                        {
                            objJsonResult.code = CodeConstant.FAIL;
                            objJsonResult.count = CountConstant.FAIL;
                            objJsonResult.Message = "第" + index + "行,不良原因名称不能为空!";
                            objJsonResult.data = null;
                            return objJsonResult;
                        }
                        //不良原因代码
                        if (HNum == "")
                        {
                            objJsonResult.code = CodeConstant.FAIL;
                            objJsonResult.count = CountConstant.FAIL;
                            objJsonResult.Message = "第" + index + "行,不良原因代码不能为空!";
                            objJsonResult.data = null;
                            return objJsonResult;
                        }
                    }
                    else
                    {
                        objJsonResult.code = CodeConstant.FAIL;
                        objJsonResult.count = CountConstant.FAIL;
                        objJsonResult.Message = "第" + index + "行,组织代码为空";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                }
                objJsonResult.code = CodeConstant.SUCCEED;
                objJsonResult.count = CountConstant.SUCCEED;
                objJsonResult.Message = error;
                objJsonResult.data = tb2;
                return objJsonResult;
            }
            catch (Exception e)
            {
                objJsonResult.code = CodeConstant.FAIL;
                objJsonResult.count = CountConstant.FAIL;
                objJsonResult.Message = "Exception!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
        #region 不良原因项目 导入(保存)
        [Route("Gy_BadReason/Gy_BadReason_btnSave")]
        [HttpPost]
        public object Gy_BadReason_btnSave([FromBody] JObject sMainSub)
        {
            var _value = sMainSub["sMainSub"].ToString();
            string msg1 = _value.ToString();
            string[] sArray = msg1.Split(new string[] { "&和" }, StringSplitOptions.RemoveEmptyEntries);
            string msg2 = sArray[0].ToString();
            string user = sArray[1].ToString();
            try
            {
                if (!DBUtility.ClsPub.Security_Log("Gy_BadReason_Edit", 1, false, user))
                {
                    objJsonResult.code = CodeConstant.FAIL;
                    objJsonResult.count = CountConstant.FAIL;
                    objJsonResult.Message = "无保存权限!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                List<object> Excel = Newtonsoft.Json.JsonConvert.DeserializeObject<List<object>>(msg2);
                List<Dictionary<string, string>> list = new List<Dictionary<string, string>>();
                foreach (JObject item in Excel)
                {
                    Dictionary<string, string> dic = new Dictionary<string, string>();
                    foreach (var itm in item.Properties())
                    {
                        dic.Add(itm.Name, itm.Value.ToString());
                    }
                    list.Add(dic);
                }
                oCN.BeginTran();
                int i = 1;
                foreach (Dictionary<string, string> item in list)
                {
                    string HOrgID = item["HOrgID"].ToString();//组织ID
                    string HDeptID = item["HDeptID"].ToString();//部门ID
                    string HProcID = item["HProcID"].ToString();//工序ID
                    string HName = item["不良原因"].ToString();
                    string HNumber = item["不良原因代码"].ToString();
                    string HRemark = item["备注"].ToString();
                    string HHelpCode = item["助记码"].ToString();
                    string sShortNumber;
                    sShortNumber = DBUtility.ClsPub.GetShortNumber(HNumber);//短代码
                    if (sShortNumber.Trim() == "")
                    {
                        objJsonResult.code = CodeConstant.FAIL;
                        objJsonResult.count = CountConstant.FAIL;
                        objJsonResult.Message = "保存失败!短代码为空!";
                        objJsonResult.data = 1;
                        return objJsonResult;
                    }
                    int HEndFlag = 1;//末级标志
                    int HLevel = DBUtility.ClsPub.GetLevel(HNumber); //等级
                    if (!DBUtility.ClsPub.AllowNumber(HNumber.Trim()))
                    {
                        objJsonResult.code = CodeConstant.FAIL;
                        objJsonResult.count = CountConstant.FAIL;
                        objJsonResult.Message = "保存失败!代码中不能出现连续‘.’并且首位末位不能为‘.’!";
                        objJsonResult.data = 1;
                        return objJsonResult;
                    }
                    ds = oCN.RunProcReturn("select * from Gy_BadReason where HNumber='" + HNumber + "'", "Gy_BadReason");
                    if (ds.Tables[0].Rows.Count == 0)
                    {
                        oCN.RunProc("Insert into "  + "Gy_BadReason " +
                        " (HNumber,HName,HHelpCode,HShortNumber,HParentID" +
                        ",HDeptID,HProcID" +
                        ",HLevel,HEndFlag,HStopflag,HRemark,HBadTypeID) " +
                        " Values('" + HNumber + "','" + HName + "','" + HHelpCode + "','" + sShortNumber + "'," + 0 +
                        "," + HDeptID.ToString() + "," + HProcID.ToString() +
                        "," + HLevel.ToString() + "," + HEndFlag + "," + 0 + ",'" + HRemark + "'," + 0 + ")", ref DBUtility.ClsPub.sExeReturnInfo);
                    }
                    else
                    {
                        oCN.RunProc("Update Gy_BadReason"+ " set " +
                        "HName='" + HName + "'" +
                        ",HShortNumber='" + sShortNumber + "'" +
                        ",HHelpCode='" + HHelpCode + "'" +
                        ",HLevel=" + HLevel.ToString() +
                        ",HDeptID=" + HDeptID.ToString() +
                        ",HProcID=" + HProcID.ToString() +
                        ",HRemark= '" + HRemark + "' Where HNumber='" + HNumber + "'", ref DBUtility.ClsPub.sExeReturnInfo);
                    }
                    i++;
                }
                oCN.Commit();
                objJsonResult.code = CodeConstant.SUCCEED;
                objJsonResult.count = CountConstant.SUCCEED;
                objJsonResult.Message = "导入成功!";
                objJsonResult.data = null;
                return objJsonResult;
            }
            catch (Exception e)
            {
                LogService.Write(e);
                objJsonResult.code = CodeConstant.FAIL;
                objJsonResult.count = CountConstant.FAIL;
                objJsonResult.Message = "Exception!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
        #endregion
        #endregion
        #region 不良类型  设置列表/保存/编辑/删除方法
        /// <summary>
        /// 保存不良类型
@@ -2938,7 +3416,7 @@
                    oItem.HShortNumber = sShortNumber;//短代码
                    oItem.HEndFlag = true;//末级标志
                    oItem.HLevel = DBUtility.ClsPub.GetLevel(oItem.HNumber.Trim()); //等级
                    oItem.HMakeEmp = msg2;
                    oBill.oModel = oItem;
                }
@@ -2947,19 +3425,17 @@
                bool bResult;
                if (oBill.oModel.HItemID == 0)
                {
                    // bResult = oBill.AddBill(ref DBUtility.ClsPub.sExeReturnInfo);
                    bResult = oBill.AddNew();
                    bResult = oBill.AddNew(ref DBUtility.ClsPub.sExeReturnInfo);
                }
                else
                {
                    bResult = oBill.ModifyByID(oBill.oModel.HItemID);
                    bResult = oBill.ModifyByID(oBill.oModel.HItemID, ref DBUtility.ClsPub.sExeReturnInfo);
                }
                if (bResult)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "保存成功!";
                    //WebAPIController.Add_Log("送货单下推", UserName, "生成送货单");
                    objJsonResult.data = 1;
                    return objJsonResult;
                }
@@ -2982,6 +3458,452 @@
            }
        }
        /// <summary>
        /// 不良类型获取信息
        /// </summary>
        /// <returns></returns>
        [Route("GetGy_BadTypeDetail")]
        [HttpGet]
        public ApiResult<DataSet> GetGy_BadTypeDetail(string HID)
        {
            var dataSet = oCN.RunProcReturn("select top 1 * from h_v_gy_BadTypeList  where HItemID= " + HID + " ", "h_v_gy_BadTypeList");
            if (dataSet == null || dataSet.Tables[0].Rows.Count == 0)
                return new ApiResult<DataSet> { code = -1, msg = "不存在不良类型数据" };
            return new ApiResult<DataSet> { code = 1, msg = "查询成功", data = dataSet };
        }
        /// <summary>
        /// 不良类型删除功能
        /// </summary>
        /// <returns></returns>
        [Route("DeltetGy_BadType")]
        [HttpGet]
        public object DeltetGy_BadType(string HItemID, string user)
        {
            DataSet ds;
            //string ModRightNameCheck = "Sc_ProcessReport_check";
            try
            {
                //删除权限
                if (!DBUtility.ClsPub.Security_Log("Gy_BadType_Drop", 1, false, user))
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "无删除权限!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
                if (string.IsNullOrWhiteSpace(HItemID))
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "HItemID为空!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                oCN.BeginTran();//开始事务
                ds = oCN.RunProcReturn("select * from Gy_BadType where HItemID=" + HItemID, "Gy_BadType");
                if (ds == null || ds.Tables[0].Rows.Count == 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "没有数据,无法删除!";
                    objJsonResult.data = null;
                    return objJsonResult; ;
                }
                //var HStopflag = Convert.ToBoolean(ds.Tables[0].Rows[0]["HStopflag"]);
                //if (HStopflag)
                //{
                //    oCN.RollBack();//回滚事务
                //    objJsonResult.code = "0";
                //    objJsonResult.count = 0;
                //    objJsonResult.Message = "数据已删除无法再次删除!";
                //    objJsonResult.data = null;
                //    return objJsonResult;
                //}
                //删除前控制=========================================
                string sql1 = "exec h_p_Gy_BadType_BeforeDelCtrl " + HItemID + ",'" + user + "'";
                ds = oCN.RunProcReturn(sql1, "h_p_Gy_BadType_BeforeDelCtrl");
                if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "删除失败!原因:删除前判断失败,请与网络管理人员联系";
                    objJsonResult.data = null;
                    oCN.RollBack();
                    return objJsonResult;
                }
                if (ds.Tables[0].Rows[0]["HBack"].ToString() != "0")
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "删除失败!原因:" + ds.Tables[0].Rows[0]["HRemark"].ToString(); ;
                    objJsonResult.data = null;
                    oCN.RollBack();
                    return objJsonResult;
                }
                //==================================================================================
                oCN.RunProc("delete Gy_BadType where HItemID=" + HItemID);
                //删除后控制=========================================
                string sql2 = "exec h_p_Gy_BadType_AfterDelCtrl " + HItemID + ",'" + user + "'";
                ds = oCN.RunProcReturn(sql2, "h_p_Gy_BadType_AfterDelCtrl");
                if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "删除失败!原因:删除后判断失败,请与网络管理人员联系";
                    objJsonResult.data = null;
                    oCN.RollBack();
                    return objJsonResult;
                }
                if (ds.Tables[0].Rows[0]["HBack"].ToString() != "0")
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "删除失败!原因:" + ds.Tables[0].Rows[0]["HRemark"].ToString(); ;
                    objJsonResult.data = null;
                    oCN.RollBack();
                    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;
            }
        }
        #region 不良类型 文件导入保存
        #region 不良类型 文件上传
        [Route("Gy_BadType/Gy_BadType_Excel")]
        [HttpPost]
        public object Gy_BadType_Excel()
        {
            try
            {
                //获取文件名称
                var file = HttpContext.Current.Request.Files[0];
                //获取文件物理路径
                string ExcelPath = HttpContext.Current.Server.MapPath("~/" + file.FileName);
                //保存文件
                file.SaveAs(ExcelPath);
                NpoiHelper np = new NpoiHelper();
                DataSet ExcelDs = np.ReadExcel(ExcelPath, 1, 1, "0");
                //删除文件
                File.Delete(ExcelPath);
                //创建临时表
                DataTable tb2 = new DataTable("dt2");
                //添加列名
                for (int i = 0; i < ExcelDs.Tables[0].Columns.Count; i++)
                {
                    tb2.Columns.Add(ExcelDs.Tables[0].Rows[0][i].ToString());
                }
                //模板缺少列 但需要从数据库中查询出来显示在页面的字段
                tb2.Columns.Add("HOrgID", typeof(Int32));//组织ID
                tb2.Columns.Add("HGroupID", typeof(Int32));//班组ID
                //添加数据
                for (int i = 1; i < ExcelDs.Tables[0].Rows.Count; i++)
                {
                    DataRow row = tb2.NewRow();
                    for (int j = 0; j < ExcelDs.Tables[0].Columns.Count; j++)
                    {
                        row[j] = ExcelDs.Tables[0].Rows[i][j].ToString();
                    }
                    tb2.Rows.Add(row);
                }
                var error = "";
                //查询没有的列
                if (!tb2.Columns.Contains("组织代码"))
                    error += "没有找到【组织代码】的标题,";
                if (!tb2.Columns.Contains("组织名称"))
                    error += "没有找到【组织名称】的标题,";
                if (!tb2.Columns.Contains("不良类型代码"))
                    error += "没有找到【不良类型代码】的标题,";
                if (!tb2.Columns.Contains("不良类型"))
                    error += "没有找到【不良类型】的标题,";
                if (!tb2.Columns.Contains("默认班组代码"))
                    error += "没有找到【默认班组代码】的标题,";
                if (!tb2.Columns.Contains("默认班组名称"))
                    error += "没有找到【默认班组名称】的标题,";
                if (!tb2.Columns.Contains("备注"))
                    error += "没有找到【备注】的标题,";
                if (!tb2.Columns.Contains("助记码"))
                    error += "没有找到【助记码】的标题,";
                if (error.Length > 0)
                {
                    objJsonResult.code = CodeConstant.FAIL;
                    objJsonResult.count = CountConstant.FAIL;
                    objJsonResult.Message = $"Excel模板存在错误,{error}\r\n";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                for (int i = 0; i <= tb2.Rows.Count - 1; i++)
                {
                    string HName = "";
                    string HNum = "";
                    string HORGNumber = "";
                    string HORGName = "";
                    string HGroupNumber = "";
                    string HGroupName = "";
                    HName = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["不良类型"].ToString());
                    HNum = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["不良类型代码"].ToString());
                    HORGNumber = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["组织代码"].ToString());
                    HORGName = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["组织名称"].ToString());
                    HGroupNumber = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["默认班组代码"].ToString());
                    HGroupName = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["默认班组名称"].ToString());
                    //检查物料
                    int index = i + 1;
                    if (HORGNumber != "")
                    {
                        //查询组织
                        ds = oCN.RunProcReturn("select * from Xt_ORGANIZATIONS where  HNumber='" + HORGNumber + "' and Hname='" + HORGName + "'", "Xt_ORGANIZATIONS");
                        if (ds.Tables[0].Rows.Count == 0)
                        {
                            objJsonResult.code = CodeConstant.FAIL;
                            objJsonResult.count = CountConstant.FAIL;
                            objJsonResult.Message = "第" + index + "行,组织不存在!";
                            objJsonResult.data = null;
                            return objJsonResult;
                        }
                        else
                        {
                            tb2.Rows[i]["HOrgID"] = ds.Tables[0].Rows[0]["HItemID"].ToString();
                        }
                        if(HGroupNumber != "")
                        {
                            //查询班组
                            ds = oCN.RunProcReturn("select * from Gy_Group where  HNumber='" + HGroupNumber + "' and Hname='" + HGroupName + "'", "Gy_Group");
                            if (ds.Tables[0].Rows.Count == 0)
                            {
                                objJsonResult.code = CodeConstant.FAIL;
                                objJsonResult.count = CountConstant.FAIL;
                                objJsonResult.Message = "第" + index + "行,班组不存在!";
                                objJsonResult.data = null;
                                return objJsonResult;
                            }
                            else
                            {
                                tb2.Rows[i]["HGroupID"] = ds.Tables[0].Rows[0]["HItemID"].ToString();
                            }
                        }
                        else
                        {
                            tb2.Rows[i]["HGroupID"] = 0;
                        }
                        //不良类型名称
                        if (HName == "")
                        {
                            objJsonResult.code = CodeConstant.FAIL;
                            objJsonResult.count = CountConstant.FAIL;
                            objJsonResult.Message = "第" + index + "行,不良类型名称不能为空!";
                            objJsonResult.data = null;
                            return objJsonResult;
                        }
                        //不良类型代码
                        if (HNum == "")
                        {
                            objJsonResult.code = CodeConstant.FAIL;
                            objJsonResult.count = CountConstant.FAIL;
                            objJsonResult.Message = "第" + index + "行,不良类型代码不能为空!";
                            objJsonResult.data = null;
                            return objJsonResult;
                        }
                    }
                    else
                    {
                        objJsonResult.code = CodeConstant.FAIL;
                        objJsonResult.count = CountConstant.FAIL;
                        objJsonResult.Message = "第" + index + "行,组织代码为空";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                }
                objJsonResult.code = CodeConstant.SUCCEED;
                objJsonResult.count = CountConstant.SUCCEED;
                objJsonResult.Message = error;
                objJsonResult.data = tb2;
                return objJsonResult;
            }
            catch (Exception e)
            {
                objJsonResult.code = CodeConstant.FAIL;
                objJsonResult.count = CountConstant.FAIL;
                objJsonResult.Message = "Exception!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
        #region 不良类型项目 导入(保存)
        [Route("Gy_BadType/Gy_BadType_btnSave")]
        [HttpPost]
        public object Gy_BadType_btnSave([FromBody] JObject sMainSub)
        {
            var _value = sMainSub["sMainSub"].ToString();
            string msg1 = _value.ToString();
            string[] sArray = msg1.Split(new string[] { "&和" }, StringSplitOptions.RemoveEmptyEntries);
            string msg2 = sArray[0].ToString();
            string user = sArray[1].ToString();
            try
            {
                if (!DBUtility.ClsPub.Security_Log("Gy_BadType_Edit", 1, false, user))
                {
                    objJsonResult.code = CodeConstant.FAIL;
                    objJsonResult.count = CountConstant.FAIL;
                    objJsonResult.Message = "无保存权限!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                List<object> Excel = Newtonsoft.Json.JsonConvert.DeserializeObject<List<object>>(msg2);
                List<Dictionary<string, string>> list = new List<Dictionary<string, string>>();
                foreach (JObject item in Excel)
                {
                    Dictionary<string, string> dic = new Dictionary<string, string>();
                    foreach (var itm in item.Properties())
                    {
                        dic.Add(itm.Name, itm.Value.ToString());
                    }
                    list.Add(dic);
                }
                oCN.BeginTran();
                int i = 1;
                foreach (Dictionary<string, string> item in list)
                {
                    string HOrgID = item["HOrgID"].ToString();//组织ID
                    string HGroupID = item["HGroupID"].ToString();//班组ID
                    string HName = item["不良类型"].ToString();
                    string HNumber = item["不良类型代码"].ToString();
                    string HRemark = item["备注"].ToString();
                    string HHelpCode = item["助记码"].ToString();
                    string sShortNumber;
                    sShortNumber = DBUtility.ClsPub.GetShortNumber(HNumber);//短代码
                    if (sShortNumber.Trim() == "")
                    {
                        objJsonResult.code = CodeConstant.FAIL;
                        objJsonResult.count = CountConstant.FAIL;
                        objJsonResult.Message = "保存失败!短代码为空!";
                        objJsonResult.data = 1;
                        return objJsonResult;
                    }
                    int HEndFlag = 1;//末级标志
                    int HLevel = DBUtility.ClsPub.GetLevel(HNumber); //等级
                    if (!DBUtility.ClsPub.AllowNumber(HNumber.Trim()))
                    {
                        objJsonResult.code = CodeConstant.FAIL;
                        objJsonResult.count = CountConstant.FAIL;
                        objJsonResult.Message = "保存失败!代码中不能出现连续‘.’并且首位末位不能为‘.’!";
                        objJsonResult.data = 1;
                        return objJsonResult;
                    }
                    ds = oCN.RunProcReturn("select * from Gy_BadType where HNumber='" + HNumber + "'", "Gy_BadType");
                    if (ds.Tables[0].Rows.Count == 0)
                    {
                            oCN.RunProc("Insert into Gy_BadType" + " " +
                        " (HNumber,HName,HHelpCode,HShortNumber,HParentID" +
                        ",HGroupID" +
                        ",HLevel,HEndFlag,HStopflag,HRemark,HUSEORGID,HCREATEORGID,HUseFlag,HMakeEmp,HMakeTime) " +
                        " Values('" + HNumber + "','" + HName + "','" + HHelpCode + "','" + sShortNumber + "'," + 0 +
                        "," + HGroupID.ToString() +
                        "," + HLevel.ToString() + "," + HEndFlag + "," + 0 + ",'" + HRemark + "'," + HOrgID + "," + HOrgID + ",'" + "未检测" + "','" + user + "',getdate())", ref DBUtility.ClsPub.sExeReturnInfo);
                    }
                    else
                    {
                        oCN.RunProc("Update " + "Gy_BadType " + " set " +
                        "HName='" + HName + "'" +
                        ",HHelpCode='" + HHelpCode + "'" +
                        ",HRemark= '" + HRemark + "'" +
                        ",HGroupID= '" + HGroupID + "'" +
                        ",HModifyEmp= '" + user + "'" +
                        ",HModifyTime=getdate()" +
                        ",HUSEORGID=" + HOrgID +
                        " where HNumber='" + HNumber + "'");
                    }
                    i++;
                }
                oCN.Commit();
                objJsonResult.code = CodeConstant.SUCCEED;
                objJsonResult.count = CountConstant.SUCCEED;
                objJsonResult.Message = "导入成功!";
                objJsonResult.data = null;
                return objJsonResult;
            }
            catch (Exception e)
            {
                LogService.Write(e);
                objJsonResult.code = CodeConstant.FAIL;
                objJsonResult.count = CountConstant.FAIL;
                objJsonResult.Message = "Exception!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
        #endregion
        #endregion
        #region  异常类型   设置列表/保存/编辑/删除方法
        /// <summary>
        /// 保存异常类型
@@ -3622,175 +4544,6 @@
        }
        #endregion
        #endregion
        /// <summary>
        /// 不良类型获取信息
        /// </summary>
        /// <returns></returns>
        [Route("GetGy_BadTypeDetail")]
        [HttpGet]
        public ApiResult<DataSet> GetGy_BadTypeDetail(string HID)
        {
            var dataSet = oCN.RunProcReturn("select top 1 * from h_v_gy_BadTypeList  where HItemID= " + HID + " ", "h_v_gy_BadTypeList");
            if (dataSet == null || dataSet.Tables[0].Rows.Count == 0)
                return new ApiResult<DataSet> { code = -1, msg = "不存在不良类型数据" };
            return new ApiResult<DataSet> { code = 1, msg = "查询成功", data = dataSet };
        }
        /// <summary>
        /// 不良类型删除功能
        /// </summary>
        /// <returns></returns>
        [Route("DeltetGy_BadType")]
        [HttpGet]
        public object DeltetGy_BadType(string HItemID, string user)
        {
            DataSet ds;
            //string ModRightNameCheck = "Sc_ProcessReport_check";
            try
            {
                //删除权限
                if (!DBUtility.ClsPub.Security_Log("Gy_BadType_Drop", 1, false, user))
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "无删除权限!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
                if (string.IsNullOrWhiteSpace(HItemID))
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "HItemID为空!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                oCN.BeginTran();//开始事务
                ds = oCN.RunProcReturn("select * from Gy_BadType where HItemID=" + HItemID, "Gy_BadType");
                if (ds == null || ds.Tables[0].Rows.Count == 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "没有数据,无法删除!";
                    objJsonResult.data = null;
                    return objJsonResult; ;
                }
                //var HStopflag = Convert.ToBoolean(ds.Tables[0].Rows[0]["HStopflag"]);
                //if (HStopflag)
                //{
                //    oCN.RollBack();//回滚事务
                //    objJsonResult.code = "0";
                //    objJsonResult.count = 0;
                //    objJsonResult.Message = "数据已删除无法再次删除!";
                //    objJsonResult.data = null;
                //    return objJsonResult;
                //}
                oCN.RunProc("delete Gy_BadType where HItemID=" + HItemID);
                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;
            }
        }
        /// <summary>
        /// 不良原因获取信息
        /// </summary>
        /// <returns></returns>
        [Route("GetGy_BadReasonDetail")]
        [HttpGet]
        public ApiResult<DataSet> GetGy_BadReasonDetail(string HID)
        {
            var model = LuBaoSevice.GetGy_BadReasonBillDetail(HID);
            return model;
        }
        /// <summary>
        /// 不良原因删除功能
        /// </summary>
        /// <returns></returns>
        [Route("DeltetGy_BadReason")]
        [HttpGet]
        public object DeltetGy_BadReason(string HItemID, string user)
        {
            DataSet ds;
            //string ModRightNameCheck = "Sc_ProcessReport_check";
            try
            {
                //删除权限
                if (!DBUtility.ClsPub.Security_Log("Gy_BadReason_Delete", 1, false, user))
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "无删除权限!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
                if (string.IsNullOrWhiteSpace(HItemID))
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "HItemID为空!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                oCN.BeginTran();//开始事务
                ds = oCN.RunProcReturn("select * from Gy_BadReason where HItemID=" + HItemID, "Gy_BadReason");
                if (ds == null || ds.Tables[0].Rows.Count == 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "没有数据,无法删除!";
                    objJsonResult.data = null;
                    return objJsonResult; ;
                }
                //var HStopflag = Convert.ToBoolean(ds.Tables[0].Rows[0]["HStopflag"]);
                //if (HStopflag)
                //{
                //    oCN.RollBack();//回滚事务
                //    objJsonResult.code = "0";
                //    objJsonResult.count = 0;
                //    objJsonResult.Message = "数据已删除无法再次删除!";
                //    objJsonResult.data = null;
                //    return objJsonResult;
                //}
                oCN.RunProc("delete Gy_BadReason where HItemID=" + HItemID);
                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
@@ -3965,11 +4718,11 @@
                if (oBill.oModel.HItemID == 0)
                {
                    // bResult = oBill.AddBill(ref DBUtility.ClsPub.sExeReturnInfo);
                    bResult = oBill.AddNew();
                    bResult = oBill.AddNew(ref DBUtility.ClsPub.sExeReturnInfo);
                }
                else
                {
                    bResult = oBill.ModifyByID(oBill.oModel.HItemID);
                    bResult = oBill.ModifyByID(oBill.oModel.HItemID, ref DBUtility.ClsPub.sExeReturnInfo);
                }
                if (bResult)
                {
@@ -4063,7 +4816,58 @@
                //    return objJsonResult;
                //}
                //删除前控制=========================================
                string sql1 = "exec h_p_Gy_BadResult_BeforeDelCtrl " + HItemID + ",'" + user + "'";
                ds = oCN.RunProcReturn(sql1, "h_p_Gy_BadResult_BeforeDelCtrl");
                if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "删除失败!原因:删除前判断失败,请与网络管理人员联系";
                    objJsonResult.data = null;
                    oCN.RollBack();
                    return objJsonResult;
                }
                if (ds.Tables[0].Rows[0]["HBack"].ToString() != "0")
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "删除失败!原因:" + ds.Tables[0].Rows[0]["HRemark"].ToString(); ;
                    objJsonResult.data = null;
                    oCN.RollBack();
                    return objJsonResult;
                }
                //==================================================================================
                oCN.RunProc("delete Gy_BadResult where HItemID=" + HItemID);
                //删除后控制=========================================
                string sql2 = "exec h_p_Gy_BadResult_AfterDelCtrl " + HItemID + ",'" + user + "'";
                ds = oCN.RunProcReturn(sql2, "h_p_Gy_BadResult_AfterDelCtrl");
                if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "删除失败!原因:删除后判断失败,请与网络管理人员联系";
                    objJsonResult.data = null;
                    oCN.RollBack();
                    return objJsonResult;
                }
                if (ds.Tables[0].Rows[0]["HBack"].ToString() != "0")
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "删除失败!原因:" + ds.Tables[0].Rows[0]["HRemark"].ToString(); ;
                    objJsonResult.data = null;
                    oCN.RollBack();
                    return objJsonResult;
                }
                //==================================================================================
                oCN.Commit();//提交事务
                objJsonResult.code = "0";
                objJsonResult.count = 1;
@@ -4081,6 +4885,277 @@
                return objJsonResult;
            }
        }
        #region 不良后果 文件导入保存
        #region 不良后果 文件上传
        [Route("Gy_BadResult/Gy_BadResult_Excel")]
        [HttpPost]
        public object Gy_BadResult_Excel()
        {
            try
            {
                //获取文件名称
                var file = HttpContext.Current.Request.Files[0];
                //获取文件物理路径
                string ExcelPath = HttpContext.Current.Server.MapPath("~/" + file.FileName);
                //保存文件
                file.SaveAs(ExcelPath);
                NpoiHelper np = new NpoiHelper();
                DataSet ExcelDs = np.ReadExcel(ExcelPath, 1, 1, "0");
                //删除文件
                File.Delete(ExcelPath);
                //创建临时表
                DataTable tb2 = new DataTable("dt2");
                //添加列名
                for (int i = 0; i < ExcelDs.Tables[0].Columns.Count; i++)
                {
                    tb2.Columns.Add(ExcelDs.Tables[0].Rows[0][i].ToString());
                }
                //模板缺少列 但需要从数据库中查询出来显示在页面的字段
                tb2.Columns.Add("HOrgID", typeof(Int32));//组织ID
                //添加数据
                for (int i = 1; i < ExcelDs.Tables[0].Rows.Count; i++)
                {
                    DataRow row = tb2.NewRow();
                    for (int j = 0; j < ExcelDs.Tables[0].Columns.Count; j++)
                    {
                        row[j] = ExcelDs.Tables[0].Rows[i][j].ToString();
                    }
                    tb2.Rows.Add(row);
                }
                var error = "";
                //查询没有的列
                if (!tb2.Columns.Contains("组织代码"))
                    error += "没有找到【组织代码】的标题,";
                if (!tb2.Columns.Contains("组织名称"))
                    error += "没有找到【组织名称】的标题,";
                if (!tb2.Columns.Contains("不良后果代码"))
                    error += "没有找到【不良后果代码】的标题,";
                if (!tb2.Columns.Contains("不良后果"))
                    error += "没有找到【不良后果】的标题,";
                if (!tb2.Columns.Contains("备注"))
                    error += "没有找到【备注】的标题,";
                if (!tb2.Columns.Contains("助记码"))
                    error += "没有找到【助记码】的标题,";
                if (error.Length > 0)
                {
                    objJsonResult.code = CodeConstant.FAIL;
                    objJsonResult.count = CountConstant.FAIL;
                    objJsonResult.Message = $"Excel模板存在错误,{error}\r\n";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                for (int i = 0; i <= tb2.Rows.Count - 1; i++)
                {
                    string HName = "";
                    string HNum = "";
                    string HORGNumber = "";
                    string HORGName = "";
                    HName = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["不良后果"].ToString());
                    HNum = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["不良后果代码"].ToString());
                    HORGNumber = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["组织代码"].ToString());
                    HORGName = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["组织名称"].ToString());
                    //检查物料
                    int index = i + 1;
                    if (HORGNumber != "")
                    {
                        //查询组织
                        ds = oCN.RunProcReturn("select * from Xt_ORGANIZATIONS where  HNumber='" + HORGNumber + "' and Hname='" + HORGName + "'", "Xt_ORGANIZATIONS");
                        if (ds.Tables[0].Rows.Count == 0)
                        {
                            objJsonResult.code = CodeConstant.FAIL;
                            objJsonResult.count = CountConstant.FAIL;
                            objJsonResult.Message = "第" + index + "行,组织不存在!";
                            objJsonResult.data = null;
                            return objJsonResult;
                        }
                        else
                        {
                            tb2.Rows[i]["HOrgID"] = ds.Tables[0].Rows[0]["HItemID"].ToString();
                        }
                        //不良后果名称
                        if (HName == "")
                        {
                            objJsonResult.code = CodeConstant.FAIL;
                            objJsonResult.count = CountConstant.FAIL;
                            objJsonResult.Message = "第" + index + "行,不良后果名称不能为空!";
                            objJsonResult.data = null;
                            return objJsonResult;
                        }
                        //不良后果代码
                        if (HNum == "")
                        {
                            objJsonResult.code = CodeConstant.FAIL;
                            objJsonResult.count = CountConstant.FAIL;
                            objJsonResult.Message = "第" + index + "行,不良后果代码不能为空!";
                            objJsonResult.data = null;
                            return objJsonResult;
                        }
                    }
                    else
                    {
                        objJsonResult.code = CodeConstant.FAIL;
                        objJsonResult.count = CountConstant.FAIL;
                        objJsonResult.Message = "第" + index + "行,组织代码为空";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                }
                objJsonResult.code = CodeConstant.SUCCEED;
                objJsonResult.count = CountConstant.SUCCEED;
                objJsonResult.Message = error;
                objJsonResult.data = tb2;
                return objJsonResult;
            }
            catch (Exception e)
            {
                objJsonResult.code = CodeConstant.FAIL;
                objJsonResult.count = CountConstant.FAIL;
                objJsonResult.Message = "Exception!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
        #region 不良后果项目 导入(保存)
        [Route("Gy_BadResult/Gy_BadResult_btnSave")]
        [HttpPost]
        public object Gy_BadResult_btnSave([FromBody] JObject sMainSub)
        {
            var _value = sMainSub["sMainSub"].ToString();
            string msg1 = _value.ToString();
            string[] sArray = msg1.Split(new string[] { "&和" }, StringSplitOptions.RemoveEmptyEntries);
            string msg2 = sArray[0].ToString();
            string user = sArray[1].ToString();
            try
            {
                if (!DBUtility.ClsPub.Security_Log("Gy_BadResult_Edit", 1, false, user))
                {
                    objJsonResult.code = CodeConstant.FAIL;
                    objJsonResult.count = CountConstant.FAIL;
                    objJsonResult.Message = "无保存权限!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                List<object> Excel = Newtonsoft.Json.JsonConvert.DeserializeObject<List<object>>(msg2);
                List<Dictionary<string, string>> list = new List<Dictionary<string, string>>();
                foreach (JObject item in Excel)
                {
                    Dictionary<string, string> dic = new Dictionary<string, string>();
                    foreach (var itm in item.Properties())
                    {
                        dic.Add(itm.Name, itm.Value.ToString());
                    }
                    list.Add(dic);
                }
                oCN.BeginTran();
                int i = 1;
                foreach (Dictionary<string, string> item in list)
                {
                    string HOrgID = item["HOrgID"].ToString();//组织ID
                    string HName = item["不良后果"].ToString();
                    string HNumber = item["不良后果代码"].ToString();
                    string HRemark = item["备注"].ToString();
                    string HHelpCode = item["助记码"].ToString();
                    string sShortNumber;
                    sShortNumber = DBUtility.ClsPub.GetShortNumber(HNumber);//短代码
                    if (sShortNumber.Trim() == "")
                    {
                        objJsonResult.code = CodeConstant.FAIL;
                        objJsonResult.count = CountConstant.FAIL;
                        objJsonResult.Message = "保存失败!短代码为空!";
                        objJsonResult.data = 1;
                        return objJsonResult;
                    }
                    int HEndFlag = 1;//末级标志
                    int HLevel = DBUtility.ClsPub.GetLevel(HNumber); //等级
                    if (!DBUtility.ClsPub.AllowNumber(HNumber.Trim()))
                    {
                        objJsonResult.code = CodeConstant.FAIL;
                        objJsonResult.count = CountConstant.FAIL;
                        objJsonResult.Message = "保存失败!代码中不能出现连续‘.’并且首位末位不能为‘.’!";
                        objJsonResult.data = 1;
                        return objJsonResult;
                    }
                    ds = oCN.RunProcReturn("select * from Gy_BadResult where HNumber='" + HNumber + "'", "Gy_BadResult");
                    if (ds.Tables[0].Rows.Count == 0)
                    {
                        oCN.RunProc("Insert into Gy_BadResult"  +
                        " (HNumber,HName,HHelpCode,HShortNumber,HParentID" +
                        ",HLevel,HEndFlag,HStopflag,HRemark,HMakeTime,HUSEORGID,HUseFlag,HMakeEmp,HISsystemSet,HCREATEORGID,HERPItemID) " +
                        " Values('" + HNumber + "','" + HName + "','" + HHelpCode + "','" + sShortNumber + "'," + 0 +
                        "," + HLevel.ToString() + "," + HEndFlag + "," + 0 + ",'" + HRemark + "','" + DateTime.Now + "','" + HOrgID + "','" + "未检测" + "','" + user + "','" + 0 + "','" + HOrgID + "','" + 0 + "')", ref DBUtility.ClsPub.sExeReturnInfo);
                    }
                    else
                    {
                        oCN.RunProc("Update " + "Gy_BadResult " + " set " +
                        "HName='" + HName + "'" +
                        ",HHelpCode='" + HHelpCode + "'" +
                        ",HRemark= '" + HRemark + "'" +
                        ",HModifyEmp= '" + user + "'" +
                        ",HModifyTime=getdate()" +
                        ",HUSEORGID=" + HOrgID +
                        " where HNumber='" + HNumber + "'");
                    }
                    i++;
                }
                oCN.Commit();
                objJsonResult.code = CodeConstant.SUCCEED;
                objJsonResult.count = CountConstant.SUCCEED;
                objJsonResult.Message = "导入成功!";
                objJsonResult.data = null;
                return objJsonResult;
            }
            catch (Exception e)
            {
                LogService.Write(e);
                objJsonResult.code = CodeConstant.FAIL;
                objJsonResult.count = CountConstant.FAIL;
                objJsonResult.Message = "Exception!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
        #endregion
        #endregion
@@ -6084,19 +7159,17 @@
                bool bResult;
                if (oBill.oModel.HItemID == 0)
                {
                    // bResult = oBill.AddBill(ref DBUtility.ClsPub.sExeReturnInfo);
                    bResult = oBill.AddNew();
                    bResult = oBill.AddNew(ref DBUtility.ClsPub.sExeReturnInfo);
                }
                else
                {
                    bResult = oBill.ModifyByID(oBill.oModel.HItemID);
                    bResult = oBill.ModifyByID(oBill.oModel.HItemID, ref DBUtility.ClsPub.sExeReturnInfo);
                }
                if (bResult)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "保存成功!";
                    //WebAPIController.Add_Log("送货单下推", UserName, "生成送货单");
                    objJsonResult.data = 1;
                    return objJsonResult;
                }
@@ -6139,8 +7212,7 @@
        [HttpGet]
        public object DeltetGy_PostSkill(string HItemID, string user)
        {
            DataSet ds;
            //string ModRightNameCheck = "Sc_ProcessReport_check";
            DataSet ds;
            try
            {
                //删除权限
@@ -6173,8 +7245,58 @@
                    return objJsonResult; ;
                }
                //删除前控制=========================================
                string sql1 = "exec h_p_Gy_PostSkill_BeforeDelCtrl " + HItemID + ",'" + user + "'";
                ds = oCN.RunProcReturn(sql1, "h_p_Gy_PostSkill_BeforeDelCtrl");
                if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "删除失败!原因:删除前判断失败,请与网络管理人员联系";
                    objJsonResult.data = null;
                    oCN.RollBack();
                    return objJsonResult;
                }
                if (ds.Tables[0].Rows[0]["HBack"].ToString() != "0")
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "删除失败!原因:" + ds.Tables[0].Rows[0]["HRemark"].ToString(); ;
                    objJsonResult.data = null;
                    oCN.RollBack();
                    return objJsonResult;
                }
                //==================================================================================
                oCN.RunProc("delete Gy_PostSkill where HItemID=" + HItemID);
                //删除后控制=========================================
                string sql2 = "exec h_p_Gy_PostSkill_AfterDelCtrl " + HItemID + ",'" + user + "'";
                ds = oCN.RunProcReturn(sql2, "h_p_Gy_PostSkill_AfterDelCtrl");
                if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "删除失败!原因:删除后判断失败,请与网络管理人员联系";
                    objJsonResult.data = null;
                    oCN.RollBack();
                    return objJsonResult;
                }
                if (ds.Tables[0].Rows[0]["HBack"].ToString() != "0")
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "删除失败!原因:" + ds.Tables[0].Rows[0]["HRemark"].ToString(); ;
                    objJsonResult.data = null;
                    oCN.RollBack();
                    return objJsonResult;
                }
                //==================================================================================
                oCN.Commit();//提交事务
                objJsonResult.code = "0";
                objJsonResult.count = 1;
@@ -6668,19 +7790,17 @@
                bool bResult;
                if (oBill.oModel.HItemID == 0)
                {
                    // bResult = oBill.AddBill(ref DBUtility.ClsPub.sExeReturnInfo);
                    bResult = oBill.AddNew();
                    bResult = oBill.AddNew(ref DBUtility.ClsPub.sExeReturnInfo);
                }
                else
                {
                    bResult = oBill.ModifyByID(oBill.oModel.HItemID);
                    bResult = oBill.ModifyByID(oBill.oModel.HItemID, ref DBUtility.ClsPub.sExeReturnInfo);
                }
                if (bResult)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "保存成功!";
                    //WebAPIController.Add_Log("送货单下推", UserName, "生成送货单");
                    objJsonResult.data = 1;
                    return objJsonResult;
                }
@@ -6724,7 +7844,6 @@
        public object DeltetGy_Post(string HItemID, string user)
        {
            DataSet ds;
            //string ModRightNameCheck = "Sc_ProcessReport_check";
            try
            {
                //删除权限
@@ -6757,8 +7876,59 @@
                    return objJsonResult; ;
                }
                //删除前控制=========================================
                string sql1 = "exec h_p_Gy_Post_BeforeDelCtrl " + HItemID + ",'" + user + "'";
                ds = oCN.RunProcReturn(sql1, "h_p_Gy_Post_BeforeDelCtrl");
                if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "删除失败!原因:删除前判断失败,请与网络管理人员联系";
                    objJsonResult.data = null;
                    oCN.RollBack();
                    return objJsonResult;
                }
                if (ds.Tables[0].Rows[0]["HBack"].ToString() != "0")
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "删除失败!原因:" + ds.Tables[0].Rows[0]["HRemark"].ToString(); ;
                    objJsonResult.data = null;
                    oCN.RollBack();
                    return objJsonResult;
                }
                //==================================================================================
                oCN.RunProc("delete Gy_Post where HItemID=" + HItemID);
                //删除后控制=========================================
                string sql2 = "exec h_p_Gy_Post_AfterDelCtrl " + HItemID + ",'" + user + "'";
                ds = oCN.RunProcReturn(sql2, "h_p_Gy_Post_AfterDelCtrl");
                if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "删除失败!原因:删除后判断失败,请与网络管理人员联系";
                    objJsonResult.data = null;
                    oCN.RollBack();
                    return objJsonResult;
                }
                if (ds.Tables[0].Rows[0]["HBack"].ToString() != "0")
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "删除失败!原因:" + ds.Tables[0].Rows[0]["HRemark"].ToString(); ;
                    objJsonResult.data = null;
                    oCN.RollBack();
                    return objJsonResult;
                }
                //==================================================================================
                oCN.Commit();//提交事务
                objJsonResult.code = "0";
                objJsonResult.count = 1;
@@ -9009,6 +10179,278 @@
                return objJsonResult;
            }
        }
        #region 供应商分类 文件导入保存
        #region 供应商分类 文件上传
        [Route("Gy_SupType/Gy_SupType_Excel")]
        [HttpPost]
        public object Gy_SupType_Excel()
        {
            try
            {
                //获取文件名称
                var file = HttpContext.Current.Request.Files[0];
                //获取文件物理路径
                string ExcelPath = HttpContext.Current.Server.MapPath("~/" + file.FileName);
                //保存文件
                file.SaveAs(ExcelPath);
                NpoiHelper np = new NpoiHelper();
                DataSet ExcelDs = np.ReadExcel(ExcelPath, 1, 1, "0");
                //删除文件
                File.Delete(ExcelPath);
                //创建临时表
                DataTable tb2 = new DataTable("dt2");
                //添加列名
                for (int i = 0; i < ExcelDs.Tables[0].Columns.Count; i++)
                {
                    tb2.Columns.Add(ExcelDs.Tables[0].Rows[0][i].ToString());
                }
                //模板缺少列 但需要从数据库中查询出来显示在页面的字段
                tb2.Columns.Add("HOrgID", typeof(Int32));//组织ID
                //添加数据
                for (int i = 1; i < ExcelDs.Tables[0].Rows.Count; i++)
                {
                    DataRow row = tb2.NewRow();
                    for (int j = 0; j < ExcelDs.Tables[0].Columns.Count; j++)
                    {
                        row[j] = ExcelDs.Tables[0].Rows[i][j].ToString();
                    }
                    tb2.Rows.Add(row);
                }
                var error = "";
                //查询没有的列
                if (!tb2.Columns.Contains("组织代码"))
                    error += "没有找到【组织代码】的标题,";
                if (!tb2.Columns.Contains("组织名称"))
                    error += "没有找到【组织名称】的标题,";
                if (!tb2.Columns.Contains("供应商分类代码"))
                    error += "没有找到【供应商分类代码】的标题,";
                if (!tb2.Columns.Contains("供应商分类"))
                    error += "没有找到【供应商分类】的标题,";
                if (!tb2.Columns.Contains("备注"))
                    error += "没有找到【备注】的标题,";
                if (!tb2.Columns.Contains("助记码"))
                    error += "没有找到【助记码】的标题,";
                if (error.Length > 0)
                {
                    objJsonResult.code = CodeConstant.FAIL;
                    objJsonResult.count = CountConstant.FAIL;
                    objJsonResult.Message = $"Excel模板存在错误,{error}\r\n";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                for (int i = 0; i <= tb2.Rows.Count - 1; i++)
                {
                    string HName = "";
                    string HNum = "";
                    string HORGNumber = "";
                    string HORGName = "";
                    HName = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["供应商分类"].ToString());
                    HNum = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["供应商分类代码"].ToString());
                    HORGNumber = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["组织代码"].ToString());
                    HORGName = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["组织名称"].ToString());
                    //检查物料
                    int index = i + 1;
                    if (HORGNumber != "")
                    {
                        //查询组织
                        ds = oCN.RunProcReturn("select * from Xt_ORGANIZATIONS where  HNumber='" + HORGNumber + "' and Hname='" + HORGName + "'", "Xt_ORGANIZATIONS");
                        if (ds.Tables[0].Rows.Count == 0)
                        {
                            objJsonResult.code = CodeConstant.FAIL;
                            objJsonResult.count = CountConstant.FAIL;
                            objJsonResult.Message = "第" + index + "行,组织不存在!";
                            objJsonResult.data = null;
                            return objJsonResult;
                        }
                        else
                        {
                            tb2.Rows[i]["HOrgID"] = ds.Tables[0].Rows[0]["HItemID"].ToString();
                        }
                        //供应商分类名称
                        if (HName == "")
                        {
                            objJsonResult.code = CodeConstant.FAIL;
                            objJsonResult.count = CountConstant.FAIL;
                            objJsonResult.Message = "第" + index + "行,供应商分类名称不能为空!";
                            objJsonResult.data = null;
                            return objJsonResult;
                        }
                        //供应商分类代码
                        if (HNum == "")
                        {
                            objJsonResult.code = CodeConstant.FAIL;
                            objJsonResult.count = CountConstant.FAIL;
                            objJsonResult.Message = "第" + index + "行,供应商分类代码不能为空!";
                            objJsonResult.data = null;
                            return objJsonResult;
                        }
                    }
                    else
                    {
                        objJsonResult.code = CodeConstant.FAIL;
                        objJsonResult.count = CountConstant.FAIL;
                        objJsonResult.Message = "第" + index + "行,组织代码为空";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                }
                objJsonResult.code = CodeConstant.SUCCEED;
                objJsonResult.count = CountConstant.SUCCEED;
                objJsonResult.Message = error;
                objJsonResult.data = tb2;
                return objJsonResult;
            }
            catch (Exception e)
            {
                objJsonResult.code = CodeConstant.FAIL;
                objJsonResult.count = CountConstant.FAIL;
                objJsonResult.Message = "Exception!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
        #region 供应商分类项目 导入(保存)
        [Route("Gy_SupType/Gy_SupType_btnSave")]
        [HttpPost]
        public object Gy_SupType_btnSave([FromBody] JObject sMainSub)
        {
            var _value = sMainSub["sMainSub"].ToString();
            string msg1 = _value.ToString();
            string[] sArray = msg1.Split(new string[] { "&和" }, StringSplitOptions.RemoveEmptyEntries);
            string msg2 = sArray[0].ToString();
            string user = sArray[1].ToString();
            try
            {
                if (!DBUtility.ClsPub.Security_Log("Gy_SupType_Edit", 1, false, user))
                {
                    objJsonResult.code = CodeConstant.FAIL;
                    objJsonResult.count = CountConstant.FAIL;
                    objJsonResult.Message = "无保存权限!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                List<object> Excel = Newtonsoft.Json.JsonConvert.DeserializeObject<List<object>>(msg2);
                List<Dictionary<string, string>> list = new List<Dictionary<string, string>>();
                foreach (JObject item in Excel)
                {
                    Dictionary<string, string> dic = new Dictionary<string, string>();
                    foreach (var itm in item.Properties())
                    {
                        dic.Add(itm.Name, itm.Value.ToString());
                    }
                    list.Add(dic);
                }
                oCN.BeginTran();
                int i = 1;
                foreach (Dictionary<string, string> item in list)
                {
                    string HOrgID = item["HOrgID"].ToString();//组织ID
                    string HName = item["供应商分类"].ToString();
                    string HNumber = item["供应商分类代码"].ToString();
                    string HRemark = item["备注"].ToString();
                    string HHelpCode = item["助记码"].ToString();
                    string sShortNumber;
                    sShortNumber = DBUtility.ClsPub.GetShortNumber(HNumber);//短代码
                    if (sShortNumber.Trim() == "")
                    {
                        objJsonResult.code = CodeConstant.FAIL;
                        objJsonResult.count = CountConstant.FAIL;
                        objJsonResult.Message = "保存失败!短代码为空!";
                        objJsonResult.data = 1;
                        return objJsonResult;
                    }
                    int HEndFlag = 1;//末级标志
                    int HLevel = DBUtility.ClsPub.GetLevel(HNumber); //等级
                    if (!DBUtility.ClsPub.AllowNumber(HNumber.Trim()))
                    {
                        objJsonResult.code = CodeConstant.FAIL;
                        objJsonResult.count = CountConstant.FAIL;
                        objJsonResult.Message = "保存失败!代码中不能出现连续‘.’并且首位末位不能为‘.’!";
                        objJsonResult.data = 1;
                        return objJsonResult;
                    }
                    ds = oCN.RunProcReturn("select * from Gy_SupType where HNumber='" + HNumber + "'", "Gy_SupType");
                    if (ds.Tables[0].Rows.Count == 0)
                    {
                            oCN.RunProc("Insert into "  + "Gy_SupType " +
                        " (HNumber,HName,HHelpCode,HShortNumber,HParentID" +
                        ",HLevel,HEndFlag,HStopflag,HRemark,HMakeTime,HUSEORGID,HUseFlag,HMakeEmp,HCREATEORGID) " +
                        " Values('" + HNumber + "','" + HName + "','" + HHelpCode + "','" + sShortNumber + "'," + 0 +
                        "," + HLevel.ToString() + "," + HEndFlag + "," + 0 + ",'" + HRemark + "','" + DateTime.Now + "','" + HOrgID + "','" + "未检测" + "','" + user + "','" + HOrgID + "')", ref DBUtility.ClsPub.sExeReturnInfo);
                    }
                    else
                    {
                        oCN.RunProc("Update " + "Gy_SupType " + " set " +
                        "HName='" + HName + "'" +
                        ",HShortNumber='" + sShortNumber + "'" +
                        ",HHelpCode='" + HHelpCode + "'" +
                        ",HRemark= '" + HRemark + "'" +
                        ",HModifyEmp= '" + user + "'" +
                        ",HModifyTime=getdate()" +
                        ",HUSEORGID=" + HOrgID +
                        " where HNumber='" + HNumber + "'");
                    }
                    i++;
                }
                oCN.Commit();
                objJsonResult.code = CodeConstant.SUCCEED;
                objJsonResult.count = CountConstant.SUCCEED;
                objJsonResult.Message = "导入成功!";
                objJsonResult.data = null;
                return objJsonResult;
            }
            catch (Exception e)
            {
                LogService.Write(e);
                objJsonResult.code = CodeConstant.FAIL;
                objJsonResult.count = CountConstant.FAIL;
                objJsonResult.Message = "Exception!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
        #endregion
        #endregion
        #region  工艺参数分类  设置列表/保存/编辑/删除方法
@@ -9181,19 +10623,17 @@
                bool bResult;
                if (oBill.oModel.HItemID == 0)
                {
                    // bResult = oBill.AddBill(ref DBUtility.ClsPub.sExeReturnInfo);
                    bResult = oBill.AddNew();
                    bResult = oBill.AddNew(ref DBUtility.ClsPub.sExeReturnInfo);
                }
                else
                {
                    bResult = oBill.ModifyByID(oBill.oModel.HItemID);
                    bResult = oBill.ModifyByID(oBill.oModel.HItemID, ref DBUtility.ClsPub.sExeReturnInfo);
                }
                if (bResult)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "保存成功!";
                    //WebAPIController.Add_Log("送货单下推", UserName, "生成送货单");
                    objJsonResult.data = 1;
                    return objJsonResult;
                }
@@ -9225,7 +10665,6 @@
        public object DeltetGy_TechnologyType(string HItemID, string user)
        {
            DataSet ds;
            //string ModRightNameCheck = "Sc_ProcessReport_check";
            try
            {
                //删除权限
@@ -9258,8 +10697,59 @@
                    return objJsonResult; ;
                }
                //删除前控制=========================================
                string sql1 = "exec h_p_Gy_TechnologyParameterClass_BeforeDelCtrl " + HItemID + ",'" + user + "'";
                ds = oCN.RunProcReturn(sql1, "h_p_Gy_TechnologyParameterClass_BeforeDelCtrl");
                if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "删除失败!原因:删除前判断失败,请与网络管理人员联系";
                    objJsonResult.data = null;
                    oCN.RollBack();
                    return objJsonResult;
                }
                if (ds.Tables[0].Rows[0]["HBack"].ToString() != "0")
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "删除失败!原因:" + ds.Tables[0].Rows[0]["HRemark"].ToString(); ;
                    objJsonResult.data = null;
                    oCN.RollBack();
                    return objJsonResult;
                }
                //==================================================================================
                oCN.RunProc("delete Gy_TechnologyParameterClass where HItemID=" + HItemID);
                //删除后控制=========================================
                string sql2 = "exec h_p_Gy_TechnologyParameterClass_AfterDelCtrl " + HItemID + ",'" + user + "'";
                ds = oCN.RunProcReturn(sql2, "h_p_Gy_TechnologyParameterClass_AfterDelCtrl");
                if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "删除失败!原因:删除后判断失败,请与网络管理人员联系";
                    objJsonResult.data = null;
                    oCN.RollBack();
                    return objJsonResult;
                }
                if (ds.Tables[0].Rows[0]["HBack"].ToString() != "0")
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "删除失败!原因:" + ds.Tables[0].Rows[0]["HRemark"].ToString(); ;
                    objJsonResult.data = null;
                    oCN.RollBack();
                    return objJsonResult;
                }
                //==================================================================================
                oCN.Commit();//提交事务
                objJsonResult.code = "0";
                objJsonResult.count = 1;
@@ -9571,6 +11061,278 @@
                return objJsonResult;
            }
        }
        #region 客户分类 文件导入保存
        #region 客户分类 文件上传
        [Route("Gy_CusType/Gy_CusType_Excel")]
        [HttpPost]
        public object Gy_CusType_Excel()
        {
            try
            {
                //获取文件名称
                var file = HttpContext.Current.Request.Files[0];
                //获取文件物理路径
                string ExcelPath = HttpContext.Current.Server.MapPath("~/" + file.FileName);
                //保存文件
                file.SaveAs(ExcelPath);
                NpoiHelper np = new NpoiHelper();
                DataSet ExcelDs = np.ReadExcel(ExcelPath, 1, 1, "0");
                //删除文件
                File.Delete(ExcelPath);
                //创建临时表
                DataTable tb2 = new DataTable("dt2");
                //添加列名
                for (int i = 0; i < ExcelDs.Tables[0].Columns.Count; i++)
                {
                    tb2.Columns.Add(ExcelDs.Tables[0].Rows[0][i].ToString());
                }
                //模板缺少列 但需要从数据库中查询出来显示在页面的字段
                tb2.Columns.Add("HOrgID", typeof(Int32));//组织ID
                //添加数据
                for (int i = 1; i < ExcelDs.Tables[0].Rows.Count; i++)
                {
                    DataRow row = tb2.NewRow();
                    for (int j = 0; j < ExcelDs.Tables[0].Columns.Count; j++)
                    {
                        row[j] = ExcelDs.Tables[0].Rows[i][j].ToString();
                    }
                    tb2.Rows.Add(row);
                }
                var error = "";
                //查询没有的列
                if (!tb2.Columns.Contains("组织代码"))
                    error += "没有找到【组织代码】的标题,";
                if (!tb2.Columns.Contains("组织名称"))
                    error += "没有找到【组织名称】的标题,";
                if (!tb2.Columns.Contains("客户分类代码"))
                    error += "没有找到【客户分类代码】的标题,";
                if (!tb2.Columns.Contains("客户分类"))
                    error += "没有找到【客户分类】的标题,";
                if (!tb2.Columns.Contains("备注"))
                    error += "没有找到【备注】的标题,";
                if (!tb2.Columns.Contains("助记码"))
                    error += "没有找到【助记码】的标题,";
                if (error.Length > 0)
                {
                    objJsonResult.code = CodeConstant.FAIL;
                    objJsonResult.count = CountConstant.FAIL;
                    objJsonResult.Message = $"Excel模板存在错误,{error}\r\n";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                for (int i = 0; i <= tb2.Rows.Count - 1; i++)
                {
                    string HName = "";
                    string HNum = "";
                    string HORGNumber = "";
                    string HORGName = "";
                    HName = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["客户分类"].ToString());
                    HNum = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["客户分类代码"].ToString());
                    HORGNumber = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["组织代码"].ToString());
                    HORGName = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["组织名称"].ToString());
                    //检查物料
                    int index = i + 1;
                    if (HORGNumber != "")
                    {
                        //查询组织
                        ds = oCN.RunProcReturn("select * from Xt_ORGANIZATIONS where  HNumber='" + HORGNumber + "' and Hname='" + HORGName + "'", "Xt_ORGANIZATIONS");
                        if (ds.Tables[0].Rows.Count == 0)
                        {
                            objJsonResult.code = CodeConstant.FAIL;
                            objJsonResult.count = CountConstant.FAIL;
                            objJsonResult.Message = "第" + index + "行,组织不存在!";
                            objJsonResult.data = null;
                            return objJsonResult;
                        }
                        else
                        {
                            tb2.Rows[i]["HOrgID"] = ds.Tables[0].Rows[0]["HItemID"].ToString();
                        }
                        //客户分类名称
                        if (HName == "")
                        {
                            objJsonResult.code = CodeConstant.FAIL;
                            objJsonResult.count = CountConstant.FAIL;
                            objJsonResult.Message = "第" + index + "行,客户分类名称不能为空!";
                            objJsonResult.data = null;
                            return objJsonResult;
                        }
                        //客户分类代码
                        if (HNum == "")
                        {
                            objJsonResult.code = CodeConstant.FAIL;
                            objJsonResult.count = CountConstant.FAIL;
                            objJsonResult.Message = "第" + index + "行,客户分类代码不能为空!";
                            objJsonResult.data = null;
                            return objJsonResult;
                        }
                    }
                    else
                    {
                        objJsonResult.code = CodeConstant.FAIL;
                        objJsonResult.count = CountConstant.FAIL;
                        objJsonResult.Message = "第" + index + "行,组织代码为空";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                }
                objJsonResult.code = CodeConstant.SUCCEED;
                objJsonResult.count = CountConstant.SUCCEED;
                objJsonResult.Message = error;
                objJsonResult.data = tb2;
                return objJsonResult;
            }
            catch (Exception e)
            {
                objJsonResult.code = CodeConstant.FAIL;
                objJsonResult.count = CountConstant.FAIL;
                objJsonResult.Message = "Exception!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
        #region 客户分类项目 导入(保存)
        [Route("Gy_CusType/Gy_CusType_btnSave")]
        [HttpPost]
        public object Gy_CusType_btnSave([FromBody] JObject sMainSub)
        {
            var _value = sMainSub["sMainSub"].ToString();
            string msg1 = _value.ToString();
            string[] sArray = msg1.Split(new string[] { "&和" }, StringSplitOptions.RemoveEmptyEntries);
            string msg2 = sArray[0].ToString();
            string user = sArray[1].ToString();
            try
            {
                if (!DBUtility.ClsPub.Security_Log("Gy_CusType_Edit", 1, false, user))
                {
                    objJsonResult.code = CodeConstant.FAIL;
                    objJsonResult.count = CountConstant.FAIL;
                    objJsonResult.Message = "无保存权限!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                List<object> Excel = Newtonsoft.Json.JsonConvert.DeserializeObject<List<object>>(msg2);
                List<Dictionary<string, string>> list = new List<Dictionary<string, string>>();
                foreach (JObject item in Excel)
                {
                    Dictionary<string, string> dic = new Dictionary<string, string>();
                    foreach (var itm in item.Properties())
                    {
                        dic.Add(itm.Name, itm.Value.ToString());
                    }
                    list.Add(dic);
                }
                oCN.BeginTran();
                int i = 1;
                foreach (Dictionary<string, string> item in list)
                {
                    string HOrgID = item["HOrgID"].ToString();//组织ID
                    string HName = item["客户分类"].ToString();
                    string HNumber = item["客户分类代码"].ToString();
                    string HRemark = item["备注"].ToString();
                    string HHelpCode = item["助记码"].ToString();
                    string sShortNumber;
                    sShortNumber = DBUtility.ClsPub.GetShortNumber(HNumber);//短代码
                    if (sShortNumber.Trim() == "")
                    {
                        objJsonResult.code = CodeConstant.FAIL;
                        objJsonResult.count = CountConstant.FAIL;
                        objJsonResult.Message = "保存失败!短代码为空!";
                        objJsonResult.data = 1;
                        return objJsonResult;
                    }
                    int HEndFlag = 1;//末级标志
                    int HLevel = DBUtility.ClsPub.GetLevel(HNumber); //等级
                    if (!DBUtility.ClsPub.AllowNumber(HNumber.Trim()))
                    {
                        objJsonResult.code = CodeConstant.FAIL;
                        objJsonResult.count = CountConstant.FAIL;
                        objJsonResult.Message = "保存失败!代码中不能出现连续‘.’并且首位末位不能为‘.’!";
                        objJsonResult.data = 1;
                        return objJsonResult;
                    }
                    ds = oCN.RunProcReturn("select * from Gy_CusType where HNumber='" + HNumber + "'", "Gy_CusType");
                    if (ds.Tables[0].Rows.Count == 0)
                    {
                        oCN.RunProc("Insert into " + " Gy_CusType" +
                    " (HNumber,HName,HHelpCode,HShortNumber,HParentID" +
                    ",HLevel,HEndFlag,HStopflag,HRemark,HMakeTime,HUSEORGID,HUseFlag,HMakeEmp,HCREATEORGID) " +
                    " Values('" + HNumber + "','" + HName + "','" + HHelpCode + "','" + sShortNumber + "'," + 0 +
                    "," + HLevel.ToString() + "," + HEndFlag + "," + 0 + ",'" + HRemark + "','" + DateTime.Now + "','" + HOrgID + "','" + "未检测" + "','" + user + "','" + HOrgID + "')", ref DBUtility.ClsPub.sExeReturnInfo);
                    }
                    else
                    {
                        oCN.RunProc("Update " + "Gy_CusType " + " set " +
                        "HName='" + HName + "'" +
                        ",HShortNumber='" + sShortNumber + "'" +
                        ",HHelpCode='" + HHelpCode + "'" +
                        ",HRemark= '" + HRemark + "'" +
                        ",HModifyEmp= '" + user + "'" +
                        ",HModifyTime=getdate()" +
                        ",HUSEORGID=" + HOrgID +
                        " where HNumber='" + HNumber + "'");
                    }
                    i++;
                }
                oCN.Commit();
                objJsonResult.code = CodeConstant.SUCCEED;
                objJsonResult.count = CountConstant.SUCCEED;
                objJsonResult.Message = "导入成功!";
                objJsonResult.data = null;
                return objJsonResult;
            }
            catch (Exception e)
            {
                LogService.Write(e);
                objJsonResult.code = CodeConstant.FAIL;
                objJsonResult.count = CountConstant.FAIL;
                objJsonResult.Message = "Exception!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
        #endregion
        #endregion
        #region  盘点方案  设置列表/保存/编辑/删除方法
@@ -10883,11 +12645,11 @@
                if (oBill.oModel.HItemID == 0)
                {
                    // bResult = oBill.AddBill(ref DBUtility.ClsPub.sExeReturnInfo);
                    bResult = oBill.AddNew();
                    bResult = oBill.AddNew(ref DBUtility.ClsPub.sExeReturnInfo);
                }
                else
                {
                    bResult = oBill.ModifyByID(oBill.oModel.HItemID);
                    bResult = oBill.ModifyByID(oBill.oModel.HItemID,ref DBUtility.ClsPub.sExeReturnInfo);
                }
                if (bResult)
                {
@@ -10991,8 +12753,59 @@
                    return objJsonResult;
                }
                //删除前控制=========================================
                string sql1 = "exec h_p_Gy_BadPhenomena_BeforeDelCtrl " + HItemID + ",'" + user + "'";
                ds = oCN.RunProcReturn(sql1, "h_p_Gy_BadPhenomena_BeforeDelCtrl");
                if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "删除失败!原因:删除前判断失败,请与网络管理人员联系";
                    objJsonResult.data = null;
                    oCN.RollBack();
                    return objJsonResult;
                }
                if (ds.Tables[0].Rows[0]["HBack"].ToString() != "0")
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "删除失败!原因:" + ds.Tables[0].Rows[0]["HRemark"].ToString(); ;
                    objJsonResult.data = null;
                    oCN.RollBack();
                    return objJsonResult;
                }
                //==================================================================================
                oCN.RunProc("delete Gy_BadPhenomena where HItemID=" + HItemID);
                //删除后控制=========================================
                string sql2 = "exec h_p_Gy_BadPhenomena_AfterDelCtrl " + HItemID + ",'" + user + "'";
                ds = oCN.RunProcReturn(sql2, "h_p_Gy_BadPhenomena_AfterDelCtrl");
                if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "删除失败!原因:删除后判断失败,请与网络管理人员联系";
                    objJsonResult.data = null;
                    oCN.RollBack();
                    return objJsonResult;
                }
                if (ds.Tables[0].Rows[0]["HBack"].ToString() != "0")
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "删除失败!原因:" + ds.Tables[0].Rows[0]["HRemark"].ToString(); ;
                    objJsonResult.data = null;
                    oCN.RollBack();
                    return objJsonResult;
                }
                //==================================================================================
                oCN.Commit();//提交事务
                objJsonResult.code = "0";
                objJsonResult.count = 1;
@@ -11010,6 +12823,279 @@
                return objJsonResult;
            }
        }
        #region 不良现象 文件导入保存
        #region 不良现象 文件上传
        [Route("Gy_BadPhenomena/Gy_BadPhenomena_Excel")]
        [HttpPost]
        public object Gy_BadPhenomena_Excel()
        {
            try
            {
                //获取文件名称
                var file = HttpContext.Current.Request.Files[0];
                //获取文件物理路径
                string ExcelPath = HttpContext.Current.Server.MapPath("~/" + file.FileName);
                //保存文件
                file.SaveAs(ExcelPath);
                NpoiHelper np = new NpoiHelper();
                DataSet ExcelDs = np.ReadExcel(ExcelPath, 1, 1, "0");
                //删除文件
                File.Delete(ExcelPath);
                //创建临时表
                DataTable tb2 = new DataTable("dt2");
                //添加列名
                for (int i = 0; i < ExcelDs.Tables[0].Columns.Count; i++)
                {
                    tb2.Columns.Add(ExcelDs.Tables[0].Rows[0][i].ToString());
                }
                //模板缺少列 但需要从数据库中查询出来显示在页面的字段
                tb2.Columns.Add("HOrgID", typeof(Int32));//组织ID
                //添加数据
                for (int i = 1; i < ExcelDs.Tables[0].Rows.Count; i++)
                {
                    DataRow row = tb2.NewRow();
                    for (int j = 0; j < ExcelDs.Tables[0].Columns.Count; j++)
                    {
                        row[j] = ExcelDs.Tables[0].Rows[i][j].ToString();
                    }
                    tb2.Rows.Add(row);
                }
                var error = "";
                //查询没有的列
                if (!tb2.Columns.Contains("组织代码"))
                    error += "没有找到【组织代码】的标题,";
                if (!tb2.Columns.Contains("组织名称"))
                    error += "没有找到【组织名称】的标题,";
                if (!tb2.Columns.Contains("不良现象代码"))
                    error += "没有找到【不良现象代码】的标题,";
                if (!tb2.Columns.Contains("不良现象"))
                    error += "没有找到【不良现象】的标题,";
                if (!tb2.Columns.Contains("备注"))
                    error += "没有找到【备注】的标题,";
                if (!tb2.Columns.Contains("助记码"))
                    error += "没有找到【助记码】的标题,";
                if (error.Length > 0)
                {
                    objJsonResult.code = CodeConstant.FAIL;
                    objJsonResult.count = CountConstant.FAIL;
                    objJsonResult.Message = $"Excel模板存在错误,{error}\r\n";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                for (int i = 0; i <= tb2.Rows.Count - 1; i++)
                {
                    string HName = "";
                    string HNum = "";
                    string HORGNumber = "";
                    string HORGName = "";
                    HName = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["不良现象"].ToString());
                    HNum = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["不良现象代码"].ToString());
                    HORGNumber = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["组织代码"].ToString());
                    HORGName = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["组织名称"].ToString());
                    //检查物料
                    int index = i + 1;
                    if (HORGNumber != "")
                    {
                        //查询组织
                        ds = oCN.RunProcReturn("select * from Xt_ORGANIZATIONS where  HNumber='" + HORGNumber + "' and Hname='" + HORGName + "'", "Xt_ORGANIZATIONS");
                        if (ds.Tables[0].Rows.Count == 0)
                        {
                            objJsonResult.code = CodeConstant.FAIL;
                            objJsonResult.count = CountConstant.FAIL;
                            objJsonResult.Message = "第" + index + "行,组织不存在!";
                            objJsonResult.data = null;
                            return objJsonResult;
                        }
                        else
                        {
                            tb2.Rows[i]["HOrgID"] = ds.Tables[0].Rows[0]["HItemID"].ToString();
                        }
                        //不良现象名称
                        if (HName == "")
                        {
                            objJsonResult.code = CodeConstant.FAIL;
                            objJsonResult.count = CountConstant.FAIL;
                            objJsonResult.Message = "第" + index + "行,不良现象名称不能为空!";
                            objJsonResult.data = null;
                            return objJsonResult;
                        }
                        //不良现象代码
                        if (HNum == "")
                        {
                            objJsonResult.code = CodeConstant.FAIL;
                            objJsonResult.count = CountConstant.FAIL;
                            objJsonResult.Message = "第" + index + "行,不良现象代码不能为空!";
                            objJsonResult.data = null;
                            return objJsonResult;
                        }
                    }
                    else
                    {
                        objJsonResult.code = CodeConstant.FAIL;
                        objJsonResult.count = CountConstant.FAIL;
                        objJsonResult.Message = "第" + index + "行,组织代码为空";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                }
                objJsonResult.code = CodeConstant.SUCCEED;
                objJsonResult.count = CountConstant.SUCCEED;
                objJsonResult.Message = error;
                objJsonResult.data = tb2;
                return objJsonResult;
            }
            catch (Exception e)
            {
                objJsonResult.code = CodeConstant.FAIL;
                objJsonResult.count = CountConstant.FAIL;
                objJsonResult.Message = "Exception!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
        #region 不良现象项目 导入(保存)
        [Route("Gy_BadPhenomena/Gy_BadPhenomena_btnSave")]
        [HttpPost]
        public object Gy_BadPhenomena_btnSave([FromBody] JObject sMainSub)
        {
            var _value = sMainSub["sMainSub"].ToString();
            string msg1 = _value.ToString();
            string[] sArray = msg1.Split(new string[] { "&和" }, StringSplitOptions.RemoveEmptyEntries);
            string msg2 = sArray[0].ToString();
            string user = sArray[1].ToString();
            try
            {
                if (!DBUtility.ClsPub.Security_Log("Gy_BadPhenomena_Edit", 1, false, user))
                {
                    objJsonResult.code = CodeConstant.FAIL;
                    objJsonResult.count = CountConstant.FAIL;
                    objJsonResult.Message = "无保存权限!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                List<object> Excel = Newtonsoft.Json.JsonConvert.DeserializeObject<List<object>>(msg2);
                List<Dictionary<string, string>> list = new List<Dictionary<string, string>>();
                foreach (JObject item in Excel)
                {
                    Dictionary<string, string> dic = new Dictionary<string, string>();
                    foreach (var itm in item.Properties())
                    {
                        dic.Add(itm.Name, itm.Value.ToString());
                    }
                    list.Add(dic);
                }
                oCN.BeginTran();
                int i = 1;
                foreach (Dictionary<string, string> item in list)
                {
                    string HOrgID = item["HOrgID"].ToString();//组织ID
                    string HName = item["不良现象"].ToString();
                    string HNumber = item["不良现象代码"].ToString();
                    string HRemark = item["备注"].ToString();
                    string HHelpCode = item["助记码"].ToString();
                    string sShortNumber;
                    sShortNumber = DBUtility.ClsPub.GetShortNumber(HNumber);//短代码
                    if (sShortNumber.Trim() == "")
                    {
                        objJsonResult.code = CodeConstant.FAIL;
                        objJsonResult.count = CountConstant.FAIL;
                        objJsonResult.Message = "保存失败!短代码为空!";
                        objJsonResult.data = 1;
                        return objJsonResult;
                    }
                    int HEndFlag = 1;//末级标志
                    int HLevel = DBUtility.ClsPub.GetLevel(HNumber); //等级
                    if (!DBUtility.ClsPub.AllowNumber(HNumber.Trim()))
                    {
                        objJsonResult.code = CodeConstant.FAIL;
                        objJsonResult.count = CountConstant.FAIL;
                        objJsonResult.Message = "保存失败!代码中不能出现连续‘.’并且首位末位不能为‘.’!";
                        objJsonResult.data = 1;
                        return objJsonResult;
                    }
                    ds = oCN.RunProcReturn("select * from Gy_BadPhenomena where HNumber='" + HNumber + "'", "Gy_BadPhenomena");
                    if (ds.Tables[0].Rows.Count == 0)
                    {
                        oCN.RunProc("Insert into " + "Gy_BadPhenomena " +
                        " (HNumber,HName,HHelpCode,HShortNumber,HParentID" +
                        ",HLevel,HEndFlag,HStopflag,HRemark,HMakeTime,HUSEORGID,HUseFlag,HMakeEmp,HCREATEORGID) " +
                        " Values('" + HNumber + "','" + HName + "','" + HHelpCode + "','" + sShortNumber + "'," + 0 +
                        "," + HLevel.ToString() + "," + HEndFlag + "," + 0 + ",'" + HRemark + "','" + DateTime.Now + "','" + HOrgID + "','" + "未检测" + "','" + user + "','" + HOrgID + "')", ref DBUtility.ClsPub.sExeReturnInfo);
                    }
                    else
                    {
                        oCN.RunProc("Update " + "Gy_BadPhenomena " + " set " +
                        "HName='" + HName + "'" +
                        ",HShortNumber='" + sShortNumber + "'" +
                        ",HHelpCode='" + HHelpCode + "'" +
                        ",HRemark= '" + HRemark + "'" +
                        ",HModifyEmp= '" + user + "'" +
                        ",HModifyTime=getdate()" +
                        ",HUSEORGID=" + HOrgID +
                        " where HNumber='" + HNumber + "'");
                    }
                    i++;
                }
                oCN.Commit();
                objJsonResult.code = CodeConstant.SUCCEED;
                objJsonResult.count = CountConstant.SUCCEED;
                objJsonResult.Message = "导入成功!";
                objJsonResult.data = null;
                return objJsonResult;
            }
            catch (Exception e)
            {
                LogService.Write(e);
                objJsonResult.code = CodeConstant.FAIL;
                objJsonResult.count = CountConstant.FAIL;
                objJsonResult.Message = "Exception!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
        #endregion
        #endregion
        #region  项目类别  设置列表/保存/编辑/删除方法
@@ -12054,11 +14140,11 @@
                if (oBill.oModel.HItemID == 0)
                {
                    // bResult = oBill.AddBill(ref DBUtility.ClsPub.sExeReturnInfo);
                    bResult = oBill.AddNew();
                    bResult = oBill.AddNew(ref DBUtility.ClsPub.sExeReturnInfo);
                }
                else
                {
                    bResult = oBill.ModifyByID(oBill.oModel.HItemID);
                    bResult = oBill.ModifyByID(oBill.oModel.HItemID, ref DBUtility.ClsPub.sExeReturnInfo);
                }
                if (bResult)
                {
@@ -12133,8 +14219,56 @@
                }
                oCN.BeginTran();//开始事务
                //删除前控制=========================================
                string sql1 = "exec h_p_Gy_PreventErrMould_BeforeDelCtrl " + HItemID + ",'" + user + "'";
                ds = oCN.RunProcReturn(sql1, "h_p_Gy_PreventErrMould_BeforeDelCtrl");
                if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "删除失败!原因:删除前判断失败,请与网络管理人员联系";
                    objJsonResult.data = null;
                    oCN.RollBack();
                    return objJsonResult;
                }
                if (ds.Tables[0].Rows[0]["HBack"].ToString() != "0")
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "删除失败!原因:" + ds.Tables[0].Rows[0]["HRemark"].ToString(); ;
                    objJsonResult.data = null;
                    oCN.RollBack();
                    return objJsonResult;
                }
                //==================================================================================
                oCN.RunProc("delete Gy_PreventErrMould where HItemID=" + HItemID);
                //删除后控制=========================================
                string sql2 = "exec h_p_Gy_PreventErrMould_AfterDelCtrl " + HItemID + ",'" + user + "'";
                ds = oCN.RunProcReturn(sql2, "h_p_Gy_PreventErrMould_AfterDelCtrl");
                if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "删除失败!原因:删除后判断失败,请与网络管理人员联系";
                    objJsonResult.data = null;
                    oCN.RollBack();
                    return objJsonResult;
                }
                if (ds.Tables[0].Rows[0]["HBack"].ToString() != "0")
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "删除失败!原因:" + ds.Tables[0].Rows[0]["HRemark"].ToString(); ;
                    objJsonResult.data = null;
                    oCN.RollBack();
                    return objJsonResult;
                }
                //==================================================================================
                oCN.Commit();//提交事务
                objJsonResult.code = "0";
                objJsonResult.count = 1;
@@ -12187,7 +14321,6 @@
            DataSet Maxds = oCN.RunProcReturn("select isNull(MAX(HItemID),0) HItemID from Gy_MaintainLev ", "Gy_MaintainLev");
            if (Maxds != null || Maxds.Tables[0].Rows.Count > 0)
            {
                //HItemID= Maxds.Tables[0].Rows[0]["HItemID"]
                var maxid = Convert.ToInt32(Maxds.Tables[0].Rows[0]["HItemID"]);
                maxid += 1;
                HItemID = maxid;
@@ -12326,18 +14459,17 @@
                if (oBill.oModel.HItemID == 0)
                {
                    // bResult = oBill.AddBill(ref DBUtility.ClsPub.sExeReturnInfo);
                    bResult = oBill.AddNew();
                    bResult = oBill.AddNew(ref DBUtility.ClsPub.sExeReturnInfo);
                }
                else
                {
                    bResult = oBill.ModifyByID(oBill.oModel.HItemID);
                    bResult = oBill.ModifyByID(oBill.oModel.HItemID, ref DBUtility.ClsPub.sExeReturnInfo);
                }
                if (bResult)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "保存成功!";
                    //WebAPIController.Add_Log("送货单下推", UserName, "生成送货单");
                    objJsonResult.data = 1;
                    return objJsonResult;
                }
@@ -12379,9 +14511,7 @@
        [Route("DeltetGy_MaintainLev")]
        [HttpGet]
        public object DeltetGy_MaintainLev(string HItemID, string user)
        {
            DataSet ds;
            //string ModRightNameCheck = "Sc_ProcessReport_check";
        {
            try
            {
                //删除权限
@@ -12405,8 +14535,59 @@
                }
                oCN.BeginTran();//开始事务
                //删除前控制=========================================
                string sql1 = "exec h_p_Gy_MaintainLev_BeforeDelCtrl " + HItemID + ",'" + user + "'";
                ds = oCN.RunProcReturn(sql1, "h_p_Gy_MaintainLev_BeforeDelCtrl");
                if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "删除失败!原因:删除前判断失败,请与网络管理人员联系";
                    objJsonResult.data = null;
                    oCN.RollBack();
                    return objJsonResult;
                }
                if (ds.Tables[0].Rows[0]["HBack"].ToString() != "0")
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "删除失败!原因:" + ds.Tables[0].Rows[0]["HRemark"].ToString(); ;
                    objJsonResult.data = null;
                    oCN.RollBack();
                    return objJsonResult;
                }
                //==================================================================================
                oCN.RunProc("delete Gy_MaintainLev where HItemID=" + HItemID);
                //删除后控制=========================================
                string sql2 = "exec h_p_Gy_MaintainLev_AfterDelCtrl " + HItemID + ",'" + user + "'";
                ds = oCN.RunProcReturn(sql2, "h_p_Gy_MaintainLev_AfterDelCtrl");
                if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "删除失败!原因:删除后判断失败,请与网络管理人员联系";
                    objJsonResult.data = null;
                    oCN.RollBack();
                    return objJsonResult;
                }
                if (ds.Tables[0].Rows[0]["HBack"].ToString() != "0")
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "删除失败!原因:" + ds.Tables[0].Rows[0]["HRemark"].ToString(); ;
                    objJsonResult.data = null;
                    oCN.RollBack();
                    return objJsonResult;
                }
                //==================================================================================
                oCN.Commit();//提交事务
                objJsonResult.code = "0";
                objJsonResult.count = 1;
@@ -12596,11 +14777,11 @@
                bool bResult;
                if (oBill.oModel.HItemID == 0)
                {
                    bResult = oBill.AddNew();
                    bResult = oBill.AddNew(ref DBUtility.ClsPub.sExeReturnInfo);
                }
                else
                {
                    bResult = oBill.ModifyByID(oBill.oModel.HItemID);
                    bResult = oBill.ModifyByID(oBill.oModel.HItemID, ref DBUtility.ClsPub.sExeReturnInfo);
                }
                if (bResult)
                {
@@ -12673,8 +14854,58 @@
                }
                oCN.BeginTran();//开始事务
                //删除前控制=========================================
                string sql1 = "exec h_p_Gy_CheckNoteItem_BeforeDelCtrl " + HItemID + ",'" + user + "'";
                ds = oCN.RunProcReturn(sql1, "h_p_Gy_CheckNoteItem_BeforeDelCtrl");
                if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "删除失败!原因:删除前判断失败,请与网络管理人员联系";
                    objJsonResult.data = null;
                    oCN.RollBack();
                    return objJsonResult;
                }
                if (ds.Tables[0].Rows[0]["HBack"].ToString() != "0")
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "删除失败!原因:" + ds.Tables[0].Rows[0]["HRemark"].ToString(); ;
                    objJsonResult.data = null;
                    oCN.RollBack();
                    return objJsonResult;
                }
                //==================================================================================
                oCN.RunProc("delete Gy_CheckNoteItem where HItemID=" + HItemID);
                //删除后控制=========================================
                string sql2 = "exec h_p_Gy_CheckNoteItem_AfterDelCtrl " + HItemID + ",'" + user + "'";
                ds = oCN.RunProcReturn(sql2, "h_p_Gy_CheckNoteItem_AfterDelCtrl");
                if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "删除失败!原因:删除后判断失败,请与网络管理人员联系";
                    objJsonResult.data = null;
                    oCN.RollBack();
                    return objJsonResult;
                }
                if (ds.Tables[0].Rows[0]["HBack"].ToString() != "0")
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "删除失败!原因:" + ds.Tables[0].Rows[0]["HRemark"].ToString(); ;
                    objJsonResult.data = null;
                    oCN.RollBack();
                    return objJsonResult;
                }
                //==================================================================================
                oCN.Commit();//提交事务
                objJsonResult.code = "0";
                objJsonResult.count = 1;
@@ -13330,9 +15561,9 @@
        #endregion
        #region  环境检测单  设置列表/保存/编辑/删除方法
        #region  环境检测项目  设置列表/保存/编辑/删除方法
        /// <summary>
        /// 保存环境检测单
        /// 保存环境检测项目
        /// </summary>
        /// <param name="msg"></param>
        /// <returns></returns>
@@ -13363,7 +15594,6 @@
            DataSet Maxds = oCN.RunProcReturn("select MAX(HItemID) HItemID from Gy_EnvironmentTestItem ", "Gy_EnvironmentTestItem");
            if (Maxds != null || Maxds.Tables[0].Rows.Count > 0)
            {
                //HItemID= Maxds.Tables[0].Rows[0]["HItemID"]
                var maxid = Convert.ToInt32(Maxds.Tables[0].Rows[0]["HItemID"]);
                maxid += 1;
                HItemID = maxid;
@@ -13499,12 +15729,12 @@
                //保存完毕后处理
                bool bResult;
                if (oBill.oModel.HItemID == 0)
                {
                    bResult = oBill.AddNew();
                {
                    bResult = oBill.AddNew(ref DBUtility.ClsPub.sExeReturnInfo);
                }
                else
                {
                    bResult = oBill.ModifyByID(oBill.oModel.HItemID);
                    bResult = oBill.ModifyByID(oBill.oModel.HItemID, ref DBUtility.ClsPub.sExeReturnInfo);
                }
                if (bResult)
                {
@@ -13584,9 +15814,59 @@
                    objJsonResult.Message = "没有数据,无法删除!";
                    objJsonResult.data = null;
                    return objJsonResult; ;
                }
                }
                //删除前控制=========================================
                string sql1 = "exec h_p_Gy_EnvironmentTestItem_BeforeDelCtrl " + HItemID + ",'" + user + "'";
                ds = oCN.RunProcReturn(sql1, "h_p_Gy_EnvironmentTestItem_BeforeDelCtrl");
                if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "删除失败!原因:删除前判断失败,请与网络管理人员联系";
                    objJsonResult.data = null;
                    oCN.RollBack();
                    return objJsonResult;
                }
                if (ds.Tables[0].Rows[0]["HBack"].ToString() != "0")
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "删除失败!原因:" + ds.Tables[0].Rows[0]["HRemark"].ToString(); ;
                    objJsonResult.data = null;
                    oCN.RollBack();
                    return objJsonResult;
                }
                //==================================================================================
                oCN.RunProc("delete Gy_EnvironmentTestItem where HItemID=" + HItemID);
                //删除后控制=========================================
                string sql2 = "exec h_p_Gy_EnvironmentTestItem_AfterDelCtrl " + HItemID + ",'" + user + "'";
                ds = oCN.RunProcReturn(sql2, "h_p_Gy_EnvironmentTestItem_AfterDelCtrl");
                if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "删除失败!原因:删除后判断失败,请与网络管理人员联系";
                    objJsonResult.data = null;
                    oCN.RollBack();
                    return objJsonResult;
                }
                if (ds.Tables[0].Rows[0]["HBack"].ToString() != "0")
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "删除失败!原因:" + ds.Tables[0].Rows[0]["HRemark"].ToString(); ;
                    objJsonResult.data = null;
                    oCN.RollBack();
                    return objJsonResult;
                }
                //==================================================================================
                oCN.Commit();//提交事务
                objJsonResult.code = "0";
                objJsonResult.count = 1;
@@ -15129,12 +17409,16 @@
        /// <returns></returns>
        [Route("Web/GetCheckItemID")]
        [HttpGet]
        public object GetCheckItemID(string HName,string HProName)
        public object GetCheckItemID(string HName,string HProName,string HSourceID)
        {         
            try
            {
                SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
                ds = oCN.RunProcReturn("select  top 1 * from h_v_Gy_QCCheckProjectList_Main where 物料名称='"+HName+ "' and 工序名称='" + HProName + "'   order by 日期 desc ", "h_v_Gy_QCCheckProjectList_Main");
                ds = oCN.RunProcReturn("select  top 1 * from h_v_Gy_QCCheckProjectList_Main where 物料名称='"+HName+ "' and 工序名称='" + HProName + "' and HSourceID='" + HSourceID + "'   order by 日期 desc ", "h_v_Gy_QCCheckProjectList_Main");
                if (ds == null || ds.Tables[0].Rows.Count <= 0)
                {
                    ds = oCN.RunProcReturn("select  top 1 * from h_v_Gy_QCCheckProjectList_Main where 物料名称='" + HName + "' and 工序名称='" + HProName + "'  order by 日期 desc ", "h_v_Gy_QCCheckProjectList_Main");
                }
                if (ds == null || ds.Tables[0].Rows.Count <= 0)
                {
                    objjson.code = "0";
@@ -16292,7 +18576,7 @@
                    if ((ds.Tables[0] == null || ds.Tables[0].Rows.Count == 0))
                    {
                        sql = "Select * from Gy_Menu_1 where HType = '" + HType + "' Order by HPosition,len(HitemID),HitemID  ";
                        ds = oCn.RunProcReturn(sql, "Gy_Menu");
                        ds = oCn.RunProcReturn(sql, "Gy_Menu_1");
                    }                 
                }
@@ -17215,6 +19499,67 @@
            }
        }
        /// <summary>
        /// 金帅WMS接口
        /// </summary>
        /// <returns></returns>
        [Route("Web/WMSBarcodeQuery")]
        [HttpGet]
        public object WMSBarcodeQuery(DateTime dateTime, string UserName, string PassWord)
        {
            try
            {
                SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
                //权限判定
                DAL.ClsUser oUser = new DAL.ClsUser();
                DataSet DS;
                DS = oCN.RunProcReturn("select * from Gy_Czygl where Czymc='" + UserName.Trim() + "' and Czmm='" + DBUtility.ClsPub.StrToPsd(PassWord.Trim()) + "' ", "Gy_Czygl");
                if (UserName == "" || UserName != "售后条码查询")
                {
                    objjson.code = "0";
                    objjson.count = 0;
                    objjson.Message = "用户不对!";
                    objjson.data = null;
                    return objjson;
                }
                if (DS == null || DS.Tables[0].Rows.Count == 0)
                {
                    objjson.code = "0";
                    objjson.count = 0;
                    objjson.Message = "密码错误!";
                    objjson.data = null;
                    return objjson;
                }
                ds = oCN.RunProcReturn("exec h_p_WMSBarcodeQuery '" + dateTime + "'", "h_p_WMSBarcodeQuery");
                if (ds == null || ds.Tables[0].Rows.Count <= 0)
                {
                    objjson.code = "0";
                    objjson.count = 0;
                    objjson.Message = "获取失败" + DBUtility.ClsPub.sErrInfo;
                    objjson.data = null;
                    return objjson;
                }
                else
                {
                    objjson.code = "1";
                    objjson.count = 1;
                    objjson.Message = "获取成功!";
                    objjson.data = ds.Tables[0];
                    return objjson;
                }
            }
            catch (Exception ex)
            {
                objjson.code = "0";
                objjson.count = 0;
                objjson.Message = "获取失败" + ex.ToString();
                objjson.data = null;
                return objjson;
            }
        }
    }
}