爱思开
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

232 lines
10 KiB

using ICSSoft.Common;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
using ICSSoft.Entity;
namespace ICSSoft.DataProject
{
public class ICSQueryService
{
private static log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
private static string connString = System.Configuration.ConfigurationManager.AppSettings["ConnStr"];
#region 查询物料信息
public static DataTable MaterialGet(ICSQueryModel JsonData)
{
var language = LanguageHelper.GetName("WMSAPIInfo");
using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
{
conn.Open();
SqlTransaction sqlTran = conn.BeginTransaction();
SqlCommand cmd = new SqlCommand();
cmd.Transaction = sqlTran;
cmd.Connection = conn;
try
{
string sql = @"IF NOT EXISTS ( SELECT LotNo FROM ICSInventoryLot WHERE LotNo = '{0}' AND WorkPoint = '{1}' )
BEGIN
SELECT a.InvCode,a.InvName,a.InvStd,b.LotNo,c.Quantity,a.InvUnit,d.WarehouseCode,d.WarehouseName,e.LocationCode,e.LocationName,f.ProjectCode,f.Brand,f.BatchCode,f.cFree1,f.cFree2,f.cFree3,f.cFree4,f.cFree5,f.cFree6,f.cFree7,f.cFree8,f.cFree9,f.cFree10
FROM
ICSInventory a
INNER JOIN ICSInventoryLot b ON b.InvCode = a.InvCode
AND b.WorkPoint = a.WorkPoint
INNER JOIN ICSWareHouseLotInfo c ON c.InvCode = b.InvCode
AND c.WorkPoint = b.WorkPoint
INNER JOIN ICSWarehouse d ON d.WarehouseCode = c.WarehouseCode
AND d.WorkPoint = c.WorkPoint
INNER JOIN ICSLocation e ON e.WHID = d.ID
AND e.WorkPoint = d.WorkPoint
INNER JOIN ICSExtension f ON f.ID = b.ExtensionID
AND f.WorkPoint = e.WorkPoint
WHERE
a.InvCode = '{0}'
AND a.WorkPoint = '{1}' RETURN
END
SELECT a.InvCode,a.InvName,a.InvStd,b.LotNo,c.Quantity,a.InvUnit,d.WarehouseCode,d.WarehouseName,e.LocationCode,e.LocationName,f.ProjectCode,f.Brand,f.BatchCode,f.cFree1,f.cFree2,f.cFree3,f.cFree4,f.cFree5,f.cFree6,f.cFree7,f.cFree8,f.cFree9,f.cFree10
FROM
ICSInventory a
INNER JOIN ICSInventoryLot b ON b.InvCode = a.InvCode
AND b.WorkPoint = a.WorkPoint
INNER JOIN ICSWareHouseLotInfo c ON c.InvCode = b.InvCode
AND c.WorkPoint = b.WorkPoint
INNER JOIN ICSWarehouse d ON d.WarehouseCode = c.WarehouseCode
AND d.WorkPoint = c.WorkPoint
INNER JOIN ICSLocation e ON e.WHID = d.ID
AND e.WorkPoint = d.WorkPoint
INNER JOIN ICSExtension f ON f.ID = b.ExtensionID
AND f.WorkPoint = e.WorkPoint
WHERE
a.InvCode = ( SELECT InvCode FROM ICSInventoryLot WHERE LotNo = '{0}' AND WorkPoint = '{1}' )
AND a.WorkPoint = '{1}'
";
sql = string.Format(sql, JsonData.Material, JsonData.WorkPoint);
DataTable data = DBHelper.SQlReturnData(sql, cmd);
cmd.Transaction.Commit();
return data;
}
catch (Exception ex)
{
if (cmd.Transaction != null)
cmd.Transaction.Rollback();
log.Error(ex.Message);
throw new Exception(ex.Message);
}
finally
{
if (conn.State == ConnectionState.Open)
{
conn.Close();
}
conn.Dispose();
}
}
}
#endregion
#region 查询条码信息(库存)
public static DataTable BarCodeGet(BarCodeModel JsonData)
{
var language = LanguageHelper.GetName("WMSAPIInfo");
using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
{
conn.Open();
SqlTransaction sqlTran = conn.BeginTransaction();
SqlCommand cmd = new SqlCommand();
cmd.Transaction = sqlTran;
cmd.Connection = conn;
try
{
string sql = @"SELECT a.LotNo,b.InvCode,b.InvName,b.InvStd,c.Quantity,b.InvUnit,e.WarehouseCode,e.WarehouseName,d.LocationCode,d.LocationName,f.ProjectCode,f.Brand,f.BatchCode,f.cFree1,f.cFree2,f.cFree3,f.cFree4,f.cFree5,f.cFree6,f.cFree7,f.cFree8,f.cFree9,f.cFree10
FROM ICSInventoryLot a
INNER JOIN ICSInventory b ON b.InvCode=a.InvCode AND b.WorkPoint=a.WorkPoint
INNER JOIN ICSWareHouseLotInfo c ON c.LotNo=a.LotNo AND c.WorkPoint=a.WorkPoint
INNER JOIN ICSLocation d ON d.LocationCode=c.LocationCode AND d.WorkPoint=c.WorkPoint
INNER JOIN ICSWarehouse e ON e.ID=d.WHID AND e.WorkPoint=d.WorkPoint
INNER JOIN ICSExtension f ON f.ID=a.ExtensionID AND f.WorkPoint=e.WorkPoint
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
";
sql = string.Format(sql, JsonData.Code, JsonData.WorkPoint);
DataTable data = DBHelper.SQlReturnData(sql, cmd);
cmd.Transaction.Commit();
return data;
}
catch (Exception ex)
{
if (cmd.Transaction != null)
cmd.Transaction.Rollback();
log.Error(ex.Message);
throw new Exception(ex.Message);
}
finally
{
if (conn.State == ConnectionState.Open)
{
conn.Close();
}
conn.Dispose();
}
}
}
#endregion
#region 查询库位信息
public static DataTable LocationGet(ICSQueryModel JsonData)
{
var language = LanguageHelper.GetName("WMSAPIInfo");
using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
{
conn.Open();
SqlTransaction sqlTran = conn.BeginTransaction();
SqlCommand cmd = new SqlCommand();
cmd.Transaction = sqlTran;
cmd.Connection = conn;
try
{
string sql = @"SELECT c.LotNo,e.InvCode,e.InvName,e.InvStd,c.Quantity,e.InvUnit,b.WarehouseCode,b.WarehouseName,a.LocationCode,a.LocationName,f.ProjectCode,f.Brand,f.BatchCode,f.cFree1,f.cFree2,f.cFree3,f.cFree4,f.cFree5,f.cFree6,f.cFree7,f.cFree8,f.cFree9,f.cFree10
FROM ICSLocation a
INNER JOIN ICSWarehouse b ON b.ID=a.WHID AND b.WorkPoint=a.WorkPoint
INNER JOIN ICSWareHouseLotInfo c ON c.LocationCode=a.LocationCode AND c.WorkPoint=a.WorkPoint
INNER JOIN ICSInventoryLot d ON d.LotNo=c.LotNo AND d.WorkPoint=c.WorkPoint
INNER JOIN ICSInventory e ON e.InvCode=d.InvCode AND e.WorkPoint=d.WorkPoint
INNER JOIN ICSExtension f ON f.ID=d.ExtensionID AND f.WorkPoint=d.WorkPoint
WHERE a.LocationCode='{0}' AND a.WorkPoint='{1}' AND c.Quantity>0
";
sql = string.Format(sql, JsonData.LocationCode, JsonData.WorkPoint);
DataTable data = DBHelper.SQlReturnData(sql, cmd);
cmd.Transaction.Commit();
return data;
}
catch (Exception ex)
{
if (cmd.Transaction != null)
cmd.Transaction.Rollback();
log.Error(ex.Message);
throw new Exception(ex.Message);
}
finally
{
if (conn.State == ConnectionState.Open)
{
conn.Close();
}
conn.Dispose();
}
}
}
#endregion
#region 查询条码信息(条码表)
public static DataTable BarCodeGetNew(BarCodeModel JsonData)
{
var language = LanguageHelper.GetName("WMSAPIInfo");
using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
{
conn.Open();
SqlTransaction sqlTran = conn.BeginTransaction();
SqlCommand cmd = new SqlCommand();
cmd.Transaction = sqlTran;
cmd.Connection = conn;
try
{
string sql = @"SELECT a.LotNo,b.InvCode,b.InvName,b.InvStd,a.Quantity,b.InvUnit,f.ProjectCode,f.Brand,f.BatchCode,f.cFree1,f.cFree2,f.cFree3,f.cFree4,f.cFree5,f.cFree6,f.cFree7,f.cFree8,f.cFree9,f.cFree10
FROM ICSInventoryLot a
INNER JOIN ICSInventory b ON b.InvCode=a.InvCode AND b.WorkPoint=a.WorkPoint
INNER JOIN ICSExtension f ON f.ID=a.ExtensionID AND f.WorkPoint=a.WorkPoint
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
";
sql = string.Format(sql, JsonData.Code, JsonData.WorkPoint);
DataTable data = DBHelper.SQlReturnData(sql, cmd);
cmd.Transaction.Commit();
return data;
}
catch (Exception ex)
{
if (cmd.Transaction != null)
cmd.Transaction.Rollback();
log.Error(ex.Message);
throw new Exception(ex.Message);
}
finally
{
if (conn.State == ConnectionState.Open)
{
conn.Close();
}
conn.Dispose();
}
}
}
#endregion
}
}