protected void notOutofOrder(String id, frmStock load) { try { conn = new MySqlConnection(this.connection()); conn.Open(); using (command = new MySqlCommand("UPDATE stocks INNER JOIN product ON product.products_id = stocks.products_id SET status = 'Functioning' WHERE product.quantity > 0 AND stock_id = '" + id + "'", conn)) { bool check = (int)command.ExecuteNonQuery() > 0; if (check == true) { load.loadStocks(); } else { command = new MySqlCommand("UPDATE stocks INNER JOIN product ON product.products_id = stocks.products_id SET status = 'Out of order' WHERE product.quantity = 0 AND stock_id = '" + id + "'", conn); command.ExecuteNonQuery(); load.loadStocks(); } command.Dispose(); } conn.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
protected void insert(String pcode, frmStock load, TextBox[] textStocks, String date, String id) { try { DialogResult result = MessageBox.Show("Do you want to save this data?", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question); conn = new MySqlConnection(this.connection()); if (result == DialogResult.Yes) { conn.Open(); command = new MySqlCommand("INSERT INTO stocks (referenceNo, products_id, stockDate, stockInBy, vendor_id) VALUES (@referenceNo ,@id, @Date, @stockBy, @vendors)", conn); command.Parameters.AddWithValue("@referenceNo", textStocks[0].Text); command.Parameters.AddWithValue("@id", pcode); command.Parameters.AddWithValue("@Date", date); command.Parameters.AddWithValue("@stockBy", textStocks[1].Text); command.Parameters.AddWithValue("@vendors", id); bool checkResult = (int)command.ExecuteNonQuery() > 0; if (checkResult == true) { MessageBox.Show("You data save successfully", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); load.loadStocks(); } } else { MessageBox.Show("You data is safe", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); } command.Dispose(); conn.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
protected void updateQuantity(String QTY, String REF, String stockInBy, String id, frmStock update) { try { conn = new MySqlConnection(this.connection()); conn.Open(); command = new MySqlCommand("UPDATE stocks INNER JOIN product ON product.products_id = stocks.products_id SET quantity = @qty, referenceNo = @ref, stockInBy = @stockby WHERE stock_id = @id ", conn); command.Parameters.AddWithValue("@qty", QTY); command.Parameters.AddWithValue("@ref", REF); command.Parameters.AddWithValue("@stockby", stockInBy); command.Parameters.AddWithValue("@id", id); bool result = (int)command.ExecuteNonQuery() > 0; if (result == true) { MessageBox.Show("Data Updated Successfully", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); update.loadStocks(); update.getDataProducts(); } conn.Close(); command.Dispose(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
protected void Delete(String id, frmStock load) { try { conn = new MySqlConnection(this.connection()); conn.Open(); DialogResult result = MessageBox.Show("Do you want to delete your data?", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { using (command = new MySqlCommand("DELETE FROM stocks WHERE stock_id = @id", conn)) { command.Parameters.AddWithValue("@id", id); bool checkResult = (int)command.ExecuteNonQuery() > 0; if (checkResult == true) { MessageBox.Show("Deleted Successfully", "Successfully", MessageBoxButtons.OK, MessageBoxIcon.Information); load.loadStocks(); } command.Dispose(); } } else { MessageBox.Show("Your Data is safe", "Safe", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } conn.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }