|
|
|
|
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.Solvent.Material
|
|
|
|
|
{
|
|
|
|
|
class MaterialHelper
|
|
|
|
|
{
|
|
|
|
|
#region 查询物料信息
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 查询物料信息
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>物料信息表</returns>
|
|
|
|
|
public static DataTable getMaterial()
|
|
|
|
|
{
|
|
|
|
|
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,row_number() over(order by ID) as '序号', Material_code, Material_name, Remark, Batch_number, Barcode1, Barcode2, Barcode3 FROM xl_material";
|
|
|
|
|
dbHelper.CommandText = strSql;
|
|
|
|
|
DataTable table = dbHelper.ToDataTable();
|
|
|
|
|
return table;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 新增物料
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 向数据库中新增物料信息
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="material"></param>
|
|
|
|
|
public static void addMaterial(xl_material material)
|
|
|
|
|
{
|
|
|
|
|
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 xl_material(ID, Material_code, Material_name) VALUES(@M_ID, @M_Code, @M_Name)";
|
|
|
|
|
dbHelper.CommandText = insertUserSql;
|
|
|
|
|
|
|
|
|
|
dbHelper.AddParameter("@M_ID", material.ID);
|
|
|
|
|
dbHelper.AddParameter("@M_Code", material.Material_code);
|
|
|
|
|
dbHelper.AddParameter("@M_Name", material.Material_name);
|
|
|
|
|
dbHelper.ExecuteNonQuery();
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 根据ID修改物料信息
|
|
|
|
|
public static void updateMaterial(xl_material material)
|
|
|
|
|
{
|
|
|
|
|
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 xl_material SET Material_code=@MaterialCode, Material_name=@MaterialName WHERE ID=@ID";
|
|
|
|
|
dbHelper.CommandText = strSql;
|
|
|
|
|
dbHelper.AddParameter("@MaterialCode", material.Material_code);
|
|
|
|
|
dbHelper.AddParameter("@MaterialName", material.Material_name);
|
|
|
|
|
dbHelper.AddParameter("@ID", material.ID);
|
|
|
|
|
dbHelper.ExecuteNonQuery();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
ICSharpCode.Core.LoggingService<MaterialHelper>.Error("修改物料信息异常:" + ex.Message, ex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 根据物料ID删除物料
|
|
|
|
|
public static void deleteMaterial(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 xl_material WHERE ID = @ID";
|
|
|
|
|
dbHelper.CommandText = strSql;
|
|
|
|
|
dbHelper.AddParameter("@ID", id);
|
|
|
|
|
dbHelper.ExecuteNonQuery();
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 获取物料对象集合
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取包含所有物料对象的集合
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>返回一个list集合 其中是Material对象</returns>
|
|
|
|
|
public static List<xl_material> getMaterialList()
|
|
|
|
|
{
|
|
|
|
|
DataTable table = getMaterial();
|
|
|
|
|
List<xl_material> lst = new List<xl_material>();
|
|
|
|
|
|
|
|
|
|
foreach (DataRow row in table.Rows)
|
|
|
|
|
{
|
|
|
|
|
xl_material material = new xl_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),
|
|
|
|
|
};
|
|
|
|
|
lst.Add(material);
|
|
|
|
|
}
|
|
|
|
|
return lst;
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|