//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); }
private bool ErrorCheck() { bool check = false; ClearErrorProvider(); ImageConversion image = new ImageConversion(); Bitmap bitmap; Product product = ProductBindingSource.Current as Product; if (product.image != null) { bitmap = new Bitmap(product.image); string product_image = image.ImageToBase64(bitmap); } else { _image.Focus(); errorProvider.SetError(_image, "Please select an image!"); check = true; } Color colour = product.colour; int a = colour.ToArgb(); string product_code = code_.Text; string product_description = description.Text; string product_height = height.Text; string product_width = width.Text; string product_depth = depth.Text; string product_colour = a.ToString(); string product_category = category_comboBox.Text; //code if (string.IsNullOrWhiteSpace(product_code)) { code_.Focus(); errorProvider.SetError(code_, "Please enter a valid product code!"); check = true; } else if (product_code.Length > 10) { code_.Focus(); errorProvider.SetError(code_, "Please enter a valid product code of up to 10 characters!"); check = true; } //description if (string.IsNullOrWhiteSpace(product_description)) { description.Focus(); errorProvider.SetError(description, "Please enter a valid customer name!"); check = true; } else if (product_description.Length > 50) { description.Focus(); errorProvider.SetError(description, "Please enter a valid customer name of up to 50 characters!"); check = true; } //height if (string.IsNullOrWhiteSpace(product_height)) { height.Focus(); errorProvider.SetError(height, "Please enter a valid height value!"); check = true; } else if (product_height.Length > 4) { height.Focus(); errorProvider.SetError(height, "Please enter a valid height value consisting of up to 4 characters!"); check = true; } if (product_height == "0") { height.Focus(); errorProvider.SetError(height, "Height value cannot be zero!"); check = true; } //width if (string.IsNullOrWhiteSpace(product_width)) { width.Focus(); errorProvider.SetError(width, "Please enter a valid width value!"); check = true; } else if (product_width.Length > 4) { width.Focus(); errorProvider.SetError(width, "Please enter a valid width value consisting of up to 4 characters!"); check = true; } if (product_width == "0") { width.Focus(); errorProvider.SetError(width, "Width value cannot be zero!"); check = true; } //depth if (string.IsNullOrWhiteSpace(product_depth)) { depth.Focus(); errorProvider.SetError(depth, "Please enter a valid depth value!"); check = true; } else if (product_depth.Length > 4) { depth.Focus(); errorProvider.SetError(depth, "Please enter a valid depth value consisting of up to 4 characters!"); check = true; } if (product_depth == "0") { depth.Focus(); errorProvider.SetError(depth, "Depth value cannot be zero!"); check = true; } //colour if (product_colour == "0") { _colour.Focus(); errorProvider.SetError(_colour, "Please select a colour!"); check = true; } //category if (category_comboBox.Text == "") { category_comboBox.Focus(); errorProvider.SetError(category_comboBox, "Please select a category!"); check = true; } return(check); }