using System.Linq; using System.Web.UI.WebControls; namespace BLL { /// /// 供应商信息 /// public static class SupplierService { /// /// 根据主键获取供应商信息 /// /// /// public static Model.Weld_Supplier GetSupplierById(string id) { return Funs.DB.Weld_Supplier.FirstOrDefault(e => e.SupplierId == id); } /// /// 添加供应商信息 /// /// 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(); } /// /// 修改供应商信息 /// /// 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(); } } /// /// 根据主键删除供应商信息 /// /// 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(); } } /// /// 验证供应商代号是否存在 /// /// /// /// 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; } } /// /// 获取供应商 /// /// 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; } } }