// grabs supplier from DB, builds obj private Supplier_AS3 CreateSupplier(int _id) { // build command, get reader string _query = string.Format("SELECT * FROM Supplier WHERE (SupplierID = {0});", _id); OleDbCommand _cmd = new OleDbCommand(_query, connection); OleDbDataReader _reader = _cmd.ExecuteReader(); if (!_reader.Read()) { Trace.Warn("shop errors", string.Format("No supplier record for id={0}", _id)); return(null); } // parse information // SupplierID, Company, Contact, Phone, AreaCode int _supplierID = (int)_reader["SupplierID"]; string _company = (string)_reader["Company"]; string _contact = (string)_reader["Contact"]; string _phone = (string)_reader["Phone"]; string _area = (string)_reader["AreaCode"]; // build obj, add to list Supplier_AS3 _supplier = new Supplier_AS3(_supplierID, _company, _contact, _phone, _area); suppliers.Add(_supplier); return(_supplier); }
// gets/creates a list of suppliers that provide the given SKU private List <Supplier_AS3> GetCreateSuppliers(int _sku) { // build command, get reader string _query = string.Format("SELECT * FROM Supplied WHERE (SKU = {0});", _sku); OleDbCommand _cmd = new OleDbCommand(_query, connection); OleDbDataReader _reader = _cmd.ExecuteReader(); // Parse records, build lines list List <Supplier_AS3> _suppliers = new List <Supplier_AS3>(); while (_reader.Read()) { // parse out the SupplierID int _supplierID = (int)_reader["SupplierID"]; Supplier_AS3 _supplier = GetCreateSupplier(_supplierID); if (_supplier == null) { Trace.Warn("shop errors", "failed to parse line record"); } else { _suppliers.Add(_supplier); } } return(_suppliers); }