Está en la página 1de 34

AP7-AA4-Ev2-Desarrollo de aplicaciones WEB con ASP NET y C# usando

visual studio .net

Aprendiz:
María Del Pilar Gutiérrez Rodriguez

Presentado a:
Víctor Hernán Arismendy Agudelo
Instructor de Analisis y Sistemas de Información

SENA
ANÁLISIS Y DESARROLLO DE SISTEMAS DE INFORMACIÓN
Junio 03 de 2018
BOGOTÁ DC
Complejo Tecnológico Minero Agro empresarial. Calle 43 # 20 - 37 Barrio la Malena, Puerto
Berrio SENA Regional Antioquia

1
Realizar la práctica expuesta en el laboratorio 16. “Desarrollo de aplicaciones WEB
con ASP .NET y C# en Visual Studio .NET”, donde se plantea la construcción de
una aplicación para una biblioteca municipal.

La plantilla HTML que utilize para el desarrollo de esta web fue descargada del
siguiente enlace:

http://www.free-css.com/free-css-templates/page1/plusbusiness#shout

CLASE PARA LA CONEXIÓN

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

/// <summary>
/// Descripción breve de ClsConexion
/// </summary>
public class ClsConexion
{
protected SqlDataReader reader;
protected SqlDataAdapter
AdaptadorDatos; protected DataSet data;
protected SqlConnection oconecccion = new SqlConnection();

public ClsConexion()
{
//
// TODO: Agregar aquí la lógica del constructor
//
}
public void conectar(string tabla)
{
String strConeccion=
ConfigurationManager.ConnectionStrings["BibliotecaConnectionString1"].ConnectionStr
in g;
oconecccion.ConnectionString = strConeccion;
oconecccion.Open();
AdaptadorDatos = new SqlDataAdapter("select * from " + tabla, oconecccion);
SqlCommandBuilder ejecutacomandos = new
Complejo Tecnológico Minero Agro empresarial. Calle 43 # 20 - 37 Barrio la Malena, Puerto
Berrio SENA Regional Antioquia

2
SqlCommandBuilder(AdaptadorDatos);
Data = new DataSet();
AdaptadorDatos.Fill(Data, tabla);

oconecccion.Close();
}

public DataSet Data


{
set { data = value; }
get { return data; }
}
public SqlDataReader Datareader
{
set { reader=value;}
get { return reader;}
}
}

AREA LIBROS
Codigo de la Clase Areas

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
usingSystem.Data.SqlClient;
using System.Data;

/// <summary>

Complejo Tecnológico Minero Agro empresarial. Calle 43 # 20 - 37 Barrio la Malena, Puerto


Berrio SENA Regional Antioquia

3
/// Descripción breve de ClsAreas
/// </summary>
public class ClsAreas : ClsConexion
{
string tabla = "Areas";
protected string nombre;
protected int codigo,tiempo;

public ClsAreas(int codigo, string nombre, int tiempo)


{
this.codigo = codigo;
this.nombre = nombre;
this.tiempo = tiempo;
}
public int Codigo
{
set { codigo = value; }
get { return codigo; }
}
public string Nombre
{
set { nombre = value;
} get { return nombre;
}
}
public int Tiempo
{
set { tiempo = value; }
get { return tiempo; }
}
public void agregar()
{
conectar(tabla);
DataRow fila;
fila = Data.Tables[tabla].NewRow();
fila["areCodigo"] = codigo;
fila["areNombre"] = Nombre;
fila["areTiempo"] = tiempo;

Data.Tables[tabla].Rows.Add(fila);
AdaptadorDatos.Update(Data, tabla);
}

public bool eliminar(int valor)


{
Complejo Tecnológico Minero Agro empresarial. Calle 43 # 20 - 37 Barrio la Malena, Puerto
Berrio SENA Regional Antioquia

4
conectar(tabla);

DataRow fila;
int x = Data.Tables[tabla].Rows.Count -
1; for (int i = 0; i <= x; i++)
{
fila = Data.Tables[tabla].Rows[i];

if (int.Parse(fila["areCodigo"].ToString()) == valor)
{

fila = Data.Tables[tabla].Rows[i];
fila.Delete( );
DataTable tablaborrados;
tablaborrados = Data.Tables[tabla].GetChanges(DataRowState.Deleted);
AdaptadorDatos.Update(tablaborrados);
Data.Tables[tabla].AcceptChanges();
return true;
}
}
return false;
}
}

CODIGO PARA INGRESAR LIBROS

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class pageIngresoAreas : System.Web.UI.Page


{
protected void Page_Load(object sender, EventArgs e)
{
}

protected void Button1_Click(object sender, EventArgs e)

{
try

Complejo Tecnológico Minero Agro empresarial. Calle 43 # 20 - 37 Barrio la Malena, Puerto


Berrio SENA Regional Antioquia

5
{
ClsAreas are = new ClsAreas(0, "", 1);
are.Codigo = int.Parse(TxtCodigo.Text);
are.Nombre = TxtNombre.Text; are.Tiempo = int.Parse(TxtTiempo.Text);
are.agregar( );
LblEstado.Text = "Registro Agregado Exitosamente";
TxtCodigo.Text = "";
TxtNombre.Text = ""; TxtTiempo.Text = "";
}
catch
{
LblEstado.Text = "El Registro ya Existe";
}
}
}

CODIGO PARA CONSULTAR AREAS

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class pageConsultarAreas : System.Web.UI.Page


{
protected void Page_Load(object sender, EventArgs e)
{
}

protected void Button1_Click(object sender, EventArgs e)

Complejo Tecnológico Minero Agro empresarial. Calle 43 # 20 - 37 Barrio la Malena, Puerto


Berrio SENA Regional Antioquia

6
{
}

protected void SqlDataSource1_Selecting(object


sender, SqlDataSourceSelectingEventArgs e)
{
}

protected void ObjectDataSource1_Selecting(object


sender, ObjectDataSourceSelectingEventArgs e)
{
}
}

CODIGO PARA MODIFICAR AREAS


<%@ Page

Title="" Language="C#" MasterPageFile="~/MasterPage.master"


AutoEventWireup="true" CodeFile="pageModificarArea.aspx.cs"
Inherits="pageModificarArea" %>

<asp:Content ID="Content1"
ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<form id="form1" runat="server">
<table style="width: 100%">
<tr>
<td rowspan="4" style="width: 21px">
<img alt="" src="images/demo/areas/2.jpg" style="width: 293px; height:
222px"
/></td>
<td style="height:
48px;"
dir="ltr">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n
bsp;&n
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&
Complejo Tecnológico Minero Agro empresarial. Calle 43 # 20 - 37 Barrio la Malena, Puerto
Berrio SENA Regional Antioquia

7
nbsp;&nbsp;
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n
bsp;&nbsp;&n
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

MODIFICAR AREAS</td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
<tr>
<td>
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AutoGenerateColumns="False" CellPadding="4"
DataKeyNames="areCodigo"
DataSourceID="ObjectDataSource1" ForeColor="#333333"
GridLines="None" PageSize="5">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:CommandField ButtonType="Button" ShowEditButton="True" />
<asp:BoundField DataField="areCodigo"
HeaderText="areCodigo" ReadOnly="True"
SortExpression="areCodigo" />
<asp:BoundField DataField="areNombre"
HeaderText="areNombre"
SortExpression="areNombre" />

<asp:BoundField DataField="areTiempo"
HeaderText="areTiempo"
SortExpression="areTiempo" />
</Columns>
<EditRowStyle BackColor="#7C6F57" />
<FooterStyle BackColor="#1C5E55" Font-Bold="True"
ForeColor="White" />
<HeaderStyle BackColor="#1C5E55" Font-Bold="True"
ForeColor="White"
/>
<PagerStyle BackColor="#666666" ForeColor="White"
HorizontalAlign="Center" />
Complejo Tecnológico Minero Agro empresarial. Calle 43 # 20 - 37 Barrio la Malena, Puerto
Berrio SENA Regional Antioquia

8
<RowStyle BackColor="#E3EAEB" />
<SelectedRowStyle BackColor="#C5BBAF" Font-
Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F8FAFA" />
<SortedAscendingHeaderStyle BackColor="#246B61" />
<SortedDescendingCellStyle BackColor="#D4DFE1" />
<SortedDescendingHeaderStyle BackColor="#15524A" />
</asp:GridView>
<asp:ObjectDataSource ID="ObjectDataSource1"
runat="server" DeleteMethod="Delete"
InsertMethod="Insert"
OldValuesParameterFormatString="original_{0}"
SelectMethod="GetData"
TypeName="DataSetTableAdapters.AreasTableAdapter"
UpdateMethod="Update">
<DeleteParameters>
<asp:Parameter Name="Original_areCodigo" Type="Decimal" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="areCodigo" Type="Decimal" />
<asp:Parameter Name="areNombre" Type="String" />
<asp:Parameter Name="areTiempo" Type="Decimal" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="areNombre" Type="String" />
<asp:Parameter Name="areTiempo" Type="Decimal" />
<asp:Parameter Name="Original_areCodigo" Type="Decimal" />
</UpdateParameters>
</asp:ObjectDataSource>
<br />
</td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
</table>
</form>
</asp:Content>

Complejo Tecnológico Minero Agro empresarial. Calle 43 # 20 - 37 Barrio la Malena, Puerto


Berrio SENA Regional Antioquia

9
CODIGO PARA ELIMINAR AREAS
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class PageEliminarAreas : System.Web.UI.Page


