public Delete(string name) { { SqlConnection conn = new SqlConnection(connectionString); string query = "DELETE FROM StockTable WHERE[Name]='" + name + "'"; IdPresent IP = new IdPresent(name); if (IP.Idpresent()) //To insure tha entered user id exists in data base { DialogResult DR = MessageBox.Show("Are You Sure You Want To Delete", "Warning", MessageBoxButtons.YesNo); if (DR == DialogResult.Yes) { conn.Close(); try { conn.Open(); SqlCommand cmnd = new SqlCommand(query, conn); cmnd.ExecuteNonQuery(); delete = true; } catch (Exception e) { MessageBox.Show(e.Message); } conn.Close(); } } else { MessageBox.Show("This Id does not exists"); } conn.Close(); } }
//For Product public Update(string name, double TP, int quantity, int discount) { double finalrate = Discount(TP, discount); SqlConnection conn = new SqlConnection(connectionString); string query = "UPDATE StockTable SET [Name]='" + name + "', [TP]='" + TP + "', [Quantity]='" + quantity + "', [Discount]='" + discount + "', [Final Rate]='" + finalrate + "' WHERE[Name]='" + name + "'"; IdPresent IP = new IdPresent(name); if (IP.Idpresent()) //To insure tha entered id exists in data base { conn.Close(); try { conn.Open(); SqlCommand cmnd = new SqlCommand(query, conn); cmnd.ExecuteNonQuery(); update = true; } catch (Exception e) { MessageBox.Show(e.Message); } } else { MessageBox.Show("This Id does not exists"); } conn.Close(); }
public Search(string name) { conn = new SqlConnection(connectionString); string query = "SELECT * FROM StockTable WHERE[Name]= '" + name + "'"; conn.Open(); IdPresent IP = new IdPresent(name); if (IP.Idpresent()) //To insure tha entered user id exists in data base { try { SqlCommand cmnd = new SqlCommand(query, conn); reader = cmnd.ExecuteReader(); if (reader.Read()) { search = true; } } catch (Exception e) { MessageBox.Show(e.Message); } } else { MessageBox.Show("This Id does not exists"); } }