public DataTable agregarCarrito(E_venta user) { DataTable agregar = new DataTable(); NpgsqlConnection conectar = new NpgsqlConnection(ConfigurationManager.ConnectionStrings["Postgres"].ConnectionString); try { NpgsqlDataAdapter dataAdapter = new NpgsqlDataAdapter("venta.agregar_venta", conectar); dataAdapter.SelectCommand.CommandType = CommandType.StoredProcedure; dataAdapter.SelectCommand.Parameters.Add("_id_estado", NpgsqlDbType.Integer).Value = user.Id_estado; dataAdapter.SelectCommand.Parameters.Add("_cantidad", NpgsqlDbType.Integer).Value = user.Cantidad; dataAdapter.SelectCommand.Parameters.Add("_id_cliente", NpgsqlDbType.Integer).Value = user.Id_cliente; dataAdapter.SelectCommand.Parameters.Add("_id_producto", NpgsqlDbType.Integer).Value = user.Id_producto; conectar.Open(); dataAdapter.Fill(agregar); } catch (Exception Ex) { throw Ex; } finally { if (conectar != null) { conectar.Close(); } } return(agregar); }
protected void GV_Verproducto_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "B_agregarp") { int index; index = int.Parse(e.CommandArgument.ToString()); ClientScriptManager cm = this.ClientScript; if (Int32.Parse(TB_cantidad.Text) <= index) { E_venta nuevo = new E_venta(); Dao_carrito agregar = new Dao_carrito(); nuevo.Cantidad = Int32.Parse(TB_cantidad.Text); nuevo.Id_estado = 2; nuevo.Id_cliente = Int32.Parse(Session["id_usuaro"].ToString()); nuevo.Id_producto = Int32.Parse(Session["id_producto"].ToString()); agregar.agregarCarrito(nuevo); cm.RegisterClientScriptBlock(this.GetType(), "", "<script type='text/javascript'>alert('Producto agregado corectamente');window.location=\"seleccionCarrito.aspx\"</script>"); } else { cm.RegisterClientScriptBlock(this.GetType(), "", "<script type='text/javascript'>alert('No contamos con la cantidad solicitada. ');window.location=\"Catalogo_Cliente.aspx\"</script>"); } } }