Segundo Laboratorio

SEGUNDO LABORATORIO Implemente una página utilizando controles lista  Haz un programa que lea los siguientes datos de

Views 204 Downloads 8 File size 373KB

Report DMCA / Copyright

DOWNLOAD FILE

Recommend stories

Citation preview

SEGUNDO LABORATORIO

Implemente una página utilizando controles lista 

Haz un programa que lea los siguientes datos de una persona: Nombre, sueldo mensual, edad y sexo. A continuación, el programa deberá clasificar a la persona en alguna de las siguientes categorías: a) Hombre pobre. Aquellos hombres cuyo sueldo sea inferior a 500 soles/mes. b) Mujer rica. Las mujeres cuyo sueldo supere los 6000 soles/mes. c) Joven Mujer de clase media. Mujer cuya edad esté comprendida entre los 20 y los 30 años y cuyo sueldo esté entre 1200 y 2000 soles/mes.

Es posible que una persona no entre dentro de ninguna de estas categorías. En tal caso imprime un mensaje que lo indique

Solución

Partial Public Class _Default Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load End Sub Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnAcepatr.Click Dim sueldo As Double Dim edad As Integer edad = txtedad.Text sueldo = txtsueldo.Text Select Case ddlSexo.Text Case "Masculino" If sueldo = 6000 lblresul.Text = "Mujer Rica" Case 1200 To 2000 If edad > 20 And edad < 30 Then lblresul.Text = "Joven Mujer Clase Media" Else lblresul.Text = "Clase no Existe" End If Case Else lblresul.Text = "Clase no Existe" End Select End Select End Sub End Class



Implemente más páginas y realice diferentes acciones con manejo de controles

Partial Public Class _Default Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load End Sub Protected Sub btnSuma_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSuma.Click Dim num1, num2, resu As Decimal num1 = txtN1.Text num2 = txtN2.Text resu = num1 + num2 lblresul.Text = resu

End Sub Protected Sub btnRest_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnRest.Click Dim num1, num2, resu As Decimal num1 = txtN1.Text num2 = txtN2.Text resu = num1 - num2 lblresul.Text = resu End Sub Protected Sub btnMul_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnMul.Click Dim num1, num2, resu As Decimal num1 = txtN1.Text num2 = txtN2.Text resu = num1 * num2 lblresul.Text = resu End Sub Protected Sub btndiv_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btndiv.Click Dim num1, num2, resu As Decimal num1 = txtN1.Text num2 = txtN2.Text resu = num1 / num2 lblresul.Text = resu End Sub End Class

TERCER LABORATORIO

Respaldo

INICIO

Module Inicio Public Aempleado As New ArrayList End Module

ENTIDAD EMPLEADO Public Class Entidad_Empleado Private Private Private Private Private Private

_cod As Integer _datos As String _estado As String _email As String _logn As String _password As String

Public Property cod() As Integer Get Return _cod End Get Set(ByVal value As Integer) _cod = value End Set End Property Public Property datos() As String Get Return _datos End Get Set(ByVal value As String) _datos = value End Set End Property Public Property estado() As String Get Return _estado End Get Set(ByVal value As String) _estado = value End Set End Property Public Property email() As String Get Return _email End Get Set(ByVal value As String) _email = value End Set End Property Public Property login() As String Get Return _logn End Get Set(ByVal value As String) _logn = value End Set End Property Public Property password() As String Get Return _password End Get Set(ByVal value As String) _password = value End Set End Property End Class

WEB FORM Imports System.IO Partial Public Class _Default Inherits System.Web.UI.Page Dim Eempleado As New Entidad_Empleado Sub llenarGV() Try Me.GridView1.DataSource = Aempleado Me.GridView1.DataBind() Catch ex As Exception Response.Write(ex.Message) End Try End Sub Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load End Sub Protected Sub btnRegistrar_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnRegistrar.Click Try Eempleado.cod = Aempleado.Count + 1 Eempleado.datos = txtNombre.Text Eempleado.email = txtEmail.Text Eempleado.login = txtLogin.Text Eempleado.password = txtPassword.Text If rbESTADO.SelectedValue = "Soltero" Then Eempleado.estado = "Soltero" Else Eempleado.estado = "Casado" End If Aempleado.Add(Eempleado) llenarGV() Catch ex As Exception Response.Write(ex.Message) End Try End Sub

Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles GridView1.SelectedIndexChanged End Sub Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click Try Dim wFile As System.IO.FileStream Dim byteData() As Byte byteData = Encoding.ASCII.GetBytes("Cod" & ":" & Aempleado.Count & "Apellido y Nombres " & ": " & txtNombre.Text & " "

& " - " & "Estado" & ": " & rbESTADO.Text & " " & "Email" & ": " & txtEmail.Text) wFile = New FileStream("Respaldo.txt", FileMode.Append) wFile.Write(byteData, 0, byteData.Length) wFile.Close() Catch ex As IOException MsgBox(ex.ToString) End Try End Sub Protected Sub btnEliminar_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnEliminar.Click Dim FILA As Integer Try FILA = Convert.ToInt32(txtCod.Text) Aempleado.RemoveAt(FILA - 1) llenarGV() Catch ex As Exception Response.Write(ex.Message) End Try End Sub End Class

2.

Acceso

Imports System.Data.SqlClient Public Class acceso Private conexion As New SqlConnection("data source=.; initial catalog=EXAM; integrated security=true") Public Function cs() As SqlConnection Return conexion End Function Sub conectar() conexion.Open() End Sub Sub desconectar() conexion.Close() End Sub End Class

Procedimiento Imports System.Data.SqlClient Module Procedimiento Public codusuario, datos As String Dim cmd As SqlCommand Dim dr As SqlDataReader 'crear funcion para evaluar resultados Public Function validar(ByVal cadena As String, ByVal parametro As String) Dim resultado As String Dim cnn As New Acceso cmd = New SqlCommand(cadena, cnn.cs) cmd.Parameters.Add("@para1", SqlDbType.VarChar).Value = parametro cnn.conectar() If IsDBNull(cmd.ExecuteScalar) Then

resultado = 0 Else resultado = cmd.ExecuteScalar End If If cnn.cs.State = ConnectionState.Open Then cnn.desconectar() End If Return resultado End Function End Module

Web Form Partial Public Class _Default Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load End Sub Dim cont As Integer Protected Sub btnAceptar_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnAceptar.Click Dim usuario, password, passwordbd, sentencia As String usuario = txtUsuario.Text password = txtContraseña.Text 'creo la sentencia para evaluar si existe el usuario sentencia = "select loigin from usuario where nombre =@para1 " 'llamando la funcion validar para evaluar el usuario passwordbd = validar(sentencia, usuario) 'si devuelve resultado el usuario existe If passwordbd "" Then 'si existe el usuario/validar el password If password = passwordbd Then 'obtener los datos del empleado codusuario = validar("select loigin from usuario where nombre = @para1", usuario) Server.Transfer("Producto.aspx") Else MsgBox("password incorrecto") txtUsuario.Text = "" txtUsuario.Focus() txtContraseña.Text = "" txtContraseña.Focus() cont = cont + 1 End If Else lblre.Text = ("Error en las 3 orportunidades") txtUsuario.Text = "" txtUsuario.Focus() cont = cont + 1 End If If cont = 3 Then lblre.Text = ("Error en las 3 orportunidades para loguearse" & vbLf & "El sistema se cerrará") End If End Sub End Class

4.

Public Partial Class año_bisiesto Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load End Sub Protected Sub btnCalcular_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnCalcular.Click Dim A As Integer A = txtAño.Text If (A Mod 4 = 0 And A Mod 100 0 Or A Mod 400 = 0) Then lblres.Text = "el año " + Trim(A) + " Si es bisiesto" Else lblres.Text = "el año " + Trim(A) + " No es bisiesto" End If End Sub End Class

5.

Partial Public Class _Default Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load End Sub Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnMostrar.Click Dim texto As String

texto = TextBox1.Text = "" If TextBox1.Text = "hola" Then Label1.Text = "la cadena es minuscula" Else Label1.Text = "la cadena es MAYUSCULA" End If End Sub End Class

6.

Partial Public Class _Default Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load End Sub Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnMostrar.Click Dim I As Integer Dim caracteres As Long For I = 1 To Len(TextBox1.Text) If IsNumeric(Mid(TextBox1.Text, I, 1)) Then Else caracteres = caracteres + 1 End If Next Label1.Text = "Total de Caracteres: " & caracteres & " " End Sub

End Class

7.

Partial Public Class _Default Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load End Sub Public Function factorial(ByVal X As Integer, ByVal N As Integer) If (N > 0) Then X = factorial(X, N - 1) X = X * N Else X = 1 End If Return X End Function Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnMostrar.Click Dim X As Integer Dim N As Integer N = TextBox1.Text X = factorial(X, N) Label1.Text = Trim(X) End Sub End Class

