纽威
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.
 
 
 
 
 

200 lines
8.4 KiB

using ICSSoft.Common;
using ICSSoft.Entity;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ICSSoft.DataProject
{
/// <summary>
/// 管控方式
/// </summary>
public class ICSControlModeService
{
private static log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
private static string connString = System.Configuration.ConfigurationManager.AppSettings["ConnStr"];
private static string ERPDB = System.Configuration.ConfigurationManager.AppSettings["ERPDB"];
DataTable table = null;
SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString);
string sql = string.Empty;
string sqlInfo = string.Empty;
VerificationMethod verification = new VerificationMethod();
/// <summary>
/// 获取当前启用的管控方式
/// </summary>
/// <param name="cmd"></param>
/// <param name="language"></param>
/// <returns></returns>
/// <exception cref="Exception"></exception>
public static ControlMode GetControlMode()
{
using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
{
conn.Open();
SqlCommand cmd = new SqlCommand();
SqlTransaction sqlTran = conn.BeginTransaction();
cmd.Transaction = sqlTran;
cmd.Connection = conn;
try
{
string sql = @"SELECT TOP 1 F_ItemCode as itemCode,F_ItemName as itemName,F_EnabledMark as enableMark
FROM [dbo].[Sys_SRM_ItemsDetail] WHERE F_ItemId='14361ce1-c5e3-4e85-a253-51aa3cdde3e6'AND F_EnabledMark='1' ORDER BY F_ItemCode";
DataTable table = DBHelper.SQlReturnData(sql, cmd);
string json = JsonConvert.SerializeObject(table);
List<ControlMode> model = JsonConvert.DeserializeObject<List<ControlMode>>(json);
cmd.Transaction.Commit();
return model[0];
}
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();
}
}
}
/// <summary>
/// 获取建议库位方式
/// </summary>
/// <param name="cmd"></param>
/// <param name="language"></param>
/// <returns></returns>
/// <exception cref="Exception"></exception>
public static ControlMode GetSuLocation()
{
using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
{
conn.Open();
SqlCommand cmd = new SqlCommand();
SqlTransaction sqlTran = conn.BeginTransaction();
cmd.Transaction = sqlTran;
cmd.Connection = conn;
try
{
string sql = @"SELECT Top 1 a.F_ItemCode as itemCode,a.F_ItemName as itemName,a.F_EnabledMark as enableMark
FROM [dbo].[Sys_SRM_ItemsDetail] a
LEFT JOIN [dbo].[Sys_SRM_Items] b ON a.F_ItemId=b.F_Id AND b.F_EnabledMark='1'
WHERE F_ItemId='c8767643-1429-48b1-ad31-c6b19a1dfcb9'AND a.F_EnabledMark='1' ORDER BY a.F_ItemCode";
DataTable table = DBHelper.SQlReturnData(sql, cmd);
string json = JsonConvert.SerializeObject(table);
List<ControlMode> model = JsonConvert.DeserializeObject<List<ControlMode>>(json);
cmd.Transaction.Commit();
return model?.FirstOrDefault();
}
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();
}
}
}
/// <summary>
/// 根据条码获取信息
/// </summary>
/// <param name="LotNo"></param>
/// <param name="WorkPoint"></param>
/// <returns></returns>
/// <exception cref="Exception"></exception>
public static string QueryLotNo(string LotNo,string WorkPoint)
{
using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
{
conn.Open();
SqlCommand cmd = new SqlCommand();
SqlTransaction sqlTran = conn.BeginTransaction();
cmd.Transaction = sqlTran;
cmd.Connection = conn;
try
{
string sql = @"SELECT a.ID,
con.ContainerCode,
con.ContainerName,
a.LotNo,
a.InvCode,
inv.InvName,
inv.InvStd,
inv.InvUnit,-- {0}
inv.AmountUnit,
ext.ID AS ExtensionID,
ext.ProjectCode,
ext.Version,
ext.BatchCode,
ext.Brand,
ext.cFree1,
ext.cFree2,
ext.cFree3,
ext.cFree4,
ext.cFree5,
ext.cFree6,
ext.cFree7,
ext.cFree8,
ext.cFree9,
ext.cFree10,
a.MUSER AS [ USER ],
a.MTIME AS [ MTime ]
FROM
ICSInventoryLot a
LEFT JOIN ICSContainerLot conlot ON a.LotNo = conlot.LotNo AND a.WorkPoint = conlot.WorkPoint
LEFT JOIN ICSContainer con ON conlot.ContainerID = con.ID AND conlot.WorkPoint = con.WorkPoint
INNER JOIN ICSInventory inv ON a.InvCode = inv.InvCode AND a.WorkPoint = inv.WorkPoint
INNER JOIN ICSExtension ext ON a.ExtensionID = ext.ID AND a.WorkPoint = ext.WorkPoint
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'";
sql = string.Format(sql, LotNo, WorkPoint);
DataTable table = DBHelper.SQlReturnData(sql, cmd);
string json = JsonConvert.SerializeObject(table);
//List<LotNoMode> model = JsonConvert.DeserializeObject<List<LotNoMode>>(json);
cmd.Transaction.Commit();
return json;
}
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();
}
}
}
}
}