{
protected void Page_Load(object sender, EventArgs e)
{
}

protected void Button1_Click(object sender, EventArgs e)


{
ClsAreas are = new ClsAreas(0, "", 1);
if (are.eliminar(int.Parse(DropDownList1.Text)))
{
LblEstado.Text = "El Registro se Elimino con Exito";
}
else { LblEstado.Text = "El Registro No Se Elimino"; }
}
}

Complejo Tecnológico Minero Agro empresarial. Calle 43 # 20 - 37 Barrio la Malena, Puerto


Berrio SENA Regional Antioquia

10
CLASE LIBROS

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data;

/// <summary>
/// Descripción breve de ClsLibros
/// </summary>
public class ClsLibros : ClsConexion
{
string tabla = "Libros";
protected string nombre, autor, editorial;
protected int codigo, numpag, area;

public ClsLibros (int codigo, string nombre, int numpag, string autor, string
editorial, int area)
{
this.codigo = codigo;
this.nombre = nombre;
this.numpag = numpag;
this.autor = autor;
this.editorial = editorial;
this.area = area;
}
public int Codigo
{
set { codigo = value; }

Complejo Tecnológico Minero Agro empresarial. Calle 43 # 20 - 37 Barrio la Malena, Puerto


Berrio SENA Regional Antioquia

11
get { return codigo; }
}
public string Nombre
{
set { nombre = value;
} get { return nombre;
}
}
public int NumPag
{
set { numpag =
value; } get { return
numpag; }
}

public string Autor


{
set { autor = value;
} get { return autor;
}
}

public string Editorial


{
set { editorial = value;
} get { return editorial;
}
}
public int Area
{
set { area = value; }
get { return area; }
}
public void Agregar()
{
conectar(tabla);
DataRow fila;
fila = Data.Tables[tabla].NewRow( );
fila["libCodigo"] = codigo;
fila["libNombre"] = nombre;
fila["libNumPag"] = numpag;
fila["libAutor"] = autor;
fila["libEditorial"] = editorial;
fila["libArea"] = area;

Complejo Tecnológico Minero Agro empresarial. Calle 43 # 20 - 37 Barrio la Malena, Puerto


Berrio SENA Regional Antioquia

12
Data.Tables[tabla].Rows.Add(fila);

AdaptadorDatos.Update(Data, tabla);
}
public bool eliminar(int valor)
{
conectar(tabla);
DataRow fila;
int x = Data.Tables[tabla].Rows.Count -
1; for (int i = 0; i <= x; i++)
{
fila = Data.Tables[tabla].Rows[i];

if (int.Parse(fila["libCodigo"].ToString()) == valor)
{
fila = Data.Tables[tabla].Rows[i];
fila.Delete( );
DataTable tablaborrados;
tablaborrados = Data.Tables[tabla].GetChanges(DataRowState.Deleted);
AdaptadorDatos.Update(tablaborrados);
Data.Tables[tabla].AcceptChanges( );
return true;
}
}
return false;
}
}

CODIGO PARA INGRESO DE LIBROS

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class pageIngresarNuevoLibro : System.Web.UI.Page


{
protected void Page_Load(object sender, EventArgs e)
{
}

Complejo Tecnológico Minero Agro empresarial. Calle 43 # 20 - 37 Barrio la Malena, Puerto


Berrio SENA Regional Antioquia

13
protected void Button1_Click1(object sender, EventArgs e)
{
try
{
ClsLibros lib = new ClsLibros(0, "", 1, "", "", 2);
lib.Codigo = int.Parse(TxtCodigoLb.Text);
lib.Nombre = TxtNombreLb.Text;
lib.NumPag = int.Parse(TxtNumPagLb.Text);
lib.Autor = TxtAutorLb.Text;
lib.Editorial = TxtEditorialLb.Text;
lib.Area = int.Parse(DropDownList1.Text);

lib.Agregar();
LblEstadoLb.Text = "Registro Agregado Exitosamente";
TxtCodigoLb.Text = "";
TxtNombreLb.Text = "";
TxtNumPagLb.Text = "";
TxtAutorLb.Text = "";
TxtEditorialLb.Text = "";
}
catch
{
LblEstadoLb.Text = "El Registro ya Existe";
}
}
}

Complejo Tecnológico Minero Agro empresarial. Calle 43 # 20 - 37 Barrio la Malena, Puerto


Berrio SENA Regional Antioquia

14
CODIGO PARA CONSULTA DE LIBROS

<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master"


AutoEventWireup="true"
CodeFile="pageConsultarLibros.aspx.c
s" Inherits="pageConsultarLibros" %>

<asp:Content ID="Content1"
ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<form id="form1" runat="server">
<table style="width: 100%">
<tr>
<td rowspan="6" style="width: 30px">
<img alt="" src="images/demo/libros/3U8A9955.jpg" style="width: 300px;
height: 209px" /></td>
<td style="width: 142px">Consulta Libros</td>
<td>&nbsp;</td>
</tr>
<tr>
<td style="width: 142px">&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td style="width: 142px">Seleccione Libro:</td>
<td>
<asp:DropDownList ID="DropDownList1"
runat="server"
DataSourceID="SqlDataSource1" DataTextField="libNombre"
DataValueField="libNombre" Height="16px" Width="175px">
</asp:DropDownList>

