public bool EditDrug(Drug drug, int drugId, Form form) { bool isSuccess = false; SqlConnection conn = new SqlConnection(myconnstring); try { string query = "Update Drug Set drug = @drug, cost = @cost WHERE drug_id = @drugId"; SqlCommand cmd = new SqlCommand(query, conn); cmd.Parameters.AddWithValue("@drug", drug.name); cmd.Parameters.AddWithValue("@cost", drug.cost); cmd.Parameters.AddWithValue("@drugId", drugId); conn.Open(); int rows = cmd.ExecuteNonQuery(); if (rows > 0) { isSuccess = true; } else { isSuccess = false; } } catch (Exception ex) { MessageBox.Show(ex.ToString()); //CustomMessageBox cm = new CustomMessageBox("Failed to add patient", form); //cm.Show(); } finally { conn.Close(); } return(isSuccess); }
public bool AddNewDrug(Drug drug, Form form) { bool isSuccess = false; SqlConnection conn = new SqlConnection(myconnstring); try { string query = "INSERT INTO Drug (drug_id, drug, cost) VALUES (NEXT VALUE FOR drug_seq ,@name, @cost)"; SqlCommand cmd = new SqlCommand(query, conn); cmd.Parameters.AddWithValue("@name", drug.name); cmd.Parameters.AddWithValue("@cost", drug.cost); conn.Open(); int rows = cmd.ExecuteNonQuery(); if (rows > 0) { isSuccess = true; } else { isSuccess = false; } } catch (Exception ex) { MessageBox.Show(ex.ToString()); //CustomMessageBox cm = new CustomMessageBox("Failed to add drug", form); //cm.Show(); } finally { conn.Close(); } return(isSuccess); }