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;
|
|
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", 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) //审核判断
|
{
|
oCN.RunProc("update Gy_ConkReason set HCheckEmp='" + CurUserName + "',HCheckTime=getdate() where HItemID=" + HInterID);
|
|
objJsonResult.code = "1";
|
objJsonResult.count = 1;
|
objJsonResult.Message = "审核成功";
|
objJsonResult.data = null;
|
}
|
if (IsAudit == 1) //反审核判断
|
{
|
oCN.RunProc("update Gy_ConkReason set HCheckEmp='',HCheckTime=null where HItemID=" + HInterID);
|
|
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) //禁用判断
|
{
|
oCN.RunProc("update Gy_ConkReason set HStopEmp='" + CurUserName + "',HStopTime=getdate(),HStopflag=1 where HItemID=" + HInterID);
|
|
objJsonResult.code = "1";
|
objJsonResult.count = 1;
|
objJsonResult.Message = "禁用成功";
|
objJsonResult.data = null;
|
}
|
if (IsStop == 1) //反禁用判断
|
{
|
oCN.RunProc("update Gy_ConkReason set HStopEmp='',HStopTime=null,HStopflag=0 where HItemID=" + HInterID);
|
|
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.RunProc("Delete from Gy_ConkReason where HItemID=" + lngBillKey);
|
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)
|
{
|
oCn.RunProc("Insert into Gy_ConkReason " +
|
" (HNumber,HName,HHelpCode,HShortNumber,HParentID" +
|
",HLevel,HEndFlag,HStopflag,HRemark,HUseFlag,HMakeTime,HMakeEmp,HExplanation,HConkTypeID) " +
|
" Values('" + oBill.HNumber + "','" + oBill.HName + "','" + oBill.HHelpCode + "','" + oBill.HShortNumber + "'," + oBill.HParentID.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);
|
|
objJsonResult.code = "0";
|
objJsonResult.count = 1;
|
objJsonResult.Message = "保存成功!";
|
//WebAPIController.Add_Log("送货单下推", UserName, "生成送货单");
|
objJsonResult.data = 1;
|
return objJsonResult;
|
}
|
else
|
{
|
oCN.RunProc("UpDate Gy_ConkReason set " +
|
" HNumber='" + oBill.HNumber + "'" + //固定赋值===============
|
",HName='" + oBill.HName + "'" +
|
",HShortNumber='" + oBill.HShortNumber + "'" +
|
",HHelpCode='" + oBill.HHelpCode + "'" +
|
",HUseFlag='" + oBill.HUseFlag + "'" +
|
",HRemark='" + oBill.HRemark + "'" +
|
",HExplanation='" + oBill.HExplanation + "'" +
|
",HModifyTime=getdate()" +
|
",HModifyEmp='" + msg3 + "'" +
|
",HStopflag=" + Convert.ToString(oBill.HStopflag ? 1 : 0) +
|
" where HInterID=" + oBill.HItemID.ToString());
|
|
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
|
}
|
}
|