zrg
2025-02-25 a1c3a3d1b0b0b8c28a19e99177e4cee5a64949b7
WebAPI/Controllers/JHGL/Gy_MaterialTechParamBillController.cs
@@ -10,7 +10,9 @@
using System.Web.Http;
using System.Windows.Forms;
using WebAPI.Models;
using WebAPI.Controllers.SCGL.日计划管理;
using System.IO;
using SyntacticSugar.constant;
namespace WebAPI.Controllers.MJGL
{
    public class Gy_MaterialTechParamBillController : ApiController
@@ -358,12 +360,13 @@
        #region 产品工艺参数清单列表 审核/反审核功能
        [Route("Gy_MaterialTechParamBill/CheckGy_MaterialTechParamBillMain")]
        [HttpGet]
        public object CheckGy_MaterialTechParamBillMain(string HInterID, int IsAudit, string user)
        public object CheckGy_MaterialTechParamBillMain(int HInterID, int IsAudit, string CurUserName)
        {
            DBUtility.ClsPub.CurUserName = CurUserName;
            try
            {
                //审核权限
                if (!DBUtility.ClsPub.Security_Log_second("Gy_MaterialTechParamBillMain_Check", 1, false, user))
                if (!DBUtility.ClsPub.Security_Log_second("Gy_MaterialTechParamBillMain_Check", 1, false, CurUserName))
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
@@ -372,12 +375,43 @@
                    return objJsonResult;
                }
                var ds = oCN.RunProcReturn("select * from Gy_MaterialTechParamBillMain  where HInterID=" + HInterID, "Gy_MaterialTechParamBillMain ");
                if (ds.Tables[0].Rows.Count > 0)
                //HInterID数据判断
                if (HInterID <= 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "HInterID小于0!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                Int64 lngBillKey = 0;
                lngBillKey = DBUtility.ClsPub.isLong(HInterID);                                         //对HInterID进行类型的转换
                DAL.ClsGy_MaterialTechParamBillMain oBill = new DAL.ClsGy_MaterialTechParamBillMain();                              //实例化单据操作类,用于进行相关操作
                //针对需要进行的操作,检验当前单据的状态是否支持需要进行的操作
                if (oBill.ShowBill(lngBillKey, ref DBUtility.ClsPub.sExeReturnInfo))                    //根据HInterID获取该单据的数据
                {
                    if (oBill.omodel.HCloseMan.Trim() != "")
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "单据已关闭!不能再次审核!";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                    if (oBill.omodel.HDeleteMan.Trim() != "")
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "单据已作废!不能再次审核!";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                    if (IsAudit == 0)  //审核判断
                    {
                        if (ds.Tables[0].Rows[0]["HChecker"].ToString() != "")
                        if (oBill.omodel.HChecker.Trim() != "")
                        {
                            objJsonResult.code = "0";
                            objJsonResult.count = 0;
@@ -388,7 +422,7 @@
                    }
                    if (IsAudit == 1) //反审核判断
                    {
                        if (ds.Tables[0].Rows[0]["HChecker"].ToString() == "")
                        if (oBill.omodel.HChecker.Trim() == "")
                        {
                            objJsonResult.code = "0";
                            objJsonResult.count = 0;
@@ -402,38 +436,117 @@
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "单据不存在!";
                    objJsonResult.Message = "单据不存在!原因:" + DBUtility.ClsPub.sExeReturnInfo;
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                oCN.BeginTran();
                if (IsAudit == 0)  //审核判断
                //进行需要进行的审核/反审核操作
                if (IsAudit == 0) //审核提交
                {
                    oCN.RunProc("update Gy_MaterialTechParamBillMain  set HChecker='" + user + "',HCheckDate=getdate() where HInterID=" + HInterID);
                    oCN.BeginTran();
                    objJsonResult.code = "1";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "审核成功";
                    objJsonResult.data = null;
                    //记录返回信息
                    string msg = "";
                    //审核前控制=========================================
                    string sql1 = "exec h_p_Gy_MaterialTechParamBill_BeforeCheckCtrl " + oBill.omodel.HInterID + ",'" + oBill.omodel.HBillNo + "','" + CurUserName + "'";
                    ds = oCN.RunProcReturn(sql1, "h_p_Gy_MaterialTechParamBill_BeforeCheckCtrl");
                    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;
                    }
                    //==================================================================================
                    //审核提交
                    if (oBill.CheckBill(oBill.omodel.HInterID, oBill.omodel.HBillNo, "h_p_Gy_MaterialTechParamBill_AfterCheckCtrl", CurUserName, ref DBUtility.ClsPub.sExeReturnInfo) == true)
                    {
                        oCN.Commit();
                        objJsonResult.code = "1";
                        objJsonResult.count = 1;
                        objJsonResult.Message = "审核成功!" + msg;
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                    else
                    {
                        oCN.RollBack();
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "审核失败!原因:" + DBUtility.ClsPub.sExeReturnInfo;
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                }
                if (IsAudit == 1) //反审核判断
                if (IsAudit == 1) //反审核提交
                {
                    oCN.RunProc("update Gy_MaterialTechParamBillMain  set HChecker='',HCheckDate=null where HInterID=" + HInterID);
                    objJsonResult.code = "1";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "反审核成功";
                    objJsonResult.data = null;
                    //反审核前控制=========================================
                    string sql1 = "exec h_p_Gy_MaterialTechParamBill_BeforeUnCheckCtrl " + oBill.omodel.HInterID + ",'" + oBill.omodel.HBillNo + "','" + CurUserName + "'";
                    ds = oCN.RunProcReturn(sql1, "h_p_Gy_MaterialTechParamBill_BeforeUnCheckCtrl");
                    if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 1;
                        objJsonResult.Message = "反审核失败!原因:反审核前判断失败,请与网络管理人员联系";
                        objJsonResult.data = null;
                        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;
                        return objJsonResult;
                    }
                    //===========================================================
                    //反审核提交AbandonCheck
                    if (oBill.AbandonCheck(oBill.omodel.HInterID, oBill.omodel.HBillNo, "h_p_Gy_MaterialTechParamBill_AfterUnCheckCtrl", CurUserName, ref DBUtility.ClsPub.sExeReturnInfo) == true)
                    {
                        objJsonResult.code = "1";
                        objJsonResult.count = 1;
                        objJsonResult.Message = "反审核成功";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                    else
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "反审核失败!原因:" + DBUtility.ClsPub.sExeReturnInfo;
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                }
                oCN.Commit();
                return objJsonResult;
            }
            catch (Exception e)
            {
                oCN.RollBack();
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "审核失败或者反审核失败!" + e.ToString();
@@ -532,5 +645,484 @@
            }
        }
        #endregion
        #region 产品工艺参数 文件导入保存
        #region 产品工艺参数 文件上传
        [Route("Gy_MaterialTechParamBill/Gy_MaterialTechParamBill_Excel")]
        [HttpPost]
        public object Gy_MaterialTechParamBill_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("HEmpID", typeof(Int32));//负责人ID
                tb2.Columns.Add("HMaterID", typeof(Int32));//物料ID
                tb2.Columns.Add("HTechParamID", typeof(Int32));//工艺参数ID
                tb2.Columns.Add("HTechParamUnitID", 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 (!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 HORGNumber = "";
                    string HORGName = "";
                    string HDeptName = "";
                    string HDeptNumber = "";
                    string HEmpName = "";
                    string HEmpNumber = "";
                    string HMaterNumber = "";
                    string HMaterName = "";
                    string HTechParamNumber = "";
                    string HTechParamName = "";
                    string HTechParamUnitNumber = "";
                    string HTechParamUnitName = "";
                    string HBillNo = "";
                    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());
                    HEmpNumber = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["负责人代码"].ToString());
                    HEmpName = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["负责人名称"].ToString());
                    HMaterNumber = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["物料代码"].ToString());
                    HMaterName = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["物料名称"].ToString());
                    HTechParamNumber = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["工艺参数代码"].ToString());
                    HTechParamName = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["工艺参数名称"].ToString());
                    HTechParamUnitNumber = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["工艺参数单位代码"].ToString());
                    HTechParamUnitName = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["工艺参数单位名称"].ToString());
                    HBillNo = 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();
                        }
                    }
                    else
                    {
                        objJsonResult.code = CodeConstant.FAIL;
                        objJsonResult.count = CountConstant.FAIL;
                        objJsonResult.Message = "第" + index + "行,组织代码为空";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                    //部门代码
                    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 (HEmpNumber != "")
                    {
                        ds = oCN.RunProcReturn("select * from Gy_Employee where  HNumber='" + HEmpNumber + "' and Hname='" + HEmpName + "'", "Gy_Employee");
                        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]["HEmpID"] = ds.Tables[0].Rows[0]["HItemID"].ToString();
                        }
                    }
                    //物料代码
                    if (HMaterNumber != "")
                    {
                        ds = oCN.RunProcReturn("select * from Gy_Material where  HNumber='" + HMaterNumber + "' and Hname='" + HMaterName + "'", "Gy_Material");
                        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]["HMaterID"] = ds.Tables[0].Rows[0]["HItemID"].ToString();
                        }
                    }
                    //工艺参数代码
                    if (HTechParamNumber != "")
                    {
                        ds = oCN.RunProcReturn("select * from Gy_TechnologyParameter where  HNumber='" + HTechParamNumber + "' and Hname='" + HTechParamName + "'", "Gy_TechnologyParameter");
                        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]["HTechParamID"] = ds.Tables[0].Rows[0]["HItemID"].ToString();
                        }
                    }
                    //工艺参数单位代码
                    if (HTechParamUnitNumber != "")
                    {
                        ds = oCN.RunProcReturn("select * from Gy_TechnologyParameterUnit where  HNumber='" + HTechParamUnitNumber + "' and Hname='" + HTechParamUnitName + "'", "Gy_TechnologyParameterUnit");
                        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]["HTechParamUnitID"] = ds.Tables[0].Rows[0]["HItemID"].ToString();
                        }
                    }
                    //单据号
                    if (HBillNo == "")
                    {
                        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_MaterialTechParamBill/Gy_MaterialTechParamBill_btnSave")]
        [HttpPost]
        public object Gy_MaterialTechParamBill_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_MaterialTechParamBillMain_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 HBillType = "3334";
                    string HMaker = user;//制单人
                    DateTime HDate = DBUtility.ClsPub.isDate(DateTime.Now.ToString("yyyy-MM-dd"));//  --日期
                    long HYear = DBUtility.ClsPub.isLong(DateTime.Now.Year);
                    long HPeriod = DBUtility.ClsPub.isLong(DateTime.Now.Month);
                    string HBillNo = item["单据号"].ToString();//单据号
                    string HOrgID = item["HOrgID"].ToString();//组织ID
                    string HDeptID = item["HDeptID"].ToString() == "" ? "0" : item["HDeptID"].ToString();
                    string HEmpID = item["HEmpID"].ToString() == "" ? "0" : item["HEmpID"].ToString();
                    string HMaterID = item["HMaterID"].ToString()== "" ? "0" : item["HMaterID"].ToString();
                    string HRemark = item["备注"].ToString();
                    //子表
                    string HTechParamID = item["HTechParamID"].ToString() == "" ? "0" : item["HTechParamID"].ToString();//工艺参数
                    string HTechParamUnitID = item["HTechParamUnitID"].ToString() == "" ? "0" : item["HTechParamUnitID"].ToString();//工艺参数代码
                    string HStd = item["标准值"].ToString() == "" ? "0" : item["标准值"].ToString();
                    string HMax = item["上限"].ToString() == "" ? "0" : item["上限"].ToString();
                    string HMin = item["下限"].ToString() == "" ? "0" : item["下限"].ToString();
                    string HDataForm = item["采集来源"].ToString();
                    string HDataTimes = item["采集周期频率"].ToString() == "" ? "0" : item["采集周期频率"].ToString();
                    string HDataUnit = item["采集周期单位"].ToString();
                    ds = oCN.RunProcReturn("select * from Gy_MaterialTechParamBillMain where HBillNo='" + HBillNo + "'", "Gy_MaterialTechParamBillMain");
                    if (ds.Tables[0].Rows.Count == 0)
                    {
                        long HInterID = DBUtility.ClsPub.CreateBillID(HBillType, ref DBUtility.ClsPub.sExeReturnInfo);
                        //插入主表
                        oCN.RunProc("insert into Gy_MaterialTechParamBillMain" +
                            "(HYear,HPeriod,HBillType,HBillSubType,HInterID,HDate,HBillNo,HRemark,HMaker,HMakeDate" +
                            ",HDeptID,HEmpID,HMaterID,HWorkCenterID,HEquipID,HOrgID,HProcID,HMouldID ) " +
                            "values(" +
                            "" + HYear.ToString() +
                            "," + HPeriod.ToString() +
                            ",'" + HBillType +
                            "','" + HBillType +
                            "'," + HInterID +
                            ",'" + HDate +
                            "','" + HBillNo +
                            "','" + HRemark +
                            "','" + HMaker +
                            "'," + "getdate()" +
                            "," + HDeptID +
                            "," + HEmpID +
                            ",'" + HMaterID +
                            "','" + 0 +
                            "','" + 0 +
                            "','" + HOrgID +
                            "','" + 0 +
                             "','" + 0 +
                            "')");
                        //插入子表
                        oCN.RunProc("insert into Gy_MaterialTechParamBillSub" +
                           "(HInterID,HEntryID,HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType" +
                           ",HTechParamID,HTechParamUnitID,HStd,HMax,HMin,HDataForm,HDataUnit,HDataTimes,HTechParamClassID,HSNO,HStdNextTimes,HTechParamIDStd) " +
                           " values(" +
                           "" + HInterID.ToString() +
                           "," + 1 +
                           "," + 0 +
                           "," + 0 +
                           ",'" + "" +
                           "','" + "" +
                           "','" + HTechParamID +
                           "','" + HTechParamUnitID +
                           "','" + HStd +
                           "','" + HMax +
                           "','" + HMin +
                           "','" + HDataForm +
                           "','" + HDataUnit +
                           "','" + HDataTimes +
                           "','" + 0 +
                           "','" + 0 +
                           "','" + 0 +
                           "','" + "" +
                           "')");
                    }
                    else
                    {
                        long HInterID = long.Parse(ds.Tables[0].Rows[0]["HInterID"].ToString());
                        //获取最大子id
                        DataSet ds2 = oCN.RunProcReturn("select max(HEntryID) HEntryID from Gy_MaterialTechParamBillSub where HInterID='" + HInterID + "'", "Gy_MaterialTechParamBillSub");
                        long HEntryID = 1;
                        if (ds2.Tables[0].Rows.Count > 0)
                        {
                            HEntryID = long.Parse(ds2.Tables[0].Rows[0]["HEntryID"].ToString()) + 1;
                        }
                        //插入子表
                        oCN.RunProc("insert into Gy_MaterialTechParamBillSub" +
                           "(HInterID,HEntryID,HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType" +
                           ",HTechParamID,HTechParamUnitID,HStd,HMax,HMin,HDataForm,HDataUnit,HDataTimes,HTechParamClassID,HSNO,HStdNextTimes,HTechParamIDStd) " +
                           " values(" +
                           "" + HInterID.ToString() +
                           "," + HEntryID +
                           "," + 0 +
                           "," + 0 +
                           ",'" + "" +
                           "','" + "" +
                           "','" + HTechParamID +
                           "','" + HTechParamUnitID +
                           "','" + HStd +
                           "','" + HMax +
                           "','" + HMin +
                           "','" + HDataForm +
                           "','" + HDataUnit +
                           "','" + HDataTimes +
                           "','" + 0 +
                           "','" + 0 +
                           "','" + 0 +
                           "','" + "" +
                           "')");
                    }
                    i++;
                }
                oCN.Commit();
                objJsonResult.code = CodeConstant.SUCCEED;
                objJsonResult.count = CountConstant.SUCCEED;
                objJsonResult.Message = "导入成功!";
                objJsonResult.data = null;
                return objJsonResult;
            }
            catch (Exception e)
            {
                LogService.Write(e);
                oCN.RollBack();
                objJsonResult.code = CodeConstant.FAIL;
                objJsonResult.count = CountConstant.FAIL;
                objJsonResult.Message = "Exception!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
        #endregion
    }
}