Exemplo n.º 1
0
        //********************************************************************************
        public static int agregar(Agregar pAlumno)
        {
            int          retorno = 0;
            MySqlCommand comado  = new MySqlCommand(string.Format("Insert into comida (ID, Producto , Marca , Precio, Cantidad) values('{0}','{1}','{2}','{3}','{4}')", pAlumno.Id, pAlumno.Producto, pAlumno.Marca, pAlumno.Precio, pAlumno.Cantidad), conexionBD.ObtenerConexion());

            retorno = comado.ExecuteNonQuery();
            return(retorno);
        }
        protected void Unnamed1_Click(object sender, EventArgs e)
        {
            if (txtmarca.Text.Trim() != "" && txtproducto.Text.Trim() != "" && txtprecio.Text.Trim() != "" && txtcantidad.Text.Trim() != "")
            {
                try
                {
                    Agregar pAlumno = new Agregar();
                    pAlumno.Marca    = txtmarca.Text.Trim();
                    pAlumno.Producto = txtproducto.Text.Trim();
                    pAlumno.Precio   = txtprecio.Text.Trim();
                    pAlumno.Cantidad = txtcantidad.Text.Trim();
                    int resultado = datos.agregar(pAlumno);
                    conec.Open();
                    MySqlCommand cmd = conec.CreateCommand();
                    cmd.CommandText = "select * from comida";
                    cmd.ExecuteNonQuery();
                    DataTable        dt = new DataTable();
                    MySqlDataAdapter da = new MySqlDataAdapter(cmd);
                    da.Fill(dt);
                    gvdlista.DataSource = dt;
                    gvdlista.DataBind();
                    conec.Close();

                    alerta.Text      = "<script>Swal.fire('Su producto se Agrego con exito.', '¡Gracias por preferirnos!', 'success'); </script>";
                    txtproducto.Text = "";
                    txtprecio.Text   = "";
                    txtcantidad.Text = "";
                    txtmarca.Text    = "";
                }
                catch
                {
                    alerta.Text = "<script>Swal.fire('Algo salio mal', 'Intentalo otra vez', 'error') </script>";
                }
            }
            else
            {
                alerta.Text = "<script>Swal.fire('ADVERTENCIA', 'No deje espacios en blanco', 'error') </script>";
            }
        }