public void CreateProductSelection(int customerid, int productid) { using (UniConnection con = DatabaseConnection.MakeConnection()) { con.Open(); if (con.State == System.Data.ConnectionState.Open) { using (UniCommand command = new UniCommand("INSERT into customer_products(customer_id, product_id) VALUES (:customer_id, :product_id) returning id", con)) { //INSERT OPERATION BELOW.. command.Parameters.Add("customer_id", UniDbType.Int).Value = customerid; command.Parameters.Add("product_id", UniDbType.Int).Value = productid; command.ExecuteScalar(); } } else { MessageBox.Show("Not open..."); } con.Close(); } }
//INSERT OPERATIONS - ProductForm.cs public void InsertProduct(Product product) { using (UniConnection con = DatabaseConnection.MakeConnection()) { con.Open(); using (UniCommand command = new UniCommand("INSERT into products(code, description, height, width, depth, colour, image, category) VALUES (:code, :description, :height, :width, :depth, :colour, :image, :category) returning id", con)) { ImageConversion images = new ImageConversion(); //INSERT OPERATION BELOW.. command.Parameters.Add("code", UniDbType.VarChar).Value = product.code; command.Parameters.Add("description", UniDbType.VarChar).Value = product.description; command.Parameters.Add("height", UniDbType.Int).Value = product.height; command.Parameters.Add("width", UniDbType.Int).Value = product.width; command.Parameters.Add("depth", UniDbType.Int).Value = product.depth; command.Parameters.Add("colour", UniDbType.Int).Value = product.colour.ToArgb(); command.Parameters.Add("image", UniDbType.VarChar).Value = images.ImageToBase64(product.image); //passing base64 string in command.Parameters.Add("category", UniDbType.VarChar).Value = product.category; int newProductID = (int)command.ExecuteScalar(); } con.Close(); } }
//INSERT OPERATIONS - CustomerForm.cs public void InsertCustomer(Customer customer) { using (UniConnection con = DatabaseConnection.MakeConnection()) { con.Open(); if (con.State == System.Data.ConnectionState.Open) { using (UniCommand command = new UniCommand("INSERT into customers(account, name, address_line_1, address_line_2, address_line_3, address_line_4, address_postcode) VALUES (:account, :name, :address_line_1, :address_line_2, :address_line_3, :address_line_4, :address_postcode) returning id", con)) { //INSERT OPERATION BELOW.. command.Parameters.Add("account", UniDbType.VarChar).Value = customer.account; command.Parameters.Add("name", UniDbType.VarChar).Value = customer.name; command.Parameters.Add("address_line_1", UniDbType.VarChar).Value = customer.address_line_1; command.Parameters.Add("address_line_2", UniDbType.VarChar).Value = customer.address_line_2; command.Parameters.Add("address_line_3", UniDbType.VarChar).Value = customer.address_line_3; command.Parameters.Add("address_line_4", UniDbType.VarChar).Value = customer.address_line_4; command.Parameters.Add("address_postcode", UniDbType.VarChar).Value = customer.address_postcode; int newCustomerID = (int)command.ExecuteScalar(); } } con.Close(); } }