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.
136 lines
5.5 KiB
C#
136 lines
5.5 KiB
C#
using Mesnac.Action.ChemicalWeighing.Entity;
|
|
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.SmallMaterial.Parameter
|
|
{
|
|
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 Pmt_material";
|
|
dbHelper.CommandText = strSql;
|
|
DataTable table = dbHelper.ToDataTable();
|
|
return table;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 新增物料
|
|
/// <summary>
|
|
/// 向数据库中新增物料信息
|
|
/// </summary>
|
|
/// <param name="material"></param>
|
|
public static void addMaterial(Pmt_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 Pmt_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(Pmt_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 Pmt_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 Pmt_material 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),
|
|
};
|
|
lst.Add(material);
|
|
}
|
|
return lst;
|
|
}
|
|
#endregion
|
|
|
|
}
|
|
}
|