Anda di halaman 1dari 8

Cdigo de programacin

Tabla usuario, la que controla el acceso a la base de datos

Imports MySql.Data.MySqlClient Public Class USUARIOS Private Bandera As Integer Dim conector As New MySqlConnection("server=localhost;user=root;password=casasola;database=mydb;port= 3306") Dim dr As MySqlDataReader Dim Nombre_emple As String Dim idemple_emple As String Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click Close() End Sub Private Sub Button1_Click(sender As Object, e As EventArgs) Handles INGRESAR.Click Dim consulta As String consulta = "select * from usuario where usuario='" + Me.USER.Text + "' and login='" + Me.PASS.Text + "'" Dim consultar As New MySqlCommand(consulta, conector) Try conector.Open() dr = consultar.ExecuteReader() While dr.Read() If Me.USER.Text = dr("USUARIO").ToString() Then If Me.PASS.Text = dr("LOGIN").ToString() Then Nombre_emple = dr("NOMBRE").ToString() idemple_emple = dr("idUsuario").ToString() Bandera = 1 CONTROL.Show() Else

MessageBox.Show("El password proporcionado, es incorrecto", "Sistema de Inventario", MessageBoxButtons.OK, MessageBoxIcon.Information) Me.PASS.SelectAll() : Me.PASS.Focus() End If Else MessageBox.Show("El nombre de usuario, es incorrecto", "Sistema de Inventario", MessageBoxButtons.OK, MessageBoxIcon.Information) Me.USER.SelectAll() : Me.USER.Focus() End If End While conector.Close() dr.Close() Catch mierror As MySqlException MessageBox.Show("Error de Conexin a la Base de Datos: " & mierror.Message) End Try End Sub Private Sub Frm_login_FormClosed(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles MyBase.FormClosed If Bandera <> 1 Then Application.Exit() End If End Sub Private Sub USUARIOS_Load(sender As Object, e As EventArgs) Handles MyBase.Load End Sub End Class

Imports MySql.Data.MySqlClient Public Class CONTROL Dim conector As New MySqlConnection("server=localhost;user=root;password=casasola;database=mydb;port= 3306") Private Property con As Object Private Sub SALIRToolStripMenuItem1_Click_1(sender As Object, e As EventArgs) Handles SALIRToolStripMenuItem1.Click USUARIOS.Close() Close() End Sub Private Sub RadioButton1_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton1.CheckedChanged Try conector.Open() MsgBox("LA CONEXION FUE EXITOSA") Catch ex As Exception MsgBox("Error DE CONEXION") RadioButton1.Visible = False End Try End Sub Private Sub AGREGARToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles AGREGARToolStripMenuItem.Click Me.Close() AGREGAR_RECEPCION.Show() End Sub Private Sub INSERTARADMINISTRADORToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles INSERTARADMINISTRADORToolStripMenuItem.Click Me.Close() ADMINISTRADOR.Show() End Sub Private Sub ELIMINARADMINISTRADORToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ELIMINARADMINISTRADORToolStripMenuItem.Click Me.Close() ELIMINARRECEP.Show() End Sub Private Sub MODIFICARToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles MODIFICARToolStripMenuItem.Click Me.Close() MODREC.Show() End Sub End Class

Imports MySql.Data.MySqlClient Public Class ADMINISTRADOR Dim conector As New MySqlConnection("server=localhost;user=root;password=casasola;database=mydb;port= 3306") Private Property con As Object Private Sub AGREGAR_Click_1(sender As Object, e As EventArgs) Handles AGREGAR.Click Try Dim agregarg As String agregarg = String.Format("INSERT INTO Usuario(idUsuario, Nombre, Apaterno, Amaterno, Direccion, Telefono, Usuario, Login) VALUES ({0},'{1}','{2}','{3}','{4}',{5},'{6}','{7}')", idUsuariog.Text, NOMBREG.Text, APATERNOG.Text, AMATERNOG.Text, DIRECCIONG.Text, TELEFONOG.Text, USUARIOG.Text, LOGING.Text) Dim insertar As New MySqlCommand(agregarg, conector) If idUsuariog.Text >= 3 Then conector.Open() insertar.ExecuteNonQuery() MsgBox("EL REGISTRO FUE AGREGADO CORRECTAMENTE") conector.Close() Me.Close() CONTROL.Show() Else MsgBox("DEMASIADOS USUARIOS") End If Catch ex As Exception MsgBox("Error: " & ex.Message, vbCritical, "Error") End Try Me.Close() CONTROL.Show() End Sub Private Sub CANCELAR_Click_1(sender As Object, e As EventArgs) Handles CANCELAR.Click Me.Close() CONTROL.Show() End Sub

Private Sub ADMINISTRADOR_Load(sender As Object, e As EventArgs) Handles MyBase.Load End Sub End Class

Imports MySql.Data.MySqlClient Public Class ELIMINARRECEP Dim row As Integer Dim conector As New MySqlConnection("server=localhost;user=root;password=casasola;database=mydb;port= 3306") Private Property con As Object Private Sub CANCELAR_Click(sender As Object, e As EventArgs) Handles CANCELAR.Click Close() End Sub Private Sub AGREGAR_Click(sender As Object, e As EventArgs) Handles MODIFICAR.Click If (MessageBox.Show("Estas seguro de actualizar los datos del administrador?", "SISTEMA DE INVENTARIO", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes) Then conector.Open() Dim Strquery As String Strquery = "update usuario set nombre=@NOMBRE," Strquery &= "Apaterno=@Apaterno,Amaterno=@Amaterno, Direccion=@Direccion, Telefono=@Telefono, Usuario=@Usuario, Login=@Login where idUsuario=" & id_userREC.Text Dim CmdPa As New MySql.Data.MySqlClient.MySqlCommand(Strquery, conector) CmdPa.Parameters.AddWithValue("@NOMBRE", Me.NOMBREC.Text) CmdPa.Parameters.AddWithValue("@Apaterno", Me.PATERNOREC.Text) CmdPa.Parameters.AddWithValue("@Amaterno", Me.MATERNOREC.Text) CmdPa.Parameters.AddWithValue("@Direccion", Me.DIRREC.Text) CmdPa.Parameters.AddWithValue("@Telefono", Me.TELEFONOREC.Text) CmdPa.Parameters.AddWithValue("@Usuario", Me.USERREC.Text) CmdPa.Parameters.AddWithValue("@Login", Me.LOGIN.Text) CmdPa.ExecuteNonQuery() MessageBox.Show("Se ah actualizado correctamente")

End If End Sub Sub EliminaCliente(ByVal IDCLIENTE As Integer) End Sub Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click conector.Open() Dim elim As String elim = "delete from usuario where idUsuario=" & id_userREC.Text Dim cmd As New MySqlCommand(elim, conector) cmd.ExecuteNonQuery() If MessageBox.Show("Esta seguro de eliminar al usuario?", "SISTEMA DE INVENTARIO", MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.Yes Then End If End Sub Private Sub ELIMINARRECEP_Load(sender As Object, e As EventArgs) Handles MyBase.Load End Sub End Class

Imports MySql.Data.MySqlClient Public Class AGREGAR_RECEPCION Dim conector As New MySqlConnection("server=localhost;user=root;password=casasola;database=mydb;port= 3306") Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click Me.Close() CONTROL.Show() End Sub Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Try Dim cliente As String Dim reservacion As String Dim DateTime As String

Dim DateTime2 As String DateTime2 = FESALIDA.CanSelect DateTime = FEENTRADA.CanSelect reservacion = String.Format("INSERT INTO RESERVACION(idReservacion, Cliente, FormPago, Tipohabit, Servicio, Impuestos, MontoTotal, Fecha_ingreso, Fecha_salida) VALUES ({0},{1},{2},{3},{4},{5},{6},'{7}','{8}')", IDRES.Text, IDRES.Text, FORPAGO.SelectedItem, TIPO.SelectedItem, SERVICIO.SelectedItem, IMPUESTO.Text, MONTO.Text, DateTime, DateTime2) cliente = String.Format("INSERT INTO CLIENTE(idCliente, Nombre, APATERNOCL, AMATERNOCL, EDAD, SEXO, TELEFONO, MAIL) VALUES ({0},'{1}','{2}','{3}',{4},'{5}',{6},'{7}')", IDRES.Text, NOMBRECLI.Text, PATERNOCLI.Text, MATERNOCLI.Text, EDADCLI.Text, SEXOCLI.SelectedItem, TELCLI.Text, EMAIL.Text) Dim insertarres As New MySqlCommand(reservacion, conector) Dim insertarcli As New MySqlCommand(cliente, conector) conector.Open() insertarres.ExecuteNonQuery() insertarcli.ExecuteNonQuery() MsgBox("RESERVACION NO. " + IDRES.Text + " conector.Close() Me.Close() CONTROL.Show()

AGREGADA CORRECTAMENTE")

Catch ex As Exception MsgBox("Error: " & ex.Message, vbCritical, "Error") End Try End Sub Private Sub FORPAGO_SelectedIndexChanged(sender As Object, e As EventArgs) Handles FORPAGO.SelectedIndexChanged If FORPAGO.SelectedItem = 1 Then FORMAP.Text = "EFECTIVO" ElseIf FORPAGO.SelectedItem = 2 Then FORMAP.Text = "TARGETA DE CREDITO" End If End Sub Private Sub TIPO_SelectedIndexChanged(sender As Object, e As EventArgs) Handles TIPO.SelectedIndexChanged If TIPO.SelectedItem = 1 Then TIPOHABIT.Text = "SENCILLA" ElseIf TIPO.SelectedItem = 2 Then TIPOHABIT.Text = "DOBLE" ElseIf TIPO.SelectedItem = 3 Then TIPOHABIT.Text = "SUITE" Else TIPOHABIT.Text = "SUITE PRESIDENCIAL" End If End Sub Private Sub TIPOHABIT_TextChanged(sender As Object, e As EventArgs) Handles TIPOHABIT.TextChanged If TIPOHABIT.Text = "SENCILLA" Then MONTO.Text = 1200 ElseIf TIPOHABIT.Text = "DOBLE" Then MONTO.Text = 1650 ElseIf TIPOHABIT.Text = "SUITE" Then MONTO.Text = 2100 Else

MONTO.Text = 2500 End If End Sub Private Sub SERVICIO_SelectedIndexChanged(sender As Object, e As EventArgs) Handles SERVICIO.SelectedIndexChanged Dim SPA As Integer = 320 Dim LAVANDERIA As Integer = 120 If SERVICIO.SelectedItem = 1 Then SERV.Text = SPA ElseIf SERVICIO.SelectedItem = 2 Then SERV.Text = LAVANDERIA Else SERV.Text = "NINGUNO" End If End Sub Private Sub AGREGAR_RECEPCION_Load(sender As Object, e As EventArgs) Handles MyBase.Load End Sub End Class