You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

222 lines
9.1 KiB
C#

1 year ago
using Mesnac.Action.ChemicalWeighing.Entity;
using Mesnac.Action.ChemicalWeighing.Entity.Barrel;
using Mesnac.Action.ChemicalWeighing.Entity.material;
using Mesnac.Action.ChemicalWeighing.Entity.Package;
using Mesnac.Action.ChemicalWeighing.Entity.station;
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.Package
{
public class PackageHelper
{
#region 查询桶信息
/// <summary>
/// 查询物料信息
/// </summary>
/// <returns>物料信息表</returns>
public static DataTable QueryPackage()
{
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 ID,Name,BarCode,MaterialID,MaterialName,IsEnable FROM Hw_Package ";
dbHelper.CommandText = strSql;
DataTable table = dbHelper.ToDataTable();
return table;
}
#endregion
#region 根据条码查询桶信息
/// <summary>
/// 查询物料信息
/// </summary>
/// <returns>物料信息表</returns>
public static DataTable QueryIsExePackage(string barCode, int id)
{
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 ID,Name,BarCode,MaterialID,MaterialName,IsEnable FROM Hw_Package where IsEnable='是' and BarCode=@BarCode and ID<>@ID";
dbHelper.CommandText = strSql;
dbHelper.AddParameter("@BarCode", barCode);
dbHelper.AddParameter("@ID", id);
DataTable table = dbHelper.ToDataTable();
if (table != null && table.Rows.Count > 0)
{
return table;
}
return null;
}
#endregion
#region 新增物料
/// <summary>
/// 向数据库中新增物料信息
/// </summary>
/// <param name="material"></param>
public static void AddPackage(Hw_Package package)
{
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 insertUserSql = "INSERT INTO Hw_Package(Name, BarCode,MaterialID,MaterialName,IsEnable) VALUES(@Name, @BarCode, @MaterialID,@MaterialName,@IsEnable)";
dbHelper.CommandText = insertUserSql;
dbHelper.AddParameter("@Name", package.Name);
dbHelper.AddParameter("@BarCode", package.BarCode);
dbHelper.AddParameter("@MaterialID", package.MaterialID);
dbHelper.AddParameter("@MaterialName", package.MaterialName);
dbHelper.AddParameter("@IsEnable", package.IsEnable);
dbHelper.ExecuteNonQuery();
}
#endregion
#region 根据ID修改物料信息
public static void UpdatePackage(Hw_Package package)
{
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 Hw_Package SET Name=@Name, BarCode=@BarCode,IsEnable=@IsEnable WHERE ID=@ID";
dbHelper.CommandText = strSql;
dbHelper.AddParameter("@Name", package.Name);
dbHelper.AddParameter("@BarCode", package.BarCode);
dbHelper.AddParameter("@IsEnable", package.IsEnable);
dbHelper.AddParameter("@ID", package.ID);
dbHelper.ExecuteNonQuery();
}
catch (Exception ex)
{
ICSharpCode.Core.LoggingService<PackageHelper>.Error("修改整包信息异常:" + ex.Message, ex);
}
}
#endregion
#region 根据物料ID删除物料
public static void delete(string id)
{
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
dbHelper.CommandType = CommandType.Text;
dbHelper.ClearParameter();
string strSql = "DELETE FROM Hw_Package WHERE ID = @ID";
dbHelper.CommandText = strSql;
dbHelper.AddParameter("@ID", id);
dbHelper.ExecuteNonQuery();
}
#endregion
#region 获取物料对象集合
/// <summary>
/// 获取包含所有物料对象的集合
/// </summary>
/// <returns>返回一个list集合 其中是Material对象</returns>
//public static List<Pmt_material> getMaterialList()
//{
// DataTable table = getMaterial();
// List<Pmt_material> lst = new List<Pmt_material>();
// foreach (DataRow row in table.Rows)
// {
// Pmt_material material = new Pmt_material
// {
// ID = Mesnac.Basic.DataProcessor.RowValue(row, "ID", String.Empty),
// Material_code = Mesnac.Basic.DataProcessor.RowValue(row, "Material_code", String.Empty),
// Material_name = Mesnac.Basic.DataProcessor.RowValue(row, "Material_name", String.Empty),
// Remark = Mesnac.Basic.DataProcessor.RowValue(row, "Remark", String.Empty),
// Batch_number = Mesnac.Basic.DataProcessor.RowValue(row, "Batch_number", String.Empty),
// Barcode1 = Mesnac.Basic.DataProcessor.RowValue(row, "Barcode1", String.Empty),
// Barcode2 = Mesnac.Basic.DataProcessor.RowValue(row, "Barcode2", String.Empty),
// Barcode3 = Mesnac.Basic.DataProcessor.RowValue(row, "Barcode3", String.Empty),
// IsEnable = Mesnac.Basic.DataProcessor.RowValue(row, "IsEnable", String.Empty),
// };
// lst.Add(material);
// }
// return lst;
//}
#endregion
/// <summary>
/// 获取仓库
/// </summary>
/// <param name="code"></param>
/// <returns></returns>
/// <exception cref="Exception"></exception>
public static MaterialBarCode QueryMaterBarCode(string code)
{
MaterialBarCode entity = new MaterialBarCode();
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
dbHelper.CommandType = CommandType.Text;
string strSql = "select b.Bin_Serial,b.Bin_Name,m.Material_code,m.Material_name from Pmt_Bin b left join xl_material m on b.Material_ID=m.ID where Material_code = @Code and IsEnable='是'";
dbHelper.CommandText = strSql;
dbHelper.ClearParameter();
dbHelper.AddParameter("@Code", code);
DataTable table = dbHelper.ToDataTable();
if (table != null && table.Rows.Count > 0)
{
foreach (DataRow dr in table.Rows)
{
entity = ConvertDataRowToBarCode(dr);
return entity;
}
}
return entity;
}
private static MaterialBarCode ConvertDataRowToBarCode(DataRow dr)
{
if (dr != null)
{
MaterialBarCode bar = new MaterialBarCode();
bar.Bin_Serial = Mesnac.Basic.DataProcessor.RowValue(dr, "Bin_Serial", 0);
bar.Bin_Name = Mesnac.Basic.DataProcessor.RowValue(dr, "Bin_Name", String.Empty);
bar.Material_code = Mesnac.Basic.DataProcessor.RowValue(dr, "Material_code", String.Empty);
bar.Material_name = Mesnac.Basic.DataProcessor.RowValue(dr, "Material_name", String.Empty);
return bar;
}
else
{
return null;
}
}
}
}