public List <Product> LoadCustomerProducts(int id) { CustomerForm customerForm = new CustomerForm(); List <Product> products = new List <Product>(); string sql = "SELECT products.id, products.code, products.description, products.category FROM products INNER JOIN customer_products ON products.id = customer_products.product_id WHERE customer_products.customer_id = :id ORDER BY products.code"; using (UniConnection con = DatabaseConnection.MakeConnection()) { con.Open(); UniCommand command = new UniCommand(sql, con); command.Parameters.Add("id", UniDbType.Int).Value = id; if (con.State == System.Data.ConnectionState.Open) { using (UniDataReader dr = command.ExecuteReader()) { while (dr.Read()) { Product product = new Product(); product.id = dr.GetInt32(ProductConstants.ProductId); product.code = dr.GetString(ProductConstants.Code); product.description = dr.GetString(ProductConstants.Description); product.category = dr.GetString(ProductConstants.Category); products.Add(product); } } } } return(products); }
//SELECT OPERATIONS - ProductForm.cs public List <Product> LoadProducts() { List <Product> products = new List <Product>(); string sql = "SELECT id, code, description, height, width, depth, colour, image, category FROM products ORDER BY id"; using (UniConnection con = DatabaseConnection.MakeConnection()) { con.Open(); UniCommand command = new UniCommand(sql, con); if (con.State == System.Data.ConnectionState.Open) { using (UniDataReader dr = command.ExecuteReader()) { while (dr.Read()) { Product product = new Product(); ImageConversion images = new ImageConversion(); product.id = dr.GetInt32(ProductConstants.ProductId); product.code = dr.GetString(ProductConstants.Code); product.description = dr.GetString(ProductConstants.Description); product.height = dr.GetInt32(ProductConstants.Height); product.width = dr.GetInt32(ProductConstants.Width); product.depth = dr.GetInt32(ProductConstants.Depth); product.colour = Color.FromArgb(dr.GetInt32(ProductConstants.Colour)); product.image = images.Base64ToImage(dr.GetString(ProductConstants.Image)); product.category = dr.GetString(ProductConstants.Category); products.Add(product); } } } con.Close(); } return(products); }
//SELECT OPERATIONS - ProductSelectionForm.cs public List <Product> LoadCustomerProducts() { List <Product> products = new List <Product>(); string sql = "SELECT id, code, description, height, width, depth FROM products ORDER BY id"; using (UniConnection con = DatabaseConnection.MakeConnection()) { con.Open(); UniCommand command = new UniCommand(sql, con); if (con.State == System.Data.ConnectionState.Open) { using (UniDataReader dr = command.ExecuteReader()) { while (dr.Read()) { Product product = new Product(); product.id = dr.GetInt32(ProductConstants.ProductId); product.code = dr.GetString(ProductConstants.Code); product.description = dr.GetString(ProductConstants.Description); product.height = dr.GetInt32(ProductConstants.Height); product.width = dr.GetInt32(ProductConstants.Width); product.depth = dr.GetInt32(ProductConstants.Depth); products.Add(product); } } } con.Close(); return(products); } }
//SELECT OPERATIONS - CustomerForm.cs public List <Customer> LoadCustomers() { List <Customer> customers = new List <Customer>(); string sql = "SELECT id, account, name, address_line_1, address_line_2, address_line_3, address_line_4, address_postcode FROM customers ORDER BY id"; using (UniConnection con = DatabaseConnection.MakeConnection()) { con.Open(); UniCommand command = new UniCommand(sql, con); if (con.State == System.Data.ConnectionState.Open) { using (UniDataReader dr = command.ExecuteReader()) { while (dr.Read()) { Customer customer = new Customer(); customer.id = dr.GetInt32(CustomerConstants.CustomerId); customer.account = dr.GetString(CustomerConstants.Account); customer.name = dr.GetString(CustomerConstants.Name); customer.address_line_1 = dr.GetString(CustomerConstants.AddressLine1); customer.address_line_2 = dr.GetString(CustomerConstants.AddressLine2); customer.address_line_3 = dr.GetString(CustomerConstants.AddressLine3); customer.address_line_4 = dr.GetString(CustomerConstants.AddressLine4); customer.address_postcode = dr.GetString(CustomerConstants.AddressPostcode); customers.Add(customer); } } } con.Close(); } return(customers); }