Example #1
0
        private void btn_save_click(object sender, RoutedEventArgs e)
        {
            if (txt_supplierAddress.Text == "" || txt_supplierContact.Text == "" || txt_supplierName.Text == "")
            {
                MessageBox.Show("Incomplete details");
                return;
            }
            try
            {
                MessageBoxResult messageBoxResult = System.Windows.MessageBox.Show("Save Supplier details?", "Add Supplier", System.Windows.MessageBoxButton.YesNo);
                if (messageBoxResult == MessageBoxResult.Yes)
                {
                    string          query   = "insert into supplier values ('',@supplier_name,@supplier_contact,@supplier_address) ";
                    String          con     = System.Configuration.ConfigurationManager.ConnectionStrings["connectionString"].ConnectionString;
                    MySqlConnection connect = new MySqlConnection(con);
                    connect.Open();
                    MySqlCommand cmd = new MySqlCommand(query, connect);
                    cmd.Prepare();
                    cmd.Parameters.AddWithValue("@supplier_name", txt_supplierName.Text);
                    cmd.Parameters.AddWithValue("@supplier_address", txt_supplierAddress.Text);
                    cmd.Parameters.AddWithValue("@supplier_contact", txt_supplierContact.Text);
                    cmd.ExecuteNonQuery();

                    MessageBox.Show("Successfully Saved Data!", "Add Supplier", MessageBoxButton.OK, MessageBoxImage.Information);


                    clear_details();
                    show_supplier();
                    Forms.Inventory inventory = new Forms.Inventory();
                    inventory.show_inventory();

                    connect.Close();
                }
                else
                {
                    return;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Example #2
0
        private void insert_product()
        {
            String       dateNow = DateTime.Now.ToString("yyyy-MM-dd");
            FileStream   fs;
            BinaryReader br;

            byte[] ImageData = new byte[0];
            string FileName  = "";

            if (image_text != "")
            {
                FileName  = image_text;
                fs        = new FileStream(FileName, FileMode.Open, FileAccess.Read);
                br        = new BinaryReader(fs);
                ImageData = br.ReadBytes((int)fs.Length);
                br.Close();
                fs.Close();
            }

            if (cbox_supplier.Text == "" || cbox_category.Text == "")
            {
                MessageBox.Show("Incomplete details");
                return;
            }
            try
            {
                MessageBoxResult messageBoxResult = System.Windows.MessageBox.Show("Save product details?", "Add Product", System.Windows.MessageBoxButton.YesNo);
                if (messageBoxResult == MessageBoxResult.Yes)
                {
                    string query = "insert into inventory values " +
                                   "(@product_id," +
                                   "@product_name," +
                                   "(select category_id from category where category_name = @category_name)," +
                                   "(select supplier_id from supplier where supplier_name = @supplier_name)," +
                                   "@product_capital," +
                                   "@product_price," +
                                   "@product_quantity," +
                                   "@product_image," +
                                   "@dateNow) ";
                    String          con     = System.Configuration.ConfigurationManager.ConnectionStrings["connectionString"].ConnectionString;
                    MySqlConnection connect = new MySqlConnection(con);
                    connect.Open();
                    MySqlCommand cmd = new MySqlCommand(query, connect);
                    cmd.Prepare();
                    cmd.Parameters.AddWithValue("@product_id", txt_code.Text);
                    cmd.Parameters.AddWithValue("@product_name", txt_description.Text);
                    cmd.Parameters.AddWithValue("@category_name", cbox_category.Text);
                    cmd.Parameters.AddWithValue("@supplier_name", cbox_supplier.Text);
                    cmd.Parameters.AddWithValue("@product_capital", txt_capital.Text);
                    cmd.Parameters.AddWithValue("@product_price", txt_price.Text);
                    cmd.Parameters.AddWithValue("@product_quantity", txt_quantity.Text);
                    cmd.Parameters.AddWithValue("@product_image", ImageData);
                    cmd.Parameters.AddWithValue("@dateNow", dateNow);
                    cmd.ExecuteNonQuery();

                    MessageBox.Show("Successfully Saved Data!", "Add Product", MessageBoxButton.OK, MessageBoxImage.Information);

                    clear_details();

                    inventory.show_inventory();

                    connect.Close();
                }
                else
                {
                    return;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Example #3
0
        private void btn_update_click(object sender, RoutedEventArgs e)
        {
            String query = "";

            if (image_text == "")
            {
                query = "update inventory set " +
                        "product_name = @product_name, " +
                        "category_id = (select category_id from category where category_name = @category_name), " +
                        "supplier_id = (select supplier_id from supplier where supplier_name = @supplier_name), " +
                        "product_capital = @product_capital, " +
                        "product_price = @product_price, " +
                        "date_registered = @dateNow, " +
                        "product_quantity = @product_quantity " +
                        " where product_id = @product_id";
            }
            else
            {
                query = "update inventory set " +
                        "product_name = @product_name, " +
                        "category_id = (select category_id from category where category_name = @category_name), " +
                        "supplier_id = (select supplier_id from supplier where supplier_name = @supplier_name), " +
                        "product_capital = @product_capital, " +
                        "product_price = @product_price, " +
                        "product_quantity = @product_quantity," +
                        "date_registered = @dateNow, " +
                        "product_image = @product_image " +
                        " where product_id = @product_id";
            }
            FileStream   fs;
            BinaryReader br;

            byte[] ImageData = new byte[0];
            string FileName  = "";

            if (image_text != "")
            {
                FileName  = image_text;
                fs        = new FileStream(FileName, FileMode.Open, FileAccess.Read);
                br        = new BinaryReader(fs);
                ImageData = br.ReadBytes((int)fs.Length);
                br.Close();
                fs.Close();
            }

            if (cbox_supplier.Text == "" || cbox_category.Text == "")
            {
                MessageBox.Show("Incomplete details");
                return;
            }
            try
            {
                MessageBoxResult messageBoxResult = System.Windows.MessageBox.Show("Update product details?", "Edit Product", System.Windows.MessageBoxButton.YesNo);
                if (messageBoxResult == MessageBoxResult.Yes)
                {
                    String          con     = System.Configuration.ConfigurationManager.ConnectionStrings["connectionString"].ConnectionString;
                    MySqlConnection connect = new MySqlConnection(con);
                    connect.Open();
                    MySqlCommand cmd = new MySqlCommand(query, connect);
                    cmd.Prepare();
                    cmd.Parameters.AddWithValue("@product_id", txt_code.Text);
                    cmd.Parameters.AddWithValue("@product_name", txt_description.Text);
                    cmd.Parameters.AddWithValue("@category_name", cbox_category.Text);
                    cmd.Parameters.AddWithValue("@supplier_name", cbox_supplier.Text);
                    cmd.Parameters.AddWithValue("@product_capital", txt_capital.Text);
                    cmd.Parameters.AddWithValue("@product_price", txt_price.Text);
                    cmd.Parameters.AddWithValue("@product_quantity", txt_quantity.Text);
                    cmd.Parameters.AddWithValue("@@dateNow", DateTime.Now.ToString("yyyy-MM-dd"));
                    cmd.Parameters.AddWithValue("@product_image", ImageData);

                    cmd.ExecuteNonQuery();

                    MessageBox.Show("Successfully Updated Data!", "Edit Product", MessageBoxButton.OK, MessageBoxImage.Information);
                    inventory.show_inventory();

                    connect.Close();
                    this.Close();
                }
                else
                {
                    return;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }