using DevExpress.Xpo.Helpers ;
using Mesnac.Action.ChemicalWeighing.Entity ;
using Mesnac.Action.ChemicalWeighing.Entity.material ;
using Mesnac.Codd.Session ;
using System ;
using System.Collections.Generic ;
using System.Data ;
using System.Linq ;
using System.Text ;
using System.Threading.Tasks ;
namespace Mesnac.Action.ChemicalWeighing.BinManage
{
public class BinHelper
{
#region 查询料仓信息
/// <summary>
/// 查询料仓信息
/// </summary>
/// <returns>料仓信息表</returns>
public static DataTable getBin ( )
{
DbHelper dbHelper = Mesnac . Basic . DataSourceFactory . Instance . GetDbHelper ( Mesnac . Basic . DataSourceFactory . MCDbType . Local ) ;
if ( dbHelper = = null )
{
throw new Exception ( Mesnac . Basic . LanguageHelper . DataBaseConnectError ) ;
}
dbHelper . ClearParameter ( ) ;
dbHelper . CommandType = CommandType . Text ;
string strSql = "SELECT Bin_Serial,Bin_Name,Bin_Code,Material_ID, Material_name,Station_Weight_Medium,Station_Weight_Low,Station_Weight_Advance,Station_Speed_Hight,Station_Speed_Medium,Station_Speed_Low FROM Pmt_Bin LEFT JOIN xl_material ON Pmt_Bin.Material_ID=xl_material.ID ORDER BY Bin_Serial" ;
dbHelper . CommandText = strSql ;
DataTable table = dbHelper . ToDataTable ( ) ;
return table ;
}
# endregion
#region 获取物料名与ID对象集合
/// <summary>
/// 获取所有物料对象集合
/// </summary>
/// <returns></returns>
public static List < xl_material > GetXlMaterialList ( )
{
DbHelper dbHelper = Mesnac . Basic . DataSourceFactory . Instance . GetDbHelper ( Mesnac . Basic . DataSourceFactory . MCDbType . Local ) ;
if ( dbHelper = = null )
{
throw new Exception ( Mesnac . Basic . LanguageHelper . DataBaseConnectError ) ;
}
dbHelper . ClearParameter ( ) ;
dbHelper . CommandType = CommandType . Text ;
string sqlstr = "SELECT ID, Material_name FROM xl_material where IsEnable='是'" ;
dbHelper . CommandText = sqlstr ;
DataTable table = dbHelper . ToDataTable ( ) ;
List < xl_material > lst = new List < xl_material > ( ) ;
xl_material material = null ;
foreach ( DataRow row in table . Rows )
{
material = new xl_material ( ) ;
material . ID = Mesnac . Basic . DataProcessor . RowValue ( row , "ID" , String . Empty ) ;
material . Material_name = Mesnac . Basic . DataProcessor . RowValue ( row , "Material_name" , String . Empty ) ;
lst . Add ( material ) ;
}
return lst ;
}
# endregion
#region 根据料仓号修改对应物料
public static void updateBin ( Pmt_Bin bin )
{
try
{
DbHelper dbHelper = Mesnac . Basic . DataSourceFactory . Instance . GetDbHelper ( Mesnac . Basic . DataSourceFactory . MCDbType . Local ) ;
if ( dbHelper = = null )
{
throw new Exception ( Mesnac . Basic . LanguageHelper . DataBaseConnectError ) ;
}
dbHelper . ClearParameter ( ) ;
dbHelper . CommandType = CommandType . Text ;
string strSql = "UPDATE Pmt_Bin SET Bin_Code=@Bin_Code,Material_ID=@MaterialId,Station_Weight_Medium=@Station_Weight_Medium,Station_Weight_Low=@Station_Weight_Low,Station_Weight_Advance=@Station_Weight_Advance,Station_Speed_Hight=@Station_Speed_Hight,Station_Speed_Medium=@Station_Speed_Medium,Station_Speed_Low=@Station_Speed_Low,IF_FLAG=@IfFlag WHERE Bin_Serial=@BinSerial" ;
dbHelper . CommandText = strSql ;
dbHelper . AddParameter ( "@Bin_Code" , bin . Bin_Code ) ;
dbHelper . AddParameter ( "@MaterialId" , bin . Material_ID ) ;
dbHelper . AddParameter ( "@BinSerial" , bin . Bin_Serial ) ;
dbHelper . AddParameter ( "@Station_Weight_Medium" , bin . Station_Weight_Medium ) ;
dbHelper . AddParameter ( "@Station_Weight_Low" , bin . Station_Weight_Low ) ;
dbHelper . AddParameter ( "@Station_Weight_Advance" , bin . Station_Weight_Advance ) ;
dbHelper . AddParameter ( "@Station_Speed_Hight" , bin . Station_Speed_Hight ) ;
dbHelper . AddParameter ( "@Station_Speed_Medium" , bin . Station_Speed_Medium ) ;
dbHelper . AddParameter ( "@Station_Speed_Low" , bin . Station_Speed_Low ) ;
dbHelper . AddParameter ( "@IfFlag" , 1 ) ;
dbHelper . ExecuteNonQuery ( ) ;
}
catch ( Exception ex )
{
ICSharpCode . Core . LoggingService < BinHelper > . Error ( "修改料仓信息异常:" + ex . Message , ex ) ;
}
}
# endregion
#region 获取bin对象集合
public static List < Pmt_Bin > getBinList ( )
{
DataTable userTable = getBin ( ) ;
List < Pmt_Bin > lst = new List < Pmt_Bin > ( ) ;
foreach ( DataRow row in userTable . Rows )
{
Pmt_Bin bin = new Pmt_Bin
{
Bin_Serial = Mesnac . Basic . DataProcessor . RowValue ( row , "Bin_Serial" , 0 ) ,
Material_ID = Mesnac . Basic . DataProcessor . RowValue ( row , "Material_ID" , String . Empty ) ,
Bin_Name = Mesnac . Basic . DataProcessor . RowValue ( row , "Bin_Name" , String . Empty ) ,
Bin_Code = Mesnac . Basic . DataProcessor . RowValue ( row , "Bin_Code" , String . Empty ) ,
Station_Weight_Medium = decimal . Parse ( Mesnac . Basic . DataProcessor . RowValue ( row , "Station_Weight_Medium" , 0.000 ) . ToString ( ) ) ,
Station_Weight_Low = decimal . Parse ( Mesnac . Basic . DataProcessor . RowValue ( row , "Station_Weight_Low" , 0.000 ) . ToString ( ) ) ,
Station_Weight_Advance = decimal . Parse ( Mesnac . Basic . DataProcessor . RowValue ( row , "Station_Weight_Advance" , 0.000 ) . ToString ( ) ) ,
Station_Speed_Hight = decimal . Parse ( Mesnac . Basic . DataProcessor . RowValue ( row , "Station_Speed_Hight" , 0.0 ) . ToString ( ) ) ,
Station_Speed_Medium = decimal . Parse ( Mesnac . Basic . DataProcessor . RowValue ( row , "Station_Speed_Medium" , 0.0 ) . ToString ( ) ) ,
Station_Speed_Low = decimal . Parse ( Mesnac . Basic . DataProcessor . RowValue ( row , "Station_Speed_Low" , 0.0 ) . ToString ( ) )
} ;
lst . Add ( bin ) ;
}
return lst ;
}
# endregion
#region 获取物料
public static DataTable GetBinMaterial ( )
{
string sql = @ "select distinct m.ID MaterialID,m.Material_code MaterialCode, m.Material_name MaterialName
FROM Pmt_Bin b inner join xl_material m ON b . Material_ID = m . ID ";
IFreeSql fsql = DBHelper . FreeHelper . Instance ;
DataTable dt = fsql . Select < object > ( ) . WithSql ( sql ) . ToDataTable ( "*" ) ;
return dt ;
}
# endregion
#region 获取物料
public static DataTable GetBinMaterial2 ( )
{
string sql = @ "select distinct m.ID MaterialID,m.Material_code MaterialCode, m.Material_name MaterialName
FROM Pmt_Bin b inner join xl_material m ON b . Material_ID = m . ID ";
IFreeSql fsql = DBHelper . FreeHelper . Instance ;
DataTable dt = fsql . Select < object > ( ) . WithSql ( sql ) . ToDataTable ( "*" ) ;
return dt ;
}
# endregion
}
}