一厂MES,含注塑,喷涂,冲孔
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.

931 lines
38 KiB

2 months ago
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;
using System.Reflection;
using MESClassLibrary.BLL.Log;
using MESClassLibrary.Model;
using Microsoft.SqlServer.Server;
namespace MESClassLibrary.DAL.BasicInfo
{
public class BarCodeDAl
{
public static string TableName = "tb_BarCode";
public DataTable SearchInfoByPartNo(string PartNo)
{
string sql = "";
DateTime time;
try
{
time = GetDateTime();
if (time.Hour>=8 &&time.Hour<=23)
{
sql = @"select top 1 * from v_Code where PartNo=@PartNo and PrintType <>2 and " +
"substring([BarCode],len( [BarCode])-10,6)= right(DATENAME(yy, GETDATE()),2)+ RIGHT('00'+CAST(MONTH(GETDATE()) AS VARCHAR(2)),2)+RIGHT('00'+CAST(Day(GETDATE()) AS VARCHAR(2)),2)" +
" order by [CreateTime] desc";
}
else
{
sql = @"select top 1 * from v_Code where PartNo=@PartNo and PrintType <>2 and " +
"substring([BarCode],len( [BarCode])-10,6)= right(DATENAME(yy, DATEADD(dd,-1, GETDATE())),2)+ RIGHT('00'+CAST(MONTH(DATEADD(dd,-1, GETDATE())) AS VARCHAR(2)),2)+RIGHT('00'+CAST(Day(DATEADD(dd,-1, GETDATE())) AS VARCHAR(2)),2)" +
" order by [CreateTime] desc";
}
SqlParameter[] param = new SqlParameter[1];
param[0] = new SqlParameter("@PartNo", SqlDbType.VarChar);
param[0].Value = PartNo;
return SqlHelper.ExecuteDataset(SqlHelper.GetConnSting(), CommandType.Text, sql, param).Tables[0];
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return null;
}
}
public DataTable searchBarCode(string barcode ,int flag)
{
try
{
string sql = "";
if (flag == 1)
{
sql = @"select * from v_Code where OneBarCode=@barcode";
}
if (flag == 2)
{
sql = @"select * from v_Code where BarCode=@barcode";
}
SqlParameter[] param = new SqlParameter[1];
param[0] = new SqlParameter("@barcode", SqlDbType.VarChar);
param[0].Value = barcode;
return SqlHelper.ExecuteDataset(SqlHelper.GetConnSting(), CommandType.Text, sql, param).Tables[0];
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return null;
}
}
public DataTable SearchInfoByStock(string stock)
{
string sql = "";
DateTime time;
try
{
time = GetDateTime();
if (time.Hour >= 8 && time.Hour <= 23)
{
sql = @"select top 1 * from " + TableName + " where StockNo=@StockNo and PrintType <>2 and " +
"substring([BarCode],len( [BarCode])-10,6)= right(DATENAME(yy, GETDATE()),2)+ RIGHT('00'+CAST(MONTH(GETDATE()) AS VARCHAR(2)),2)+RIGHT('00'+CAST(Day(GETDATE()) AS VARCHAR(2)),2)" +
" order by [CreateTime] desc";
}
else
{
sql = @"select top 1 * from " + TableName + " where StockNo=@StockNo and PrintType <>2 and " +
"substring([BarCode],len( [BarCode])-10,6)= right(DATENAME(yy, DATEADD(dd,-1, GETDATE())),2)+ RIGHT('00'+CAST(MONTH(DATEADD(dd,-1, GETDATE())) AS VARCHAR(2)),2)+RIGHT('00'+CAST(Day(DATEADD(dd,-1, GETDATE())) AS VARCHAR(2)),2)" +
" order by [CreateTime] desc";
}
SqlParameter[] param = new SqlParameter[1];
param[0] = new SqlParameter("@StockNo", SqlDbType.VarChar);
param[0].Value = stock;
return SqlHelper.ExecuteDataset(SqlHelper.GetConnSting(), CommandType.Text, sql, param).Tables[0];
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return null;
}
}
public bool AddInfo(BarCodeModel md)
{
try
{
#region 添加数据
string sql = "";
SqlParameter[] param = null;
sql = "INSERT INTO " + TableName + " (ID,StationID,OneBarCode,[BarCode],[StockNo],[PrintType],[CreateTime],[IsImport],StationID2,PlanID";
sql += ") VALUES (";
sql += "@ID,";
sql += "@StationID,";
sql += "@OneBarCode,";
sql += "@BarCode,";
sql += "@StockNo,";
sql += "@PrintType,";
//sql += "@CreateTime,";
sql += "(select getdate()),";
sql += "@IsImport,";
sql += "@StationID2,";
sql += "@PlanID)";
#region 添加参数
param = new SqlParameter[9];
param[0] = new SqlParameter("@ID", SqlDbType.VarChar);
param[0].Value = md.ID;
param[1] = new SqlParameter("@StationID", SqlDbType.VarChar);
param[1].Value = md.StationID;
param[2] = new SqlParameter("@OneBarCode", SqlDbType.VarChar);
param[2].Value = md.OneBarCode;
param[3] = new SqlParameter("@BarCode", SqlDbType.VarChar);
param[3].Value = md.BarCode;
param[4] = new SqlParameter("@StockNo", SqlDbType.VarChar);
param[4].Value = md.StockNo;
param[5] = new SqlParameter("@PrintType", SqlDbType.Int);
param[5].Value =md.PrintType;
//param[6] = new SqlParameter("@CreateTime", SqlDbType.DateTime);
//param[6].Value = md.CreateTime;
param[6] = new SqlParameter("@IsImport", SqlDbType.Text);
param[6].Value = md.Import;
param[7] = new SqlParameter("@StationID2", SqlDbType.VarChar);
param[7].Value = md.StationID2;
param[8] = new SqlParameter("@PlanID", SqlDbType.VarChar);
param[8].Value = md.PlanID;
#endregion
SqlHelper.ExecuteNonQuery(SqlHelper.GetConnSting(), CommandType.Text, sql, param);
#endregion
return true;
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return false;
}
}
public bool AddInfoNew(BarCodeModel md,string tableName)
{
try
{
#region 添加数据
string sql = "";
SqlParameter[] param = null;
sql = "INSERT INTO " + tableName + " (ID,StationID,OneBarCode,[BarCode],[StockNo],[PartNo],[PrintType],[CreateTime],[IsImport],StationID2,PlanID,ProductNature";
sql += ") VALUES (";
sql += "@ID,";
sql += "@StationID,";
sql += "@OneBarCode,";
sql += "@BarCode,";
sql += "@StockNo,";
sql += "@PartNo,";
sql += "@PrintType,";
//sql += "@CreateTime,";
sql += "(select getdate()),";
sql += "@IsImport,";
sql += "@StationID2,";
sql += "@PlanID,";
sql += "@ProductNature)";
#region 添加参数
param = new SqlParameter[11];
param[0] = new SqlParameter("@ID", SqlDbType.VarChar);
param[0].Value = md.ID;
param[1] = new SqlParameter("@StationID", SqlDbType.VarChar);
param[1].Value = md.StationID;
param[2] = new SqlParameter("@OneBarCode", SqlDbType.VarChar);
param[2].Value = md.OneBarCode;
param[3] = new SqlParameter("@BarCode", SqlDbType.VarChar);
param[3].Value = md.BarCode;
param[4] = new SqlParameter("@StockNo", SqlDbType.VarChar);
param[4].Value = md.StockNo;
param[5] = new SqlParameter("@PartNo", SqlDbType.VarChar);
param[5].Value = md.PartNo;
param[6] = new SqlParameter("@PrintType", SqlDbType.Int);
param[6].Value = md.PrintType;
param[7] = new SqlParameter("@IsImport", SqlDbType.Text);
param[7].Value = md.Import;
param[8] = new SqlParameter("@StationID2", SqlDbType.VarChar);
param[8].Value = md.StationID2;
param[9] = new SqlParameter("@PlanID", SqlDbType.VarChar);
param[9].Value = md.PlanID;
param[10] = new SqlParameter("@ProductNature", SqlDbType.VarChar);
param[10].Value = md.ProductNature;
#endregion
SqlHelper.ExecuteNonQuery(SqlHelper.GetConnSting(), CommandType.Text, sql, param);
#endregion
return true;
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return false;
}
}
public DataTable SearchInfo(string stationNo)
{
try
{
string sql = "";
if (stationNo.Substring(2, 2) == "01" || stationNo.Substring(2, 2) == "02" ||
stationNo.Substring(2, 2) == "03" || stationNo.Substring(2, 2) == "04")
{
sql = @"SELECT top 100 dbo.tb_BarCode1.BarCode, dbo.tb_Product.ProductName,
CASE dbo.tb_BarCode1.PrintType WHEN 0 THEN '' when 1 then '' when 2 then '' END AS PrintType,
dbo.tb_BarCode1.CreateTime
FROM dbo.tb_BarCode1 LEFT OUTER JOIN
dbo.tb_Product ON dbo.tb_BarCode1.StockNo = dbo.tb_Product.StockNo LEFT OUTER JOIN
dbo.tb_Station ON dbo.tb_BarCode1.StationID = dbo.tb_Station.StationID
where dbo.tb_Station.StationNo=@stationNo and IsDel=0 " + " order by [CreateTime] desc";
}
if (stationNo.Substring(2, 2) == "05" || stationNo.Substring(2, 2) == "06" ||
stationNo.Substring(2, 2) == "07" || stationNo.Substring(2, 2) == "08")
{
sql = @"SELECT top 100 dbo.tb_BarCode2.BarCode, dbo.tb_Product.ProductName,
CASE dbo.tb_BarCode2.PrintType WHEN 0 THEN '' when 1 then '' when 2 then '' END AS PrintType,
dbo.tb_BarCode2.CreateTime
FROM dbo.tb_BarCode2 LEFT OUTER JOIN
dbo.tb_Product ON dbo.tb_BarCode2.StockNo = dbo.tb_Product.StockNo LEFT OUTER JOIN
dbo.tb_Station ON dbo.tb_BarCode2.StationID = dbo.tb_Station.StationID
where dbo.tb_Station.StationNo=@stationNo and IsDel=0 " + " order by [CreateTime] desc";
}
if (stationNo.Substring(2, 2) == "09" || stationNo.Substring(2, 2) == "10" ||
stationNo.Substring(2, 2) == "11" || stationNo.Substring(2, 2) == "12")
{
sql = @"SELECT top 100 dbo.tb_BarCode3.BarCode, dbo.tb_Product.ProductName,
CASE dbo.tb_BarCode3.PrintType WHEN 0 THEN '' when 1 then '' when 2 then '' END AS PrintType,
dbo.tb_BarCode3.CreateTime
FROM dbo.tb_BarCode3 LEFT OUTER JOIN
dbo.tb_Product ON dbo.tb_BarCode3.StockNo = dbo.tb_Product.StockNo LEFT OUTER JOIN
dbo.tb_Station ON dbo.tb_BarCode3.StationID = dbo.tb_Station.StationID
where dbo.tb_Station.StationNo=@stationNo and IsDel=0 " + " order by [CreateTime] desc";
}
if (stationNo.Substring(2, 2) == "13" || stationNo.Substring(2, 2) == "14" ||
stationNo.Substring(2, 2) == "15" || stationNo.Substring(2, 2) == "16")
{
sql = @"SELECT top 100 dbo.tb_BarCode4.BarCode, dbo.tb_Product.ProductName,
CASE dbo.tb_BarCode4.PrintType WHEN 0 THEN '' when 1 then '' when 2 then '' END AS PrintType,
dbo.tb_BarCode4.CreateTime
FROM dbo.tb_BarCode4 LEFT OUTER JOIN
dbo.tb_Product ON dbo.tb_BarCode4.StockNo = dbo.tb_Product.StockNo LEFT OUTER JOIN
dbo.tb_Station ON dbo.tb_BarCode4.StationID = dbo.tb_Station.StationID
where dbo.tb_Station.StationNo=@stationNo and IsDel=0 " + " order by [CreateTime] desc";
}
if (stationNo.Substring(2, 2) == "17" || stationNo.Substring(2, 2) == "18" ||
stationNo.Substring(2, 2) == "19" || stationNo.Substring(2, 2) == "20")
{
sql = @"SELECT top 100 dbo.tb_BarCode5.BarCode, dbo.tb_Product.ProductName,
CASE dbo.tb_BarCode5.PrintType WHEN 0 THEN '' when 1 then '' when 2 then '' END AS PrintType,
dbo.tb_BarCode5.CreateTime
FROM dbo.tb_BarCode5 LEFT OUTER JOIN
dbo.tb_Product ON dbo.tb_BarCode5.StockNo = dbo.tb_Product.StockNo LEFT OUTER JOIN
dbo.tb_Station ON dbo.tb_BarCode5.StationID = dbo.tb_Station.StationID
where dbo.tb_Station.StationNo=@stationNo and IsDel=0 " + " order by [CreateTime] desc";
}
SqlParameter[] param = new SqlParameter[1];
param[0] = new SqlParameter("@stationNo", SqlDbType.VarChar);
param[0].Value = stationNo;
return SqlHelper.ExecuteDataset(SqlHelper.GetConnSting(), CommandType.Text, sql, param).Tables[0];
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return null;
}
}
public DataTable SearchInfoAll()
{
try
{
string sql = @"SELECT dbo.tb_BarCode.BarCode, dbo.tb_Product.ProductName,
CASE dbo.tb_BarCode.PrintType WHEN 0 THEN '' when 1 then '' when 2 then '' END AS PrintType,
dbo.tb_BarCode.PrintTime
FROM dbo.tb_BarCode LEFT OUTER JOIN
dbo.tb_Product ON dbo.tb_BarCode.StockNo = dbo.tb_Product.StockNo LEFT OUTER JOIN
dbo.tb_Station ON dbo.tb_BarCode.StationID = dbo.tb_Station.StationID
where dbo.tb_Station.StationNo=@stationNo and IsDel=0 " +
//" and substring([BarCode],len( [BarCode])-10,6)= right(DATENAME(yy, GETDATE()),2)+ RIGHT('00'+CAST(MONTH(GETDATE()) AS VARCHAR(2)),2)+RIGHT('00'+CAST(Day(GETDATE()) AS VARCHAR(2)),2)" +
" order by [CreateTime] desc";
return SqlHelper.ExecuteDataset(SqlHelper.GetConnSting(), CommandType.Text, sql, null).Tables[0];
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return null;
}
}
public DataTable SearchBarCode()
{
try
{
string sql = @"SELECT TOP (1000) dbo.tb_BarCode.BarCode, dbo.tb_Product.ProductName,
CASE dbo.tb_BarCode.PrintType WHEN 0 THEN '' WHEN 1 THEN '' WHEN 2 THEN '' END AS PrintType,
dbo.tb_BarCode.PrintTime, dbo.tb_BarCode.OneBarCode, dbo.tb_BarCode.PlanID,
dbo.tb_InjectPlanReport.MaterialName, dbo.tb_InjectPlanReport.BatchNo
FROM dbo.tb_BarCode LEFT OUTER JOIN
dbo.tb_InjectPlanReport ON dbo.tb_BarCode.PlanID = dbo.tb_InjectPlanReport.InjectionPlanID LEFT OUTER JOIN
dbo.tb_Product ON dbo.tb_BarCode.StockNo = dbo.tb_Product.StockNo LEFT OUTER JOIN
dbo.tb_Station ON dbo.tb_BarCode.StationID = dbo.tb_Station.StationID
WHERE (dbo.tb_BarCode.IsDel = 0)
ORDER BY dbo.tb_BarCode.CreateTime DESC";
return SqlHelper.ExecuteDataset(SqlHelper.GetConnSting(), CommandType.Text, sql, null).Tables[0];
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return null;
}
}
public DataTable SearchBarCodeByOne(string oneBarCode)
{
try
{
string sql = @"SELECT dbo.tb_BarCode.BarCode, dbo.tb_Product.ProductName,
CASE dbo.tb_BarCode.PrintType WHEN 0 THEN '' WHEN 1 THEN '' WHEN 2 THEN '' END AS PrintType,
dbo.tb_BarCode.PrintTime, dbo.tb_BarCode.OneBarCode,dbo.tb_BarCode.PlanID,
dbo.tb_InjectPlanReport.MaterialName, dbo.tb_InjectPlanReport.BatchNo
FROM dbo.tb_BarCode LEFT OUTER JOIN
dbo.tb_InjectPlanReport ON dbo.tb_BarCode.PlanID = dbo.tb_InjectPlanReport.InjectionPlanID LEFT OUTER JOIN
dbo.tb_Product ON dbo.tb_BarCode.StockNo = dbo.tb_Product.StockNo LEFT OUTER JOIN
dbo.tb_Station ON dbo.tb_BarCode.StationID = dbo.tb_Station.StationID
WHERE dbo.tb_BarCode.IsDel = 0 and dbo.tb_BarCode.OneBarCode=@OneBarCode
ORDER BY dbo.tb_BarCode.CreateTime DESC";
SqlParameter[] param = new SqlParameter[1];
param[0] = new SqlParameter("@OneBarCode", SqlDbType.VarChar);
param[0].Value = oneBarCode;
return SqlHelper.ExecuteDataset(SqlHelper.GetConnSting(), CommandType.Text, sql, param).Tables[0];
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return null;
}
}
public DataTable SearchBarCodeByTwo(string BarCode)
{
try
{
// string sql = @"SELECT dbo.tb_BarCode.BarCode, dbo.tb_Product.ProductName,
// CASE dbo.tb_BarCode.PrintType WHEN 0 THEN '自动打印' WHEN 1 THEN '手动打印' WHEN 2 THEN '补打' END AS PrintType,
// dbo.tb_BarCode.PrintTime, dbo.tb_BarCode.OneBarCode
// FROM dbo.tb_BarCode LEFT OUTER JOIN
// dbo.tb_Product ON dbo.tb_BarCode.StockNo = dbo.tb_Product.StockNo LEFT OUTER JOIN
// dbo.tb_Station ON dbo.tb_BarCode.StationID = dbo.tb_Station.StationID
// WHERE dbo.tb_BarCode.IsDel = 0 and dbo.tb_BarCode.BarCode=@BarCode
// ORDER BY dbo.tb_BarCode.CreateTime DESC";
string sql = @"SELECT dbo.tb_BarCode.BarCode, dbo.tb_Product.ProductName,
CASE dbo.tb_BarCode.PrintType WHEN 0 THEN '' WHEN 1 THEN '' WHEN 2 THEN '' END AS PrintType,
dbo.tb_BarCode.PrintTime, dbo.tb_BarCode.OneBarCode,dbo.tb_BarCode.PlanID,
dbo.tb_InjectPlanReport.MaterialName, dbo.tb_InjectPlanReport.BatchNo
FROM dbo.tb_BarCode LEFT OUTER JOIN
dbo.tb_InjectPlanReport ON dbo.tb_BarCode.PlanID = dbo.tb_InjectPlanReport.InjectionPlanID LEFT OUTER JOIN
dbo.tb_Product ON dbo.tb_BarCode.StockNo = dbo.tb_Product.StockNo LEFT OUTER JOIN
dbo.tb_Station ON dbo.tb_BarCode.StationID = dbo.tb_Station.StationID
WHERE dbo.tb_BarCode.IsDel = 0 and dbo.tb_BarCode.BarCode=@BarCode
ORDER BY dbo.tb_BarCode.CreateTime DESC";
SqlParameter[] param = new SqlParameter[1];
param[0] = new SqlParameter("@BarCode", SqlDbType.VarChar);
param[0].Value = BarCode;
return SqlHelper.ExecuteDataset(SqlHelper.GetConnSting(), CommandType.Text, sql, param).Tables[0];
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return null;
}
}
/// <summary>
/// 查找流水号
/// </summary>
/// <param name="Code">零件号.批次</param>
/// <returns></returns>
public DataTable SearchSerialNoByBarCode(string Code)
{
try
{
string sql = @"select top 1 * from " + TableName + " where left([BarCode],len([BarCode])-5)=@Code and PrintType <> 2" +
" order by [CreateTime] desc";
SqlParameter[] param = new SqlParameter[1];
param[0] = new SqlParameter("@Code", SqlDbType.VarChar);
param[0].Value = Code;
return SqlHelper.ExecuteDataset(SqlHelper.GetConnSting(), CommandType.Text, sql, param).Tables[0];
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return null;
}
}
/// <summary>
/// 查找流水号-New
/// </summary>
/// <param name="Code">零件号.批次</param>
/// <returns></returns>
public DataTable SearchSerialNoByBarCodeNew(string Code,string tableName)
{
try
{
string sql = @"select top 1 * from " + tableName + " where left([BarCode],len([BarCode])-5)=@Code and PrintType <> 2" +
" order by [CreateTime] desc";
SqlParameter[] param = new SqlParameter[1];
param[0] = new SqlParameter("@Code", SqlDbType.VarChar);
param[0].Value = Code;
return SqlHelper.ExecuteDataset(SqlHelper.GetConnSting(), CommandType.Text, sql, param).Tables[0];
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return null;
}
}
public DataTable SearchInfoByBarCode(string BarCode)
{
try
{
string sql = @"select top 1 * from " + TableName + " where BarCode=@BarCode order by [CreateTime] desc ";
SqlParameter[] param = new SqlParameter[1];
param[0] = new SqlParameter("@BarCode", SqlDbType.VarChar);
param[0].Value = BarCode;
return SqlHelper.ExecuteDataset(SqlHelper.GetConnSting(), CommandType.Text, sql, param).Tables[0];
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return null;
}
}
public DataTable SearchInfoByBarCodeNew(string BarCode,string tableName)
{
try
{
string sql = @"select top 1 * from " + tableName + " where BarCode=@BarCode order by [CreateTime] desc ";
SqlParameter[] param = new SqlParameter[1];
param[0] = new SqlParameter("@BarCode", SqlDbType.VarChar);
param[0].Value = BarCode;
return SqlHelper.ExecuteDataset(SqlHelper.GetConnSting(), CommandType.Text, sql, param).Tables[0];
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return null;
}
}
/// <summary>
/// 更改打印时间
/// </summary>
/// <param name="md"></param>
/// <returns></returns>
public bool UpdateInfo(BarCodeModel md)
{
try
{
#region 添加数据
string sql = "";
SqlParameter[] param = null;
sql = @"update tb_BarCode set PrintTime=(select getdate()) where [StationID]=@StationID and PrintTime is null";
#region 添加参数
param = new SqlParameter[1];
param[0] = new SqlParameter("@StationID", SqlDbType.VarChar);
param[0].Value = md.StationID;
//param[1] = new SqlParameter("@PrintTime", SqlDbType.DateTime);
//param[1].Value = md.PrintTime;
#endregion
SqlHelper.ExecuteNonQuery(SqlHelper.GetConnSting(), CommandType.Text, sql, param);
#endregion
return true;
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return false;
}
}
/// <summary>
/// 删除手工打印条码
/// </summary>
/// <param name="md"></param>
/// <returns></returns>
public bool DelBarCode(BarCodeModel md)
{
try
{
#region 添加数据
string sql = "";
SqlParameter[] param = null;
sql = @"update tb_BarCode set IsDel=1 where BarCode=@BarCode";
#region 添加参数
param = new SqlParameter[1];
param[0] = new SqlParameter("@BarCode", SqlDbType.VarChar);
param[0].Value = md.BarCode;
#endregion
SqlHelper.ExecuteNonQuery(SqlHelper.GetConnSting(), CommandType.Text, sql, param);
#endregion
return true;
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return false;
}
}
/// <summary>
/// 删除手工打印条码-New
/// </summary>
/// <param name="md"></param>
/// <returns></returns>
public bool DelBarCode_New(BarCodeModel md,string tableName)
{
try
{
#region 添加数据
string sql = "";
SqlParameter[] param = null;
sql = @"update " + tableName + " set IsDel=1 where BarCode=@BarCode";
#region 添加参数
param = new SqlParameter[1];
param[0] = new SqlParameter("@BarCode", SqlDbType.VarChar);
param[0].Value = md.BarCode;
#endregion
SqlHelper.ExecuteNonQuery(SqlHelper.GetConnSting(), CommandType.Text, sql, param);
#endregion
return true;
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return false;
}
}
public DateTime GetDateTime()
{
string sql = "";
DateTime time;
DataTable dt;
try
{
sql = @"select getdate() as time";
dt= SqlHelper.ExecuteDataset(SqlHelper.GetConnSting(), CommandType.Text, sql, null).Tables[0];
if (dt != null && dt.Rows.Count > 0)
{
time = Convert.ToDateTime(dt.Rows[0]["time"].ToString());
}
else
{
time=DateTime.Now;
}
return time;
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return DateTime.Now;
}
}
public DataTable SearchBoxIsNull(string partNo, string StationID, string tableName, string ProductNature)
{
try
{
string sql = @"select count(*) as SumCount from " + tableName + " where PartNo=@PartNo and StationID=@StationID and BoxNo is null and PrintType in (0,1) and IsDel=0 and IsBad=0 and ProductNature=@ProductNature";
SqlParameter[] param = new SqlParameter[3];
param[0] = new SqlParameter("@PartNo", SqlDbType.VarChar);
param[0].Value = partNo;
param[1] = new SqlParameter("@StationID", SqlDbType.VarChar);
param[1].Value = StationID;
param[2] = new SqlParameter("@ProductNature", SqlDbType.VarChar);
param[2].Value = ProductNature;
return SqlHelper.ExecuteDataset(SqlHelper.GetConnSting(), CommandType.Text, sql, param).Tables[0];
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return null;
}
}
/// <summary>
/// 是否存在售后件
/// </summary>
/// <param name="partNo"></param>
/// <param name="StationID"></param>
/// <param name="tableName"></param>
/// <returns></returns>
public DataTable IsHave(string partNo, string StationID, string tableName)
{
try
{
string sql = @"select * from " + tableName + " where PartNo=@PartNo and StationID=@StationID and BoxNo is null and PrintType in (0,1) and IsDel=0 and IsBad=0 and ProductNature='售后件'";
SqlParameter[] param = new SqlParameter[2];
param[0] = new SqlParameter("@PartNo", SqlDbType.VarChar);
param[0].Value = partNo;
param[1] = new SqlParameter("@StationID", SqlDbType.VarChar);
param[1].Value = StationID;
return SqlHelper.ExecuteDataset(SqlHelper.GetConnSting(), CommandType.Text, sql, param).Tables[0];
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return null;
}
}
public bool UpdateBoxNo(string tableName, string boxNo,string partNo)
{
try
{
#region 添加数据
string sql = "";
SqlParameter[] param = null;
sql = @"update " + tableName + " set BoxNo=@BoxNo where PartNo=@PartNo and BoxNo is null";
#region 添加参数
param = new SqlParameter[2];
param[0] = new SqlParameter("@BoxNo", SqlDbType.VarChar);
param[0].Value = boxNo;
param[1] = new SqlParameter("@PartNo", SqlDbType.VarChar);
param[1].Value = partNo;
#endregion
SqlHelper.ExecuteNonQuery(SqlHelper.GetConnSting(), CommandType.Text, sql, param);
#endregion
return true;
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return false;
}
}
public bool UpdateIsBad(string tableName, string onebarcode, string barcode)
{
try
{
#region 添加数据
string sql = "";
SqlParameter[] param = null;
param = new SqlParameter[1];
if (onebarcode != "")
{
sql = @"update " + tableName + " set IsBad=1 where OneBarCode=@OneBarCode and BoxNo is null";
#region 添加参数
param[0] = new SqlParameter("@OneBarCode", SqlDbType.VarChar);
param[0].Value = onebarcode;
#endregion
}
if (barcode != "")
{
sql = @"update " + tableName + " set IsBad=1 where BarCode=@BarCode and BoxNo is null";
#region 添加参数
param[0] = new SqlParameter("@BarCode", SqlDbType.VarChar);
param[0].Value = barcode;
#endregion
}
SqlHelper.ExecuteNonQuery(SqlHelper.GetConnSting(), CommandType.Text, sql, param);
#endregion
return true;
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return false;
}
}
public DataTable SearchCountByBox(string boxNo,string tableName)
{
try
{
string sql = @"select Count(*) as SumCount from " + tableName + " where BoxNo=@BoxNo and PrintType in (0,1) and IsDel=0 and IsBad=0";
SqlParameter[] param = new SqlParameter[1];
param[0] = new SqlParameter("@BoxNo", SqlDbType.VarChar);
param[0].Value = boxNo;
return SqlHelper.ExecuteDataset(SqlHelper.GetConnSting(), CommandType.Text, sql, param).Tables[0];
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return null;
}
}
public DataTable SearchInfoByBox(string boxNo, string tableName)
{
try
{
string sql = @"select * from " + tableName + " where BoxNo=@BoxNo and PrintType in (0,1) and IsDel=0 ";
SqlParameter[] param = new SqlParameter[1];
param[0] = new SqlParameter("@BoxNo", SqlDbType.VarChar);
param[0].Value = boxNo;
return SqlHelper.ExecuteDataset(SqlHelper.GetConnSting(), CommandType.Text, sql, param).Tables[0];
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return null;
}
}
/// <summary>
/// 小件,查找箱子里需要报废的条码
/// </summary>
/// <param name="boxNo"></param>
/// <param name="tableName"></param>
/// <param name="row"></param>
/// <returns></returns>
public DataTable SearchBarCode(string boxNo, string tableName, string row)
{
try
{
string sql = @"select top " + row + " * from " + tableName + " where BoxNo=@BoxNo IsDel=0 order by CreateTime desc";
SqlParameter[] param = new SqlParameter[1];
param[0] = new SqlParameter("@BoxNo", SqlDbType.VarChar);
param[0].Value = boxNo;
return SqlHelper.ExecuteDataset(SqlHelper.GetConnSting(), CommandType.Text, sql, param).Tables[0];
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return null;
}
}
/// <summary>
/// 将产品转为市场件
/// </summary>
/// <param name="tableName"></param>
/// <param name="barcode"></param>
/// <returns></returns>
public bool updateProductNature(string tableName, string barcode)
{
try
{
#region 添加数据
string sql = "";
SqlParameter[] param = null;
param = new SqlParameter[1];
sql = @"update " + tableName + " set ProductNature='市场件' where BarCode=@BarCode ";
#region 添加参数
param[0] = new SqlParameter("@BarCode", SqlDbType.VarChar);
param[0].Value = barcode;
#endregion
SqlHelper.ExecuteNonQuery(SqlHelper.GetConnSting(), CommandType.Text, sql, param);
#endregion
return true;
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return false;
}
}
/// <summary>
/// 根据一维码或二维码查找所有信息
/// </summary>
/// <param name="barCode"></param>
/// <param name="tableName"></param>
/// <returns></returns>
public DataTable SeachInfoByOne(string barCode, string tableName,int flag)
{
try
{
string sql = "";
if (flag==1)
{
sql = @"select * from " + tableName + " where OneBarCode=@BarCode ";
}
else
{
sql = @"select * from " + tableName + " where BarCode=@BarCode ";
}
SqlParameter[] param = new SqlParameter[1];
param[0] = new SqlParameter("@BarCode", SqlDbType.VarChar);
param[0].Value = barCode;
return SqlHelper.ExecuteDataset(SqlHelper.GetConnSting(), CommandType.Text, sql, param).Tables[0];
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return null;
}
}
}
}