using Newtonsoft.Json;
|
using Newtonsoft.Json.Linq;
|
using Pub_Class;
|
using SyntacticSugar.constant;
|
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
|
{
|
public class Gy_MateNumRelationController : ApiController
|
{
|
//获取系统参数
|
Pub_Class.ClsXt_SystemParameter oSystemParameter = new Pub_Class.ClsXt_SystemParameter();
|
public DBUtility.ClsPub.Enum_BillStatus BillStatus;
|
|
private json objJsonResult = new json();
|
SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
|
DataSet ds;
|
|
|
#region 列表
|
[Route("Gy_MateNumRelation/list")]
|
[HttpGet]
|
public object list(string sWhere, string user)
|
{
|
try
|
{
|
List<object> columnNameList = new List<object>();
|
//查看权限
|
if (!DBUtility.ClsPub.Security_Log("Gy_MateNumRelation_Sec_Query", 1, false, user))
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "无查看权限";
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
string sql1 = string.Format(@"select * from h_v_Gy_MateNumRelation_SecList where 1=1");
|
if (sWhere == null || sWhere.Equals(""))
|
{
|
ds = oCN.RunProcReturn(sql1 + sWhere + "order by HItemID", "h_v_Gy_MateNumRelation_SecList");
|
}
|
else
|
{
|
string sql = sql1 + sWhere + "order by HItemID ";
|
ds = oCN.RunProcReturn(sql, "h_v_Gy_MateNumRelation_SecList");
|
}
|
|
//添加列名
|
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 = 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 cx编辑获取信息
|
/// <summary>
|
/// 根据基础资料ID 查找记录
|
///参数:string sql。
|
///返回值:object。
|
/// </summary>
|
[Route("Gy_MateNumRelation/cx")]
|
[HttpGet]
|
public object cx(long HCusID)
|
{
|
try
|
{
|
ds = oCN.RunProcReturn("select * from h_v_Gy_MateNumRelation_SecEdit where HCusID = " + HCusID, "h_v_Gy_MateNumRelation_SecEdit");
|
if (ds == null || ds.Tables[0].Rows.Count == 0)
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "false!";
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
else
|
{
|
objJsonResult.code = "1";
|
objJsonResult.count = 1;
|
objJsonResult.Message = "Sucess!";
|
objJsonResult.data = ds.Tables[0];
|
return objJsonResult;
|
}
|
}
|
catch (Exception e)
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "Exception!" + e.ToString();
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
}
|
|
[Route("Gy_MateNumRelation/getDetail")]
|
[HttpGet]
|
public object getDetail(long HItemID)
|
{
|
try
|
{
|
ds = oCN.RunProcReturn("select * from h_v_Gy_MateNumRelation_SecEdit where HItemID = " + HItemID, "h_v_Gy_MateNumRelation_SecEdit");
|
if (ds == null || ds.Tables[0].Rows.Count == 0)
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "false!";
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
else
|
{
|
objJsonResult.code = "1";
|
objJsonResult.count = 1;
|
objJsonResult.Message = "Sucess!";
|
objJsonResult.data = ds.Tables[0];
|
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_MateNumRelation/Delete")]
|
[HttpGet]
|
public object DeltetGy_MateNumRelation(string HItemID, string user)
|
{
|
DataSet ds;
|
try
|
{
|
//删除权限
|
if (!DBUtility.ClsPub.Security_Log("Gy_MateNumRelation_Sec_Delete", 1, false, user))
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "无删除权限";
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
|
SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
|
if (string.IsNullOrWhiteSpace(HItemID))
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "HItemID为空!";
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
oCN.BeginTran();//开始事务
|
ds = oCN.RunProcReturn("select * from Gy_MateNumRelation_Sec where HItemID=" + HItemID, "Gy_MateNumRelation_Sec");
|
if (ds == null || ds.Tables[0].Rows.Count == 0)
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "没有数据,无法删除!";
|
objJsonResult.data = null;
|
return objJsonResult; ;
|
}
|
string HUseFlag = Convert.ToString(ds.Tables[0].Rows[0]["HChecker"]);
|
if (HUseFlag != "")
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "此项目已审核,不能删除!";
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
|
|
oCN.RunProc("delete from Gy_MateNumRelation_Sec where HItemID=" + HItemID);
|
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 保存
|
|
#region 客户物料对应表保存
|
[Route("Gy_MateNumRelation/SaveGy_MateNumRelation")]
|
[HttpPost]
|
public object SaveGy_MateNumRelation([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();//hcusid
|
string msg4 = sArray[2].ToString();//user
|
|
//删除权限
|
if (!DBUtility.ClsPub.Security_Log("Gy_MateNumRelation_Sec_Edit", 1, false, msg4))
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "无编辑权限";
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
if(msg3=="" || msg3 == "0")
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "请选择客户";
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
try
|
{
|
List<Models.Gy_MateNumRelation_Sec> lsmain = new List<Models.Gy_MateNumRelation_Sec>();
|
msg2 = msg2.Substring(1, msg2.Length - 2);
|
msg2 = msg2.Replace("\\", "");
|
msg2 = msg2.Replace("\n", ""); //\n
|
msg2 = "[" + msg2.ToString() + "]";
|
lsmain = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Models.Gy_MateNumRelation_Sec>>(msg2);
|
oCN.BeginTran();
|
//删除已经关联的数据
|
oCN.RunProc("Delete From Gy_MateNumRelation_Sec where HCusID='" + msg3.ToString() + "'");
|
foreach (Models.Gy_MateNumRelation_Sec oItem in lsmain)
|
{
|
//重新写入关联数据
|
oCN.RunProc("insert into Gy_MateNumRelation_Sec (HCusID,HMaterID,HCusRelationNumber,HCusRelationName,HMaker,HMakeDate,HCusRelationModel,HTemplateID) " +
|
"values ('" + msg3 + "','" + oItem.HMaterID + "','" + oItem.HCusRelationNumber + "','" + oItem.HCusRelationName + "','" + msg4 + "',getdate(),' " + oItem.HCusRelationModel + "'," + oItem.HTemplateID +
|
")");
|
}
|
oCN.Commit();
|
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
|
|
#endregion
|
|
#region 审核、反审核
|
/// <summary>
|
///
|
/// </summary>
|
/// <param name="HInterID">单据ID</param>
|
/// <param name="IsAudit">审核(0),反审核(1)</param>
|
/// <param name="CurUserName">审核人</param>
|
/// <returns></returns>
|
[Route("Gy_MateNumRelation/CheckGy_MateNumRelation")]
|
[HttpGet]
|
public object CheckGy_MateNumRelation(long HInterID, int IsAudit, string CurUserName)
|
{
|
try
|
{
|
//审核权限
|
if (!DBUtility.ClsPub.Security_Log_second("Gy_MateNumRelation_Sec_Check", 1, false, CurUserName))
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "审核失败!无权限!";
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
|
var ds = oCN.RunProcReturn("select * from Gy_MateNumRelation_Sec where HItemID=" + HInterID, "Gy_MateNumRelation");
|
if (ds.Tables[0].Rows.Count > 0)
|
{
|
if (IsAudit == 0) //审核判断
|
{
|
if (ds.Tables[0].Rows[0]["HChecker"].ToString() != "")
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "单据已审核!不能再次审核!";
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
}
|
if (IsAudit == 1) //反审核判断
|
{
|
if (ds.Tables[0].Rows[0]["HChecker"].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_MateNumRelation_Sec set HChecker='" + CurUserName + "',HCheckDate=getdate() where HItemID=" + HInterID);
|
|
objJsonResult.code = "1";
|
objJsonResult.count = 1;
|
objJsonResult.Message = "审核成功";
|
objJsonResult.data = null;
|
}
|
if (IsAudit == 1) //反审核判断
|
{
|
oCN.RunProc("update Gy_MateNumRelation_Sec set HChecker='',HCheckDate=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="Type">审核(0),反审核(1)</param>
|
/// <param name="HMaker">审核人</param>
|
/// <returns></returns>
|
[Route("Gy_MateNumRelation/CheckAll")]
|
[HttpGet]
|
public object CheckAll(string ids, int Type, string HMaker)
|
{
|
try
|
{
|
//处理字符串
|
if (!string.IsNullOrEmpty(ids))
|
{
|
long[] idArray = Array.ConvertAll(ids.Split(','), long.Parse);
|
// 处理idArray...
|
for (int i = 0; i < idArray.Length; i++)
|
{
|
objJsonResult = (json)CheckGy_MateNumRelation(idArray[i], Type, HMaker);//审核执行
|
if (objJsonResult.count == 0)
|
{
|
|
objJsonResult.Message += "第" + (i + 1) + "行出现问题无法继续完成";
|
return objJsonResult;
|
}
|
}
|
}
|
else
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "请选择正确行";
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
|
objJsonResult.code = CodeConstant.SUCCEED;
|
objJsonResult.count = CountConstant.SUCCEED;
|
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
|
}
|
}
|