Anda di halaman 1dari 4

Realizar un sistema que me permita tener una opcin de productos en la que despliegue una pantalla que me permita seleccionar

en combobox la categora de productos y que en un datagrid o listview muestre los productos dependiendo de su categora, adicionalmente se ubicara Se mostrara los botones nuevo, modificar, eliminar
select CategoryID, ProductName from Products where CategoryID = '4' select *from Categories select *from Products create procedure sp_productos ( @ProductID int, @ProductName nvarchar(40), @SupplierID int, @CategoryID int, @QuantityPerUnit nvarchar(20), @UnitPrice money, @UnitsInStock smallint, @UnitsOnOrder smallint, @ReorderLevel smallint, @Discontinued bit, @accion int ) as begin if @accion = 1 begin insert into Products (ProductID,ProductName,SupplierID,CategoryID, QuantityPerUnit,UnitPrice, UnitsInStock, UnitsOnOrder,ReorderLevel,Discontinued) values(@ProductID,@ProductName,@SupplierID,@CategoryID, @QuantityPerUnit,@UnitPrice, @UnitsInStock, @UnitsOnOrder,@ReorderLevel,@Discontinued) end if @accion =2 begin update Products set ProductName = @ProductName,SupplierID = @SupplierID, CategoryID = @CategoryID, QuantityPerUnit =@QuantityPerUnit,UnitPrice =@UnitPrice, UnitsInStock = @UnitsInStock, UnitsOnOrder = @UnitsOnOrder,ReorderLevel =@ReorderLevel,Discontinued =@Discontinued where ProductID = @ProductID end if @accion = 3 begin delete Products where ProductID = @ProductID end end set IDENTITY_INSERT Products ON exec sp_productos 79,'CARNE',24,8,1.34,0.10,4,10,20,'False',3

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using DATOSACCESO; using System.Data.SqlClient; namespace EJERCIO1CONSULPRODUCTONET { public partial class Form1 : Form { public Form1() { InitializeComponent(); } int ID; SqlConnection cnn = new SqlConnection(); DataSet ds = new DataSet(); SqlDataAdapter da = new SqlDataAdapter(); private void Form1_Load(object sender, EventArgs e) { DATOSACCESO.selecciones consulta_categoria = new selecciones(); consulta_categoria.consul_catego(); //llenamos el combobox con la variable datareader global while (DATOSACCESO.CONEXION.DRresultado.Read()) { cbo_catnom.Items.Add(DATOSACCESO.CONEXION.DRresultado.GetString(0)); } //cierro la conexion que abri en la clase de acceso de datos en metodo consultaDatos.cons_Departamento() DATOSACCESO.CONEXION.DRresultado.Close(); // (@ProductID,@ProductName,@SupplierID,@CategoryID, @QuantityPerUnit,@UnitPrice, @UnitsInStock, @UnitsOnOrder,@ReorderLevel,@Discontinued) SqlConnection cnn = new SqlConnection("Data Source= EDUARD ; Initial Catalog=Northwind;" + "Integrated Security=SSPI"); SqlCommand cmdUpdate = cnn.CreateCommand(); cmdUpdate.CommandType = CommandType.Text; SqlCommand cmdSelect = cnn.CreateCommand(); cmdSelect.CommandType = CommandType.Text; cmdSelect.CommandText = "select ProductID," + " ProductName from Products"; // cmdUpdate.CommandText = "update customers set " + " companyname = @companyname, contactname = " + " @contactname " + " where customerId = @customerId"; //cmdUpdate.CommandText = "update Products set ProductName = @ProductName,SupplierID = @SupplierID,CategoryID = @CategoryID, QuantityPerUnit =@QuantityPerUnit,UnitPrice =@UnitPrice, UnitsInStock = @UnitsInStock, UnitsOnOrder = @UnitsOnOrder,ReorderLevel =@ReorderLevel,Discontinued =@Discontinued where ProductID = @ProductID";

cmdUpdate.CommandText = "update Products set ProductName = @ProductName,SupplierID = @SupplierID,CategoryID = @CategoryID, QuantityPerUnit =@QuantityPerUnit where ProductID = @ProductID"; //cmdUpdate.CommandText = "update Products set " + " ProductName = @ProductName,SupplierID = "+" @SupplierID, CategoryID = "+" @CategoryID, QuantityPerUnit = " + " @QuantityPerUnit " + " where ProductID = @ProductID"; cmdUpdate.Parameters.Add("@ProductName", SqlDbType.NVarChar, 40, "ProductName"); cmdUpdate.Parameters.Add("@SupplierID", SqlDbType.NChar, 5, "SupplierID"); cmdUpdate.Parameters.Add("@CategoryID", SqlDbType.NChar, 5, "CategoryID"); cmdUpdate.Parameters.Add("@QuantityPerUnit", SqlDbType.NVarChar, 20, "QuantityPerUnit"); cmdUpdate.Parameters.Add("@ProductID", SqlDbType.NChar, 5, "ProductID"); cmdUpdate.Parameters["@ProductID"].SourceVersion = DataRowVersion.Original; SqlCommand cmdInsert = cnn.CreateCommand(); cmdInsert.CommandType = CommandType.Text; cmdInsert.CommandText = "insert into Products (ProductID,ProductName,SupplierID,CategoryID, QuantityPerUnit) values (@ProductID,@ProductName,@SupplierID,@CategoryID, @QuantityPerUnit)"; cmdInsert.Parameters.Add("@ProductName", SqlDbType.NVarChar, 30, "ProductName"); cmdInsert.Parameters.Add("@SupplierID", SqlDbType.NChar, 5, "SupplierID"); cmdInsert.Parameters.Add("@CategoryID", SqlDbType.NChar, 5, "CategoryID"); cmdInsert.Parameters.Add("@QuantityPerUnit", SqlDbType.NVarChar, 20, "QuantityPerUnit"); cmdInsert.Parameters.Add("@ProductID", SqlDbType.NChar, 5, "ProductID"); cmdInsert.Parameters["@ProductID"].SourceVersion = DataRowVersion.Original; SqlCommand cmdDelete = cnn.CreateCommand(); cmdDelete.CommandType = CommandType.Text; cmdDelete.CommandText = "delete Products where ProductID = @ProductID "; cmdDelete.Parameters.Add("@ProductID", SqlDbType.NChar, 5, "ProductID"); cmdDelete.Parameters["@ProductID"].SourceVersion = DataRowVersion.Original; da.SelectCommand = cmdSelect; da.UpdateCommand = cmdUpdate; da.InsertCommand = cmdInsert; da.DeleteCommand = cmdDelete; da.Fill(ds, "Products"); dataGridView1.DataSource = ds; dataGridView1.DataMember = "Products";

} private void button1_Click(object sender, EventArgs e) { }

private void cbo_catnom_SelectedIndexChanged(object sender, EventArgs e) { DATOSACCESO.selecciones consulta_ID = new selecciones(); ID = consulta_ID.cons_ID(cbo_catnom.Text); DATOSACCESO.selecciones GRID = new selecciones(); GRID.cons_GRID(Convert.ToInt32(ID).ToString()); dataGridView1.DataSource = DATOSACCESO.CONEXION.DS; dataGridView1.DataMember = "Products"; } private void button2_Click(object sender, EventArgs e) { da.Update(ds, "Products"); } } }

SqlCommand cmdselect = new SqlCommand(); cmdselect.CommandType = CommandType.Text; cmdselect.CommandText = "select CategoryName from Categories"; cbo_catnom.Text = (cmdselect.ExecuteNonQuery()).ToString();

Anda mungkin juga menyukai