using DBUtility; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Net; using System.Net.Http; using System.Web.Http; using WebAPI.Models; using System.Web; using WebAPI.Controllers.SCGL.日计划管理; using System.IO; namespace WebAPI.Controllers.SBGL { public class Sb_EquipDotCheckRuleBillController : ApiController { private json objJsonResult = new json(); public DataSet ds = new DataSet(); public DBUtility.ClsPub.Enum_BillStatus BillStatus;//单据状态(新增,修改,浏览,更新单价,变更) SQLHelper.ClsCN oCN = new SQLHelper.ClsCN(); public DLL.ClsSb_EquipDotCheckRuleBill BillNew = new DLL.ClsSb_EquipDotCheckRuleBill(); //对应单据类 public DLL.ClsSb_EquipDotCheckRuleBill BillOld = new DLL.ClsSb_EquipDotCheckRuleBill(); //对应单据类 #region 设备点检规程单列表 [Route("Sb_EquipDotCheckRuleBill/GetEquipDotCheckRuleList")] [HttpGet] public object GetEquipDotCheckRuleList(string sWhere,string user) { try { List columnNameList = new List(); if (!DBUtility.ClsPub.Security_Log("Sb_EquipDotCheckRuleBillList", 1, false, user)) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "无查看权限!"; objJsonResult.data = null; return objJsonResult; } if (sWhere == null || sWhere.Equals("")) { ds = oCN.RunProcReturn("select * from h_v_Sb_EquipDotCheckRuleList " + sWhere + " order by hmainid desc", "h_v_Sb_EquipDotCheckRuleList"); } else { string sql1 = "select * from h_v_Sb_EquipDotCheckRuleList where 1 = 1"; string sql = sql1 + sWhere + " order by hmainid desc"; ds = oCN.RunProcReturn(sql, "h_v_Sb_EquipDotCheckRuleList"); } //添加列名 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 ex) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "没有返回任何记录!" + ex.ToString(); objJsonResult.data = null; return objJsonResult; } } #endregion #region 设备点检规程单列表PDA [Route("Sb_EquipDotCheckRuleBill/GetEquipDotCheckRuleListPDA")] [HttpGet] public object GetEquipDotCheckRuleListPDA(string sWhere, string user) { try { List columnNameList = new List(); if (!DBUtility.ClsPub.Security_Log("Sb_EquipDotCheckRuleBillList", 1, false, user)) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "无查看权限!"; objJsonResult.data = null; return objJsonResult; } if (sWhere == null || sWhere.Equals("")) { ds = oCN.RunProcReturn("select * from h_v_Sb_GetDotCheckRuleListByEquip " + sWhere , "h_v_Sb_GetDotCheckRuleListByEquip"); } else { string sql1 = "select * from h_v_Sb_GetDotCheckRuleListByEquip where 1 = 1"; string sql = sql1 + sWhere; ds = oCN.RunProcReturn(sql, "h_v_Sb_GetDotCheckRuleListByEquip"); } //添加列名 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 ex) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "没有返回任何记录!" + ex.ToString(); objJsonResult.data = null; return objJsonResult; } } #endregion #region 设备点检规程记录删除功能 [Route("Sb_EquipDotCheckRuleBill/DeleteEquipDotCheckRuleBillList")] [HttpGet] public object DeleteEquipDotCheckRuleBillList(string HInterID,string user) { if (!DBUtility.ClsPub.Security_Log("Sb_EquipDotCheckRuleBill_Delete", 1, false, user)) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "无删除权限!"; objJsonResult.data = null; return objJsonResult; } Int64 lngBillKey = 0; lngBillKey = DBUtility.ClsPub.isLong(HInterID); if (lngBillKey == 0) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "单据ID为空!"; objJsonResult.data = null; return objJsonResult; } DLL.ClsSb_EquipDotCheckRuleBill oBill = new DLL.ClsSb_EquipDotCheckRuleBill(); ds = oCN.RunProcReturn("select * from Sb_EquipDotCheckRuleBillMain where HInterID=" + HInterID, "Sb_EquipDotCheckRuleBillMain"); if (ds.Tables[0].Rows.Count>0) { //数据库空值判断 if (ds.Tables[0].Rows[0]["HBillStatus"] == DBNull.Value) { ds.Tables[0].Rows[0]["HBillStatus"] = 1; } if (int.Parse(ds.Tables[0].Rows[0]["HBillStatus"].ToString()) > 1) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "单据当前处于不能删除状态!"; objJsonResult.data = null; return objJsonResult; } bool IsDete = oBill.DeleteBill(lngBillKey, ref DBUtility.ClsPub.sExeReturnInfo); if (IsDete) { objJsonResult.code = "0"; objJsonResult.count = 1; objJsonResult.Message = DBUtility.ClsPub.sExeReturnInfo; objJsonResult.data = null; return objJsonResult; } else { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = DBUtility.ClsPub.sExeReturnInfo; objJsonResult.data = null; return objJsonResult; } } else { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "单据未找到"; objJsonResult.data = null; return objJsonResult; } } #endregion #region[设备点检规程单编辑时获取表头数据] [Route("Sb_EquipDotCheckRuleBill/Sb_EquipDotCheckRuleBillListCheckDetai")] [HttpGet] public ApiResult Sb_EquipDotCheckRuleBillListCheckDetai(string HID) { if (string.IsNullOrEmpty(HID)) return new ApiResult { code = -1, msg = "ID不能为空" }; SQLHelper.ClsCN oCN = new SQLHelper.ClsCN(); var dataSet = oCN.RunProcReturn("select top 1 * from h_v_Sb_EquipDotCheckRuleList where hmainid= " + HID + " ", "h_v_Sb_EquipDotCheckRuleList"); if (dataSet == null || dataSet.Tables[0].Rows.Count == 0) return new ApiResult { code = -1, msg = "不存在点检规程表" }; return new ApiResult { code = 1, msg = "查询成功", data = dataSet }; } #endregion #region[设备点检规程单编辑时获取表体数据] [Route("Sb_EquipDotCheckRuleBill/Sb_EquipDotCheckRuleBillListProjectDetai")] [HttpGet] public object Sb_EquipDotCheckRuleBillListProjectDetai(string sqlWhere) { DataSet ds; try { SQLHelper.ClsCN oCN = new SQLHelper.ClsCN(); string sql1 = @"select * from h_v_Sb_EquipDotCheckRuleList a left join Gy_DotCheck b on a.点检项目ID =b.HItemID where 1 = 1 "; string sql = sql1 + sqlWhere; ds = oCN.RunProcReturn(sql, "h_v_Sb_EquipDotCheckRuleList"); objJsonResult.code = "0"; objJsonResult.count = 1; objJsonResult.Message = "获取信息成功!"; objJsonResult.data = ds.Tables[0]; } catch (Exception e) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "没有返回任何记录!" + e.ToString(); objJsonResult.data = null; } return objJsonResult; } #endregion #region 设备点检规程单 保存/编辑 /// /// 设备点检规程单 保存 /// /// /// [Route("Sb_EquipDotCheckRuleBill/SaveEquipDotCheckRuleBill")] [HttpPost] public object SaveEquipDotCheckRuleBill([FromBody] JObject msg) { var _value = msg["msg"].ToString(); string msg1 = _value.ToString(); string[] sArray = msg1.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries); string msg2 = sArray[0].ToString(); string msg3 = sArray[1].ToString(); string msg4 = sArray[2].ToString(); string UserName = ""; ListModels oListModels = new ListModels(); try { if (!DBUtility.ClsPub.Security_Log("Sb_EquipDotCheckRuleBill_Edit", 1, false, msg4)) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "无保存权限!"; objJsonResult.data = null; return objJsonResult; } DLL.ClsSb_EquipDotCheckRuleBill oBill = new DLL.ClsSb_EquipDotCheckRuleBill(); List lsmain = new List(); msg2 = msg2.Replace("\\", ""); msg2 = msg2.Replace("\n", ""); //\n lsmain = oListModels.getObjectByJson_Sb_EquipDotCheckRuleBillMain(msg2); foreach (Models.ClsSb_EquipDotCheckRuleBillMain oItem in lsmain) { UserName = oItem.HMaker; //制单人 oItem.HBillType = "3913"; oItem.HBillSubType = "3913"; DBUtility.ClsPub.CurUserName = UserName; oItem.HDate = DBUtility.ClsPub.isDate(DateTime.Now.ToString("yyyy-MM-dd"));// --日期 oItem.HYear = DBUtility.ClsPub.isLong(DateTime.Now.Year); if (DBUtility.ClsPub.isStrNull(oItem.HDate) == "") { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "保存失败!没有单据日期,无法保存!"; objJsonResult.data = 1; return objJsonResult; } oBill.omodel = oItem; } //表体数据 按 },{来拆分数组 //去掉【和】 msg3 = msg3.Substring(1, msg3.Length - 2); msg3 = msg3.Replace("\\", ""); msg3 = msg3.Replace("\n", ""); //\n //msg2 = msg2.Replace("'", "’"); List ls = new List(); ls = oListModels.getObjectByJson_Sb_EquipDotCheckRuleBillSub(msg3); int i = 0; foreach (Models.ClsSb_EquipDotCheckRuleBillSub oItemSub in ls) { i++; oItemSub.HEntryID = i; //oItemSub.HCloseMan = ""; //行关闭 oItemSub.HEntryCloseDate = DBUtility.ClsPub.isDate(DateTime.Now); oItemSub.HCloseType = false; //关闭类型 //oItemSub.HRemark = ""; //备注 oItemSub.HSourceInterID = 0; // 源单主内码 oItemSub.HSourceEntryID = 0; //源单子内码 //oItemSub.HSourceBillNo = ""; //源单单号 //oItemSub.HSourceBillType = ""; //源单类型 oItemSub.HRelationQty = 0; //关联数量 oBill.DetailColl_Mater.Add(oItemSub); } //保存 //保存完毕后处理 bool bResult; if (oBill.omodel.HInterID == 0) { // bResult = oBill.AddBill(ref DBUtility.ClsPub.sExeReturnInfo); bResult = oBill.AddBill(ref DBUtility.ClsPub.sExeReturnInfo); } else { bResult = oBill.ModifyBill(oBill.omodel.HInterID, ref DBUtility.ClsPub.sExeReturnInfo); } if (bResult) { objJsonResult.code = "0"; objJsonResult.count = 1; objJsonResult.Message = "保存成功!"; //WebAPIController.Add_Log("送货单下推", UserName, "生成送货单"); objJsonResult.data = 1; return objJsonResult; } else { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "保存失败!" + DBUtility.ClsPub.sExeReturnInfo; objJsonResult.data = 1; return objJsonResult; } } catch (Exception e) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "保存失败!" + e.ToString(); objJsonResult.data = 1; return objJsonResult; } } #endregion #region 设备点检规程单审核/反审核功能 [Route("Sb_EquipDotCheckRuleBill/CheckSb_EquipDotCheckRuleBill")] [HttpGet] public object CheckSb_EquipDotCheckRuleBill(string HInterID, int Type, string user) { try { //判断是否有删除权限 if (!DBUtility.ClsPub.Security_Log("Sb_EquipDotCheckRuleBill_Check", 1, false, user)) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "无权限审核!"; objJsonResult.data = null; return objJsonResult; } if (string.IsNullOrWhiteSpace(HInterID)) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "HInterID为空!"; objJsonResult.data = null; return objJsonResult; } ClsPub.CurUserName = user; oCN.BeginTran();//开始事务 //Type 1 审核 2 反审核 if (Type == 1) { if (!BillOld.CheckBill(int.Parse(HInterID), ref ClsPub.sExeReturnInfo)) { objJsonResult.code = "0"; objJsonResult.count = 1; objJsonResult.Message = "审核失败!原因:" + ClsPub.sExeReturnInfo; objJsonResult.data = null; return objJsonResult; } } else { if (BillOld.AbandonCheck(int.Parse(HInterID), ref ClsPub.sExeReturnInfo)) { SQLHelper.ClsCN oCn = new SQLHelper.ClsCN(); } else { objJsonResult.code = "0"; objJsonResult.count = 1; objJsonResult.Message = "审核失败!原因:" + ClsPub.sExeReturnInfo; objJsonResult.data = null; return objJsonResult; } } oCN.Commit();//提交事务 objJsonResult.code = "0"; objJsonResult.count = 1; objJsonResult.Message = "执行成功!"; objJsonResult.data = null; return objJsonResult; ; } catch (Exception e) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "执行失败!" + e.ToString(); objJsonResult.data = null; return objJsonResult; } } #endregion #region 设备点检规程单关闭/反关闭功能 [Route("Sb_EquipDotCheckRuleBill/CloseSb_EquipDotCheckRuleBill")] [HttpGet] public object CloseSb_EquipDotCheckRuleBill(string HInterID, int Type, string user) { try { //判断是否有删除权限 if (!DBUtility.ClsPub.Security_Log("Sb_EquipDotCheckRuleBill_Close", 1, false, user)) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "无权限关闭!"; objJsonResult.data = null; return objJsonResult; } if (string.IsNullOrWhiteSpace(HInterID)) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "HInterID为空!"; objJsonResult.data = null; return objJsonResult; } ClsPub.CurUserName = user; oCN.BeginTran();//开始事务 //Type 1 关闭 2 反关闭 if (Type == 1) { if (!BillOld.CloseBill(int.Parse(HInterID), ref ClsPub.sExeReturnInfo)) { objJsonResult.code = "0"; objJsonResult.count = 1; objJsonResult.Message = "关闭失败!原因:" + ClsPub.sExeReturnInfo; objJsonResult.data = null; return objJsonResult; } } else { if (!BillOld.CancelClose(int.Parse(HInterID), ref ClsPub.sExeReturnInfo)) { objJsonResult.code = "0"; objJsonResult.count = 1; objJsonResult.Message = "反关闭失败!原因:" + ClsPub.sExeReturnInfo; objJsonResult.data = null; return objJsonResult; } } oCN.Commit();//提交事务 objJsonResult.code = "0"; objJsonResult.count = 1; objJsonResult.Message = "执行成功!"; objJsonResult.data = null; return objJsonResult; ; } catch (Exception e) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "执行失败!" + e.ToString(); objJsonResult.data = null; return objJsonResult; } } #endregion #region 设备点检规程单文件上传 [Route("Sb_EquipDotCheckRuleBill/Sb_EquipDotCheckRuleBill_Excel")] [HttpPost] public object Sb_EquipDotCheckRuleBill_Excel() { try { //获取文件名称 var file = HttpContext.Current.Request.Files[0]; //获取文件物理路径 string ExcelPath = HttpContext.Current.Server.MapPath("~/" + file.FileName); // 创建一个字典来存储name到单据号和HInterID的映射 Dictionary nameToValues = new Dictionary(); string HBillType = "3913"; //保存文件 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("HDotCheckItemID", typeof(Int32));//点检项目ID tb2.Columns.Add("HDotCheckItemClassID", typeof(Int32));//点检分类ID tb2.Columns.Add("HDotCheckItemMethodID", typeof(Int32));//点检方法ID tb2.Columns.Add("HEmpID", typeof(Int32));//负责人 tb2.Columns.Add("单据号", typeof(string));//单据号 tb2.Columns.Add("HInterID", typeof(Int64));//主键 //添加数据 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 (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 HDotCheckItemNumber = ""; string HDotCheckItemName = ""; string HEmpNum = ""; string HEmpName = ""; HDotCheckItemNumber = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["点检项目代码"].ToString()); HDotCheckItemName = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["点检项目名称"].ToString()); HEmpNum = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["负责人代码"].ToString()); HEmpName = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["负责人名称"].ToString()); string HDotCheckItemMethodNumber = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["点检方法代码"].ToString()); string HDotCheckItemMethodName = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["点检方法名称"].ToString()); string HEquipDotCheckRuleName = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["点检规程名称"].ToString()); string HCycleUnit = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["周期单位"].ToString()); string HCheckCycle = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["点检周期"].ToString()); string HExplanation = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["摘要"].ToString()); string HMainRemark = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["表头备注"].ToString()); string HDotCheckPart = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["点检部位"].ToString()); string HClaim = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["具体要求"].ToString()); string HSubRemark = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["表体备注"].ToString()); int index = i + 1; //查询点检项目 ds = oCN.RunProcReturn("select * from Gy_DotCheck where HNumber='" + HDotCheckItemNumber + "' and Hname='" + HDotCheckItemName + "'", "Gy_DotCheck"); 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]["HDotCheckItemID"] = ds.Tables[0].Rows[0]["HItemID"].ToString(); tb2.Rows[i]["HDotCheckItemClassID"] = ds.Tables[0].Rows[0]["HDotCheckItemClassID"].ToString(); } //查询负责人 ds = oCN.RunProcReturn("select * from Gy_Employee where HNumber='" + HEmpNum + "' and Hname='" + HEmpName + "'", "Gy_Employee"); if (ds.Tables[0].Rows.Count == 0) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "第" + index + "行,该负责人:" + HEmpName + ",不存在!"; objJsonResult.data = null; return objJsonResult; } else { tb2.Rows[i]["HEmpID"] = ds.Tables[0].Rows[0]["HItemID"].ToString(); } //查询点检方法 ds = oCN.RunProcReturn("select * from Gy_DotCheckItemMethod where HNumber='" + HDotCheckItemMethodNumber + "' and Hname='" + HDotCheckItemMethodName + "'", "Gy_Employee"); if (ds.Tables[0].Rows.Count == 0) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "第" + index + "行,该点检方法:" + HEmpName + ",不存在!"; objJsonResult.data = null; return objJsonResult; } else { tb2.Rows[i]["HDotCheckItemMethodID"] = ds.Tables[0].Rows[0]["HItemID"].ToString(); } //设备点检规程名称 if (HEquipDotCheckRuleName == "") { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "第" + index + "行,设备点检规程单名称不能为空!"; objJsonResult.data = null; return objJsonResult; } //周期单位 if (HCycleUnit == "" || (HCycleUnit != "月" && HCycleUnit != "周" && HCycleUnit != "天")) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "第" + index + "行,周期单位不能为空且只能为天,月,周!"; objJsonResult.data = null; return objJsonResult; } //点检周期 if (HCheckCycle == "" ) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "第" + index + "行,点检周期不能为空!"; objJsonResult.data = null; return objJsonResult; } //设置单据HinterID和单据号 Int64 HInterID; string HBillNo; object[] myArray = new object[2]; // 如果字典中还没有这个点检规程的条目,就添加它 if (!nameToValues.ContainsKey(HEquipDotCheckRuleName)) { HInterID = DBUtility.ClsPub.CreateBillID(HBillType, ref DBUtility.ClsPub.sExeReturnInfo); HBillNo = DBUtility.ClsPub.CreateBillCode(HBillType, ref DBUtility.ClsPub.sExeReturnInfo, true); myArray[0] = HInterID; myArray[1] = HBillNo; nameToValues[HEquipDotCheckRuleName] = myArray; tb2.Rows[i]["HInterID"] = HInterID; tb2.Rows[i]["单据号"] = HBillNo; } // 如果字典中有这个年龄的条目,但是当前行的名称不是字典中的名称,就更新它 else if (true) { tb2.Rows[i]["HInterID"] = nameToValues[HEquipDotCheckRuleName][0]; tb2.Rows[i]["单据号"] = nameToValues[HEquipDotCheckRuleName][1];// 更新当前行单据号和id } } 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("Sb_EquipDotCheckRuleBill/Sb_EquipDotCheckRuleBill_btnSave")] [HttpPost] public object Sb_EquipDotCheckRuleBill_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("Sb_EquipDotCheckRuleBill_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 HInterID = item["HInterID"].ToString(); string HBillNo = item["单据号"].ToString(); //string HInterID = item["点检规程名称"].ToString(); string HCycleUnit = item["周期单位"].ToString(); string HCheckCycle = item["点检周期"].ToString(); string HExplanation = item["摘要"].ToString(); string HMainRemark = item["表头备注"].ToString(); string HDotCheckItemID = item["HDotCheckItemID"].ToString(); string HDotCheckItemClassID = item["HDotCheckItemClassID"].ToString(); string HDotCheckItemMethodID = item["HDotCheckItemMethodID"].ToString(); string HDotCheckItem = item["点检项目名称"].ToString(); string HDotCheckPart = item["点检部位"].ToString(); string HClaim = item["具体要求"].ToString(); string HEmpID = item["HEmpID"].ToString(); string HSubRemark = item["表体备注"].ToString(); string HBillType = "3913"; string HBillSubType = "3913"; DateTime HDate = DBUtility.ClsPub.isDate(DateTime.Now.ToString("yyyy-MM-dd")); Int64 HYear = DBUtility.ClsPub.isLong(DateTime.Now.Year); Int64 HPeriod = DBUtility.ClsPub.isLong(DateTime.Now.Month); DataSet Cs; Int64 HEntryID = 1; Cs = oCN.RunProcReturn("select MAX(HEntryID)HEntryID from Sb_EquipDotCheckRuleBillSub", "Sb_EquipDotCheckRuleBillSub"); if (Cs.Tables[0].Rows.Count != 0 && ClsPub.isLong(Cs.Tables[0].Rows[0]["HEntryID"].ToString()) != 0) { HEntryID = ClsPub.isLong(Cs.Tables[0].Rows[0]["HEntryID"].ToString()); HEntryID += 1; } ds = oCN.RunProcReturn("select * from Sb_EquipDotCheckRuleBillMain where HInterID =" + HInterID, "Sb_EquipDotCheckRuleBillMain"); if (ds.Tables[0].Rows.Count == 0) { //主表 oCN.RunProc("Insert Into Sb_EquipDotCheckRuleBillMain " + "(HBillType,HBillSubType,HInterID,HBillNo,HDate,HMaker,HMakeDate,HBillStatus" + ",HYear,HPeriod,HRemark" + ",HBeginDate,HEndDate,HCycleUnit,HCheckCycle,HExplanation" + ") " + " values('" + HBillType + "','" + HBillSubType + "'," + HInterID.ToString() + ",'" + HBillNo + "','" + HDate + "','" + user + "',getdate(),1" + "," + HYear.ToString() + "," + HPeriod.ToString() + ",'" + HMainRemark + "'" + ",getdate()" + ",getdate()" + ",'" + HCycleUnit + "','" + HCheckCycle + "','" + HExplanation + "'" + ") "); //插入子表 oCN.RunProc("Insert into Sb_EquipDotCheckRuleBillSub " + " (HInterID,HEntryID," + "HRemark," + "HDotCheckItemID,HDotCheckItem,HDotCheckPart,HClaim," + "HManagerID,HDotCheckItemClassID,HDotCheckItemMethodID" + ") values(" + HInterID.ToString() + "," + HEntryID.ToString() + ",'" + HSubRemark + "'" + ",'" + HDotCheckItemID + "','" + HDotCheckItem + "','" + HDotCheckPart + "','" + HClaim + "'," + HEmpID + "," + HDotCheckItemClassID + "," + HDotCheckItemMethodID + ") "); } else { oCN.RunProc("Insert into Sb_EquipDotCheckRuleBillSub " + " (HInterID,HEntryID," + "HRemark," + "HDotCheckItemID,HDotCheckItem,HDotCheckPart,HClaim," + "HManagerID,HDotCheckItemClassID,HDotCheckItemMethodID" + ") values(" + HInterID.ToString() + "," + HEntryID.ToString() + ",'" + HSubRemark + "'" + ",'" + HDotCheckItemID + "','" + HDotCheckItem + "','" + HDotCheckPart + "','" + HClaim + "'," + HEmpID + "," + HDotCheckItemClassID + "," + HDotCheckItemMethodID + ") "); } 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 } }