CUARTO LABORATORIO

INICIO

Module Inicio Public Aempleado As New ArrayList End Module

ENTIDAD EMPLEADO Public Class Entidad_Empleado Private Private Private Private Private Private

_cod As Integer _datos As String _estado As String _email As String _logn As String _password As String

Public Property cod() As Integer Get Return _cod End Get Set(ByVal value As Integer) _cod = value End Set End Property Public Property datos() As String Get Return _datos End Get Set(ByVal value As String) _datos = value End Set End Property Public Property estado() As String Get Return _estado End Get Set(ByVal value As String) _estado = value End Set End Property Public Property email() As String Get Return _email End Get Set(ByVal value As String) _email = value End Set End Property Public Property login() As String Get Return _logn End Get Set(ByVal value As String) _logn = value End Set End Property Public Property password() As String Get Return _password End Get Set(ByVal value As String) _password = value End Set End Property End Class

WEB FORM Imports System.IO Partial Public Class _Default Inherits System.Web.UI.Page Dim Eempleado As New Entidad_Empleado Sub llenarGV() Try Me.GridView1.DataSource = Aempleado Me.GridView1.DataBind() Catch ex As Exception Response.Write(ex.Message) End Try End Sub Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load End Sub Protected Sub btnRegistrar_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnRegistrar.Click Try Eempleado.cod = Aempleado.Count + 1 Eempleado.datos = txtNombre.Text Eempleado.email = txtEmail.Text Eempleado.login = txtLogin.Text Eempleado.password = txtPassword.Text If rbESTADO.SelectedValue = "Soltero" Then Eempleado.estado = "Soltero" Else Eempleado.estado = "Casado" End If Aempleado.Add(Eempleado) llenarGV() Catch ex As Exception Response.Write(ex.Message) End Try End Sub Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles GridView1.SelectedIndexChanged End Sub Protected Sub btnEliminar_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnEliminar.Click Dim FILA As Integer Try FILA = Convert.ToInt32(txtCod.Text) Aempleado.RemoveAt(FILA - 1) llenarGV() Catch ex As Exception Response.Write(ex.Message) End Try End Sub End Class

CUARTO LABORATORIO

QUINTO LABORATORIO 1.

Imports System.Data.SqlClient Partial Public Class Modificar Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load End Sub Public Sub habilitar() txtcodigo.Enabled = True txtdescripcion.Enabled = True txtstock.Enabled = True txtpreciou.Enabled = True End Sub Public Sub deshabilitar() txtcodigo.Enabled = False txtdescripcion.Enabled = False txtstock.Enabled = False txtpreciou.Enabled = False End Sub Protected Sub btnbuscar_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnbuscar.Click Try Dim conectar As New SqlConnection("Data Source=ARROYOPC\SQLEXPRESS;Initial Catalog=NORTHWND;Integrated Security=True") conectar.Open() Dim buscar As New String("select*from products where ProductID='" & txtcodigo.Text.ToUpper & "'") Dim comando As New SqlCommand(buscar, conectar) Dim reader As SqlDataReader reader = comando.ExecuteReader While reader.Read txtcodigo.Text = reader("ProductID") txtdescripcion.Text = reader("ProductName") txtstock.Text = reader("UnitsInStock") txtpreciou.Text = reader("UnitPrice") habilitar() MsgBox("Busqueda satisfactoria", vbInformation, "Mensaje") lbl1.Text = "" End While reader.Close() conectar.Close() Catch ex As Exception lbl1.Text = ex.Message End Try End Sub Protected Sub btnmodificar_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnmodificar.Click Try Dim conectar As New SqlConnection("Data Source=ARROYOPC\SQLEXPRESS;Initial Catalog=NORTHWND;Integrated Security=True") conectar.Open() Dim modificar As New String("update products set ProductName='" & txtdescripcion.Text.ToUpper & "',UnitsInStock='" & txtstock.Text.ToUpper & "',UnitPrice='" & txtpreciou.Text.ToUpper & "' where ProductID='" & txtcodigo.Text.ToUpper & "'")

Dim comando As New SqlCommand(modificar, conectar) comando.ExecuteNonQuery() lbl2.Text = "El producto ha sido modificado correctamente" deshabilitar() conectar.Close() Catch ex As Exception lbl1.Text = ex.Message End Try End Sub End Class

2.