Aplicaiones Web Con Ado Net

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 10

APLICACIONES WEB CON ADO.

NET STORE PROCEDURES


ASPxRoundPanel1
Aplicación 1: Default.aspx

RadioButton1

ASPxListBox1

GridView1

Label1

Procedimientos Almacenados:
CREATE PROC USPLISTADO_MESES
@CAD VARCHAR(30)
AS
IF(@CAD='Par')
BEGIN
SELECT DISTINCT DATENAME(MONTH,FECHAPEDIDO) AS MES
FROM PEDIDOS WHERE MONTH(FECHAPEDIDO)%2=0
END
ELSE IF(@CAD='Impar')
BEGIN
SELECT DISTINCT DATENAME(MONTH,FECHAPEDIDO) AS MES
FROM PEDIDOS WHERE MONTH(FECHAPEDIDO)%2=1
END
ELSE IF(@CAD='Todos')
BEGIN
SELECT DISTINCT DATENAME(MONTH,FECHAPEDIDO) AS MES
FROM PEDIDOS
END
GO
CREATE PROC USP_LISTADO_PEDIDOS
@MES VARCHAR(30)
AS
SELECT C.IDCLIENTE,NOMBRECOMPAÑIA,COUNT(P.IDPEDIDO) AS
[CANTIDAD PEDIDOS],SUM(PRECIOUNIDAD*CANTIDAD) AS TOTAL
FROM CLIENTES C,PEDIDOS P,[DETALLES DE PEDIDOS]OD
WHERE C.IDCLIENTE=P.IDCLIENTE AND OD.IDPEDIDO=P.IDPEDIDO
AND DATENAME(MONTH,FECHAPEDIDO) =@MES
GROUP BY C.IDCLIENTE,NOMBRECOMPAÑIA
GO

Cadena de Conexión: Crear esta cadena en el Archivo Web.Config.

<connectionStrings>
<add name="cn" connectionString="Server=(local);Integrated
Security=SSPI;Database=Neptuno"/>
</connectionStrings

Codigo Fuente:
Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration

Partial Class _Default


Inherits System.Web.UI.Page
Dim cN As New SqlConnection(ConfigurationManager.ConnectionStrings("cn").ConnectionString)

Protected Sub RbaPar_CheckedChanged(ByVal sender As Object, ByVal e


As System.EventArgs) Handles RbaPar.CheckedChanged
Dim cmd As New SqlCommand("USPLISTADO_MESES", cN)
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.Add("@CAD", SqlDbType.VarChar, 30).Value =
RbaPar.Text
Dim da As New SqlDataAdapter(cmd)
Dim tbl As New DataTable
da.Fill(tbl)
Me.Lstmeses.Items.Clear()
For i As Integer = 0 To tbl.Rows.Count - 1
'Llenando al ASPxListBox1
Me.Lstmeses.Items.Add(tbl.Rows(i)(0))
Next
End Sub
Protected Sub RbaImpar_CheckedChanged(ByVal sender As Object, ByVal e
As System.EventArgs) Handles RbaImpar.CheckedChanged
Dim cmd As New SqlCommand("USPLISTADO_MESES", cN)
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.Add("@CAD", SqlDbType.VarChar, 30).Value =
RbaImpar.Text
Dim da As New SqlDataAdapter(cmd)
Dim tbl As New DataTable
da.Fill(tbl)
Me.Lstmeses.Items.Clear()
For i As Integer = 0 To tbl.Rows.Count - 1
'Llenando al ASPxListBox1
Me.Lstmeses.Items.Add(tbl.Rows(i)(0))
Next
End Sub

Protected Sub RbaTodos_CheckedChanged(ByVal sender As Object, ByVal e


As System.EventArgs) Handles RbaTodos.CheckedChanged
Dim cmd As New SqlCommand("USPLISTADO_MESES", cN)
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.Add("@CAD", SqlDbType.VarChar, 30).Value =
RbaTodos.Text
Dim da As New SqlDataAdapter(cmd)
Dim tbl As New DataTable
da.Fill(tbl)
Me.Lstmeses.Items.Clear()
For i As Integer = 0 To tbl.Rows.Count - 1
'Llenando al ASPxListBox1
Me.Lstmeses.Items.Add(tbl.Rows(i)(0))
Next
End Sub

