Пример #1
0
        protected void Delete(String id, addProducts suspend)
        {
            try
            {
                conn = new MySqlConnection(this.connection());
                conn.Open();
                DialogResult result = MessageBox.Show("Do you want to Delete this Data?", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                if (result == DialogResult.Yes)
                {
                    command = new MySqlCommand("DELETE FROM product WHERE products_id = @id", conn);
                    command.Parameters.AddWithValue("@id", id);
                    bool checkResult = (int)command.ExecuteNonQuery() > 0;

                    if (checkResult == true)
                    {
                        MessageBox.Show("Successfully Deleted", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        suspend.Hide();
                    }
                }
                else
                {
                    MessageBox.Show("Your data is safe", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (MySqlException ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Пример #2
0
        protected void Update(String category_id, String brand_id, TextBox[] product, String id, addProducts suspend)
        {
            try
            {
                conn = new MySqlConnection(this.connection());
                conn.Open();
                command = new MySqlCommand("UPDATE product SET barcode = @bar, product_name = @name , category_id = @categoryid, brand_id = @brandid, description = @desc, price = @price, reorder=@reorder ,date_updated = @date_updated WHERE products_id = @id", conn);
                command.Parameters.AddWithValue("@name", product[0].Text);
                command.Parameters.AddWithValue("@bar", product[1].Text);
                command.Parameters.AddWithValue("@categoryid", int.Parse(category_id));
                command.Parameters.AddWithValue("@brandid", int.Parse(brand_id));
                command.Parameters.AddWithValue("@desc", product[2].Text);
                command.Parameters.AddWithValue("@price", product[3].Text);
                command.Parameters.AddWithValue("@reorder", product[4].Text);
                command.Parameters.AddWithValue("@date_updated", dateNow);
                command.Parameters.AddWithValue("@id", id);

                bool checkResult = (int)command.ExecuteNonQuery() > 0;
                if (checkResult == true)
                {
                    MessageBox.Show("Updated Successfully", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    suspend.Hide();
                }

                command.Dispose();
                conn.Close();
            }
            catch (MySqlException ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Пример #3
0
        protected void insert(String category_id, String brand_id, TextBox[] product, addProducts suspend)
        {
            try
            {
                Random math = new Random();
                int    rand = math.Next(1, 1000);
                String id   = "P-00" + rand.ToString();

                conn = new MySqlConnection(this.connection());
                conn.Open();
                //MessageBox.Show(brand_id);

                command = new MySqlCommand("INSERT INTO product (products_id,barcode, product_name, category_id, brand_id, description, quantity, price, reorder, date_created)" +
                                           "VALUES (@id,@bar, @names, @categoryid, @brandid, @description, @quantity, @price, @reorder, @date_created)", conn);

                command.Parameters.AddWithValue("@id", id);
                command.Parameters.AddWithValue("@names", product[0].Text);
                command.Parameters.AddWithValue("@bar", product[1].Text);
                command.Parameters.AddWithValue("@categoryid", int.Parse(category_id));
                command.Parameters.AddWithValue("@brandid", int.Parse(brand_id));
                command.Parameters.AddWithValue("@description", product[2].Text);
                command.Parameters.AddWithValue("@quantity", product[3].Text);
                command.Parameters.AddWithValue("@price", product[4].Text);
                command.Parameters.AddWithValue("@reorder", product[5].Text);
                command.Parameters.AddWithValue("@date_created", dateNow);

                bool result = (int)command.ExecuteNonQuery() > 0;

                if (result == true)
                {
                    MessageBox.Show("Successfully Added", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    suspend.Hide();
                }

                foreach (TextBox reset in product)
                {
                    reset.Clear();
                }

                command.Dispose();
                conn.Close();
            }
            catch (MySqlException ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
 public void isUpdate(String category_id, String brand_id, TextBox[] productCred, String id, addProducts suspend)
 {
     this.Update(category_id, brand_id, productCred, id, suspend);
 }
 public void isDelete(String id, addProducts suspend)
 {
     this.Delete(id, suspend);
 }
        public void insertProduct(String category_id, String brand_id, TextBox[] productCred, addProducts suspend)
        {
            bool isNumeric = error.checkNum(productCred[3].Text);
            bool isDecimal = error.isDecimal(productCred[4].Text);

            if (isDecimal == true)
            {
                if (isNumeric == true)
                {
                    foreach (TextBox txt in productCred)
                    {
                        if (string.IsNullOrEmpty(txt.Text))
                        {
                            MessageBox.Show("Please fill all blank fields try again", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            break;
                        }
                        else
                        {
                            this.insert(category_id, brand_id, productCred, suspend);
                            break;
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Quantity should be numeric please try again", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                MessageBox.Show("Price must be Numeric please try again", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }