using DBUtility;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using WebAPI.Models;
using WebAPI.WebS;
namespace WebAPI.Service
{
public class YqnQbService
{
///
/// 获取单据号
///
///
public static ApiResult GetInterBillNo()
{
var hInterId= DBUtility.ClsPub.CreateBillID(ApiConfig.HBillType, ref DBUtility.ClsPub.sExeReturnInfo);
var hBillNo= DBUtility.ClsPub.CreateBillCode(ApiConfig.HBillType, ref DBUtility.ClsPub.sExeReturnInfo, true);
if (hInterId == 0 || string.IsNullOrEmpty(hBillNo))
return new ApiResult { code = -1, msg = "获取失败" };
DocumentsView documentsView = new DocumentsView()
{
HBillNo = hBillNo,
HInterID = hInterId
};
return new ApiResult { code = 1, msg = "获取成功", data = documentsView };
}
///
/// 扫码方法
///
public static ApiResult GetHbarCodeDetail(string sBillBarCode)
{
if (string.IsNullOrEmpty(sBillBarCode))
return new ApiResult { code = -1, msg = "条码不能为空" };
sBillBarCode = sBillBarCode.CompareTo("#") > 0 ? sBillBarCode.Split(Convert.ToChar("#"))[0] : sBillBarCode;
var dataSet = GetBarCodeDb(sBillBarCode);
if (dataSet == null || dataSet.Tables[0].Rows.Count == 0)
return new ApiResult { code = -1, msg = "不存在流转卡号" };
return new ApiResult { code = 1, msg = "查询成功",data=dataSet };
}
///
/// 流转卡回车方法
///
public static ApiResult GetProcDetail(string sBillNo, string sProcNo)
{
if (string.IsNullOrEmpty(sBillNo)||string.IsNullOrEmpty(sProcNo))
return new ApiResult { code = -1, msg = "条码和流转卡不能为空" };
var dataSet = GetProcDb(sBillNo, sProcNo);
if (dataSet == null || dataSet.Tables[0].Rows.Count == 0)
return new ApiResult { code = -1, msg = "流水号或流转卡号为空" };
return new ApiResult { code = 1, msg = "查询成功", data = dataSet };
}
///
/// 获取生产资源列表
///
public static ApiResult GetSourceList(string sWhere)
{
var dataSet = GetSourceDb(sWhere);
if (dataSet == null || dataSet.Tables[0].Rows.Count == 0)
return new ApiResult { code = -1, msg = "未查询到生产资源" };
return new ApiResult { code = 1, msg = "查询成功", data = dataSet };
}
///
/// 获取生产班组列表
///
public static ApiResult GetGroupList(string sWhere)
{
var dataSet = GetGroupDb(sWhere);
if (dataSet == null || dataSet.Tables[0].Rows.Count == 0)
return new ApiResult { code = -1, msg = "未查询到生产班组" };
return new ApiResult { code = 1, msg = "查询成功", data = dataSet };
}
///
/// 获取工作中心列表
///
public static ApiResult GetWorkCenterList(string sWhere)
{
var dataSet = GetGroupDb(sWhere);
if (dataSet == null || dataSet.Tables[0].Rows.Count == 0)
return new ApiResult { code = -1, msg = "未查询到工作中心" };
return new ApiResult { code = 1, msg = "查询成功", data = dataSet };
}
///
/// 进站接收单
///
public static ApiResult SetStationInBill(ClsSc_StationInBillMain oMain)
{
WebS.WebService1 oWebs = new WebS.WebService1();
string sErrMsg = string.Empty;
var result = oWebs.set_SaveStationInBill(oMain, ref sErrMsg);
if (!result)
{
return new ApiResult { code = -1, msg = sErrMsg };
}
return new ApiResult { code = 1, msg = "操作成功" };
}
///
/// 出站接收单
///
public static ApiResult SetStationOutBill(StationOutBillView omodel)
{
WebS.WebService1 oWebs = new WebS.WebService1();
string sErrMsg = string.Empty;
var result = SetOutBill(omodel);
return result;
}
#region sql语句
public static DataSet GetBarCodeDb(string billBarCode)
{
SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
var dataSet = oCN.RunProcReturn("select top 1 * from h_v_Sc_ProcessExchangeBillList where 单据号= '" + billBarCode + "'", "h_v_Sc_ProcessExchangeBillList");
return dataSet;
}
public static DataSet GetSourceDb(string sWhere)
{
SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
var dataSet = oCN.RunProcReturn("Select HItemID,HNumber 生产资源代码,HName 生产资源 from Gy_Source where HStopflag=0 " + sWhere + " Order by HItemID ", "Gy_Source");
return dataSet;
}
public static DataSet GetGroupDb(string sWhere)
{
SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
var dataSet = oCN.RunProcReturn("Select HItemID,HNumber 工作中心代码,HName 工作中心 from Gy_WorkCenter where HStopflag=0 " + sWhere + " Order by HItemID ", "Gy_Source");
return dataSet;
}
public static DataSet GetProcDb(string sBillNo, string sProcNo)
{
SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
var dataSet = oCN.RunProcReturn("select top 1 * from h_v_Sc_ProcessExchangeBillList where 单据号= '" + sBillNo + "' and 工序号='" + sProcNo + "'", "h_v_Sc_ProcessExchangeBillList");
return dataSet;
}
///
/// 工作中心
///
///
///
public static DataSet GetWorkCenterDb(string sWhere)
{
SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
var dataSet = oCN.RunProcReturn("Select HItemID,HNumber 工作中心代码,HName 工作中心 from Gy_Group where HStopflag=0 " + sWhere + " Order by HItemID ", "Gy_Source");
return dataSet;
}
private static ConcurrentDictionary dicLock=new System.Collections.Concurrent.ConcurrentDictionary();//并发锁
public static ApiResult SetOutBill(StationOutBillView omodel)
{
try
{
if (!dicLock.TryAdd(omodel.HBillNo, omodel.HBillNo))
return new ApiResult { code = -1, msg = "服务器繁忙" };
SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
omodel.HInterID = DBUtility.ClsPub.CreateBillID("3791", ref DBUtility.ClsPub.sExeReturnInfo);
oCN.BeginTran();
var sql = "Insert Into Sc_StationOutBillMain " +
"(HBillType,HBillSubType,HInterID,HBillNo,HBillStatus,HDate,HMaker,HMakeDate" +
",HYear,HPeriod,HRemark" +
",HICMOInterID,HICMOBillNo,HProcPlanInterID,HProcPlanEntryID,HProcPlanBillNo,HProcExchInterID,HProcExchEntryID" +
",HProcExchBillNo,HMaterID,HProcID,HICMOQty,HPlanQty,HStationOutTime,HSourceID" +
",HGroupID,HDeptID,HEmpID,HBarCode,HAddr,HBarCodeMaker,HBarCodeMakeDate" +
",HSupID,HQty,HPrice,HMoney" +
") " +
" values('3791','3791'," + omodel.HInterID.ToString() + ",'" + omodel.HBillNo + "'," + omodel.HBillStatus.ToString() + ",getdate(),'" + DBUtility.ClsPub.CurUserName + "',getdate()" +
"," + omodel.HYear.ToString() + "," + omodel.HPeriod.ToString() + ",'" + omodel.HRemark + "'" +
"," + omodel.HICMOInterID.ToString() + ",'" + omodel.HICMOBillNo + "'," + omodel.HProcPlanInterID.ToString() + "," + omodel.HProcPlanEntryID.ToString() + ",'" + omodel.HProcPlanBillNo + "'," + omodel.HProcExchInterID.ToString() + "," + omodel.HProcExchEntryID.ToString() +
",'" + omodel.HProcExchBillNo + "'," + omodel.HMaterID.ToString() + "," + omodel.HProcID.ToString() + "," + omodel.HICMOQty.ToString() + "," + omodel.HPlanQty.ToString() + ",getdate()," + omodel.HSourceID.ToString() +
"," + omodel.HGroupID.ToString() + "," + omodel.HDeptID.ToString() + "," + omodel.HEmpID.ToString() + ",'" + omodel.HBarCode + "','" + omodel.HAddr + "','" + omodel.HBarCodeMaker + "',getdate()" +
"," + omodel.HSupID.ToString() + "," + omodel.HQty.ToString() + "," + omodel.HPrice.ToString() + "," + omodel.HMoney.ToString() +
") ";
oCN.RunProc(sql);
oCN.Commit();
return new ApiResult { code = 1, msg = "新增成功" };
}
catch (Exception ex)
{
return new ApiResult { code = -1, msg = "保存错误/"+ex.ToString() };
}
finally
{
dicLock.TryRemove(omodel.HBillNo, out string key);
}
}
#endregion
}
}