Ejemplo n.º 1
0
 protected void Button3_Click(object sender, EventArgs e)
 {
     ProductoEntity prod = new ProductoEntity();
     prod = ProductoBO.getById(Convert.ToInt32(txtCod.Text));
     txtName.Text = prod.nombre;
     txtPrice.Text = prod.precio.ToString();
     txtQ.Text = prod.existencia.ToString();
 }
Ejemplo n.º 2
0
 protected void Button4_Click(object sender, EventArgs e)
 {
     ProductoEntity prod = new ProductoEntity();
     prod.nombre = txtName.Text;
     prod.id = Convert.ToInt32(txtCod.Text);
     prod.precio = Convert.ToDouble(txtPrice.Text);
     prod.existencia = Convert.ToInt32(txtQ.Text);
     ProductoBO.actualizar(prod);
     Response.Write("<script>alert(' Producto Actualizado');</script>");
 }
        protected void Button1_Click(object sender, EventArgs e)
        {
            ProductoEntity prod = new ProductoEntity();
            prod.nombre = txtNombre.Text;
            prod.precio = Convert.ToDouble(txtPrecio.Text);
            prod.existencia = Convert.ToInt32(txtExistencia.Text);

            ProductoBO.guardar(prod);

            txtExistencia.Text = string.Empty;
            txtNombre.Text = string.Empty;
            txtPrecio.Text = string.Empty;
        }
Ejemplo n.º 4
0
        public static void guardar(ProductoEntity prod)
        {
            using (MySqlConnection conexion = new MySqlConnection(ConfigurationManager.ConnectionStrings["default"].ToString()))
            {
                conexion.Open();
                string sql = @"INSERT INTO inventario(nombre, precio, existencia) VALUES(@nombre, @precio, @existencia)";
                MySqlCommand cmd = new MySqlCommand(sql, conexion);
                cmd.Parameters.AddWithValue("@nombre", prod.nombre);
                cmd.Parameters.AddWithValue("@precio", prod.precio);
                cmd.Parameters.AddWithValue("@existencia", prod.existencia);

                cmd.ExecuteNonQuery();
            }
        }
Ejemplo n.º 5
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            ProductoEntity prod = new ProductoEntity();

            prod.existencia = Convert.ToInt32(txtExistencia.Text);
            prod.nombre = txtProd.Text;
            prod.precio = Convert.ToDouble(txtPrecio.Text);

            ProductoBO.guardar(prod);
            txtProd.Text = "";
            txtPrecio.Text = "";
            txtExistencia.Text = "";
            Response.Write("<script>alert('Guardo correctamente');</script>");
        }
Ejemplo n.º 6
0
        protected void Button3_Click(object sender, EventArgs e)
        {
            //try
            //{

                prod = ProductoBO.getById(Convert.ToInt32(txtCod.Text));
                txtName.Text = prod.nombre;
                txtPrice.Text = prod.precio.ToString();
                txtQ.Text = prod.existencia.ToString();
            //}
            //catch
            //{
            //    Response.Write("<script>alert('error');</script>");
            //}
        }
Ejemplo n.º 7
0
        public static void actualizar(ProductoEntity prod)
        {
            using (MySqlConnection conexion = new MySqlConnection(ConfigurationManager.ConnectionStrings["default"].ToString()))
            {
                conexion.Open();
                string sql = @"update inventario set nombre=@nombre, precio=@precio, existencia=@existencia where codproducto=@id";
                MySqlCommand cmd = new MySqlCommand(sql, conexion);
                cmd.Parameters.AddWithValue("@nombre", prod.nombre);
                cmd.Parameters.AddWithValue("@id", prod.id);
                cmd.Parameters.AddWithValue("@precio", prod.precio);
                cmd.Parameters.AddWithValue("@existencia", prod.existencia);

                cmd.ExecuteNonQuery();
            }
        }
Ejemplo n.º 8
0
        public static ProductoEntity getById(int id)
        {
            ProductoEntity prod = new ProductoEntity();
            using (MySqlConnection conexion = new MySqlConnection(ConfigurationManager.ConnectionStrings["default"].ToString()))
            {
                conexion.Open();

                string sql = @"select * from inventario where codproducto = @id";

                MySqlCommand cmd = new MySqlCommand(sql, conexion);
                cmd.Parameters.AddWithValue("@id", id);

                MySqlDataReader reader = cmd.ExecuteReader();
                if (reader.Read())
                {
                    prod = LoadProducto(reader);
                }
            }
            return prod;
        }
Ejemplo n.º 9
0
        private static ProductoEntity LoadProducto(IDataReader reader)
        {
            ProductoEntity prod = new ProductoEntity();
            prod.existencia = Convert.ToInt32(reader["existencia"]);
            prod.id = Convert.ToInt32(reader["codproducto"]);
            prod.nombre = reader["nombre"].ToString();
            prod.precio = Convert.ToDouble(reader["precio"]);

            return prod;
        }