0% found this document useful (0 votes)
42 views

CODIGO

This document contains code for a student login and account management system built with Visual Basic and an Access database. It includes classes for the login screen, registration screen, and user account screen. The login class authenticates username and password and opens the account screen if valid. The registration class inserts new user data into the database. The account class retrieves and displays user data, and allows editing basic profile information.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views

CODIGO

This document contains code for a student login and account management system built with Visual Basic and an Access database. It includes classes for the login screen, registration screen, and user account screen. The login class authenticates username and password and opens the account screen if valid. The registration class inserts new user data into the database. The account class retrieves and displays user data, and allows editing basic profile information.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Imports System.

Data
Imports System.Data.OleDb

Public Class Login


Public conex As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source='H:\usuario\Documents\Visual Studio
2010\Projects\Conexion_acces\Conexion_acces\clase2.mdb'")
' Por medio de este objeto voy a enviar todos los comandos de SQL a la tabla por
medio de la conexin
Public comm As New OleDb.OleDbCommand

Private Sub EstudianteBindingNavigatorSaveItem_Click(ByVal sender As


System.Object, ByVal e As System.EventArgs)
Me.Validate()
Me.EstudianteBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.Clase2DataSet)

End Sub

Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles MyBase.Load
'TODO: esta lnea de cdigo carga datos en la tabla
'Clase2DataSet.Estudiante' Puede moverla o quitarla segn sea necesario.
Me.EstudianteTableAdapter.Fill(Me.Clase2DataSet.Estudiante)
Try
' Trato de abrir la conexin
conex.Open()
' Inicializo el objeto Command
comm.Connection = conex
comm.CommandType = CommandType.Text
Catch ex As Exception
If Err.Number = 5 Then
MsgBox("No se pudo encontrar el archivo de la base de datos",
MsgBoxStyle.Exclamation, "Biblioteca")
End
Else
MsgBox(Err.Description, MsgBoxStyle.Exclamation, "Biblioteca")
End If
End Try
End Sub

Private Sub user_TextChanged(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles user.TextChanged

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click

'Use a variable to hold the SQL statement.


Dim selectString As String = "SELECT * FROM Estudiante where User='" &
user.Text & "' and Pass='" & pass.Text & "'"
Dim c As Integer
'Create an OleDbCommand object.
'Notice that this line passes in the SQL statement and the OleDbConnection
object.
Dim cmd As OleDbCommand = New OleDbCommand(selectString, conex)
Dim reader As OleDbDataReader = cmd.ExecuteReader()
c = 0
While (reader.Read())
c = c + 1

End While

If c > 0 Then
Cuenta.Show()
Me.Hide()
Else
MsgBox("Usuario o password incorrectos")

End If
End Sub

Private Sub LinkLabel1_LinkClicked(ByVal sender As System.Object, ByVal e As


System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked

Registrar.Show()

End Sub
End Class

REGISTRAR
Imports System.Data
Imports System.Data.OleDb

Public Class Registrar


Public conex As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source='H:\usuario\Documents\Visual Studio
2010\Projects\Conexion_acces\Conexion_acces\clase2.mdb'")
' Por medio de este objeto voy a enviar todos los comandos de SQL a la tabla por
medio de la conexin
Public comm As New OleDb.OleDbCommand
Private Sub EstudianteBindingNavigatorSaveItem_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs)
Me.Validate()
Me.EstudianteBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.Clase2DataSet)

End Sub

Private Sub Registrar_Load(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles MyBase.Load
'TODO: esta lnea de cdigo carga datos en la tabla
'Clase2DataSet.Estudiante' Puede moverla o quitarla segn sea necesario.
Me.EstudianteTableAdapter.Fill(Me.Clase2DataSet.Estudiante)
ComboBox1.Items.Add("1y2")
ComboBox1.Items.Add("3y4")

Try
' Trato de abrir la conexin
conex.Open()
' Inicializo el objeto Command
comm.Connection = conex
comm.CommandType = CommandType.Text
Catch ex As Exception
If Err.Number = 5 Then
MsgBox("No se pudo encontrar el archivo de la base de datos",
MsgBoxStyle.Exclamation, "Biblioteca")
End
Else
MsgBox(Err.Description, MsgBoxStyle.Exclamation, "Biblioteca")
End If
End Try
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click
Dim act As String
Dim na As Integer
Dim sql As String
act = ComboBox1.SelectedItem

If act.Equals("1y2") Then
na = 1
Else
na = 2

End If

' Me.EstudianteTableAdapter.Insertar(Convert.ToInt16(cedula.Text),
nombre.Text, apellido.Text, Convert.ToDouble(telefono.Text),
Convert.ToInt16(edad.Text), user.Text, pass.Text, na)
' Me.EstudianteTableAdapter.Fill(Me.Clase2DataSet.Estudiante)

