zrg
2024-05-13 ef10f06e96034f6ab3db93ea103f2a4d78fcb2b9
WebAPI/Controllers/»ù´¡×ÊÁÏ/¹¤×Ê»ù´¡×ÊÁÏ/Gy_ProcPriceController.cs
@@ -1,11 +1,15 @@
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Pub_Class;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Web;
using System.Web.Http;
using WebAPI.Controllers.SCGL.日计划管理;
using WebAPI.Models;
namespace WebAPI.Controllers
{
@@ -25,6 +29,7 @@
        {
            try
            {
                List<object> columnNameList = new List<object>();
                //查看权限
                if (!DBUtility.ClsPub.Security_Log("Gy_ProcPriceList", 1, false, user))
                {
@@ -35,23 +40,33 @@
                    return objJsonResult;
                }
                ds = oCN.RunProcReturn("select * from h_v_Gy_ProcPriceList where 1 = 1 " + sWhere, "h_v_Gy_ProcPriceList");
                if (ds == null || ds.Tables[0].Rows.Count == 0)
                ds = oCN.RunProcReturn("select * from h_v_Gy_ProcPriceList where 1 = 1 " + sWhere + " order by åˆ¶å•日期 desc", "h_v_Gy_ProcPriceList");
                //添加列名
                foreach (DataColumn col in ds.Tables[0].Columns)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "false!";
                    objJsonResult.data = null;
                    return objJsonResult;
                    Type dataType = col.DataType;
                    string ColmString = "{\"ColmCols\":\"" + col.ColumnName + "\",\"ColmType\":\"" + dataType.Name + "\"}";
                    columnNameList.Add(JsonConvert.DeserializeObject(ColmString));//获取到DataColumn列对象的列名
                }
                else
                {
                    objJsonResult.code = "1";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "Sucess!";
                    objJsonResult.data = ds.Tables[0];
                    return objJsonResult;
                }
                //if (ds.Tables[0].Rows.Count != 0 || ds != null)
                //{
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "Sucess!";
                objJsonResult.data = ds.Tables[0];
                objJsonResult.list = columnNameList;
                return objJsonResult;
                //}
                //else
                //{
                //objJsonResult.code = "0";
                //objJsonResult.count = 0;
                //objJsonResult.Message = "无数据";
                //objJsonResult.data = null;
                //return objJsonResult;
                //}
            }
            catch (Exception e)
            {
@@ -108,7 +123,7 @@
                        oSub.HMaterID = DBUtility.ClsPub.isLong(subList[i].HMaterIDCol);
                        oSub.HProcID = DBUtility.ClsPub.isLong(subList[i].HProcIDCol);
                        oSub.HSourceID = DBUtility.ClsPub.isLong(subList[i].HSourceIDCol);
                        oSub.HPrice = DBUtility.ClsPub.isLong(subList[i].HPriceCol);
                        oSub.HPrice = DBUtility.ClsPub.isDoule(subList[i].HPriceCol);
                        oSub.HBeginDate = DBUtility.ClsPub.isDate(subList[i].HBeginDateCol);
                        oSub.HEndDate = DBUtility.ClsPub.isDate(subList[i].HEndDateCol);
                        oSub.HCostFlag = DBUtility.ClsPub.GridToBool(subList[i].HCostFlagCol);
@@ -119,6 +134,17 @@
                        oSub.HMaker = DBUtility.ClsPub.isStrNull(mainList[0].HMaker);
                        oSub.HMakeDate = DateTime.Today.ToString();
                        oSub.HRemark = DBUtility.ClsPub.isStrNull(subList[i].HRemarkCol);
                        oSub.HWorkCenterID = DBUtility.ClsPub.isLong(subList[i].HWorkCenterID);
                        oSub.HWorkQty = DBUtility.ClsPub.isSingle(subList[i].HWorkQty); //小时产能
                        oSub.HStdEmp = DBUtility.ClsPub.isSingle(subList[i].HStdEmp); //标准人力
                        oSub.HChangeTimes = DBUtility.ClsPub.isSingle(subList[i].HChangeTimes); //换线时间
                        oSub.HChangeMoney = DBUtility.ClsPub.isSingle(subList[i].HChangeMoney); //换线补贴
                        oSub.HProcNo = DBUtility.ClsPub.isLong(subList[i].HProcNo); //工艺路线流水号
                        oSub.HPieceTimes = DBUtility.ClsPub.isSingle(subList[i].HPieceTimes); //单件加工时间(字段可能已经存在了)
                        oSub.HMouldQty = DBUtility.ClsPub.isSingle(subList[i].HMouldQty); //模具数量
                        oSub.HChangeMouldMoney = DBUtility.ClsPub.isSingle(subList[i].HChangeMouldMoney); //换模补贴
                        oSub.HRushQty = DBUtility.ClsPub.isSingle(subList[i].HRushQty); //单件冲次次数
                        BillNew.DetailColl.Add(oSub);
                    }
                    else
@@ -176,36 +202,24 @@
        {
            try
            {
                ds = oCN.RunProcReturn("select " +
                    "a.HItemID,ltrim(a.HMaterID)+'-'+ltrim(a.HProcID) å·¥åºå·¥ä»·èµ„料代码,a.HDeptID,b.HName HDeptName" +
                    ",a.HMaterID HMaterIDCol,c.HNumber HMaterNumberCol,c.HName HMaterNameCol,c.HModel HMaterModelCol" +
                    ",a.HProcID HProcIDCol,d.HNumber HProcNumberCol,d.HName HProcNameCol" +
                    ",a.HSourceID HSourceIDCol,e.HNumber HSourceNumberCol,e.HName HSourceNameCol" +
                    ",a.HPrice HPriceCol,a.HBeginDate HBeginDateCol,a.HEndDate HEndDateCol" +
                    ",case when a.HCostFlag<>0 then 'true'else 'false'end HCostFlagCol" +
                    ",case when a.HFlowFlag<>0 then 'true'else 'false'end HFlowFlagCol" +
                    ",case when a.HPayFlag<>0 then 'true'else 'false'end HPayFlagCol,a.HRemark HRemarkCol " +
                    " from Gy_ProcPrice a " +
                    " left join Gy_Department b on a.HDeptID = b.HItemID " +
                    " left join Gy_Material c on a.HMaterID = c.HItemID " +
                    " left join Gy_Process d on a.HProcID = d.HItemID " +
                    " left join Gy_Source e on a.HSourceID = e.HItemID where a.HItemID = " + HItemID, "Gy_ProcPrice");
                if (ds == null || ds.Tables[0].Rows.Count == 0)
                List<object> columnNameList = new List<object>();
                ds = oCN.RunProcReturn("select * from h_v_Gy_ProcPriceList where HItemID = " + HItemID, "h_v_Gy_ProcPriceList");
                //添加列名
                foreach (DataColumn col in ds.Tables[0].Columns)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "false!";
                    objJsonResult.data = null;
                    return objJsonResult;
                    Type dataType = col.DataType;
                    string ColmString = "{\"ColmCols\":\"" + col.ColumnName + "\",\"ColmType\":\"" + dataType.Name + "\"}";
                    columnNameList.Add(JsonConvert.DeserializeObject(ColmString));//获取到DataColumn列对象的列名
                }
                else
                {
                    objJsonResult.code = "1";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "Sucess!";
                    objJsonResult.data = ds.Tables[0];
                    return objJsonResult;
                }
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "Sucess!";
                objJsonResult.data = ds.Tables[0];
                objJsonResult.list = columnNameList;
                return objJsonResult;
            }
            catch (Exception e)
            {
@@ -217,5 +231,650 @@
            }
        }
        #endregion
        #region å·¥åºå·¥ä»· åˆ é™¤
        [Route("Gy_ProcPrice/DelProcPrice")]
        [HttpGet]
        public object DelProcPrice(int HInterID, string User)
        {
            try
            {
                //删除权限
                if (!DBUtility.ClsPub.Security_Log_second("Gy_ProcPriceList_Delete", 1, false, User))
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "无权限删除!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                DAL.ClsGy_ProcPrice_Ctl BillNew = new DAL.ClsGy_ProcPrice_Ctl();
                var sReturn = "";
                if (BillNew.ShowBill(HInterID, ref sReturn))
                {
                    foreach (Model.ClsGy_ProcPrice_Model oSub in BillNew.DetailColl)
                    {
                        if (oSub.HChecker.Trim() != "")
                        {
                            objJsonResult.code = "0";
                            objJsonResult.count = 0;
                            objJsonResult.Message = "当前单据不能删除!";
                            objJsonResult.data = null;
                            return objJsonResult;
                        }
                    }
                    bool flag = false;
                    oCN.BeginTran();//开启事务
                    flag= BillNew.DeleteByID(HInterID);
                    oCN.Commit();//结束事务
                    if (flag)
                    {
                        objJsonResult.code = "1";
                        objJsonResult.count = 1;
                        objJsonResult.Message = "删除成功!";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                    else
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "删除失败!";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                }
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "当前单据不存在,无法删除!";
                objJsonResult.data = null;
                return objJsonResult;
            }
            catch (Exception e)
            {
                oCN.RollBack();//回滚事务
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
        #region [工序工价审核、反审核]
        /// <summary>
        ///
        /// </summary>
        /// <param name="HInterID">单据ID</param>
        /// <param name="IsAudit">审核(0),反审核(1)</param>
        /// <param name="CurUserName">审核人</param>
        /// <returns></returns>
        [Route("Gy_ProcPrice/AuditGy_ProcPrice")]
        [HttpGet]
        public object AuditGy_ProcPrice(int HInterID, int IsAudit, string CurUserName)
        {
            try
            {
                //审核权限
                if (!DBUtility.ClsPub.Security_Log_second("Gy_ProcPriceList_Check", 1, false, CurUserName))
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "审核失败!无权限!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                DBUtility.ClsPub.CurUserName = CurUserName;
                DAL.ClsGy_ProcPrice_Ctl BillNew = new DAL.ClsGy_ProcPrice_Ctl();
                var sReturn = "";
                if (BillNew.ShowBill(HInterID, ref sReturn))
                {
                    foreach (Model.ClsGy_ProcPrice_Model oSub in BillNew.DetailColl)
                    {
                        if (IsAudit == 0)  //审核判断
                        {
                            if (oSub.HChecker.Trim() != "")
                            {
                                objJsonResult.code = "0";
                                objJsonResult.count = 0;
                                objJsonResult.Message = "单据已审核!不能再次审核!";
                                objJsonResult.data = null;
                                return objJsonResult;
                            }
                        }
                        if (IsAudit == 1) //反审核判断
                        {
                            if (oSub.HChecker.Trim() == "")
                            {
                                objJsonResult.code = "0";
                                objJsonResult.count = 0;
                                objJsonResult.Message = "单据未审核!不需要反审核!";
                                objJsonResult.data = null;
                                return objJsonResult;
                            }
                        }
                    }
                }
                else
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "单据不存在!原因:" + DBUtility.ClsPub.sExeReturnInfo;
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                foreach (Model.ClsGy_ProcPrice_Model oSub in BillNew.DetailColl)
                {
                    if (IsAudit == 0)  //审核判断
                    {
                        //审核提交
                        if (BillNew.CheckBill(HInterID, ref DBUtility.ClsPub.sExeReturnInfo) == true)
                        {
                            objJsonResult.code = "1";
                            objJsonResult.count = 1;
                            objJsonResult.Message = "审核成功";
                            objJsonResult.data = null;
                            return objJsonResult;
                        }
                        else
                        {
                            objJsonResult.code = "1";
                            objJsonResult.count = 1;
                            objJsonResult.Message = "审核失败!原因:" + DBUtility.ClsPub.sExeReturnInfo;
                            objJsonResult.data = null;
                            return objJsonResult;
                        }
                    }
                    if (IsAudit == 1) //反审核判断
                    {
                        //反审核提交AbandonCheck
                        if (BillNew.AbandonCheck(HInterID, ref DBUtility.ClsPub.sExeReturnInfo) == true)
                        {
                            objJsonResult.code = "1";
                            objJsonResult.count = 1;
                            objJsonResult.Message = "反审核成功";
                            objJsonResult.data = null;
                            return objJsonResult;
                        }
                        else
                        {
                            objJsonResult.code = "1";
                            objJsonResult.count = 1;
                            objJsonResult.Message = "反审核失败!原因:" + DBUtility.ClsPub.sExeReturnInfo;
                            objJsonResult.data = null;
                            return objJsonResult;
                        }
                    }
                }
                return objJsonResult;
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "审核失败或者反审核失败!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
        #region ç»´æŠ¤å·¥ä»·æ—¶è¿”回工艺路线信息
        [Route("Gy_RoutingBill/EditPrice")]
        [HttpGet]
        public object EditPrice(string HMaterNumber)
        {
            try
            {
                List<object> columnNameList = new List<object>();
                ds = oCN.RunProcReturn("exec Gy_RoutingBill_EditPrice '" + HMaterNumber + "'", "Gy_RoutingBill_EditPrice");
                //添加列名
                foreach (DataColumn col in ds.Tables[0].Columns)
                {
                    Type dataType = col.DataType;
                    string ColmString = "{\"ColmCols\":\"" + col.ColumnName + "\",\"ColmType\":\"" + dataType.Name + "\"}";
                    columnNameList.Add(JsonConvert.DeserializeObject(ColmString));//获取到DataColumn列对象的列名
                }
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "Sucess!";
                objJsonResult.data = ds.Tables[0];
                objJsonResult.list = columnNameList;
                return objJsonResult;
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "Exception!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
        #region å·¥åºå·¥ä»· æ–‡ä»¶ä¸Šä¼ 
        [Route("Gy_ProcPrice/Gy_ProcPrice_Excel")]
        [HttpPost]
        public object Gy_ProcPrice_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("HMaterID", typeof(Int32));//物料ID
                tb2.Columns.Add("HProcID", typeof(Int32));//工序ID
                tb2.Columns.Add("HSourceID", typeof(Int32));//生产资源ID
                tb2.Columns.Add("HWorkCenterID", 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();
                    }
                    //如果表格第i行的第一列为空,则判断为这一行的数据为空,跳出循环并且不把数据写入 tb2
                    if (ExcelDs.Tables[0].Rows[i][0].ToString() == "")
                    {
                        continue;
                    }
                    else
                    {
                        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 (!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 = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = $"Excel模板存在错误,{error}\r\n";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                for (int i = 0; i <= tb2.Rows.Count - 1; i++)
                {
                    string HMaterNumber = "";
                    string HMaterName = "";
                    string HMaterModel = "";
                    string HProcNumber = "";
                    string HProcName = "";
                    string HSourceNumber = "";
                    string HSourceName = "";
                    decimal HPrice = 0;
                    string HWorkCenterNumber = "";
                    string HWorkCenterName = "";
                    decimal HWorkQty = 0;
                    decimal HStdEmp = 0;
                    decimal HChangeTimes = 0;
                    decimal HChangeMoney = 0;
                    Int64 HProcNo = 0;
                    decimal HPieceTimes = 0;
                    decimal HMouldQty = 0;
                    decimal HChangeMouldMoney = 0;
                    decimal HRushQty = 0;
                    string HBeginDate = System.DateTime.Now.ToString("G");
                    string HEndDate = System.DateTime.Now.ToString("G");
                    Int64 HCostFlag = 0;
                    Int64 HFlowFlag = 0;
                    Int64 HPayFlag = 0;
                    string HRemark = "";
                    HMaterNumber = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["物料代码"].ToString());
                    HMaterName = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["物料名称"].ToString());
                    HMaterModel = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["规格型号"].ToString());
                    HProcNumber = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["工序代码"].ToString());
                    HProcName = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["工序名称"].ToString());
                    HSourceNumber = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["生产资源代码"].ToString());
                    HSourceName = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["生产资源名称"].ToString());
                    HPrice = DBUtility.ClsPub.isLong(tb2.Rows[i]["单价"].ToString());
                    HWorkCenterNumber = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["工作中心代码"].ToString());
                    HWorkCenterName = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["工作中心名称"].ToString());
                    HWorkQty = DBUtility.ClsPub.isLong(tb2.Rows[i]["小时产能"].ToString());
                    HStdEmp = DBUtility.ClsPub.isLong(tb2.Rows[i]["标准人力"].ToString());
                    HChangeTimes = DBUtility.ClsPub.isLong(tb2.Rows[i]["换线时间"].ToString());
                    HChangeMoney = DBUtility.ClsPub.isLong(tb2.Rows[i]["换线补贴"].ToString());
                    HProcNo = DBUtility.ClsPub.isLong(tb2.Rows[i]["工艺路线流水号"].ToString());
                    HPieceTimes = DBUtility.ClsPub.isLong(tb2.Rows[i]["单件加工时间"].ToString());
                    HMouldQty = DBUtility.ClsPub.isLong(tb2.Rows[i]["模具数量"].ToString());
                    HChangeMouldMoney = DBUtility.ClsPub.isLong(tb2.Rows[i]["换模补贴"].ToString());
                    HRushQty = DBUtility.ClsPub.isLong(tb2.Rows[i]["单件冲次次数"].ToString());
                    HBeginDate = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["开始日期"].ToString());
                    HEndDate = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["结束日期"].ToString());
                    HCostFlag = DBUtility.ClsPub.isLong(tb2.Rows[i]["成本必选"].ToString());
                    HFlowFlag = DBUtility.ClsPub.isLong(tb2.Rows[i]["流转默认"].ToString());
                    HPayFlag = DBUtility.ClsPub.isLong(tb2.Rows[i]["工资默认"].ToString());
                    HRemark = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["备注"].ToString());
                    //检查表格数据
                    int index = i + 1;
                    if (HMaterNumber != "" && HMaterName != "")
                    {
                        //查询物料
                        ds = oCN.RunProcReturn("select * from Gy_Material where  HNumber='" + HMaterNumber + "' and HName='" + HMaterName + "' and HModel ='" + HMaterModel + "'", "Gy_Material");
                        if (ds.Tables[0].Rows.Count == 0)
                        {
                            objJsonResult.code = "0";
                            objJsonResult.count = 0;
                            objJsonResult.Message = "第" + index + "行,物料不存在!";
                            objJsonResult.data = null;
                            return objJsonResult;
                        }
                        else
                        {
                            tb2.Rows[i]["HMaterID"] = ds.Tables[0].Rows[0]["HItemID"].ToString();
                        }
                        //查询工序
                        ds = oCN.RunProcReturn("select * from Gy_Process where  HNumber='" + HProcNumber + "'", "Gy_Process");
                        if (ds.Tables[0].Rows.Count == 0)
                        {
                            objJsonResult.code = "0";
                            objJsonResult.count = 0;
                            objJsonResult.Message = "第" + index + "行,工序不存在!";
                            objJsonResult.data = null;
                            return objJsonResult;
                        }
                        else
                        {
                            tb2.Rows[i]["HProcID"] = ds.Tables[0].Rows[0]["HItemID"].ToString();
                        }
                        //查询生产资源
                        ds = oCN.RunProcReturn("select * from Gy_Source where  HNumber='" + HSourceNumber + "'" , "Gy_Source");
                        if (ds.Tables[0].Rows.Count == 0)
                        {
                            objJsonResult.code = "0";
                            objJsonResult.count = 0;
                            objJsonResult.Message = "第" + index + "行,生产资源不存在!";
                            objJsonResult.data = null;
                            return objJsonResult;
                        }
                        else
                        {
                            tb2.Rows[i]["HSourceID"] = ds.Tables[0].Rows[0]["HItemID"].ToString();
                        }
                        //查询工作中心
                        ds = oCN.RunProcReturn("select * from Gy_WorkCenter where  HNumber='" + HWorkCenterNumber + "'", "Gy_WorkCenter"); //
                        if (ds.Tables[0].Rows.Count == 0)
                        {
                            objJsonResult.code = "0";
                            objJsonResult.count = 0;
                            objJsonResult.Message = "第" + index + "行,工作中心不存在!";
                            objJsonResult.data = null;
                            return objJsonResult;
                        }
                        else
                        {
                            tb2.Rows[i]["HWorkCenterID"] = ds.Tables[0].Rows[0]["HItemID"].ToString();
                        }
                        //工序代码
                        if (HProcNumber == "")
                        {
                            objJsonResult.code = "0";
                            objJsonResult.count = 0;
                            objJsonResult.Message = "第" + index + "行,工序代码不能为空!";
                            objJsonResult.data = null;
                            return objJsonResult;
                        }
                        //生产资源名称
                        if (HSourceName == "")
                        {
                            objJsonResult.code = "0";
                            objJsonResult.count = 0;
                            objJsonResult.Message = "第" + index + "行,生产资源名称不能为空!";
                            objJsonResult.data = null;
                            return objJsonResult;
                        }
                        //工作中心代码
                        if (HWorkCenterNumber == "")
                        {
                            objJsonResult.code = "0";
                            objJsonResult.count = 0;
                            objJsonResult.Message = "第" + index + "行,工作中心代码不能为空!";
                            objJsonResult.data = null;
                            return objJsonResult;
                        }
                    }
                    else
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "第" + index + "行,物料信息不全(物料代码,物料名称)";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                }
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = error;
                objJsonResult.data = tb2;
                return objJsonResult;
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "Exception!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
        #region å·¥åºå·¥ä»· å¯¼å…¥(保存)
        [Route("Gy_ProcPrice/Gy_ProcPrice_btnSave")]
        [HttpPost]
        public object Gy_ProcPrice_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_ProcPriceList_Edit", 1, false, user))
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    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 HProcID = item["HProcID"].ToString();//工序
                    string HMaterID = item["HMaterID"].ToString();//物料
                    string HSourceID = item["HSourceID"].ToString();//生产资源
                    string HWorkCenterID = item["HWorkCenterID"].ToString();//工作中心
                    string HPrice = item["单价"].ToString();
                    string HWorkQty = item["小时产能"].ToString();
                    string HStdEmp = item["标准人力"].ToString();
                    string HChangeTimes = item["换线时间"].ToString();
                    string HChangeMoney = item["换线补贴"].ToString();
                    string HProcNo = item["工艺路线流水号"].ToString();
                    string HPieceTimes = item["单件加工时间"].ToString();
                    string HMouldQty = item["模具数量"].ToString();
                    string HChangeMouldMoney = item["换模补贴"].ToString();
                    string HRushQty = item["单件冲次次数"].ToString();
                    string HCostFlag = item["成本必选"].ToString();
                    string HFlowFlag = item["流转默认"].ToString();
                    string HPayFlag = item["工资默认"].ToString();
                    string HRemark = item["备注"].ToString();
                    string HBeginDate = item["开始日期"].ToString();
                    string HEndDate = item["结束日期"].ToString();
                    string sql = "insert into Gy_ProcPrice(HMaterID,HProcID,HSourceID,HBeginDate,HEndDate,HCostFlag,HFlowFlag,HPayFlag,HDeptID,HWorkCenterID,HWorkQty,HStdEmp,HChangeTimes,HChangeMoney,HProcNo,HPieceTimes,HMouldQty,HChangeMouldMoney,HRushQty,HPrice,HStopflag,HRemark,HMaker,HMakeDate)" +
                            $"values({HMaterID}, {HProcID},{HSourceID}, '{HBeginDate}', '{HEndDate}', '{(HCostFlag == "是" ? 1 : 0)}', {(HFlowFlag == "是" ? 1 : 0)},'{(HPayFlag == "是" ? 1 : 0)}',{0},{HWorkCenterID},{HWorkQty},{HStdEmp},{HChangeTimes},{HChangeMoney},{HProcNo},{HPieceTimes},{HMouldQty},{HChangeMouldMoney},{HRushQty},{HPrice},{0},'{HRemark}','{user}','{System.DateTime.Now.ToString("G")}')";
                    oCN.RunProc(sql);
                    i++;
                }
                oCN.Commit();
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "导入成功!";
                objJsonResult.data = null;
                return objJsonResult;
            }
            catch (Exception e)
            {
                LogService.Write(e);
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "Exception!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
    }
}