<asp:GridView ID="GridView1" runat="server"


AutoGenerateColumns="False" CellPadding="4" DataKeyNames="libCodigo"
DataSourceID="SqlDataSource2" ForeColor="#333333" GridLines="None">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:BoundField DataField="libCodigo"
HeaderText="libCodigo" ReadOnly="True"
SortExpression="libCodigo" />
<asp:BoundField DataField="libNombre"
HeaderText="libNombre"
SortExpression="libNombre" />
<asp:BoundField DataField="libNumPag"
HeaderText="libNumPag"
Complejo Tecnológico Minero Agro empresarial. Calle 43 # 20 - 37 Barrio la Malena, Puerto
Berrio SENA Regional Antioquia

15
SortExpression="libNumPag" />
<asp:BoundField DataField="libAutor"
HeaderText="libAutor"
SortExpression="libAutor" />
<asp:BoundField DataField="libEditorial"
HeaderText="libEditorial"
SortExpression="libEditorial" />
<asp:BoundField DataField="libArea"
HeaderText="libArea"
SortExpression="libArea" />
</Columns>
<EditRowStyle BackColor="#7C6F57" />
<FooterStyle BackColor="#1C5E55" Font-Bold="True"
ForeColor="White" />
<HeaderStyle BackColor="#1C5E55" Font-Bold="True"
ForeColor="White"
/>
<PagerStyle BackColor="#666666" ForeColor="White"
HorizontalAlign="Center" />
<RowStyle BackColor="#E3EAEB" />
<SelectedRowStyle BackColor="#C5BBAF" Font-
Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F8FAFA" />
<SortedAscendingHeaderStyle BackColor="#246B61" />
<SortedDescendingCellStyle BackColor="#D4DFE1" />
<SortedDescendingHeaderStyle BackColor="#15524A" />
</asp:GridView>
<asp:SqlDataSource
ID="SqlDataSource2"
runat="server" ConnectionString="<%$
ConnectionStrings:BibliotecaConnectionString1
%>" SelectCommand="SELECT [libCodigo],
[libNombre], [libNumPag], [libAutor], [libEditorial], [libArea] FROM [Libros] WHERE
([libNombre] = @libNombre)">
<SelectParameters>
<asp:ControlParameter ControlID="DropDownList1"
Name="libNombre" PropertyName="SelectedValue" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
<asp:SqlDataSource
ID="SqlDataSource1"
runat="server" ConnectionString="<%$
ConnectionStrings:BibliotecaConnectionString1
%>" SelectCommand="SELECT [libNombre] FROM
[Libros]"></asp:SqlDataSource>
</td>
</tr>
Complejo Tecnológico Minero Agro empresarial. Calle 43 # 20 - 37 Barrio la Malena, Puerto
Berrio SENA Regional Antioquia

16
<tr>

<td style="width: 142px">&nbsp;</td>


<td>
&nbsp;</td>
</tr>
<tr>
<td style="width: 142px">&nbsp;</td>
<td>
<asp:Button ID="Button1" runat="server" Text="Consultar" />
</td>
</tr>
<tr>
<td style="width: 142px">&nbsp;</td>
<td>&nbsp;</td>
</tr>
</table>
</form>
</asp:Content>

CODIGO PARA MODIFICAR LIBROS

<asp:Content ID="Content1"
ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<form id="form1" runat="server">
<table style="width: 100%">
<tr>
<td rowspan="2" style="width: 7px">
<img alt="" src="images/demo/libros/descarga.jpg" style="width: 225px;
height: 225px" /></td>
<td style="height:
25px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp

Complejo Tecnológico Minero Agro empresarial. Calle 43 # 20 - 37 Barrio la Malena, Puerto


Berrio SENA Regional Antioquia

17
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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;&nbsp
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs
p;&nbsp;&nbsp;&nbsp;

MODIFICAR LIBRO
</td>
</tr>
<tr>
<td>
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AutoGenerateColumns="False" CellPadding="4"
DataKeyNames="libCodigo"
DataSourceID="ObjectDataSource1" ForeColor="#333333"
GridLines="None" PageSize="5">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:CommandField ButtonType="Button" ShowEditButton="True" />
<asp:BoundField DataField="libCodigo"
HeaderText="libCodigo" ReadOnly="True"
SortExpression="libCodigo" />
<asp:BoundField DataField="libNombre"
HeaderText="libNombre"
SortExpression="libNombre" />
<asp:BoundField DataField="libNumPag"
HeaderText="libNumPag"
SortExpression="libNumPag" />
<asp:BoundField DataField="libAutor"
HeaderText="libAutor"
SortExpression="libAutor" />
<asp:BoundField DataField="libEditorial"
HeaderText="libEditorial"
SortExpression="libEditorial" />
<asp:BoundField DataField="libArea"
HeaderText="libArea"
SortExpression="libArea" />
</Columns>
<EditRowStyle BackColor="#7C6F57" />
<FooterStyle BackColor="#1C5E55" Font-Bold="True"
ForeColor="White" />
<HeaderStyle BackColor="#1C5E55" Font-Bold="True"
ForeColor="White"
/>
<PagerStyle BackColor="#666666" ForeColor="White"
Complejo Tecnológico Minero Agro empresarial. Calle 43 # 20 - 37 Barrio la Malena, Puerto
Berrio SENA Regional Antioquia