Protected Sub Lstmeses_SelectedIndexChanged(ByVal sender As Object,


ByVal e As System.EventArgs) Handles Lstmeses.SelectedIndexChanged
Dim cmd As New SqlCommand("USP_LISTADO_PEDIDOS", cN)
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.Add("@MES", SqlDbType.VarChar, 30).Value =
Lstmeses.Value 'Recuperando el mes seleccionado
Dim da As New SqlDataAdapter(cmd)
Dim tbl As New DataTable
da.Fill(tbl)
GridView1.DataSource = tbl
'creamos una variable session
Session("pag") = tbl
GridView1.DataBind()
'estamos contando todos los registros
lblcantidad.Text = tbl.Rows.Count
End Sub
Protected Sub GridView1_PageIndexChanging(ByVal sender As Object,
ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles
GridView1.PageIndexChanging
GridView1.PageIndex = e.NewPageIndex
GridView1.DataSource = Session("pag")
GridView1.DataBind()
End Sub
End Class
Aplicación 2: Default2.aspx Datalist1

Label1

Image1

LinkButton1

RepeatColumns: 3
RepeatDirection: Horizontal
Procedimientos Almacenados:
CREATE PROC USP_LISTADO_PRODUCTOS
AS
SELECT * FROM ARTICULOS
GO

CREATE PROC USP_LISTADO_CABE_PRODUCTO


@ART_COD CHAR(5)
AS
SELECT art_cod,art_nom,art_pre FROM ARTICULOS
WHERE art_cod=@ART_COD
GO

CREATE PROC USP_LISTADO_PEDIDOS


@ART_COD CHAR(5)
AS
SELECT fac_num,A.art_pre,art_can,(A.art_pre*art_can)
AS TOTAL FROM Fac_deta F,ARTICULOS A
WHERE F.art_cod=A.art_cod AND F.art_cod=@ART_COD
ORDER BY TOTAL DESC
GO

Cadena de Conexión: Crear esta cadena en el Archivo Web.Config.

<connectionStrings>
<add name="cn" connectionString="Server=(local);Integrated
Security=SSPI;Database=Neptuno"/>
</connectionStrings

Codigo Fuente:
Imports System.Data
Imports System.Data.SqlClient

Partial Class Default2


Inherits System.Web.UI.Page
Dim cn As New SqlConnection(ConfigurationManager.ConnectionStrings("cn").ConnectionString)
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles
Me.Load
If Not Page.IsPostBack Then
Dim da As New SqlDataAdapter("USP_LISTADO_PRODUCTOS", cn)
Dim tbl As New DataTable
da.Fill(tbl)
DataList1.DataSource = tbl
DataList1.DataBind()
End If
End Sub
Protected Sub DataList1_ItemCreated(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataListItemEventArgs) Handles DataList1.ItemCreated
For i As Integer = 0 To DataList1.Items.Count - 1
Dim bt As LinkButton = CType(Me.DataList1.Items(i).FindControl("LinkButton1"),
LinkButton)
Dim cod As String = CType(DataList1.Items(i).FindControl("Label4"), Label).Text
bt.Attributes.Add("Onclick", "window.open('Default3.aspx?cod=" & cod & "')")
Next
End Sub
End Class
ASPxRoundPanel1

Aplicación 2: Default3.aspx

Label1 Image1

ASPxRoundPanel2

LinkButton1

Gridview1
Codigo Fuente:
Imports System.Data
Imports System.Data.SqlClient
Partial Class Default3

Inherits System.Web.UI.Page
Dim cn As New SqlConnection(ConfigurationManager.ConnectionStrings("cn").ConnectionString)
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles
Me.Load
If Not Page.IsPostBack Then
Dim cod As String = Request.QueryString("cod")
'Preguntando si el codigo esta vacio
If (cod = "") Then
Me.Response.Write("<a href='Default2.aspx'>Regresar Pagina Principal</a>")
Else
lblmensaje.Visible = False
Dim cmd As New SqlCommand("USP_LISTADO_CABE_PRODUCTO", cn)
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.Add("@ART_COD", SqlDbType.Char, 5).Value = cod
Dim da As New SqlDataAdapter(cmd)
Dim tbl As New DataTable
da.Fill(tbl)
lblproducto.Text = tbl.Rows(0)(1)
lblprecio.Text = tbl.Rows(0)(2)
Image1.ImageUrl = ".\Productos\" & tbl.Rows(0)(1) & ".jpg"
'AHORA MOSTRANDO EL DETALLE VENDIDO
Dim cmd1 As New SqlCommand("USP_LISTADO_PEDIDOS", cn)
cmd1.CommandType = CommandType.StoredProcedure
cmd1.Parameters.Add("@ART_COD", SqlDbType.Char, 5).Value = cod
Dim da1 As New SqlDataAdapter(cmd1)
Dim tbl1 As New DataTable
da1.Fill(tbl1)

If (tbl1.Rows.Count > 0) Then


GridView1.DataSource = tbl1
GridView1.DataBind()
Else
lblmensaje.Visible = True
lblmensaje.Text = "No hay Facturas Vendidas"
End If
End If

End If
End Sub

Protected Sub btncancelar_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles


btncancelar.Click
btncancelar.Attributes.Add("Onclick", "window.close()")
End Sub
Presionamos consultar y nos mostrar
una ventana emergente del producto
End Class sus facturas emitidas

You might also like