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
|
{
|
//查看权限
|
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);
|
|
//if (ds.Tables[0].Rows.Count != 0 || ds != null)
|
//{
|
objJsonResult.code = "1";
|
objJsonResult.count = 1;
|
objJsonResult.Message = "Sucess!";
|
objJsonResult.data = ds.Tables[0];
|
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");
|
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 [故障原因删除功能]
|
[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
|
}
|
}
|