If IsNumeric(telefono.Text) And IsNumeric(edad.Text) Then


sql = "INSERT INTO Estudiante VALUES (" & _
Convert.ToInt16(cedula.Text) & ",'" & nombre.Text & "','" &
apellido.Text & "'," & _
Convert.ToDouble(telefono.Text) & "," &
Convert.ToInt16(edad.Text) & ",'" & user.Text & "','" & pass.Text & "'," & na & ")"

' Asigno la instruccin SQL que se va a ejecutar


comm.CommandText = sql

Try

comm.ExecuteNonQuery()
cedula.Text = ""
nombre.Text = ""
apellido.Text = ""
telefono.Text = ""
edad.Text = ""
user.Text = ""
pass.Text = ""

MsgBox("Usuario Registrado")

Catch ex As Exception
MsgBox(Err.Description, MsgBoxStyle.Exclamation, "Biblioteca")
End Try
Else
MsgBox("El telefono y la edad deben se numericos")
End If

End Sub

Private Sub LinkLabel1_LinkClicked(ByVal sender As System.Object, ByVal e As


System.Windows.Forms.LinkLabelLinkClickedEventArgs)
Me.Hide()
Login.Show()

End Sub
End Class

CUENTA
Imports System.Data
Imports System.Data.OleDb
Public Class Cuenta
Public conex As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source='H:\usuario\Documents\Visual Studio
2010\Projects\Conexion_acces\Conexion_acces\clase2.mdb'")
' Por medio de este objeto voy a enviar todos los comandos de SQL a la tabla por
medio de la conexin
Public comm As New OleDb.OleDbCommand
Dim usuario As String
Dim password As String
Dim registro As String

Private Sub EstudianteBindingNavigatorSaveItem_Click(ByVal sender As


System.Object, ByVal e As System.EventArgs)
Me.Validate()
Me.EstudianteBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.Clase2DataSet)

End Sub

Public Sub listar()


Dim selectString As String = "SELECT * FROM Estudiante where User='" &
usuario & "' and Pass='" & password & "'"
'Create an OleDbCommand object.
'Notice that this line passes in the SQL statement and the OleDbConnection
object.
Dim adapter As OleDbDataAdapter = New OleDbDataAdapter(selectString, conex)
Dim cmd As OleDbCommand = New OleDbCommand(selectString, conex)
Dim reader As OleDbDataReader = cmd.ExecuteReader()
Dim datos As New DataSet
adapter.Fill(datos.Tables.Add("Estudiante"))
EstudianteDataGridView.DataSource = datos.Tables("Estudiante")
End Sub

Private Sub Cuenta_Load(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles MyBase.Load
'TODO: esta lnea de cdigo carga datos en la tabla
'Clase2DataSet.Estudiante' Puede moverla o quitarla segn sea necesario.
usuario = Login.user.Text
password = Login.pass.Text

RadioButton1.Checked = False

Try
' Trato de abrir la conexin
conex.Open()
' Inicializo el objeto Command
comm.Connection = conex
comm.CommandType = CommandType.Text
Catch ex As Exception
If Err.Number = 5 Then
MsgBox("No se pudo encontrar el archivo de la base de datos",
MsgBoxStyle.Exclamation, "Biblioteca")
End
Else
MsgBox(Err.Description, MsgBoxStyle.Exclamation, "Biblioteca")
End If
End Try

listar()

'' Me.EstudianteTableAdapter.FillBy(Me.Clase2DataSet.Estudiante, usuario,


password)
TextBox1.Enabled = False
TextBox2.Enabled = False
TextBox3.Enabled = False
TextBox4.Enabled = False
TextBox5.Enabled = False
TextBox6.Enabled = False
TextBox7.Enabled = False
TextBox8.Enabled = False

registro = Me.EstudianteDataGridView.Item(7, 0).Value.ToString


If Convert.ToInt16(registro) = 1 Then
AlgoritmosToolStripMenuItem.Enabled = False
AnalisisDeSistemasToolStripMenuItem.Enabled = False

Else

InglesToolStripMenuItem.Enabled = False
BasesDeDatosToolStripMenuItem.Enabled = False
End If

End Sub

Private Sub enviar_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles enviar.Click
usuario = TextBox6.Text
password = TextBox7.Text
Dim sql As String
If IsNumeric(TextBox4.Text) And IsNumeric(TextBox5.Text) Then

sql = "update Estudiante set Nombre='" & TextBox2.Text & "',Apellido='"


& TextBox3.Text & "',Telefono='" & Convert.ToDouble(TextBox4.Text) & "',Edad='" &
Convert.ToInt16(TextBox5.Text) & "',[User]='" & TextBox6.Text & "',Pass='" &
TextBox7.Text & "',Actividad='" & Convert.ToInt16(TextBox8.Text) & "' where Codigo="
& Convert.ToInt16(TextBox1.Text) & " "

' Asigno la instruccin SQL que se va a ejecutar


comm.CommandText = sql

Try
comm.ExecuteNonQuery()

'Me.EstudianteTableAdapter.FillBy(Me.Clase2DataSet.Estudiante,
usuario, password)

