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.

318 lines
13 KiB
C#

using Mesnac.Action.ChemicalWeighing.Entity;
using Mesnac.Action.ChemicalWeighing.Entity.Barrel;
using Mesnac.Action.ChemicalWeighing.Entity.material;
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;
using System.Threading.Tasks;
namespace Mesnac.Action.ChemicalWeighing.Barrel
{
public class BarrelHelper
{
#region 查询桶信息
/// <summary>
/// 查询物料信息
/// </summary>
/// <returns>物料信息表</returns>
public static DataTable QueryBarrel()
{
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 * FROM Hw_Barrel ";
dbHelper.CommandText = strSql;
DataTable table = dbHelper.ToDataTable();
return table;
}
#endregion
#region 根据条码查询桶信息
/// <summary>
/// 查询物料信息
/// </summary>
/// <returns>物料信息表</returns>
public static DataTable QueryIsExeBarrel(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 * FROM Hw_Barrel 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 addBarrel(Hw_Barrel bar)
{
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_Barrel(BarrelID, BarrelName, BarCode,IsEnable) VALUES(@BarrelID, @BarrelName, @BarCode,@IsEnable)";
dbHelper.CommandText = insertUserSql;
dbHelper.AddParameter("@BarrelID", bar.BarrelID);
dbHelper.AddParameter("@BarrelName", bar.BarrelName);
dbHelper.AddParameter("@BarCode", bar.BarCode);
dbHelper.AddParameter("@IsEnable", bar.IsEnable);
dbHelper.ExecuteNonQuery();
}
#endregion
#region 根据ID修改物料信息
public static void UpdateMaterial(Hw_Barrel barrel)
{
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_Barrel SET BarrelName=@BarrelName, BarCode=@BarCode,IsEnable=@IsEnable WHERE ID=@ID";
dbHelper.CommandText = strSql;
dbHelper.AddParameter("@BarrelName", barrel.BarrelName);
dbHelper.AddParameter("@BarCode", barrel.BarCode);
dbHelper.AddParameter("@IsEnable", barrel.IsEnable);
dbHelper.AddParameter("@ID", barrel.ID);
dbHelper.ExecuteNonQuery();
}
catch (Exception ex)
{
ICSharpCode.Core.LoggingService<BarrelHelper>.Error("修改物料信息异常:" + ex.Message, ex);
}
}
#endregion
#region 根据ID解绑物料信息
public static void SplitMaterial(int Id)
{
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_Barrel SET MaterialID=null, MaterialName=null,PlanId=null,Weight=null WHERE ID=@ID";
dbHelper.CommandText = strSql;
dbHelper.AddParameter("@ID", Id);
dbHelper.ExecuteNonQuery();
}
catch (Exception ex)
{
ICSharpCode.Core.LoggingService<BarrelHelper>.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_Barrel 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;
}
#region 根据桶条码判断是否绑定物料
/// <summary>
/// 根据计划号 查看计划是否完成
/// </summary>
/// <param name="barCode">桶条码</param>
/// <returns>true:存在;false:未完成</returns>
/// <exception cref="Exception"></exception>
public static bool IsBindBarrel(string barCode)
{
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 = "DELETE FROM Hw_Barrel WHERE BarCode = @BarCode";
dbHelper.CommandText = strSql;
dbHelper.AddParameter("@BarCode", barCode);
object result = dbHelper.ToScalar();
if (result != null && result != DBNull.Value && Convert.ToInt32(result) > 0)
{
return true;
}
else
{
return false;
}
}
#endregion
#region Bind桶
/// <summary>
/// Bind桶
/// </summary>
/// <param name="barCode">桶条码</param>
/// <returns>true:更新成功;false:失败</returns>
/// <exception cref="Exception"></exception>
public static bool BindBarrel(string barCode,string materialID,string materialName,decimal Weight)
{
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_Barrel SET MaterialID=@MaterialID, MaterialName=@MaterialName,Weight=@Weight WHERE BarCode=@BarCode";
dbHelper.CommandText = strSql;
dbHelper.AddParameter("@MaterialID", materialID);
dbHelper.AddParameter("@MaterialName", materialName);
dbHelper.AddParameter("@Weight", Weight);
dbHelper.AddParameter("@BarCode", barCode);
dbHelper.ExecuteNonQuery();
return true;
}
catch (Exception ex)
{
ICSharpCode.Core.LoggingService<BarrelHelper>.Error("修改桶信息异常:" + ex.Message, ex);
return false;
}
}
#endregion
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;
}
}
}
}