ZHJA_HJGL/HJGL_ZH/BLL/WeldMat/BaseInfo/SupplierService.cs

110 lines
3.5 KiB
C#
Raw Normal View History

2024-05-08 17:17:11 +08:00
using System.Linq;
using System.Web.UI.WebControls;
namespace BLL
{
/// <summary>
/// 供应商信息
/// </summary>
public static class SupplierService
{
/// <summary>
/// 根据主键获取供应商信息
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public static Model.Weld_Supplier GetSupplierById(string id)
{
return Funs.DB.Weld_Supplier.FirstOrDefault(e => e.SupplierId == id);
}
/// <summary>
/// 添加供应商信息
/// </summary>
/// <param name="supplier"></param>
public static void AddSupplier(Model.Weld_Supplier supplier)
{
Model.SGGLDB db = Funs.DB;
Model.Weld_Supplier newSupplier = new Model.Weld_Supplier();
newSupplier.SupplierId = supplier.SupplierId;
newSupplier.SupplierCode = supplier.SupplierCode;
newSupplier.SupplierName = supplier.SupplierName;
newSupplier.ContactMan = supplier.ContactMan;
newSupplier.ContactPhone = supplier.ContactPhone;
db.Weld_Supplier.InsertOnSubmit(newSupplier);
db.SubmitChanges();
}
/// <summary>
/// 修改供应商信息
/// </summary>
/// <param name="supplier"></param>
public static void UpdateSupplier(Model.Weld_Supplier supplier)
{
Model.SGGLDB db = Funs.DB;
Model.Weld_Supplier newSupplier = db.Weld_Supplier.FirstOrDefault(e => e.SupplierId == supplier.SupplierId);
if (newSupplier != null)
{
newSupplier.SupplierCode = supplier.SupplierCode;
newSupplier.SupplierName = supplier.SupplierName;
newSupplier.ContactMan = supplier.ContactMan;
newSupplier.ContactPhone = supplier.ContactPhone;
db.SubmitChanges();
}
}
/// <summary>
/// 根据主键删除供应商信息
/// </summary>
/// <param name="supplierId"></param>
public static void DeleteSupplierById(string supplierId)
{
Model.SGGLDB db = Funs.DB;
Model.Weld_Supplier supplier = db.Weld_Supplier.FirstOrDefault(e => e.SupplierId == supplierId);
if (supplier != null)
{
db.Weld_Supplier.DeleteOnSubmit(supplier);
db.SubmitChanges();
}
}
/// <summary>
/// 验证供应商代号是否存在
/// </summary>
/// <param name="code"></param>
/// <param name="id"></param>
/// <returns></returns>
public static bool IsExitSupplierCode(string code, string id)
{
var q = Funs.DB.Weld_Supplier.FirstOrDefault(x => x.SupplierCode == code && x.SupplierId != id);
if (q != null)
{
return true;
}
else
{
return false;
}
}
/// <summary>
/// 获取供应商
/// </summary>
/// <returns></returns>
public static ListItem[] GetSupplierList()
{
var q = (from x in Funs.DB.Weld_Supplier orderby x.SupplierName select x).ToList();
ListItem[] lis = new ListItem[q.Count()];
for (int i = 0; i < q.Count(); i++)
{
lis[i] = new ListItem(q[i].SupplierName ?? "", q[i].SupplierId);
}
return lis;
}
}
}