Exemple #1
0
        public List <CookieClass> listarCookie()
        {
            List <CookieClass> listaCookie = new List <CookieClass>();

            try
            {
                conn = new MySqlConnection(connectionString);
                conn.Open();
                String       query = "SELECT * FROM cookie";
                MySqlCommand cmd   = new MySqlCommand(query, conn);
                cmd.Prepare();
                MySqlDataReader dr = cmd.ExecuteReader();

                while (dr.Read())
                {
                    CookieClass cookie = new CookieClass()
                    {
                        Id    = Convert.ToInt32(dr["id"]),
                        Sabor = Convert.ToString(dr["sabor"]),
                        Valor = Convert.ToDecimal(dr["valor"])
                    };
                    listaCookie.Add(cookie);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            return(listaCookie);
        }
Exemple #2
0
        public void inserirCookie(CookieClass cookie)
        {
            conn = new MySqlConnection(connectionString);
            conn.Open();
            String       query = "INSERT INTO cookie (sabor, valor) VALUES(@sabor,@valor)";
            MySqlCommand cmd   = new MySqlCommand(query, conn);

            cmd.Parameters.AddWithValue("@sabor", cookie.Sabor);
            cmd.Parameters.AddWithValue("@valor", cookie.Valor);

            cmd.ExecuteNonQuery();
            conn.Close();
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            CookieClass cookie = new CookieClass()
            {
                Sabor = txtSabor.Text,
                Valor = Convert.ToDecimal(txtValor.Text)
            };

            CookieDAO dao = new CookieDAO();

            dao.inserirCookie(cookie);
            MessageBox.Show("cookie cadastrado com sucesso!!");
            txtSabor.Clear();
            txtValor.Clear();
        }