MsgBox("Usuario Editado")

Catch ex As Exception
MsgBox(Err.Description, MsgBoxStyle.Exclamation, "Biblioteca")
End Try

Dim selectString As String = "SELECT * FROM Estudiante where User='" &


usuario & "' and Pass='" & password & "'"

'Create an OleDbCommand object.


'Notice that this line passes in the SQL statement and the
OleDbConnection object.
listar()

'Me.EstudianteTableAdapter.Editar(Convert.ToInt16(TextBox1.Text),
TextBox2.Text, TextBox3.Text, Convert.ToDouble(TextBox4.Text),
Convert.ToInt16(TextBox5.Text), TextBox6.Text, TextBox7.Text, TextBox8.Text,
Convert.ToInt16(TextBox1.Text))

Else
MsgBox("Los valores de telefono y edad deben se numericos")
End If
registro = TextBox8.Text

If registro.Equals("1") Then
AlgoritmosToolStripMenuItem.Enabled = False
AnalisisDeSistemasToolStripMenuItem.Enabled = False
InglesToolStripMenuItem.Enabled = True
BasesDeDatosToolStripMenuItem.Enabled = True
Else
AlgoritmosToolStripMenuItem.Enabled = True
AnalisisDeSistemasToolStripMenuItem.Enabled = True
InglesToolStripMenuItem.Enabled = False
BasesDeDatosToolStripMenuItem.Enabled = False
End If
End Sub

Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e


As System.EventArgs) Handles RadioButton1.CheckedChanged
TextBox1.Enabled = False
TextBox2.Enabled = True
TextBox3.Enabled = True
TextBox4.Enabled = True
TextBox5.Enabled = True
TextBox6.Enabled = True
TextBox7.Enabled = True
TextBox8.Enabled = True

TextBox1.Text = Me.EstudianteDataGridView.Item(0, 0).Value.ToString


TextBox2.Text = Me.EstudianteDataGridView.Item(1, 0).Value.ToString
TextBox3.Text = Me.EstudianteDataGridView.Item(2, 0).Value.ToString
TextBox4.Text = Me.EstudianteDataGridView.Item(3, 0).Value.ToString
TextBox5.Text = Me.EstudianteDataGridView.Item(4, 0).Value.ToString
TextBox6.Text = Me.EstudianteDataGridView.Item(5, 0).Value.ToString
TextBox7.Text = Me.EstudianteDataGridView.Item(6, 0).Value.ToString
TextBox8.Text = Me.EstudianteDataGridView.Item(7, 0).Value.ToString

End Sub

Private Sub Nivel0ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e


As System.EventArgs) Handles Nivel0ToolStripMenuItem.Click
Ingles_N0.Show()

End Sub
Private Sub Nivel1ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Nivel1ToolStripMenuItem.Click
Ingles_N1.Show()
End Sub

Private Sub Nivel2ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e


As System.EventArgs) Handles Nivel2ToolStripMenuItem.Click
Ingles_N2.Show()
End Sub

Private Sub Nivel1ToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal


e As System.EventArgs) Handles Nivel1ToolStripMenuItem1.Click
BD1.Show()

End Sub

Private Sub Nivel2ToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal


e As System.EventArgs) Handles Nivel2ToolStripMenuItem1.Click
BD2.Show()

End Sub

Private Sub IntroduccinToolStripMenuItem_Click(ByVal sender As System.Object,


ByVal e As System.EventArgs) Handles IntroduccinToolStripMenuItem.Click
programacion.Show()

End Sub

Private Sub DiseoDeSistemasToolStripMenuItem_Click(ByVal sender As


System.Object, ByVal e As System.EventArgs) Handles
DiseoDeSistemasToolStripMenuItem.Click
sistemas.Show()

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button2.Click
RadioButton1.Checked = False
Me.Refresh()

End Sub
End Class

Public Class BD1


Dim con As Integer

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click

con = con + 1

If con < 10 Then


PictureBox1.ImageLocation = "H:\usuario\Documents\Visual Studio
2010\Projects\Conexion_acces\aporte2\hist" + con.ToString + ".jpg"
End If
End Sub

Private Sub BD1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles MyBase.Load
con = 0
End Sub
End Class

Public Class BD2

Dim con As Integer

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click

con = con + 1

If con < 9 Then


PictureBox1.ImageLocation = "H:\usuario\Documents\Visual Studio
2010\Projects\Conexion_acces\aporte2\hist2" + con.ToString + ".jpg"
End If

End Sub

Private Sub BD1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles MyBase.Load
con = 0
End Sub
End Class

You might also like