Actividad 4

Descargar como docx, pdf o txt
Descargar como docx, pdf o txt
Está en la página 1de 10

Actividad 4

Realizar el CRUD o ABM de la tabla Producto basado en el avance con Entity Framework y base
de datos Proyecto de Clases.

Resultado del programa


Codigo

<title></title>

<style type="text/css">

.auto-style1 {

width: 100%;

.auto-style2 {

width: 137px;

</style>

</head>

<body>

<form id="form1" runat="server">

<div>

<table class="auto-style1">

<tr>

<td>

<table class="auto-style1">

<tr>

<td class="auto-style2">

<asp:Label ID="Label2" runat="server" Font-Bold="True"


ForeColor="#FF6600" Text="Editar Datos"></asp:Label>

</td>

<td class="auto-style5">&nbsp;</td>

<td>&nbsp;</td>

</tr>

<tr>

<td class="auto-style2">

<asp:Label ID="Label3" runat="server" Font-Bold="True"


ForeColor="#0000CC" Text="Id:"></asp:Label>
</td>

<td class="auto-style10">

<asp:TextBox ID="TextBox7" runat="server"></asp:TextBox>

</td>

<td class="auto-style11"></td>

</tr>

<tr>

<td class="auto-style2">

<asp:Label ID="Label4" runat="server" Font-Bold="True"


ForeColor="#0000CC" Text="Nombre:"></asp:Label>

</td>

<td class="auto-style5">

<asp:TextBox ID="TextBox8" runat="server"


Width="172px"></asp:TextBox>

</td>

<td>&nbsp;</td>

</tr>

<tr>

<td class="auto-style2">

<asp:Label ID="Label5" runat="server" Font-Bold="True"


ForeColor="#0000CC" Text="Costo:"></asp:Label>

</td>

<td class="auto-style5">

<asp:TextBox ID="TextBox4" runat="server"


Width="78px"></asp:TextBox>

</td>

<td>&nbsp;</td>

</tr>

<tr>

<td class="auto-style2">

<asp:Label ID="Label6" runat="server" Font-Bold="True"


ForeColor="#0000CC" Text="Precio Venta :"></asp:Label>

</td>
<td class="auto-style7">

<asp:TextBox ID="TextBox9" runat="server"


Width="77px"></asp:TextBox>

</td>

<td class="auto-style8"></td>

</tr>

<tr>

<td class="auto-style2">

<asp:Label ID="Label8" runat="server" Font-Bold="True"


ForeColor="#0000CC" Text="Stock:"></asp:Label>

</td>

<td class="auto-style5">

<asp:TextBox ID="TextBox10" runat="server"


Width="81px"></asp:TextBox>

</td>

<td>&nbsp;</td>

</tr>

<tr>

<td class="auto-style2">

<asp:Label ID="Label9" runat="server" Font-Bold="True"


ForeColor="#0000CC" Text="Categoria:"></asp:Label>

</td>

<td class="auto-style5">

<asp:DropDownList ID="DropDownList1" runat="server">

</asp:DropDownList>

</td>

<td>&nbsp;</td>

</tr>

<tr>

<td class="auto-style2">&nbsp;</td>

<td class="auto-style5">&nbsp;</td>

<td>&nbsp;</td>
</tr>

</table>

</td>

<td>&nbsp;</td>

<td>&nbsp;</td>

</tr>

<tr>

<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

<asp:Button ID="Button1" runat="server" Text="Agregar"


OnClick="Button1_Click" />

</td>

<td>&nbsp;</td>

<td>&nbsp;</td>

</tr>

<tr>

<td>&nbsp;</td>

<td>&nbsp;</td>

<td>&nbsp;</td>

</tr>

<tr>

<td>&nbsp;</td>

<td>&nbsp;</td>

<td>&nbsp;</td>

</tr>

<tr>

<td>&nbsp;</td>

<td>&nbsp;</td>

<td>&nbsp;</td>

</tr>
<tr>

<td>&nbsp;</td>

<td>&nbsp;</td>

<td>&nbsp;</td>

</tr>

<tr>

<td>&nbsp;</td>

<td>&nbsp;</td>

<td>&nbsp;</td>

</tr>

</table>

</div>

</form>

</body>

</html>

<title></title>

<style type=”text/css”>

.auto-style1 {

Width: 100%;

.auto-style4 {

Text-decoration: underline;

Color: #0000FF;

Width: 339px;

Height: 18px;

.auto-style2 {

Text-decoration: underline;

Color: #0000FF;
Width: 339px;

</style>

</head>

<body>

<form id=”form1” runat=”server”>

<div style=”margin-left: 40px”>

<table class=”auto-style1”>

<tr>

<td>

<table class=”auto-style1”>

<tr>

<td class=”auto-style4”>GESTION DE PRODUCTOS</td>

</tr>

<tr>

<td class=”auto-style2”><strong>Editar Actualizar Eliminar Operaciones in


Gridview</strong></td>

</tr>

</table>

</td>

<td>&nbsp;</td>

</tr>

<tr>

<td>&nbsp;</td>

<td>&nbsp;</td>

</tr>

<tr>

<td>

<asp:GridView ID=”GridView1” runat=”server” AutoGenerateColumns=”False”


AutoGenerateDeleteButton=”True” AutoGenerateEditButton=”True”
OnRowEditing=”GridView1_RowEditing”
OnSelectedIndexChanged=”GridView1_SelectedIndexChanged”
OnRowDeleting=”GridView1_RowDeleting”>
<Columns>

<asp:BoundField DataField=”id” HeaderText=”Id” ReadOnly=”True” />

<asp:BoundField DataField=”nombre” HeaderText=”Nombre”


ReadOnly=”True” />

<asp:BoundField DataField=”pcosto” HeaderText=”PCosto” ReadOnly=”True”


/>

<asp:BoundField DataField=”pventa” HeaderText=”PVenta”


ReadOnly=”True” />

<asp:BoundField DataField=”stock” HeaderText=”Stock” ReadOnly=”True” />

<asp:BoundField DataField=”NCategoria” HeaderText=”Categoria”


ReadOnly=”True” />

</Columns>

</asp:GridView>

<br />

<asp:Button ID=”Button1” runat=”server” OnClick=”Button1_Click”


Text=”Agregar Producto” Width=”117px” />

</td>

<td>&nbsp;</td>

</tr>

<tr>

<td>&nbsp;</td>

<td>&nbsp;</td>

</tr>

</table>

</div>

</form>

</body>

</html>

Namespace Actividad4

Public partial class AltaProducto : System.Web.UI.Page

{
Protected void Page_Load(object sender, EventArgs e)

If (¡Page.IsPostBack)

Refreshdata();

Private void refreshdata()

Using (proyectoEntities1 db = new proyectoEntities1())

Var lst = from p in db.categoria

Orderby (p.nombre) descending

Select new { p.id , p.nombre };

This.DropDownList1.DataSource = lst.ToList();

This.DropDownList1.DataTextField = “nombre”;

This.DropDownList1.DataValueField = “id”;

This.DropDownList1.DataBind();

Private void Insertar()

String idcategoria = this.DropDownList1.SelectedValue;

Using (proyectoEntities1 db = new proyectoEntities1())

{
Producto oProducto = new producto();

oProducto.id = int.Parse(this.TextBox7.Text);

oProducto.nombre = this.TextBox8.Text;

oProducto.pcosto = decimal.Parse(this.TextBox4.Text);

oProducto.pventa = decimal.Parse(this.TextBox9.Text);

oProducto.stock = decimal.Parse(this.TextBox10.Text);

oProducto.IdCategoria= int.Parse(idcategoria);

db.producto.Add(oProducto);

db.SaveChanges();//GRABANDO BD

Protected void Button1_Click(object sender, EventArgs e)

This.Insertar();

Response.Redirect(“WebForm1.aspx”);

También podría gustarte