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 Sc_FeedingErrorProofingController : ApiController
|
{
|
private json objJsonResult = new json();
|
SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
|
Pub_Class.ClsXt_SystemParameter oSystemParameter = new Pub_Class.ClsXt_SystemParameter();
|
DataSet ds, ds2;
|
|
#region 投料防错单 扫描 物料条码
|
[Route("Sc_FeedingErrorProofingController/MaterErrorPreventionScanCode")]
|
[HttpGet]
|
public object MaterErrorPreventionScanCode(string HBarCode)
|
{
|
ds = oCN.RunProcReturn($@"select top 1 m.HNumber HMaterNumber, a.* from Gy_BarCodeBill a
|
left join Gy_Material m with(nolock) on a.HMaterID = m.HItemID where a.HBarCode = '{HBarCode}'", "Gy_BarCodeBill");
|
if(ds == null || ds.Tables[0].Rows.Count == 0)
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "所扫描的条码不存在!";
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
|
if(ds.Tables[0].Rows[0]["HStopFlag"].ToString() == "1")
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "条码已被关闭,不允许扫码!";
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
|
if (ds.Tables[0].Rows[0]["HBarCodeStatus"].ToString() == "已投料")
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "该条码对应的物料已投料,不允许重复投料!";
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
|
if (ds.Tables[0].Rows[0]["HBarCodeStatus"].ToString() != "正常" && ds.Tables[0].Rows[0]["HBarCodeStatus"].ToString() != "")
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "条码状态异常,不允许扫码!";
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
|
objJsonResult.code = "1";
|
objJsonResult.count = 1;
|
objJsonResult.Message = "";
|
objJsonResult.data = ds.Tables[0];
|
return objJsonResult;
|
}
|
#endregion
|
|
#region 投料放错单 保存单据
|
[Route("Sc_FeedingErrorProofingController/saveBill")]
|
[HttpPost]
|
public object saveBill([FromBody] JObject sMainSub)
|
{
|
var _value = sMainSub["sMainSub"].ToString();
|
string msg1 = _value.ToString();
|
string[] sArray = msg1.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
|
string mainBill = sArray[0].ToString(); //主表数据
|
string user = sArray[1].ToString();
|
string operationType = sArray[2].ToString();
|
string subBill = sArray[3].ToString(); // 子表数据
|
oCN.BeginTran();
|
try
|
{
|
JObject HMainBill = JObject.Parse(mainBill);
|
JArray HSubBill = JArray.Parse(subBill);
|
if(operationType.ToString() == "1")
|
{
|
// 新增
|
oCN.RunProc($@"insert into Sc_FeedingErrorProofingBillMain (HYear, HPeriod, HBillType, HBillSubType, HInterID, HDate, HBillNo, HBillStatus, HMaker, HMakeDate, HEmpID
|
, HBarCode, HRemark, HBackRemark, HMainSourceBillType, HMainSourceInterID, HMainSourceEntryID, HMainSourceBillNo, HWorkStationID, HDeptID, HOrgID)
|
values('{DateTime.Now.Year}', '{DateTime.Now.Month}', '{HMainBill["HBillType"]}', '', '{HMainBill["HInterID"]}', '{HMainBill["HDate"]}',
|
'{HMainBill["HBillNo"]}', 1, 'user', getdate(),{HMainBill["HEmpID"]}, '{HMainBill["HWorkCode"]}', '', '', '', 0, 0, '', {HMainBill["HWorkStationID"]},
|
{HMainBill["HDeptID"]},{HMainBill["HOrgID"]} )");
|
}else if(operationType.ToString() == "4")
|
{
|
// 更新
|
oCN.RunProc($@"");
|
// 删除子表
|
oCN.RunProc($@"");
|
}
|
|
int i = 1;
|
// 插入子表
|
foreach(JObject HSubItem in HSubBill)
|
{
|
oCN.RunProc($@"insert into Sc_FeedingErrorProofingBillSub (HInterID,HBillNo_bak, HEntryID, HRemark, HSourceInterID, HSourceEntryID, HSourceBillNo, HSourceBillType,
|
HRelationQty, HRelationMoney, HMaterID, HUnitID, HQty, HScanDate, HBarCode)
|
values('{HMainBill["HInterID"]}','{HMainBill["HBillNo"]}', {i++}, '', 0, 0, '', '', 0, 0, {HSubItem["HMaterID"]}, {HSubItem["HUnitID"]}, {HSubItem["HQty"]}, '{HSubItem["HScanDate"]}',
|
{HSubItem["HBarCode"]})");
|
|
// 通过系统参数判断是否需要 反写条码主档单据状态
|
if(oSystemParameter.ShowBill(ref DBUtility.ClsPub.sErrInfo))
|
{
|
if(oSystemParameter.omodel.Sc_FeedingErrorProofingBill_BarCodeCTL == "Y")
|
{
|
oCN.RunProc($@"update Gy_BarCodeBill set HBarCodeStatus='已投料' where HBarCode = '{HSubItem["HBarCode"]}'");
|
}
|
}
|
}
|
|
//TODO 通过保存后控制反写条码状态
|
|
|
oCN.Commit();
|
objJsonResult.code = "1";
|
objJsonResult.count = 1;
|
objJsonResult.Message = "Success!";
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
catch (Exception e)
|
{
|
oCN.RollBack();
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "Exception!" + e.ToString();
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
}
|
#endregion
|
|
#region
|
[Route("Sc_FeedingErrorProofingController/delBill")]
|
[HttpGet]
|
public object delBill(long HInterID)
|
{
|
oCN.BeginTran();
|
try
|
{
|
ds = oCN.RunProcReturn($@"select * from Sc_FeedingErrorProofingBillSub where HInterID = {HInterID}", "Sc_FeedingErrorProofingBillSub");
|
|
foreach(DataRow subItem in ds.Tables[0].Rows)
|
{
|
// 反写 条码主档条码状态
|
oCN.RunProc($@"update Gy_BarCodeBill set HBarCodeStatus='' where HBarCode = '{subItem["HBarCode"]}'");
|
}
|
|
// 删除子表
|
oCN.RunProc($@"delete from Sc_FeedingErrorProofingBillSub where HInterID = {HInterID}");
|
// 删除主表
|
oCN.RunProc($@"delete from Sc_FeedingErrorProofingBillMain where HInterID = {HInterID}");
|
|
|
oCN.Commit();
|
objJsonResult.code = "1";
|
objJsonResult.count = 1;
|
objJsonResult.Message = "Success!";
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
catch (Exception e)
|
{
|
oCN.RollBack();
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "Exception!" + e.ToString();
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
}
|
#endregion
|
|
#region
|
[Route("Sc_FeedingErrorProofingController/getBillListPage")]
|
[HttpGet]
|
public object getBillListPage(string sWhere, string user, int page, int size)
|
{
|
try
|
{
|
List<object> columnNameList = new List<object>();
|
|
//查看权限
|
|
if (sWhere == null || sWhere.Equals(""))
|
{
|
string sql = $@"
|
select count(1) count from h_v_Sc_FeedingErrorProofingBillList
|
select * from h_v_Sc_FeedingErrorProofingBillList order by 单据号 desc
|
offset {(page - 1) * size} rows fetch next {size} rows only";
|
ds = oCN.RunProcReturn(sql, "h_v_Sc_FeedingErrorProofingBillList");
|
}
|
else
|
{
|
string sql1 = $@"
|
select count(1) count from h_v_Sc_FeedingErrorProofingBillList where 1 = 1 {sWhere}
|
select * from h_v_Sc_FeedingErrorProofingBillList where 1 = 1
|
{sWhere} order by 单据号 desc
|
offset {(page - 1) * size} rows fetch next {size} rows only";
|
ds = oCN.RunProcReturn(sql1, "h_v_Sc_FeedingErrorProofingBillList");
|
}
|
|
//添加列名
|
foreach (DataColumn col in ds.Tables[1].Columns)
|
{
|
Type dataType = col.DataType;
|
string ColmString = "{\"ColmCols\":\"" + col.ColumnName + "\",\"ColmType\":\"" + dataType.Name + "\"}";
|
columnNameList.Add(JsonConvert.DeserializeObject(ColmString));//获取到DataColumn列对象的列名
|
}
|
|
objJsonResult.code = "1";
|
objJsonResult.count = 1;
|
objJsonResult.Message = "Sucess!";
|
objJsonResult.data = ds.Tables[1];
|
objJsonResult.list = columnNameList;
|
return objJsonResult;
|
}
|
catch (Exception ex)
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "查询数据异常,请与管理员联系!" + ex.ToString();
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
}
|
#endregion
|
|
#region
|
[Route("Sc_FeedingErrorProofingController/getBillListDetai")]
|
[HttpGet]
|
public object getBillListDetai(int HInterID)
|
{
|
try
|
{
|
List<object> columnNameList = new List<object>();
|
|
string sql = $@"
|
select top 1 * from h_v_Sc_FeedingErrorProofingBillDetai where HInterID1 = {HInterID}";
|
ds = oCN.RunProcReturn(sql, "h_v_Sc_FeedingErrorProofingBillList");
|
|
//添加列名
|
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列对象的列名
|
}
|
|
objJsonResult.code = "1";
|
objJsonResult.count = 1;
|
objJsonResult.Message = "Sucess!";
|
objJsonResult.data = ds.Tables[0];
|
objJsonResult.list = columnNameList;
|
return objJsonResult;
|
}
|
catch (Exception ex)
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "查询数据异常,请与管理员联系!" + ex.ToString();
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
}
|
#endregion
|
}
|
}
|