Example #1
0
        public static bool addMed(CatMed catMed)
        {
            string     insertStatement = "INSERT INTO CatMeds VALUES (@MedID, @CatID, @Date, @Description)";
            SqlCommand insertCommand   = new SqlCommand(insertStatement, connection);

            insertCommand.Parameters.AddWithValue("@MedID", catMed.MedID);
            insertCommand.Parameters.AddWithValue("@CatID", catMed.CatID);
            insertCommand.Parameters.AddWithValue("@Date", catMed.Date);
            insertCommand.Parameters.AddWithValue("@Description", catMed.Description);

            try
            {
                connection.Open();
                int successInd = insertCommand.ExecuteNonQuery();

                if (successInd > 0)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                connection.Close();
            }
        }
Example #2
0
        public static bool modMed(CatMed catMed)
        {
            string updateStatement = "UPDATE CatMeds " +
                                     "SET Description = @Description " +
                                     "WHERE MedID = @MedID";
            SqlCommand updateCommand = new SqlCommand(updateStatement, connection);

            updateCommand.Parameters.AddWithValue("@Description", catMed.Description);
            updateCommand.Parameters.AddWithValue("@MedID", catMed.MedID);

            try
            {
                connection.Open();
                int successInd = updateCommand.ExecuteNonQuery();

                if (successInd > 0)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                connection.Close();
            }
        }
Example #3
0
        private void BtnMod_Click(object sender, EventArgs e)
        {
            catMed = DBcommands.getMeds(txtCatID.Text);

            AddModifyMed modMed = new AddModifyMed();

            modMed.Mod    = true;
            modMed.cat    = cat;
            modMed.catMed = catMed;
            modMed.modLoad();

            DialogResult result = modMed.ShowDialog();

            LoadDataGrid();
        }
Example #4
0
        public static CatMed getMeds(string catID)
        {
            string     selectStatement = "SELECT * FROM CatMeds WHERE CatID = @CatID";
            SqlCommand selectCommand   = new SqlCommand(selectStatement, connection);

            selectCommand.Parameters.AddWithValue("@CatID", catID);

            try
            {
                connection.Open();

                SqlDataReader catReader = selectCommand.ExecuteReader(System.Data.CommandBehavior.SingleRow);

                if (catReader.Read())
                {
                    CatMed catMed = new CatMed();

                    catMed.MedID       = (int)catReader["MedID"];
                    catMed.CatID       = (int)catReader["CatID"];
                    catMed.Date        = catReader["Date"].ToString();
                    catMed.Description = catReader["Description"].ToString();

                    return(catMed);
                }
                else
                {
                    return(null);
                }
            }
            catch (SqlException ex)
            {
                throw ex;
            }
            finally
            {
                connection.Close();
            }
        }