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 < = 2 3 )
{
//sql = @"select top 1 BarCode,OneBarCode from v_Code with (nolock) 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";
sql = @"select top 1 BarCode,OneBarCode from v_Code with (nolock) where PartNo=@PartNo and PrintType <>2 and " +
"BatchNo= 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 BarCode,OneBarCode from v_Code with (nolock) 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";
sql = @"select top 1 BarCode,OneBarCode from v_Code with (nolock) where PartNo=@PartNo and PrintType <>2 and " +
"BatchNo= 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 ( ) ) ;
throw ex ;
}
}
/// <summary>
/// 直供件查询
/// </summary>
/// <param name="partNo"></param>
/// <returns></returns>
public DataTable SearchInfoByPartNo1 ( string partNo )
{
string sql = "" ;
DateTime time ;
try
{
time = GetDateTime ( ) ;
if ( time . Hour > = 8 & & time . Hour < = 2 3 )
{
//if (partNo != "P0210184-P")
//{
// //sql =
// // @"select top 1 BarCode,OneBarCode from v_Code with (nolock) where PartNo=@PartNo and PrintType <>2 and " +
// // "substring([BarCode],17,6)= right(DATENAME(yy, @time),2)+ RIGHT('00'+CAST(MONTH(@time) AS VARCHAR(2)),2)+RIGHT('00'+CAST(Day(@time) AS VARCHAR(2)),2)" +
// // " order by [CreateTime] desc";
// sql =
// @"select top 1 BarCode,OneBarCode from v_Code with (nolock) where PartNo=@PartNo and PrintType <>2 and " +
// "BatchNo= right(DATENAME(yy, @time),2)+ RIGHT('00'+CAST(MONTH(@time) AS VARCHAR(2)),2)+RIGHT('00'+CAST(Day(@time) AS VARCHAR(2)),2)" +
// " order by [CreateTime] desc";
//}
//else
//{
// sql =
// @"select top 1 BarCode,OneBarCode from v_Code with (nolock) where PartNo=@PartNo and PrintType <>2 and " +
// "substring([BarCode],12,6)= right(DATENAME(yy, @time),2)+ RIGHT('00'+CAST(MONTH(@time) AS VARCHAR(2)),2)+RIGHT('00'+CAST(Day(@time) AS VARCHAR(2)),2)" +
// " order by [CreateTime] desc";
//}
sql =
@"select top 1 BarCode,OneBarCode from v_Code with (nolock) where PartNo=@PartNo and PrintType <>2 and " +
"BatchNo= right(DATENAME(yy, @time),2)+ RIGHT('00'+CAST(MONTH(@time) AS VARCHAR(2)),2)+RIGHT('00'+CAST(Day(@time) AS VARCHAR(2)),2)" +
" order by [CreateTime] desc" ;
}
else
{
sql =
@"select top 1 BarCode,OneBarCode from v_Code with (nolock) where PartNo=@PartNo and PrintType <>2 and " +
"BatchNo= right(DATENAME(yy, DATEADD(dd,-1, @time)),2)+ RIGHT('00'+CAST(MONTH(DATEADD(dd,-1, @time)) AS VARCHAR(2)),2)+RIGHT('00'+CAST(Day(DATEADD(dd,-1, @time)) AS VARCHAR(2)),2)" +
" order by [CreateTime] desc" ;
//if (partNo != "P0210184-P")
//{
// sql =
// @"select top 1 BarCode,OneBarCode from v_Code with (nolock) where PartNo=@PartNo and PrintType <>2 and " +
// "substring([BarCode],17,6)= right(DATENAME(yy, DATEADD(dd,-1, @time)),2)+ RIGHT('00'+CAST(MONTH(DATEADD(dd,-1, @time)) AS VARCHAR(2)),2)+RIGHT('00'+CAST(Day(DATEADD(dd,-1, @time)) AS VARCHAR(2)),2)" +
// " order by [CreateTime] desc";
//}
//else
//{
// sql =
// @"select top 1 BarCode,OneBarCode from v_Code with (nolock) where PartNo=@PartNo and PrintType <>2 and " +
// "substring([BarCode],12,6)= right(DATENAME(yy, DATEADD(dd,-1, @time)),2)+ RIGHT('00'+CAST(MONTH(DATEADD(dd,-1, @time)) AS VARCHAR(2)),2)+RIGHT('00'+CAST(Day(DATEADD(dd,-1, @time)) AS VARCHAR(2)),2)" +
// " order by [CreateTime] desc";
//}
}
SqlParameter [ ] param = new SqlParameter [ 2 ] ;
param [ 0 ] = new SqlParameter ( "@PartNo" , SqlDbType . VarChar ) ;
param [ 0 ] . Value = partNo ;
param [ 1 ] = new SqlParameter ( "@time" , SqlDbType . VarChar ) ;
param [ 1 ] . Value = time ;
return SqlHelper . ExecuteDataset ( SqlHelper . GetConnSting ( ) , CommandType . Text , sql , param ) . Tables [ 0 ] ;
}
catch ( Exception ex )
{
//throw ex;
LogErrBLL . AddInfo ( ex . ToString ( ) , MethodBase . GetCurrentMethod ( ) ) ;
throw ex ;
}
}
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 < = 2 3 )
{
//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";
sql = @"select top 1 * from " + TableName + " where StockNo=@StockNo and PrintType <>2 and " +
"BatchNo= 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 " +
"BatchNo= 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 ( ) ) ;
throw ex ;
//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,Des1,Des2,Des3,Des4,Des5,BoxNo,Weight" ;
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," ;
sql + = "@Des1," ;
sql + = "@Des2," ;
sql + = "@Des3," ;
sql + = "@Des4," ;
sql + = "@Des5," ;
sql + = "@BoxNo," ;
sql + = "@Weight)" ;
#region 添加参数
param = new SqlParameter [ 1 8 ] ;
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 [ 1 0 ] = new SqlParameter ( "@ProductNature" , SqlDbType . VarChar ) ;
param [ 1 0 ] . Value = md . ProductNature ;
param [ 1 1 ] = new SqlParameter ( "@Des1" , SqlDbType . VarChar ) ;
param [ 1 1 ] . Value = md . Des1 ;
param [ 1 2 ] = new SqlParameter ( "@Des2" , SqlDbType . VarChar ) ;
param [ 1 2 ] . Value = md . Des2 ;
param [ 1 3 ] = new SqlParameter ( "@Des3" , SqlDbType . VarChar ) ;
param [ 1 3 ] . Value = md . Des3 ;
param [ 1 4 ] = new SqlParameter ( "@Des4" , SqlDbType . VarChar ) ;
param [ 1 4 ] . Value = md . Des4 ;
param [ 1 5 ] = new SqlParameter ( "@Des5" , SqlDbType . VarChar ) ;
param [ 1 5 ] . Value = md . Des5 ;
param [ 1 6 ] = new SqlParameter ( "@BoxNo" , SqlDbType . VarChar ) ;
param [ 1 6 ] . Value = md . BoxNo ;
param [ 1 7 ] = new SqlParameter ( "@Weight" , SqlDbType . Decimal ) ;
param [ 1 7 ] . Value = md . Weight ;
#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 ( LocalDBService local , BarCodeModel md , string tableName )
{
string sql = "" ;
sql = "INSERT INTO " + tableName + " (ID,StationID,OneBarCode,[BarCode],[StockNo],[PartNo],[PrintType],[CreateTime],[IsImport],StationID2,PlanID,ProductNature,Des1,Des2,Des3,Des4,Des5,BoxNo,Weight,BatchNo" ;
sql + = $") VALUES ('{md.ID}','{md.StationID}','{md.OneBarCode}','{md.BarCode}','{md.StockNo}','{md.PartNo}','{md.PrintType}',getdate(),'{md.Import}'," +
$"'{md.StationID2}','{md.PlanID}','{md.ProductNature}','{md.Des1}','{md.Des2}','{md.Des3}','{md.Des4}','{md.Des5}','{md.BoxNo}','{ md.Weight}','{ md.BatchNo}')" ;
return local . Exec_NonQuery ( sql ) ;
}
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, dbo.tb_BarCode1.BoxNo,
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 with ( nolock ) 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 and IsBad = 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, dbo.tb_BarCode2.BoxNo,
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 with ( nolock ) 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 and IsBad = 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, dbo.tb_BarCode3.BoxNo,
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 with ( nolock ) 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 and IsBad = 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, dbo.tb_BarCode4.BoxNo,
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 with ( nolock ) 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 and IsBad = 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, dbo.tb_BarCode5.BoxNo,
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 with ( nolock ) 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 and IsBad = 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.v_Code.BarCode, dbo.tb_Product.ProductName,
CASE dbo . v_Code . PrintType WHEN 0 THEN ' 自 动 打 印 ' when 1 then ' 手 动 打 印 ' when 2 then ' 补 打 ' END AS PrintType ,
dbo . v_Code . PrintTime
FROM dbo . v_Code LEFT OUTER JOIN
dbo . tb_Product ON dbo . v_Code . StockNo = dbo . tb_Product . StockNo LEFT OUTER JOIN
dbo . tb_Station ON dbo . v_Code . 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 200 dbo.v_Code.BarCode,dbo.v_Code.TableName,dbo.v_Code.BoxNo, dbo.tb_Product.ProductName,
CASE dbo . v_Code . PrintType WHEN 0 THEN ' 自 动 打 印 ' WHEN 1 THEN ' 手 动 打 印 ' WHEN 2 THEN ' 补 打 ' END AS PrintType ,
dbo . v_Code . CreateTime , dbo . v_Code . CreateTime as PrintTime , dbo . v_Code . OneBarCode , dbo . v_Code . PlanID ,
dbo . tb_InjectPlanReport . MaterialName , dbo . tb_InjectPlanReport . BatchNo
FROM dbo . v_Code with ( NOLOCK ) LEFT OUTER JOIN
dbo . tb_InjectPlanReport ON dbo . v_Code . PlanID = dbo . tb_InjectPlanReport . InjectionPlanID LEFT OUTER JOIN
dbo . tb_Product ON dbo . v_Code . StockNo = dbo . tb_Product . StockNo LEFT OUTER JOIN
dbo . tb_Station ON dbo . v_Code . StationID = dbo . tb_Station . StationID
WHERE ( dbo . v_Code . IsDel = 0 )
ORDER BY dbo . v_Code . 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.v_Code.BarCode, dbo.tb_Product.ProductName,dbo.v_Code.IsBad, dbo.v_Code.BoxNo,dbo.v_Code.PartNo, dbo.v_Code.StationID, dbo.v_Code.ID,
CASE dbo . v_Code . PrintType WHEN 0 THEN ' 自 动 打 印 ' WHEN 1 THEN ' 手 动 打 印 ' WHEN 2 THEN ' 补 打 ' END AS PrintType ,
dbo . v_Code . CreateTime as PrintTime , dbo . v_Code . OneBarCode , dbo . v_Code . PlanID , dbo . v_Code . TableName ,
dbo . tb_InjectPlanReport . MaterialName , dbo . tb_InjectPlanReport . BatchNo
FROM dbo . v_Code LEFT OUTER JOIN
dbo . tb_InjectPlanReport ON dbo . v_Code . PlanID = dbo . tb_InjectPlanReport . InjectionPlanID LEFT OUTER JOIN
dbo . tb_Product ON dbo . v_Code . StockNo = dbo . tb_Product . StockNo LEFT OUTER JOIN
dbo . tb_Station ON dbo . v_Code . StationID = dbo . tb_Station . StationID
WHERE dbo . v_Code . IsDel = 0 and dbo . v_Code . OneBarCode = @OneBarCode
ORDER BY dbo . v_Code . 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.v_Code.BarCode, dbo.tb_Product.ProductName, dbo.v_Code.BoxNo, dbo.v_Code.TableName,
CASE dbo . v_Code . PrintType WHEN 0 THEN ' 自 动 打 印 ' WHEN 1 THEN ' 手 动 打 印 ' WHEN 2 THEN ' 补 打 ' END AS PrintType ,
dbo . v_Code . CreateTime as PrintTime , dbo . v_Code . OneBarCode , dbo . v_Code . PlanID ,
dbo . tb_InjectPlanReport . MaterialName , dbo . tb_InjectPlanReport . BatchNo
FROM dbo . v_Code LEFT OUTER JOIN
dbo . tb_InjectPlanReport ON dbo . v_Code . PlanID = dbo . tb_InjectPlanReport . InjectionPlanID LEFT OUTER JOIN
dbo . tb_Product ON dbo . v_Code . StockNo = dbo . tb_Product . StockNo LEFT OUTER JOIN
dbo . tb_Station ON dbo . v_Code . StationID = dbo . tb_Station . StationID
WHERE dbo . v_Code . IsDel = 0 and dbo . v_Code . BarCode = @BarCode
ORDER BY dbo . v_Code . 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";
//string sql = @"select top 1 * from v_Code where left([BarCode],len([BarCode])-5)=@Code and PrintType <> 2" +
// " order by [CreateTime] desc";
string sql = @"select top 1 * from v_Code with (NOLOCK) 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 ( ) ) ;
throw ex ;
//return null;
}
}
/// <summary>
/// 直供件查询
/// </summary>
/// <param name="Code"></param>
/// <returns></returns>
public DataTable SearchSerialNoByBarCodeNew1 ( string Code )
{
try
{
//string sql = @"select top 1 * from " + tableName + " where left([BarCode],len([BarCode])-5)=@Code and PrintType <> 2" +
// " order by [CreateTime] desc";
string sql = @"select top 1 * from v_Code with (NOLOCK) where left([BarCode],len([BarCode])-4)=@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 dbo.tb_Product.ProductName, dbo.v_Code.*
FROM dbo . v_Code with ( NOLOCK ) LEFT OUTER JOIN
dbo . tb_Product ON dbo . v_Code . StockNo = dbo . tb_Product . StockNo where dbo . v_Code . 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 and IsBad=0 and IsDel=0 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 bool DelBarCode ( LocalDBService localDB , string barCode , string tableName , string upField = null )
{
string column1 = "OneBarCode" ;
if ( barCode . Contains ( "." ) )
{
column1 = "BarCode" ;
}
string sql = "update " + tableName + $" set IsDel=1 {upField} where {column1}='{barCode}'" ;
return localDB . Exec_NonQuery ( sql ) ;
}
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 UpdateBoxNoByID ( LocalDBService localDB , string tableName , string boxNo , string id )
{
#region 添加数据
string sql = "" ;
sql = $@"update {tableName} set BoxNo='{boxNo}' where id='{id}'" ;
localDB . Exec_NonQuery ( sql ) ;
//SqlHelper.ExecuteNonQuery(SqlHelper.GetConnSting(), CommandType.Text, sql, param);
#endregion
return true ;
}
public bool UpdateBoxNoNull ( LocalDBService localDB , string tableName , string id , string newBarCode )
{
#region 添加数据
string sql = "" ;
//sql = $@"update {tableName} set IsBad=1,BoxNo='' where id='{id}'";
sql = $@"update {tableName} set BoxNo='',Des4='被手动替换,新条码:{newBarCode}' where id='{id}'" ; //经过讨论,替换不自动报废,只是清空箱码
#region 添加参数
#endregion
localDB . Exec_NonQuery ( sql ) ;
//SqlHelper.ExecuteNonQuery(SqlHelper.GetConnSting(), CommandType.Text, sql, param);
#endregion
return true ;
}
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";
sql = @"update " + tableName + " set IsBad=1 where OneBarCode=@OneBarCode" ;
#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";
sql = @"update " + tableName + " set IsBad=1 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 ;
}
}
public bool UpdateIsBad ( LocalDBService localDB , string tableName , string onebarcode , string barcode )
{
string sql = "" ;
SqlParameter [ ] param = null ;
param = new SqlParameter [ 1 ] ;
if ( onebarcode ! = "" )
{
//sql = @"update " + tableName + " set IsBad=1 where OneBarCode=@OneBarCode and BoxNo is null";
sql = @"update " + tableName + $" set IsBad=1 where OneBarCode='{onebarcode}'" ;
}
else if ( barcode ! = "" )
{
//sql = @"update " + tableName + " set IsBad=1 where BarCode=@BarCode and BoxNo is null";
sql = @"update " + tableName + $" set IsBad=1 where BarCode='{barcode}'" ;
}
localDB . Exec_NonQuery ( sql ) ;
return true ;
}
/// <summary>
/// 根据箱码更新IsBad=1
/// </summary>
/// <param name="tableName"></param>
/// <param name="boxCode"></param>
/// <returns></returns>
public bool UpdateIsBadByBoxCode ( string tableName , string boxCode )
{
try
{
#region 添加数据
string sql = "" ;
SqlParameter [ ] param = null ;
param = new SqlParameter [ 1 ] ;
sql = @"update " + tableName + " set IsBad=1 where BoxNo=@boxCode" ;
#region 添加参数
param [ 0 ] = new SqlParameter ( "@boxCode" , SqlDbType . VarChar ) ;
param [ 0 ] . Value = boxCode ;
#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 UpdateIsBadByBoxCode ( LocalDBService localDB , string tableName , string boxCode )
{
string sql = "" ;
SqlParameter [ ] param = null ;
param = new SqlParameter [ 1 ] ;
sql = @"update " + tableName + $" set IsBad=1 where BoxNo='{boxCode}'" ;
localDB . Exec_NonQuery ( sql ) ;
//SqlHelper.ExecuteNonQuery(SqlHelper.GetConnSting(), CommandType.Text, sql, param);
return true ;
}
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 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 )
{
try
{
string sql = @"select * from v_Code where BoxNo=@BoxNo 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 ;
}
}
/// <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 and IsDel=0 and IsBad=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 ;
}
}
public DataTable SearchBarCodeByWhere ( string whereStr , string tableName , string row )
{
try
{
string sql = @"select top " + row + " * from " + tableName + $" where {whereStr} and IsDel=0 and IsBad=0 and IsNull(BoxNo,'')!='' order by CreateTime desc" ;
SqlParameter [ ] param = new SqlParameter [ 0 ] ;
// param[0] = new SqlParameter("@BoxNo", SqlDbType.VarChar);
// param[0].Value = whereStr;
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 ;
}
}
public string LastBarCode ( string tableName )
{
try
{
string res = "" ;
string sql = @"select top 1 OneBarCode from " + tableName + " where IsDel=0 order by CreateTime desc" ;
DataTable dt = SqlHelper . ExecuteDataset ( SqlHelper . GetConnSting ( ) , CommandType . Text , sql , null ) . Tables [ 0 ] ;
if ( dt ! = null & & dt . Rows . Count > 0 )
{
res = dt . Rows [ 0 ] [ "OneBarCode" ] . ToString ( ) ;
}
return res ;
}
catch ( Exception ex )
{
LogErrBLL . AddInfo ( ex . ToString ( ) , MethodBase . GetCurrentMethod ( ) ) ;
return "" ;
}
}
public bool IsExist ( string barCode )
{
try
{
bool res = false ;
string sql = @"select StationID from v_Code where OneBarCode='" + barCode + @"' and IsDel=0" ;
DataTable dt = SqlHelper . ExecuteDataset ( SqlHelper . GetConnSting ( ) , CommandType . Text , sql , null ) . Tables [ 0 ] ;
if ( dt ! = null & & dt . Rows . Count > 0 )
{
res = true ;
}
return res ;
}
catch ( Exception ex )
{
LogErrBLL . AddInfo ( ex . ToString ( ) , MethodBase . GetCurrentMethod ( ) ) ;
return false ;
}
}
}
}