18
HorizontalAlign="Center" />
<RowStyle BackColor="#E3EAEB" />
<SelectedRowStyle BackColor="#C5BBAF" Font-
Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F8FAFA" />
<SortedAscendingHeaderStyle BackColor="#246B61" />
<SortedDescendingCellStyle BackColor="#D4DFE1" />
<SortedDescendingHeaderStyle BackColor="#15524A" />
</asp:GridView>
<asp:ObjectDataSource ID="ObjectDataSource1"
runat="server" DeleteMethod="Delete"
InsertMethod="Insert"
OldValuesParameterFormatString="original_{0}"
SelectMethod="GetData"
TypeName="DataSetTableAdapters.LibrosTableAdapter"
UpdateMethod="Update">
<DeleteParameters>
<asp:Parameter Name="Original_libCodigo" Type="Decimal" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="libCodigo" Type="Decimal" />
<asp:Parameter Name="libNombre" Type="String" />
<asp:Parameter Name="libNumPag" Type="Decimal" />
<asp:Parameter Name="libAutor" Type="String" />
<asp:Parameter Name="libEditorial" Type="String" />
<asp:Parameter Name="libArea" Type="Decimal" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="libNombre" Type="String" />
<asp:Parameter Name="libNumPag" Type="Decimal" />
<asp:Parameter Name="libAutor" Type="String" />
<asp:Parameter Name="libEditorial" Type="String" />
<asp:Parameter Name="libArea" Type="Decimal" />
<asp:Parameter Name="Original_libCodigo" Type="Decimal" />
</UpdateParameters>
</asp:ObjectDataSource>
<br />
</td>
</tr>
</table>
</form>
</asp:Content>

Complejo Tecnológico Minero Agro empresarial. Calle 43 # 20 - 37 Barrio la Malena, Puerto


Berrio SENA Regional Antioquia

19
CODIGO PARA ELIMINAR LIBRO

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class pageEliminarLibro : System.Web.UI.Page


{
protected void Page_Load(object sender, EventArgs e)
{
}

protected void Button1_Click(object sender, EventArgs e)


{
ClsLibros are = new ClsLibros(0, "", 1, "", "",
2); if
(are.eliminar(int.Parse(DropDownList1.Text)))
{
LblEstado.Text = "El Registro se Elimino con Exito";
}
else { LblEstado.Text = "El Registro No Se Elimino"; }
}
}

Complejo Tecnológico Minero Agro empresarial. Calle 43 # 20 - 37 Barrio la Malena, Puerto


Berrio SENA Regional Antioquia

20
CLASE PRESTAMOS
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data;

