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 { //班组Controller public class Gy_ProcPriceController : ApiController { public DBUtility.ClsPub.Enum_BillStatus BillStatus; private json objJsonResult = new json(); SQLHelper.ClsCN oCN = new SQLHelper.ClsCN(); DataSet ds; #region 返回工序工价列表 [Route("Gy_ProcPrice/list")] [HttpGet] public object list(string sWhere,string user) { try { List columnNameList = new List(); //查看权限 if (!DBUtility.ClsPub.Security_Log("Gy_ProcPriceList", 1, false, user)) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "无查看权限!"; objJsonResult.data = null; return objJsonResult; } 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) { Type dataType = col.DataType; string ColmString = "{\"ColmCols\":\"" + col.ColumnName + "\",\"ColmType\":\"" + dataType.Name + "\"}"; columnNameList.Add(JsonConvert.DeserializeObject(ColmString));//获取到DataColumn列对象的列名 } //if (ds.Tables[0].Rows.Count != 0 || ds != null) //{ objJsonResult.code = "1"; objJsonResult.count = 1; objJsonResult.Message = "Sucess!"; objJsonResult.data = ds.Tables[0]; objJsonResult.list = columnNameList; return objJsonResult; //} //else //{ //objJsonResult.code = "0"; //objJsonResult.count = 0; //objJsonResult.Message = "无数据"; //objJsonResult.data = null; //return objJsonResult; //} } catch (Exception e) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "Exception!" + e.ToString(); objJsonResult.data = null; return objJsonResult; } } #endregion #region 工序工价保存 [Route("Gy_ProcPrice/set_SaveBill")] [HttpPost] public object set_SaveBill([FromBody] JObject sMainSub) { var _value = sMainSub["sMainSub"].ToString(); string msg1 = _value.ToString(); //保存单据 return objJsonResult = AddBillMain(msg1); } public json AddBillMain(string msg1) { string[] sArray = msg1.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries); string msg2 = sArray[0].ToString(); string msg3 = sArray[1].ToString(); string OperationType = sArray[2].ToString().Trim(); string msg4 = sArray[3].ToString(); bool bResult; try { //查看权限 if (!DBUtility.ClsPub.Security_Log("Gy_ProcPriceList_Edit", 1, false, msg4)) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "无保存权限!"; objJsonResult.data = null; return objJsonResult; } msg2 = "[" + msg2.ToString() + "]"; List mainList = Newtonsoft.Json.JsonConvert.DeserializeObject>(msg2); List subList = Newtonsoft.Json.JsonConvert.DeserializeObject>(msg3); DAL.ClsGy_ProcPrice_Ctl BillNew = new DAL.ClsGy_ProcPrice_Ctl(); BillNew.DetailColl = new List(); Model.ClsGy_ProcPrice_Model BillOld = new Model.ClsGy_ProcPrice_Model(); for (int i = 0; i < subList.ToArray().Length; i++) { if (i >= 0)//HQty { Model.ClsGy_ProcPrice_Model oSub = new Model.ClsGy_ProcPrice_Model(); 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.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); oSub.HFlowFlag = DBUtility.ClsPub.GridToBool(subList[i].HFlowFlagCol); oSub.HPayFlag = DBUtility.ClsPub.GridToBool(subList[i].HPayFlagCol); oSub.HDeptID = DBUtility.ClsPub.isLong(mainList[0].HDeptID); oSub.HStopflag = false; 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 { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "无明细行信息!"; objJsonResult.data = null; return objJsonResult; } } //保存完毕后处理 if (OperationType.Equals("1.1") || OperationType.Equals("1.2") || OperationType.Equals("2")) { bResult = BillNew.AddNew(); } else { bResult = BillNew.ModifyByID(DBUtility.ClsPub.isLong(mainList[0].HItemID)); } //提示 if (bResult == true) { objJsonResult.code = "1"; objJsonResult.count = 1; objJsonResult.Message = "保存成功!"; objJsonResult.data = null; return objJsonResult; } else { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "保存失败!原因:" + ClsPub.sExeReturnInfo; objJsonResult.data = null; return objJsonResult; } } catch (Exception e) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "Exception!" + e.ToString(); objJsonResult.data = null; return objJsonResult; } } #endregion #region 编辑时返回工序工价信息 [Route("Gy_ProcPrice/GetProcPriceValue")] [HttpGet] public object GetProcPriceValue(int HItemID) { try { List columnNameList = new List(); ds = oCN.RunProcReturn("select * from h_v_Gy_ProcPriceList where HItemID = " + HItemID, "h_v_Gy_ProcPriceList"); //添加列名 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/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 [工序工价审核、反审核] /// /// /// /// 单据ID /// 审核(0),反审核(1) /// 审核人 /// [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 columnNameList = new List(); 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 Excel = Newtonsoft.Json.JsonConvert.DeserializeObject>(msg2); List> list = new List>(); foreach (JObject item in Excel) { Dictionary dic = new Dictionary(); foreach (var itm in item.Properties()) { dic.Add(itm.Name, itm.Value.ToString()); } list.Add(dic); } oCN.BeginTran(); int i = 1; foreach (Dictionary 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 } }