using System ;
using System.Collections.Generic ;
using System.Linq ;
using System.Text ;
using System.Threading.Tasks ;
using MESClassLibrary.BLL.Log ;
using MESClassLibrary.Model ;
using System.Data ;
using System.Data.SqlClient ;
using System.Reflection ;
namespace MESClassLibrary.DAL.BasicInfo
{
public class StationDAL
{
public static string TableName = "tb_Station" ;
public DataTable SearchInfoByNo ( string station )
{
try
{
string sql = @ "SELECT s.*,l.LineName FROM dbo.tb_Station s
LEFT JOIN dbo . tb_Line l
ON l . LineID = s . LineID where StationNo = @StationNo ";
SqlParameter [ ] param = new SqlParameter [ 1 ] ;
param [ 0 ] = new SqlParameter ( "@StationNo" , SqlDbType . VarChar ) ;
param [ 0 ] . Value = station ;
return SqlHelper . ExecuteDataset ( SqlHelper . GetConnSting ( ) , CommandType . Text , sql , param ) . Tables [ 0 ] ;
}
catch ( Exception ex )
{
LogErrBLL . AddInfo ( ex . ToString ( ) , MethodBase . GetCurrentMethod ( ) ) ;
return null ;
}
}
public DataTable GetStationInfos ( string lineCode )
{
try
{
DataTable dt = SqlHelper . ExecuteDataset ( SqlHelper . GetConnSting ( ) , CommandType . Text , $"select s.* from tb_Station s ,tb_Line l where l.LineID = s.LineID and l.LineName='{lineCode}'" , null ) . Tables [ 0 ] ;
return dt ;
}
catch ( Exception ex )
{
LogErrBLL . AddInfo ( ex . ToString ( ) , MethodBase . GetCurrentMethod ( ) ) ;
return null ;
}
}
public bool UpdateTime ( DateTime time , string staionNo )
{
try
{
string sql = @"update " + TableName + " set PrintTime=@PrintTime where StationNo=@StationNo" ;
SqlParameter [ ] param = new SqlParameter [ 2 ] ;
param [ 0 ] = new SqlParameter ( "@PrintTime" , SqlDbType . DateTime ) ;
param [ 0 ] . Value = time ;
param [ 1 ] = new SqlParameter ( "@StationNo" , SqlDbType . VarChar ) ;
param [ 1 ] . Value = staionNo ;
SqlHelper . ExecuteNonQuery ( SqlHelper . GetConnSting ( ) , CommandType . Text , sql , param ) ;
return true ;
}
catch ( Exception ex )
{
LogErrBLL . AddInfo ( ex . ToString ( ) , MethodBase . GetCurrentMethod ( ) ) ;
return false ;
}
}
public string SearchStationNameByID ( string stationID )
{
try
{
string sql = @ "SELECT * FROM dbo.tb_Station s
LEFT JOIN dbo . tb_Line l
ON l . LineID = s . LineID where StationID = @StationID ";
SqlParameter [ ] param = new SqlParameter [ 1 ] ;
param [ 0 ] = new SqlParameter ( "@StationID" , SqlDbType . VarChar ) ;
param [ 0 ] . Value = stationID ;
DataTable dt = SqlHelper . ExecuteDataset ( SqlHelper . GetConnSting ( ) , CommandType . Text , sql , param ) . Tables [ 0 ] ;
if ( dt . Rows . Count > 0 )
{
return dt . Rows [ 0 ] [ "StationNo" ] . ToString ( ) ;
}
return null ;
}
catch ( Exception ex )
{
LogErrBLL . AddInfo ( ex . ToString ( ) , MethodBase . GetCurrentMethod ( ) ) ;
return null ;
}
}
}
}