/// <summary>
/// Descripción breve de ClsAreas
/// </summary>
public class ClsPrestamo : ClsConexion
{
string tabla = "Prestamos";
protected string fecha;
protected int codigo,usuario;

public ClsPrestamo(int codigo, string fecha, int usuario)


{
this.codigo = codigo;
this.fecha = fecha;
this.usuario = usuario;
}
public int Codigo
{
set { codigo = value; }
get { return codigo; }
}
public string Fecha
{
set { fecha = value;
Complejo Tecnológico Minero Agro empresarial. Calle 43 # 20 - 37 Barrio la Malena, Puerto
Berrio SENA Regional Antioquia

21
} get { return fecha;
}
}
public int Usuario
{
set { usuario = value;}
get { return usuario; }
}
public void agregar()
{
conectar(tabla);
DataRow fila;
fila = Data.Tables[tabla].NewRow( );
fila["preCodigo"] = codigo;
fila["preFecha"] = Fecha;
fila["preUsuario"] = Usuario;

Data.Tables[tabla].Rows.Add(fila);
AdaptadorDatos.Update(Data, tabla);

}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data;

/// <summary>
/// Descripción breve de ClsAreas
/// </summary>
public class ClsDtpPrestamos : ClsConexion
{
string tabla = "DetallePrestamos";
protected string fechafin, fechadev;
protected int prestamo, libro, cantidad;

public ClsDtpPrestamos(int prestamo, int libro, int cantidad, string fechafin, string
fechadev)
{
this.prestamo = prestamo;
this.libro = libro;
this.cantidad = cantidad;
this.fechafin = fechafin;
Complejo Tecnológico Minero Agro empresarial. Calle 43 # 20 - 37 Barrio la Malena, Puerto
Berrio SENA Regional Antioquia

22
this.fechadev = fechadev;
}
public int Prestamo
{
set { prestamo = value; }
get { return prestamo; }
}
public int Libro
{
set { libro = value;
get { return libro; }
}
public int Cantidad
{
set { cantidad = value; }
get { return cantidad; }
}
public string Fechafin
{
set { fechafin = value; }
get { return fechafin; }
}
public string Fechadev
{
set { fechadev = value; }
get { return fechadev; }
}
public void agregar()
{
conectar(tabla);
DataRow fila;
fila = Data.Tables[tabla].NewRow();
fila["dtpCodigo"] = prestamo;
fila["dtpLibro"] = libro;
fila["dtpCantidad"] = cantidad;
fila["dtpFechaFin"] = fechafin;
fila["dtpFechadev"] = fechadev;
Data.Tables[tabla].Rows.Add(fila);
AdaptadorDatos.Update(Data, tabla);
}
}

CODIGO PRESTAMOS
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
Complejo Tecnológico Minero Agro empresarial. Calle 43 # 20 - 37 Barrio la Malena, Puerto
Berrio SENA Regional Antioquia

23
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class pageRealizarPrestamo : System.Web.UI.Page


{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
}
protected void BtnAgregarPre_Click(object sender, EventArgs e)
{
try
{
ClsPrestamo pre = new ClsPrestamo(0, "", 1);
pre.Codigo = int.Parse(TxtCodigoPre.Text);
pre.Fecha = TxtFechaPre.Text;
pre.Usuario = int.Parse(DropDownList1.Text);
pre.agregar();
LblEstadoPre.Text = "Registro Agregado Exitosamente";
TxtCodigoPre.Text = "";
TxtFechaPre.Text = "";
}
catch
{
LblEstadoPre.Text = "El Registro ya Existe";
}
}
protected void BtnAgregarLb_Click(object sender, EventArgs e)
{
try
{
ClsDtpPrestamos dtp= new ClsDtpPrestamos(0, 1, 2, "", "");
dtp.Prestamo = int.Parse(DropDownList3.Text);
dtp.Libro = int.Parse(DropDownList2.Text);
dtp.Cantidad = int.Parse(TxtcantidadDtp.Text);
dtp.Fechafin = TxtLimiteDtp.Text;
dtp.Fechadev = TxtFechaDev.Text;
dtp.agregar( );

LblEstadoDtp.Text = "Registro Agregado Exitosamente";


TxtcantidadDtp.Text = "";
TxtLimiteDtp.Text = "";
TxtFechaDev.Text = "";
}
catch
Complejo Tecnológico Minero Agro empresarial. Calle 43 # 20 - 37 Barrio la Malena, Puerto
Berrio SENA Regional Antioquia

24
{
LblEstadoDtp.Text = "El Registro ya Existe";
}
}
}

CLASE USUARIO

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data;

/// <summary>
/// Descripción breve de ClsUsuario
/// </summary>

public class ClsUsuario : ClsConexion


{

string tabla = "Usuarios";


protected string nombre, direccion, telefono, correo, estado;
protected int documento;

public ClsUsuario(int documento, string nombre, string direccion, string telefono,


String correo, string estado)
{

this.documento = documento;
this.nombre = nombre;
this.direccion = direccion;
Complejo Tecnológico Minero Agro empresarial. Calle 43 # 20 - 37 Barrio la Malena, Puerto
Berrio SENA Regional Antioquia

25
this.telefono = telefono;
this.correo = correo;
this.estado = estado;
}

public int Documento


{
set { documento = value; }
get { return documento; }
}

public string Nombre


{
set { nombre = value; }
get { return nombre; }
}

public string Direccion


{
set { direccion = value; }
get { return direccion; }
}

public string Telefono


{
set { telefono = value; }
get { return telefono; }
}

public string Correo


{
set { correo = value; }
get { return correo; }
}

public string Estado


{
set { estado = value; }
get { return estado; }
}

public void agregar()


{

conectar(tabla);
DataRow fila;
fila = Data.Tables[tabla].NewRow( );
Complejo Tecnológico Minero Agro empresarial. Calle 43 # 20 - 37 Barrio la Malena, Puerto
Berrio SENA Regional Antioquia

26
fila["usuDocumento"] = documento;
fila["usuNombre"] = nombre;
fila["usuDireccion"] = direccion;
fila["usuTelefono"] = telefono;
fila["usuCorreo"] = correo;
fila["usuEstado"] = estado;

Data.Tables[tabla].Rows.Add(fila);
AdaptadorDatos.Update(Data, tabla);
}

public bool eliminar(int valor)


{
conectar(tabla);
DataRow fila;
int x = Data.Tables[tabla].Rows.Count - 1;
for (int i = 0; i <= x; i++)
{
fila = Data.Tables[tabla].Rows[i];
if (int.Parse(fila["usuDocumento"].ToString()) == valor)
{
fila = Data.Tables[tabla].Rows[i];

fila.Delete();
DataTable tablaborrados;
tablaborrados = Data.Tables[tabla].GetChanges(DataRowState.Deleted);
AdaptadorDatos.Update(tablaborrados);
Data.Tables[tabla].AcceptChanges();
return true;
}
}
return false;
}
}

CODIGO INGRESAR USUARIOS


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class pageIngresarNuevoUsuario : System.Web.UI.Page


{
protected void Page_Load(object sender, EventArgs e)
{
Complejo Tecnológico Minero Agro empresarial. Calle 43 # 20 - 37 Barrio la Malena, Puerto
Berrio SENA Regional Antioquia

27
}
protected void BtnIngresarUsu_Click(object sender, EventArgs e)
{
try
{

ClsUsuario usu = new ClsUsuario(0, "", "", "", "", "");


usu.Documento= int.Parse(TxtDocumentoUsu.Text);
usu.Nombre = TxtNombreUsu.Text;
usu.Direccion = TxtDireccionUsu.Text;
usu.Telefono = TxtTelefonoUsu.Text;
usu.Correo = TxtCorreoUsu.Text;
usu.Estado = TxtEstadoUsu.Text;

usu.agregar( );
LblEstadoUsu.Text = "Registro Agregado Exitosamente";
TxtDocumentoUsu.Text = "";
TxtNombreUsu.Text = "";
TxtDireccionUsu.Text = "";
TxtTelefonoUsu.Text = "";
TxtCorreoUsu.Text = "";
TxtEstadoUsu.Text = "";
}
catch
{

LblEstadoUsu.Text = "El Registro ya Existe";


}
}
}

Complejo Tecnológico Minero Agro empresarial. Calle 43 # 20 - 37 Barrio la Malena, Puerto


Berrio SENA Regional Antioquia

28
CODIGO PARA CONSULTAR USUARIOS

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1"


Runat="Server">
<form id="form1" runat="server">
<table style="width: 100%">
<tr>
<td rowspan="6" style="width: 32px">
<img alt="" src="images/demo/usuarios/images%20(3).jpg" style="width: 225px;
height: 225px" /></td>
<td>Consultar Usuarios</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>Seleccione Usuario:</td>
<td>
<asp:DropDownList ID="DropDownList1" runat="server"
DataSourceID="SqlDataSource1" DataTextField="usuDocumento"
DataValueField="usuDocumento" Height="16px" style="margin-left: 0px"
Width="173px">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:BibliotecaConnectionString1 %>"
SelectCommand="SELECT [usuDocumento], [usuNombre], [usuDireccion],
[usuTelefono],
[usuCorreo], [usuEstado] FROM [Usuarios]"></asp:SqlDataSource>
</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
CellPadding="4" DataKeyNames="usuDocumento" DataSourceID="SqlDataSource2"
ForeColor="#333333" GridLines="None">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:BoundField DataField="usuDocumento" HeaderText="usuDocumento"
ReadOnly="True" SortExpression="usuDocumento" />
<asp:BoundField DataField="usuNombre" HeaderText="usuNombre"
SortExpression="usuNombre" />
<asp:BoundField DataField="usuDireccion" HeaderText="usuDireccion"
SortExpression="usuDireccion" />
<asp:BoundField DataField="usuTelefono" HeaderText="usuTelefono"
SortExpression="usuTelefono" />
<asp:BoundField DataField="usuCorreo" HeaderText="usuCorreo"
SortExpression="usuCorreo" />
<asp:BoundField DataField="usuEstado" HeaderText="usuEstado"
Complejo Tecnológico Minero Agro empresarial. Calle 43 # 20 - 37 Barrio la Malena, Puerto
Berrio SENA Regional Antioquia

29
SortExpression="usuEstado" />
</Columns>
<EditRowStyle BackColor="#7C6F57" />
<FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White"
/>
<PagerStyle BackColor="#666666" ForeColor="White"
HorizontalAlign="Center" />
<RowStyle BackColor="#E3EAEB" />
<SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True"
ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F8FAFA" />
<SortedAscendingHeaderStyle BackColor="#246B61" />
<SortedDescendingCellStyle BackColor="#D4DFE1" />
<SortedDescendingHeaderStyle BackColor="#15524A" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:BibliotecaConnectionString1 %>"
SelectCommand="SELECT [usuDocumento], [usuNombre], [usuDireccion],
[usuTelefono],
[usuCorreo], [usuEstado] FROM [Usuarios] WHERE ([usuDocumento] =
@usuDocumento)">
<SelectParameters>
<asp:ControlParameter ControlID="DropDownList1"
Name="usuDocumento" PropertyName="SelectedValue" Type="Decimal" />
</SelectParameters>
</asp:SqlDataSource>
</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>
<asp:Button ID="Button1" runat="server" Text="Consultar" />
</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
</table>
</form>
</asp:Content>

Complejo Tecnológico Minero Agro empresarial. Calle 43 # 20 - 37 Barrio la Malena, Puerto


Berrio SENA Regional Antioquia

30
CODIGO PARA MODIFICAR USUARIOS

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1"


Runat="Server">
<form id="form1" runat="server">
<table style="width: 100%">
<tr>
<td rowspan="2" style="width: 72px">
<img alt="" src="images/demo/usuarios/images%20(2).jpg" style="width:
264px; height: 191px" /></td>

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

MODIFICAR USUARIOS </td>


</tr>
<tr>
<td>
<asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="False" CellPadding="4" DataKeyNames="usuDocumento"
DataSourceID="ObjectDataSource1" ForeColor="#333333" GridLines="None"
PageSize="5">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:CommandField ButtonType="Button" ShowEditButton="True" />
<asp:BoundField DataField="usuDocumento"
HeaderText="usuDocumento" ReadOnly="True" SortExpression="usuDocumento" />
Complejo Tecnológico Minero Agro empresarial. Calle 43 # 20 - 37 Barrio la Malena, Puerto
Berrio SENA Regional Antioquia

31
<asp:BoundField DataField="usuNombre" HeaderText="usuNombre"
SortExpression="usuNombre" />
<asp:BoundField DataField="usuDireccion" HeaderText="usuDireccion"
SortExpression="usuDireccion" />
<asp:BoundField DataField="usuTelefono" HeaderText="usuTelefono"
SortExpression="usuTelefono" />
<asp:BoundField DataField="usuCorreo" HeaderText="usuCorreo"
SortExpression="usuCorreo" />
<asp:BoundField DataField="usuEstado" HeaderText="usuEstado"
SortExpression="usuEstado" />
</Columns>
<EditRowStyle BackColor="#7C6F57" />
<FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White"
/>
<HeaderStyle BackColor="#1C5E55" Font-Bold="True"
ForeColor="White" />
<PagerStyle BackColor="#666666" ForeColor="White"
HorizontalAlign="Center" />
<RowStyle BackColor="#E3EAEB" />
<SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True"
ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F8FAFA" />
<SortedAscendingHeaderStyle BackColor="#246B61" />
<SortedDescendingCellStyle BackColor="#D4DFE1" />
<SortedDescendingHeaderStyle BackColor="#15524A" />
</asp:GridView>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
DeleteMethod="Delete" InsertMethod="Insert"
OldValuesParameterFormatString="original_{0}" SelectMethod="GetData"
TypeName="DataSetTableAdapters.UsuariosTableAdapter"
UpdateMethod="Update">
<DeleteParameters>
<asp:Parameter Name="Original_usuDocumento" Type="Decimal" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="usuDocumento" Type="Decimal" />
<asp:Parameter Name="usuNombre" Type="String" />
<asp:Parameter Name="usuDireccion" Type="String" />
<asp:Parameter Name="usuTelefono" Type="String" />
<asp:Parameter Name="usuCorreo" Type="String" />
<asp:Parameter Name="usuEstado" Type="String" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="usuNombre" Type="String" />
<asp:Parameter Name="usuDireccion" Type="String" />
<asp:Parameter Name="usuTelefono" Type="String" />
<asp:Parameter Name="usuCorreo" Type="String" />
Complejo Tecnológico Minero Agro empresarial. Calle 43 # 20 - 37 Barrio la Malena, Puerto
Berrio SENA Regional Antioquia

32
<asp:Parameter Name="usuEstado" Type="String" />
<asp:Parameter Name="Original_usuDocumento" Type="Decimal" />
</UpdateParameters>
</asp:ObjectDataSource>
<br />
</td>
</tr>
</table>
</form>
</asp:Content>

CODIGO PARA ELI MINAR USUARIOS

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class pageEliminarUsuario : System.Web.UI.Page


{

protected void Page_Load(object sender, EventArgs e)


{
}

protected void Button1_Click(object sender, EventArgs e)


{

ClsUsuario usu = new ClsUsuario(0, "", "", "", "", "");


if (usu.eliminar(int.Parse(DropDownList1.Text)))
{

Complejo Tecnológico Minero Agro empresarial. Calle 43 # 20 - 37 Barrio la Malena, Puerto


Berrio SENA Regional Antioquia

33
LblEstado.Text = "El Registro se Elimino con Exito";
}

else { LblEstado.Text = "El Registro No Se Elimino"; }


}
}

Complejo Tecnológico Minero Agro empresarial. Calle 43 # 20 - 37 Barrio la Malena, Puerto


Berrio SENA Regional Antioquia

34

También podría gustarte