public void updateSupplier() { Suppliers supplier = new SuppliersBuilder("Moji Brodovi").Build(); int res = repo.updateSupplier(supplier); Assert.IsTrue(res == 0); }
public void addSupplier() { Suppliers supplier = new SuppliersBuilder("Moji Brodovi").Build(); index = repo.addSupplier(supplier); Assert.IsTrue(index != 0); }
public Suppliers getSupplierById(int supplierID) { Suppliers supplier = null; Connection conn = new Connection(); SqlConnection connection = conn.SqlConnection; SqlCommand selectCommand = new SqlCommand(); selectCommand.Connection = connection; selectCommand.CommandType = CommandType.StoredProcedure; selectCommand.CommandText = "GetSuppliersById"; selectCommand.Parameters.Add("@SupplierID", SqlDbType.Int); selectCommand.Parameters["@SupplierID"].Value = supplierID; { try { connection.Open(); SqlDataReader dataReader = selectCommand.ExecuteReader(); if (dataReader.HasRows) { dataReader.Read(); supplier = new SuppliersBuilder(dataReader.GetInt32(0), dataReader.GetString(1)) .ContactName(dataReader.IsDBNull(2) ? (string)null : dataReader.GetString(2)) .ContactTitle(dataReader.IsDBNull(3) ? (string)null : dataReader.GetString(3)) .Address(dataReader.IsDBNull(4) ? (string)null : dataReader.GetString(4)) .City(dataReader.IsDBNull(5) ? (string)null : dataReader.GetString(5)) .Region(dataReader.IsDBNull(6) ? (string)null : dataReader.GetString(6)) .PostalCode(dataReader.IsDBNull(7) ? (string)null : dataReader.GetString(7)) .Country(dataReader.IsDBNull(8) ? (string)null : dataReader.GetString(8)) .Phone(dataReader.IsDBNull(9) ? (string)null : dataReader.GetString(9)) .Fax(dataReader.IsDBNull(10) ? (string)null : dataReader.GetString(10)) .HomePage(dataReader.IsDBNull(11) ? (string)null : dataReader.GetString(11)) .Build(); } dataReader.Close(); } catch (Exception exc) { logger.logError(DateTime.Now, "Error while trying to get Supplier with SupplierID = " + supplierID + "."); MessageBox.Show(exc.Message); } finally { connection.Close(); } logger.logInfo(DateTime.Now, "GetSupplierById method has sucessfully invoked."); return(supplier); } }
private Suppliers(SuppliersBuilder builder) { this.SupplierID = builder.GetSupplierID; this.CompanyName = builder.GetCompanyName; this.ContactName = builder.GetContactName; this.ContactTitle = builder.GetContactTitle; this.Address = builder.GetAddress; this.City = builder.GetCity; this.Region = builder.GetRegion; this.PostalCode = builder.GetPostalCode; this.Country = builder.GetCountry; this.Phone = builder.GetPhone; this.Fax = builder.GetFax; this.HomePage = builder.GetHomePage; }
public List <Suppliers> getAllSuppliers() { List <Suppliers> suppliersList = new List <Suppliers>(); Connection conn = new Connection(); SqlConnection connection = conn.SqlConnection; using (SqlCommand command = new SqlCommand("select * from Suppliers", connection)) { try { connection.Open(); SqlDataReader dataReader = command.ExecuteReader(); while (dataReader.Read()) { Suppliers supplier = new SuppliersBuilder(dataReader.GetInt32(0), dataReader.GetString(1)) .ContactName(dataReader.IsDBNull(2) ? (string)null : dataReader.GetString(2)) .ContactTitle(dataReader.IsDBNull(3) ? (string)null : dataReader.GetString(3)) .Address(dataReader.IsDBNull(4) ? (string)null : dataReader.GetString(4)) .City(dataReader.IsDBNull(5) ? (string)null : dataReader.GetString(5)) .Region(dataReader.IsDBNull(6) ? (string)null : dataReader.GetString(6)) .PostalCode(dataReader.IsDBNull(7) ? (string)null : dataReader.GetString(7)) .Country(dataReader.IsDBNull(8) ? (string)null : dataReader.GetString(8)) .Phone(dataReader.IsDBNull(9) ? (string)null : dataReader.GetString(9)) .Fax(dataReader.IsDBNull(10) ? (string)null : dataReader.GetString(10)) .HomePage(dataReader.IsDBNull(11) ? (string)null : dataReader.GetString(11)) .Build(); suppliersList.Add(supplier); } dataReader.Close(); } catch (Exception exc) { logger.logError(DateTime.Now, "Error while trying to get all Suppliers."); MessageBox.Show(exc.Message); } logger.logInfo(DateTime.Now, "GetAllSuppliers method has sucessfully invoked."); return(suppliersList); } }