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;
|
using SyntacticSugar.constant;
|
namespace WebAPI.Controllers.基础资料.基础资料
|
{
|
public class Gy_ConkReasonBillController : ApiController
|
{
|
public DBUtility.ClsPub.Enum_BillStatus BillStatus;//单据状态(新增,修改,浏览,更新单价,变更)
|
private json objJsonResult = new json();
|
public DataSet ds = new DataSet();
|
public SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();
|
public Model.ClsGy_ConkReason_Model BillNew0 = new Model.ClsGy_ConkReason_Model();
|
|
|
#region 故障原因列表
|
[Route("Gy_ConkReasonBill/Get_ConkReasonBillList")]
|
[HttpGet]
|
public object Get_ConkReasonBillList(string sWhere,string user)
|
{
|
try
|
{
|
List<object> columnNameList = new List<object>();
|
//查看权限
|
if (!DBUtility.ClsPub.Security_Log("Gy_ConkReason_Query", 1, false, user))
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "无查看权限!";
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
|
ds = Sc_GetConkReasonBill(sWhere);
|
|
//添加列名
|
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;
|
}
|
}
|
|
public static DataSet Sc_GetConkReasonBill(string sWhere)
|
{
|
string sql1 = string.Format(@"select * from h_v_Gy_ConkReasonList where 1 = 1");
|
if (sWhere == null || sWhere.Equals(""))
|
{
|
return new SQLHelper.ClsCN().RunProcReturn(sql1 + sWhere + " order by 故障原因代码 ", "h_v_Gy_ConkReasonList");
|
}
|
else
|
{
|
string sql = sql1 + sWhere + "order by 故障原因代码 ";
|
return new SQLHelper.ClsCN().RunProcReturn(sql, "h_v_Gy_ConkReasonList");
|
}
|
}
|
#endregion
|
|
#region 故障原因审核、反审核
|
/// <summary>
|
///
|
/// </summary>
|
/// <param name="HInterID">单据ID</param>
|
/// <param name="IsAudit">审核(0),反审核(1)</param>
|
/// <param name="CurUserName">审核人</param>
|
/// <returns></returns>
|
[Route("Gy_ConkReason/AuditGy_ConkReason")]
|
[HttpGet]
|
public object AuditGy_ConkReason(int HInterID, int IsAudit, string CurUserName)
|
{
|
SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
|
try
|
{
|
//审核权限
|
if (!DBUtility.ClsPub.Security_Log_second("Gy_ConkReason_Check", 1, false, CurUserName))
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "审核失败!无权限!";
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
|
var ds = oCN.RunProcReturn("select * from Gy_ConkReason where HItemID=" + HInterID, "Gy_ConkReason");
|
if (ds.Tables[0].Rows.Count > 0)
|
{
|
if (IsAudit == 0) //审核判断
|
{
|
if (ds.Tables[0].Rows[0]["HCheckEmp"].ToString() != "")
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "单据已审核!不能再次审核!";
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
}
|
if (IsAudit == 1) //反审核判断
|
{
|
if (ds.Tables[0].Rows[0]["HCheckEmp"].ToString() == "")
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "单据未审核!不需要反审核!";
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
}
|
}
|
else
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "单据不存在!";
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
|
oCN.BeginTran();
|
|
if (IsAudit == 0) //审核判断
|
{
|
//审核前控制=========================================
|
string sql1 = "exec h_p_Gy_ConkReason_BeforeCheckCtrl " + HInterID + ",'" + CurUserName + "'";
|
ds = oCN.RunProcReturn(sql1, "h_p_Gy_ConkReason_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;
|
}
|
//==================================================================================
|
|
|
oCN.RunProc("update Gy_ConkReason set HCheckEmp='" + CurUserName + "',HCheckTime=getdate() where HItemID=" + HInterID);
|
|
//审核后控制=========================================
|
string sql2 = "exec h_p_Gy_ConkReason_AfterCheckCtrl " + HInterID + ",'" + CurUserName + "'";
|
ds = oCN.RunProcReturn(sql2, "h_p_Gy_ConkReason_AfterCheckCtrl");
|
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;
|
}
|
//==================================================================================
|
|
|
objJsonResult.code = "1";
|
objJsonResult.count = 1;
|
objJsonResult.Message = "审核成功";
|
objJsonResult.data = null;
|
}
|
if (IsAudit == 1) //反审核判断
|
{
|
//反审核前控制=========================================
|
string sql1 = "exec h_p_Gy_ConkReason_BeforeUnCheckCtrl " + HInterID + ",'" + CurUserName + "'";
|
ds = oCN.RunProcReturn(sql1, "h_p_Gy_ConkReason_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;
|
}
|
//==================================================================================
|
|
|
oCN.RunProc("update Gy_ConkReason set HCheckEmp='',HCheckTime=null where HItemID=" + HInterID);
|
|
|
//反审核后控制=========================================
|
string sql2 = "exec h_p_Gy_ConkReason_AfterUnCheckCtrl " + HInterID + ",'" + CurUserName + "'";
|
ds = oCN.RunProcReturn(sql2, "h_p_Gy_ConkReason_AfterCheckCtrl");
|
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;
|
}
|
//==================================================================================
|
|
|
objJsonResult.code = "1";
|
objJsonResult.count = 1;
|
objJsonResult.Message = "反审核成功";
|
objJsonResult.data = null;
|
}
|
oCN.Commit();
|
|
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="IsStop">禁用(0),反禁用(1)</param>
|
/// <param name="CurUserName">审核人</param>
|
/// <returns></returns>
|
[Route("Gy_ConkReason/StopGy_ConkReason")]
|
[HttpGet]
|
public object StopGy_ConkReason(int HInterID, int IsStop, string CurUserName)
|
{
|
SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
|
try
|
{
|
//审核权限
|
if (!DBUtility.ClsPub.Security_Log_second("Gy_ConkReason_Stop", 1, false, CurUserName))
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "禁用失败!无权限!";
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
|
var ds = oCN.RunProcReturn("select * from Gy_ConkReason where HItemID=" + HInterID, "Gy_ConkReason");
|
if (ds.Tables[0].Rows.Count > 0)
|
{
|
if (IsStop == 0) //禁用判断
|
{
|
if (ds.Tables[0].Rows[0]["HStopEmp"].ToString() != "")
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "单据已禁用!不能再次禁用!";
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
}
|
if (IsStop == 1) //反禁用判断
|
{
|
if (ds.Tables[0].Rows[0]["HStopEmp"].ToString() == "")
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "单据未禁用!不需要反禁用!";
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
}
|
}
|
else
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "单据不存在!";
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
|
oCN.BeginTran();
|
|
if (IsStop == 0) //禁用判断
|
{
|
//禁用前控制=========================================
|
string sql1 = "exec h_p_Gy_ConkReason_BeforeStopCtrl " + HInterID + ",'" + CurUserName + "'";
|
ds = oCN.RunProcReturn(sql1, "h_p_Gy_ConkReason_BeforeStopCtrl");
|
if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 1;
|
objJsonResult.Message = "禁用失败!原因:禁用前判断失败,请与网络管理人员联系";
|
objJsonResult.data = null;
|
oCN.RollBack();
|
return objJsonResult;
|
}
|
|
if (ds.Tables[0].Rows[0]["HBack"].ToString() != "0")
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 1;
|
objJsonResult.Message = "禁用失败!原因:" + ds.Tables[0].Rows[0]["HRemark"].ToString(); ;
|
objJsonResult.data = null;
|
oCN.RollBack();
|
return objJsonResult;
|
}
|
//==================================================================================
|
|
oCN.RunProc("update Gy_ConkReason set HStopEmp='" + CurUserName + "',HStopTime=getdate(),HStopflag=1 where HItemID=" + HInterID);
|
|
|
//禁用后控制=========================================
|
string sql2 = "exec h_p_Gy_ConkReason_AfterStopCtrl " + HInterID + ",'" + CurUserName + "'";
|
ds = oCN.RunProcReturn(sql2, "h_p_Gy_ConkReason_AfterStopCtrl");
|
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;
|
}
|
//==================================================================================
|
|
|
objJsonResult.code = "1";
|
objJsonResult.count = 1;
|
objJsonResult.Message = "禁用成功";
|
objJsonResult.data = null;
|
}
|
if (IsStop == 1) //反禁用判断
|
{
|
//反禁用前控制=========================================
|
string sql1 = "exec h_p_Gy_ConkReason_BeforeUnStopCtrl " + HInterID + ",'" + CurUserName + "'";
|
ds = oCN.RunProcReturn(sql1, "h_p_Gy_ConkReason_BeforeUnStopCtrl");
|
if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 1;
|
objJsonResult.Message = "反禁用失败!原因:反禁用前判断失败,请与网络管理人员联系";
|
objJsonResult.data = null;
|
oCN.RollBack();
|
return objJsonResult;
|
}
|
|
if (ds.Tables[0].Rows[0]["HBack"].ToString() != "0")
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 1;
|
objJsonResult.Message = "反禁用失败!原因:" + ds.Tables[0].Rows[0]["HRemark"].ToString(); ;
|
objJsonResult.data = null;
|
oCN.RollBack();
|
return objJsonResult;
|
}
|
//==================================================================================
|
|
oCN.RunProc("update Gy_ConkReason set HStopEmp='',HStopTime=null,HStopflag=0 where HItemID=" + HInterID);
|
|
|
//反禁用后控制=========================================
|
string sql2 = "exec h_p_Gy_ConkReason_AfterUnStopCtrl " + HInterID + ",'" + CurUserName + "'";
|
ds = oCN.RunProcReturn(sql2, "h_p_Gy_ConkReason_AfterUnStopCtrl");
|
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;
|
}
|
//==================================================================================
|
|
|
objJsonResult.code = "1";
|
objJsonResult.count = 1;
|
objJsonResult.Message = "反禁用成功";
|
objJsonResult.data = null;
|
}
|
oCN.Commit();
|
|
return objJsonResult;
|
}
|
catch (Exception e)
|
{
|
oCN.RollBack();
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "禁用失败或者反禁用失败!" + e.ToString();
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
}
|
#endregion
|
|
|
#region [故障原因删除功能]
|
[Route("Gy_ConkReasonBill/set_DeleteBill")]
|
[HttpGet]
|
public object set_DeleteBill(string HItemID,string user)
|
{
|
//删除权限
|
if (!DBUtility.ClsPub.Security_Log("Gy_ConkReason_Delete", 1, false, user))
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "无删除权限!";
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
|
Int64 lngBillKey = 0;
|
lngBillKey = DBUtility.ClsPub.isLong(HItemID);
|
if (lngBillKey == 0)
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "单据ID为空!";
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
ds = oCn.RunProcReturn("select * from Gy_ConkReason where HItemID=" + lngBillKey, "Gy_ConkReason");
|
if (ds != null)
|
{
|
oCn.BeginTran();//开始事务
|
//删除前控制=========================================
|
string sql1 = "exec h_p_Gy_ConkReason_BeforeDelCtrl " + HItemID + ",'" + user + "'";
|
ds = oCn.RunProcReturn(sql1, "h_p_Gy_ConkReason_BeforeDelCtrl");
|
if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 1;
|
objJsonResult.Message = "删除失败!原因:删除前判断失败,请与网络管理人员联系";
|
objJsonResult.data = null;
|
oCn.RollBack();
|
return objJsonResult;
|
}
|
|
if (ds.Tables[0].Rows[0]["HBack"].ToString() != "0")
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 1;
|
objJsonResult.Message = "删除失败!原因:" + ds.Tables[0].Rows[0]["HRemark"].ToString(); ;
|
objJsonResult.data = null;
|
oCn.RollBack();
|
return objJsonResult;
|
}
|
//==================================================================================
|
|
|
oCn.RunProc("Delete from Gy_ConkReason where HItemID=" + lngBillKey);
|
|
|
//删除后控制=========================================
|
string sql2 = "exec h_p_Gy_ConkReason_AfterDelCtrl " + HItemID + ",'" + user + "'";
|
ds = oCn.RunProcReturn(sql2, "h_p_Gy_ConkReason_AfterDelCtrl");
|
if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 1;
|
objJsonResult.Message = "删除失败!原因:删除后判断失败,请与网络管理人员联系";
|
objJsonResult.data = null;
|
oCn.RollBack();
|
return objJsonResult;
|
}
|
|
if (ds.Tables[0].Rows[0]["HBack"].ToString() != "0")
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 1;
|
objJsonResult.Message = "删除失败!原因:" + ds.Tables[0].Rows[0]["HRemark"].ToString(); ;
|
objJsonResult.data = null;
|
oCn.RollBack();
|
return objJsonResult;
|
}
|
//==================================================================================
|
|
oCn.Commit();
|
|
objJsonResult.code = "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;
|
}
|
|
}
|
|
#endregion
|
|
#region [编辑显示表头]
|
[Route("Gy_ConkReasonBill/GetConkReasonByID")]
|
[HttpGet]
|
public object GetConkReasonByID(string HID)
|
{
|
Int64 lngBillKey = 0;
|
lngBillKey = DBUtility.ClsPub.isLong(HID);
|
if (lngBillKey == 0)
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "单据ID为空!";
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
ds = oCn.RunProcReturn("select * from Gy_ConkReason where HItemID=" + lngBillKey, "Gy_ConkReason");
|
if (ds != null)
|
{
|
objJsonResult.code = "1";
|
objJsonResult.count = 1;
|
objJsonResult.Message = "";
|
objJsonResult.data = ds.Tables[0];
|
return objJsonResult;
|
}
|
else
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "此单据不存在";
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
|
}
|
|
#endregion
|
|
#region 保存故障原因
|
[Route("Gy_ConkReasonBill/SaveGy_ConkReason")]
|
[HttpPost]
|
public object SaveGy_ConkReason([FromBody] JObject msg)
|
{
|
var _value = msg["msg"].ToString();
|
string msg2 = _value.ToString();
|
string[] sArray = msg2.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
|
string msg1 = sArray[0].ToString();
|
string msg3 = sArray[1].ToString();//当前人
|
SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
|
ListModels oListModels = new ListModels();
|
try
|
{
|
//查看权限
|
if (!DBUtility.ClsPub.Security_Log("Gy_ConkReason_Edit", 1, false, msg3))
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "无保存权限!";
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
Model.ClsGy_ConkReason_Model oBill = new Model.ClsGy_ConkReason_Model();
|
List<Model.ClsGy_ConkReason_Model> lsmain = new List<Model.ClsGy_ConkReason_Model>();
|
msg1 = msg1.Replace("\\", "");
|
msg1 = msg1.Replace("\n", ""); //\n
|
lsmain = oListModels.getObjectByJson_Gy_ConkReason(msg1);
|
foreach (Model.ClsGy_ConkReason_Model oItem in lsmain)
|
{
|
if (oItem.HNumber.Trim() == "")
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "保存失败!代码不能为空!";
|
objJsonResult.data = 1;
|
return objJsonResult;
|
}
|
if (oItem.HName.Trim() == "")
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "保存失败!名称不能为空!";
|
objJsonResult.data = 1;
|
return objJsonResult;
|
}
|
|
//得到短代码
|
string sShortNumber;
|
sShortNumber = DBUtility.ClsPub.GetShortNumber(oItem.HNumber.Trim());
|
if (sShortNumber.Trim() == "")
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "保存失败!短代码为空!";
|
objJsonResult.data = 1;
|
return objJsonResult;
|
}
|
oItem.HShortNumber = sShortNumber;//短代码
|
oItem.HEndFlag = true;//末级标志
|
oItem.HLevel = DBUtility.ClsPub.GetLevel(oItem.HNumber.Trim()); //等级
|
|
oBill = oItem;
|
}
|
|
//保存
|
//保存完毕后处理
|
if (oBill.HItemID == 0)
|
{
|
//保存前控制=========================================
|
string sql1 = "exec h_p_Gy_ConkReason_BeforeSaveCtrl " + msg3 + ",'" + 1 + "'";
|
ds = oCN.RunProcReturn(sql1, "h_p_Gy_ConkReason_BeforeSaveCtrl");
|
if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 1;
|
objJsonResult.Message = "保存失败!原因:保存前判断失败,请与网络管理人员联系";
|
objJsonResult.data = null;
|
oCN.RollBack();
|
return objJsonResult;
|
}
|
|
if (ds.Tables[0].Rows[0]["HBack"].ToString() != "0")
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 1;
|
objJsonResult.Message = "保存失败!原因:" + ds.Tables[0].Rows[0]["HRemark"].ToString(); ;
|
objJsonResult.data = null;
|
oCN.RollBack();
|
return objJsonResult;
|
}
|
//==================================================================================
|
|
|
oCn.RunProc("Insert into Gy_ConkReason " +
|
" (HNumber,HName,HHelpCode,HShortNumber,HParentID,HUSEORGID,HCREATEORGID" +
|
",HLevel,HEndFlag,HStopflag,HRemark,HUseFlag,HMakeTime,HMakeEmp,HExplanation,HConkTypeID) " +
|
" Values('" + oBill.HNumber + "','" + oBill.HName + "','" + oBill.HHelpCode + "','" + oBill.HShortNumber + "'," + oBill.HParentID.ToString() + "," + oBill.HUSEORGID.ToString() + "," + oBill.HCREATEORGID.ToString() +
|
"," + oBill.HLevel.ToString() + "," + Convert.ToString(oBill.HEndFlag ? 1 : 0) + "," + Convert.ToString(oBill.HStopflag ? 1 : 0) + ",'" + oBill.HRemark +
|
"','" + oBill.HUseFlag + "',getdate(),'" + msg3 + "','" + oBill.HExplanation + "',0" +
|
")", ref DBUtility.ClsPub.sExeReturnInfo);
|
//修改上级为非末级代码
|
oCn.RunProc("Update Gy_ConkReason set HEndflag=0 where HItemID=" + oBill.HParentID, ref DBUtility.ClsPub.sExeReturnInfo);
|
|
|
//保存后控制=========================================
|
string sql2 = "exec h_p_Gy_ConkReason_AfterSaveCtrl " + msg3 + ",'" + 1 + "'";
|
ds = oCN.RunProcReturn(sql2, "h_p_Gy_ConkReason_AfterSaveCtrl");
|
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;
|
}
|
//==================================================================================
|
|
|
|
objJsonResult.code = "0";
|
objJsonResult.count = 1;
|
objJsonResult.Message = "保存成功!";
|
//WebAPIController.Add_Log("送货单下推", UserName, "生成送货单");
|
objJsonResult.data = 1;
|
return objJsonResult;
|
}
|
else
|
{
|
//保存前控制=========================================
|
string sql1 = "exec h_p_Gy_ConkReason_BeforeSaveCtrl " + msg3 + ",'" + 2 + "'";
|
ds = oCN.RunProcReturn(sql1, "h_p_Gy_ConkReason_BeforeSaveCtrl");
|
if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 1;
|
objJsonResult.Message = "保存失败!原因:保存前判断失败,请与网络管理人员联系";
|
objJsonResult.data = null;
|
oCN.RollBack();
|
return objJsonResult;
|
}
|
|
if (ds.Tables[0].Rows[0]["HBack"].ToString() != "0")
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 1;
|
objJsonResult.Message = "保存失败!原因:" + ds.Tables[0].Rows[0]["HRemark"].ToString(); ;
|
objJsonResult.data = null;
|
oCN.RollBack();
|
return objJsonResult;
|
}
|
//==================================================================================
|
|
oCN.RunProc("UpDate Gy_ConkReason set " +
|
" HNumber='" + oBill.HNumber + "'" + //固定赋值===============
|
",HName='" + oBill.HName + "'" +
|
",HShortNumber='" + oBill.HShortNumber + "'" +
|
",HHelpCode='" + oBill.HHelpCode + "'" +
|
",HUseFlag='" + oBill.HUseFlag + "'" +
|
",HUSEORGID='" + oBill.HUSEORGID + "'" +
|
",HCREATEORGID='" + oBill.HCREATEORGID + "'" +
|
",HRemark='" + oBill.HRemark + "'" +
|
",HExplanation='" + oBill.HExplanation + "'" +
|
",HModifyTime=getdate()" +
|
",HModifyEmp='" + msg3 + "'" +
|
",HStopflag=" + Convert.ToString(oBill.HStopflag ? 1 : 0) +
|
" where HItemID=" + oBill.HItemID.ToString());
|
|
|
//保存后控制=========================================
|
string sql2 = "exec h_p_Gy_ConkReason_AfterSaveCtrl " + msg3 + ",'" + 2 + "'";
|
ds = oCN.RunProcReturn(sql2, "h_p_Gy_ConkReason_AfterSaveCtrl");
|
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;
|
}
|
//==================================================================================
|
|
|
objJsonResult.code = "1";
|
objJsonResult.count = 1;
|
objJsonResult.Message = "修改成功!";
|
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 故障原因 文件导入保存
|
#region 故障原因 文件上传
|
[Route("Gy_ConkReason/Gy_ConkReason_Excel")]
|
[HttpPost]
|
public object Gy_ConkReason_Excel()
|
{
|
try
|
{
|
//获取文件名称
|
var file = HttpContext.Current.Request.Files[0];
|
//获取文件物理路径
|
string ExcelPath = HttpContext.Current.Server.MapPath("~/" + file.FileName);
|
//保存文件
|
file.SaveAs(ExcelPath);
|
|
NpoiHelper np = new NpoiHelper();
|
DataSet ExcelDs = np.ReadExcel(ExcelPath, 1, 1, "0");
|
|
//删除文件
|
File.Delete(ExcelPath);
|
|
//创建临时表
|
DataTable tb2 = new DataTable("dt2");
|
|
//添加列名
|
for (int i = 0; i < ExcelDs.Tables[0].Columns.Count; i++)
|
{
|
tb2.Columns.Add(ExcelDs.Tables[0].Rows[0][i].ToString());
|
}
|
|
//模板缺少列 但需要从数据库中查询出来显示在页面的字段
|
tb2.Columns.Add("HOrgID", typeof(Int32));//组织ID
|
|
//添加数据
|
for (int i = 1; i < ExcelDs.Tables[0].Rows.Count; i++)
|
{
|
DataRow row = tb2.NewRow();
|
for (int j = 0; j < ExcelDs.Tables[0].Columns.Count; j++)
|
{
|
row[j] = ExcelDs.Tables[0].Rows[i][j].ToString();
|
}
|
tb2.Rows.Add(row);
|
}
|
|
|
var error = "";
|
|
//查询没有的列
|
if (!tb2.Columns.Contains("组织代码"))
|
error += "没有找到【组织代码】的标题,";
|
|
if (!tb2.Columns.Contains("组织名称"))
|
error += "没有找到【组织名称】的标题,";
|
|
if (!tb2.Columns.Contains("故障原因"))
|
error += "没有找到【故障原因名称】的标题,";
|
|
if (!tb2.Columns.Contains("故障原因代码"))
|
error += "没有找到【故障原因代码】的标题,";
|
if (!tb2.Columns.Contains("备注"))
|
error += "没有找到【备注】的标题,";
|
if (!tb2.Columns.Contains("助记码"))
|
error += "没有找到【助记码】的标题,";
|
|
if (error.Length > 0)
|
{
|
objJsonResult.code = CodeConstant.FAIL;
|
objJsonResult.count = CountConstant.FAIL;
|
objJsonResult.Message = $"Excel模板存在错误,{error}\r\n";
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
|
for (int i = 0; i <= tb2.Rows.Count - 1; i++)
|
{
|
string HProcessName = "";
|
string HProcessNum = "";
|
string HORGNumber = "";
|
string HORGName = "";
|
|
|
HProcessName = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["故障原因"].ToString());
|
HProcessNum = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["故障原因代码"].ToString());
|
HORGNumber = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["组织代码"].ToString());
|
HORGName = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["组织名称"].ToString());
|
|
//检查物料
|
int index = i + 1;
|
|
if (HORGNumber != "")
|
{
|
|
//查询组织
|
ds = oCn.RunProcReturn("select * from Xt_ORGANIZATIONS where HNumber='" + HORGNumber + "' and Hname='" + HORGName + "'", "Xt_ORGANIZATIONS");
|
|
if (ds.Tables[0].Rows.Count == 0)
|
{
|
objJsonResult.code = CodeConstant.FAIL;
|
objJsonResult.count = CountConstant.FAIL;
|
objJsonResult.Message = "第" + index + "行,组织不存在!";
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
else
|
{
|
tb2.Rows[i]["HOrgID"] = ds.Tables[0].Rows[0]["HItemID"].ToString();
|
}
|
string HORGid = ds.Tables[0].Rows[0]["HItemID"].ToString();
|
|
//故障原因名称
|
if (HProcessName == "")
|
{
|
objJsonResult.code = CodeConstant.FAIL;
|
objJsonResult.count = CountConstant.FAIL;
|
objJsonResult.Message = "第" + index + "行,故障原因名称不能为空!";
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
|
//故障原因代码
|
if (HProcessNum == "")
|
{
|
objJsonResult.code = CodeConstant.FAIL;
|
objJsonResult.count = CountConstant.FAIL;
|
objJsonResult.Message = "第" + index + "行,故障原因代码不能为空!";
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
}
|
else
|
{
|
objJsonResult.code = CodeConstant.FAIL;
|
objJsonResult.count = CountConstant.FAIL;
|
objJsonResult.Message = "第" + index + "行,组织代码为空";
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
}
|
|
objJsonResult.code = CodeConstant.SUCCEED;
|
objJsonResult.count = CountConstant.SUCCEED;
|
objJsonResult.Message = error;
|
objJsonResult.data = tb2;
|
return objJsonResult;
|
}
|
catch (Exception e)
|
{
|
objJsonResult.code = CodeConstant.FAIL;
|
objJsonResult.count = CountConstant.FAIL;
|
objJsonResult.Message = "Exception!" + e.ToString();
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
}
|
#endregion
|
|
#region 故障原因项目 导入(保存)
|
[Route("Gy_ConkReason/Gy_ConkReason_btnSave")]
|
[HttpPost]
|
public object Gy_ConkReason_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_ConkReason_Edit", 1, false, user))
|
{
|
objJsonResult.code = CodeConstant.FAIL;
|
objJsonResult.count = CountConstant.FAIL;
|
objJsonResult.Message = "无保存权限!";
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
|
List<object> Excel = Newtonsoft.Json.JsonConvert.DeserializeObject<List<object>>(msg2);
|
List<Dictionary<string, string>> list = new List<Dictionary<string, string>>();
|
|
foreach (JObject item in Excel)
|
{
|
Dictionary<string, string> dic = new Dictionary<string, string>();
|
foreach (var itm in item.Properties())
|
{
|
dic.Add(itm.Name, itm.Value.ToString());
|
}
|
list.Add(dic);
|
}
|
|
oCn.BeginTran();
|
int i = 1;
|
foreach (Dictionary<string, string> item in list)
|
{
|
string HOrgID = item["HOrgID"].ToString();//组织ID
|
string HName = item["故障原因"].ToString();
|
string HNumber = item["故障原因代码"].ToString();
|
string HRemark = item["备注"].ToString();
|
string HHelpCode = item["助记码"].ToString();
|
string HUseFlag = "未检测";
|
string HShortNumber;
|
HShortNumber = DBUtility.ClsPub.GetShortNumber(HNumber);//短代码
|
if (HShortNumber.Trim() == "")
|
{
|
objJsonResult.code = CodeConstant.FAIL;
|
objJsonResult.count = CountConstant.FAIL;
|
objJsonResult.Message = "保存失败!短代码为空!";
|
objJsonResult.data = 1;
|
return objJsonResult;
|
}
|
int HEndFlag = 1;//末级标志
|
int HLevel = DBUtility.ClsPub.GetLevel(HNumber); //等级
|
|
|
if (!DBUtility.ClsPub.AllowNumber(HNumber.Trim()))
|
{
|
objJsonResult.code = CodeConstant.FAIL;
|
objJsonResult.count = CountConstant.FAIL;
|
objJsonResult.Message = "保存失败!代码中不能出现连续‘.’并且首位末位不能为‘.’!";
|
objJsonResult.data = 1;
|
return objJsonResult;
|
}
|
|
ds = oCn.RunProcReturn("select * from Gy_ConkReason where HNumber='" + HNumber + "'", "Gy_ConkReason");
|
|
if (ds.Tables[0].Rows.Count == 0)
|
{
|
oCn.RunProc("Insert into Gy_ConkReason " +
|
" (HNumber,HName,HHelpCode,HShortNumber,HParentID" +
|
",HLevel,HEndFlag,HStopflag,HRemark,HUseFlag,HMakeTime,HMakeEmp,HExplanation,HConkTypeID) " +
|
" Values('" + HNumber + "','" + HName + "','" + HHelpCode + "','" + HShortNumber + "'," + 0 +
|
"," + HLevel + "," + HEndFlag + "," + 0 + ",'" + HRemark +
|
"','" + HUseFlag + "',getdate(),'" + user + "','" + "" + "',0" +
|
")", ref DBUtility.ClsPub.sExeReturnInfo);
|
|
|
}
|
else
|
{
|
oCn.RunProc("UpDate Gy_ConkReason set " +
|
//固定赋值===============
|
"HName='" + HName + "'" +
|
",HShortNumber='" + HShortNumber + "'" +
|
",HHelpCode='" + HHelpCode + "'" +
|
",HRemark='" + HRemark + "'" +
|
",HModifyTime=getdate()" +
|
",HModifyEmp='" + user + "'" +
|
" where HNumber='" + HNumber + "'");
|
}
|
|
i++;
|
}
|
|
oCn.Commit();
|
|
objJsonResult.code = CodeConstant.SUCCEED;
|
objJsonResult.count = CountConstant.SUCCEED;
|
objJsonResult.Message = "导入成功!";
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
catch (Exception e)
|
{
|
LogService.Write(e);
|
objJsonResult.code = CodeConstant.FAIL;
|
objJsonResult.count = CountConstant.FAIL;
|
objJsonResult.Message = "Exception!" + e.ToString();
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
}
|
#endregion
|
#endregion
|
}
|
}
|