codigos de algunas pantallas

63
Imports MySql Imports MySql.Data Imports MySql.Data.MySqlClient Imports MySql.Data.MySqlClient.MySqlCommand Public Class frmproveedores Public idpr As String Public num_proveedor As Integer Dim Datav1 As New DataView ' para auto completar el los texbox de busqueda Dim sqlstr As String Dim conexion As New MySql.Data.MySqlClient.MySqlConnection(StrConexion) Dim cmd As New MySqlCommand Private Sub tsbEditar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) 'APLICACION CORRECTA editar_proveedor.Show() End Sub Private Sub tsbNuevo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsbNuevo.Click 'oculta el formulario actual

Upload: dania-archaga

Post on 14-Jan-2015

1.555 views

Category:

Technology


1 download

DESCRIPTION

 

TRANSCRIPT

Page 1: codigos de algunas pantallas

Imports MySqlImports MySql.DataImports MySql.Data.MySqlClientImports MySql.Data.MySqlClient.MySqlCommand

Public Class frmproveedores

Public idpr As String Public num_proveedor As Integer Dim Datav1 As New DataView ' para auto completar el los texbox de busqueda Dim sqlstr As String Dim conexion As New MySql.Data.MySqlClient.MySqlConnection(StrConexion) Dim cmd As New MySqlCommand

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

'APLICACION CORRECTA editar_proveedor.Show()

End Sub

Private Sub tsbNuevo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsbNuevo.Click 'oculta el formulario actual Me.Visible = False

'para mostrarse enfrente de todos los formularios (ShowDialog()) nuevo_proveedor.ShowDialog() txt_nombre.Clear() txt_id.Clear()

Page 2: codigos de algunas pantallas

'muestra el formulario actual Me.Visible = True

End Sub 'Public Sub telefono_proveedores() ' Dim objconn As New MySql.Data.MySqlClient.MySqlConnection(StrConexion) ' Dim cod_proveedor As String ' Dim tipo_telefono As String ' Dim dtt As New DataTable

' Try ' For j = 0 To Data_proveedores.RowCount - 1 ' cod_proveedor = Data_proveedores.Rows(j).Cells(1).Value ' Dim cadenas = "select No_telefono, id_tipo_telefono, Id_Proveedor from telefono_proveedor where id_proveedor='" & cod_proveedor & "'" ' Dim adaptador As New MySqlDataAdapter(cadenas, objconn)

' adaptador.Fill(dtt) ' If dtt.Rows(j).Item(1) = 1 Then ' tipo_telefono = "fijo" ' ElseIf dtt.Rows(j).Item(1) = 2 Then ' tipo_telefono = "Fax" ' ElseIf dtt.Rows(j).Item(1) = 3 Then ' tipo_telefono = "Celular" ' End If

' 'combo_telefono.Items.Add(tipo_telefono & " " & dtt.Rows(j).Item(0))

' Next

' ' 'Dim cadena_proveedor = "select No_telefono, Id_tipo_telefono from telefono_proveedor " ' ' 'Dim query As New MySqlDataAdapter(cadena_proveedor, objconn) ' ' 'Dim dt As New DataTable ' ' 'query.Fill(dt) ' ' 'Try ' ' ' For i = 0 To dt.Rows.Count - 1 ' ' ' If dt.Rows(i).Item(1) = 1 Then ' ' ' tipo_telefono = "fijo" ' ' ' ElseIf dt.Rows(i).Item(1) = 2 Then ' ' ' tipo_telefono = "Fax" ' ' ' ElseIf dt.Rows(i).Item(1) = 3 Then ' ' ' tipo_telefono = "Celular" ' ' ' End If ' ' ' combo_telefono.Items.Add(tipo_telefono & " " & dt.Rows(i).Item(0)) ' ' ' Next ' ' ' Me.Data_proveedores.Columns.Add(combo_telefono) ' ' 'Catch ex As Exception ' ' ' MsgBox(ex.Message)

Page 3: codigos de algunas pantallas

' ' 'End Try

' ' 'Dim tipo_telefono As String

' ' 'Dim cadena = "select No_telefono, Id_tipo_telefono from telefono_proveedor where Id_Proveedor='" & cod_proveedor & "' "

' ' 'Dim dt As New DataTable ' ' 'Dim instruccion As New MySqlDataAdapter(cadena, objconn) ' ' 'instruccion.Fill(dt) ' ' 'Try ' ' ' For i = 0 To dt.Rows.Count - 1 ' ' ' If dt.Rows(i).Item(1) = 1 Then ' ' ' tipo_telefono = "fijo" ' ' ' ElseIf dt.Rows(i).Item(1) = 2 Then ' ' ' tipo_telefono = "Fax" ' ' ' ElseIf dt.Rows(i).Item(1) = 3 Then ' ' ' tipo_telefono = "Celular" ' ' ' End If ' ' ' combo_telefono.Items.Add(tipo_telefono & " " & dt.Rows(i).Item(0)) ' ' ' Next

' Catch ex As Exception ' MsgBox(ex.Message) ' End Try

' 'End Sub

' 'Private Sub proveedores_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ' ' ' ''ojo problemas con desbloquear los botones ' ' 'BLOQUEAR_BOTONES() ' ' llenar_data()

' End Sub Public Sub llenar_data() Try

Dim objConn = New MySql.Data.MySqlClient.MySqlConnection(StrConexion) Dim query = "select * from proveedores order by proveedores.Nombre_proveedor" 'Dim query = "select * from proveedores" Dim llenar As New MySqlDataAdapter(query, objConn) Dim dt As New DataTable llenar.Fill(dt) Data_proveedores.DataSource = dt

Page 4: codigos de algunas pantallas

Catch ex As Exception MsgBox(ex.Message) End Try

Data_proveedores.Columns.Item(0).HeaderText = "Id Proveedor" Data_proveedores.Columns.Item(0).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter Data_proveedores.Columns.Item(0).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Data_proveedores.Columns.Item(1).HeaderText = "Nombre proveedor" Data_proveedores.Columns.Item(1).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter Data_proveedores.Columns.Item(1).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Data_proveedores.Columns.Item(2).HeaderText = "Contacto" Data_proveedores.Columns.Item(2).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter Data_proveedores.Columns.Item(2).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Data_proveedores.Columns.Item(3).HeaderText = "Email" Data_proveedores.Columns.Item(3).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter Data_proveedores.Columns.Item(3).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft '''''''''''''''''''''''''''''''''''''

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Data_proveedores.Columns.Item(4).HeaderText = "Plazo pago" Data_proveedores.Columns.Item(4).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight Data_proveedores.Columns.Item(4).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Data_proveedores.Columns.Item(5).HeaderText = "Fecha ingreso" Data_proveedores.Columns.Item(5).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter Data_proveedores.Columns.Item(5).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft

Page 5: codigos de algunas pantallas

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

'para las columnas Data_proveedores.Columns.Item(0).Width = 80 Data_proveedores.Columns.Item(1).Width = 175 Data_proveedores.Columns.Item(2).Width = 175 Data_proveedores.Columns.Item(3).Width = 175 Data_proveedores.Columns.Item(4).Width = 80 Data_proveedores.Columns.Item(5).Width = 80 End Sub Sub LIMPIAR() txt_id.Clear() txt_nombre.Clear() Data_proveedores.Rows.Clear() End Sub

Sub BLOQUEAR_BOTONES() tsbNuevo.Enabled = False

End Sub

Sub DESBLOQUEAR_BOTONES() tsbNuevo.Enabled = True

End Sub

Private Sub tsbSalir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsbSalir.Click Me.Close() 'MsgBox("Desea Salir de la pantalla?", MsgBoxStyle.Question + MsgBoxStyle.OkCancel, "abandonar pantalla") End Sub

Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged

If RadioButton1.Checked = True Then txt_nombre.Visible = False txt_id.Visible = True txt_nombre.Text = Nothing txt_id.Focus() End If End Sub

Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton2.CheckedChanged

Page 6: codigos de algunas pantallas

If RadioButton2.Checked = True Then txt_id.Visible = False txt_nombre.Visible = True txt_id.Text = Nothing txt_nombre.Focus() End If End Sub

Private Sub txt_id_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txt_id.KeyPress If InStr(1, "1234567890." & Chr(8), e.KeyChar) = 0 Then If e.KeyChar = ChrW(Keys.Enter) Then e.Handled = False End If e.KeyChar = "" MsgBox("SOLO SE ACEPTAN NUMEROS") End If End Sub

Private Sub txt_id_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txt_id.TextChanged

Me.KeyPreview = True 'desde aqui es para llenar y cargar los datos del data grid conexion.Open() Me.Data_proveedores.RowHeadersVisible = False 'A partir de aca Dim da01 As New MySqlDataAdapter Dim dt1 As New DataTable 'Dim dt1 As New DataTable 'Pa crear una tabla con los nombres de los usuarios Dim dN1 As New DataSet Dim DV1 As New DataView Dim Data As New DataView 'Dim Data As New DataView 'OJO CAMBIAR SI SALE ERROR Dim Data As New DataView 'Actualiza el DataGrid de Busqueda

Try

Using conexion = New MySql.Data.MySqlClient.MySqlConnection(StrConexion) conexion.Open() sqlstr = "select pv.Id_proveedor, pv.Nombre_proveedor, pv.Contacto, Pv.Email, Pv.Plazo_pago, pv.Fecha_ingreso from proveedores as pv where pv.Id_proveedor LIKE '" & txt_id.Text & "%' order by pv.Nombre_proveedor" '' ''sqlstr = "select pv.Id_proveedor, pv.Nombre_prov, pv.Contacto, Pv.Email, Pv.Plazo_pago, pv.Fecha_ingreso from proveedores as pv order by pv.Nombre_proveedor asc" Dim da1 As New MySqlDataAdapter(sqlstr, conexion) Dim ds1 As New DataSet da1.Fill(ds1)

Datav1.Table = Nothing Datav1.Table = ds1.Tables(0)

Page 7: codigos de algunas pantallas

'Cada vez que cambie Data se actualiza el datagrid de la forma de manera automatica Data_proveedores.DataSource = Datav1 conexion.Close() ''El DataGridView se llama Data y deben asignar el siguiente ''valor en sus propiedades SelectionMode = FullRowSelect Data_proveedores.SelectionMode = DataGridViewSelectionMode.FullRowSelect Data_proveedores.ReadOnly = True End Using Catch ex As Exception

End Try

Data_proveedores.Columns.Item(0).HeaderText = "Id Proveedor" Data_proveedores.Columns.Item(0).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter Data_proveedores.Columns.Item(0).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Data_proveedores.Columns.Item(1).HeaderText = "Nombre proveedor" Data_proveedores.Columns.Item(1).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter Data_proveedores.Columns.Item(1).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Data_proveedores.Columns.Item(2).HeaderText = "Contacto" Data_proveedores.Columns.Item(2).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter Data_proveedores.Columns.Item(2).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Data_proveedores.Columns.Item(3).HeaderText = "Email" Data_proveedores.Columns.Item(3).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter Data_proveedores.Columns.Item(3).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft '''''''''''''''''''''''''''''''''''''

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Data_proveedores.Columns.Item(4).HeaderText = "Plazo pago" Data_proveedores.Columns.Item(4).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter

Page 8: codigos de algunas pantallas

Data_proveedores.Columns.Item(4).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Data_proveedores.Columns.Item(5).HeaderText = "Fecha ingreso" Data_proveedores.Columns.Item(5).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter Data_proveedores.Columns.Item(5).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

'para las columnas Data_proveedores.Columns.Item(0).Width = 80 ''Id proveedor Data_proveedores.Columns.Item(1).Width = 175 ''nombre proveedor Data_proveedores.Columns.Item(2).Width = 175 ''Contacto Data_proveedores.Columns.Item(3).Width = 175 ''Email Data_proveedores.Columns.Item(4).Width = 80 ''Plazo pago Data_proveedores.Columns.Item(5).Width = 80 ''Fecha ingreso 'Data_proveedores.Columns.Item(6).Width = 80 ''SALDO

conexion.Close()

'para auto completar de numero_identidad txt_id.AutoCompleteMode = AutoCompleteMode.SuggestAppend txt_id.AutoCompleteSource = AutoCompleteSource.CustomSource sqlstr = "SELECT DISTINCT Id_proveedor FROM proveedores ORDER By Id_proveedor ASC" AutoCompletar(Me.txt_id, sqlstr)

'mensaje que no existe id en bd, solo sirve para el nombre proveedor 'ojo con el error Using conexion = New MySql.Data.MySqlClient.MySqlConnection(StrConexion)

Dim datos As String = Me.txt_id.Text

End Using

Dim filasgrid As Integer = Data_proveedores.Rows.Count Dim resultado As Integer Using conexion = New MySql.Data.MySqlClient.MySqlConnection(StrConexion) conexion.Open() Dim consulta As New MySqlCommand("SELECT COUNT(Id_Proveedor) FROM Proveedores WHERE Id_Proveedor LIKE '" & txt_id.Text & "%'", conexion) resultado = consulta.ExecuteScalar

Page 9: codigos de algunas pantallas

conexion.Close() End Using

If resultado = 0 Then MsgBox("Este Id del proveedor no se encuentra registrado", MsgBoxStyle.Information + MsgBoxStyle.OkOnly, "AVISO") txt_id.Clear() txt_id.Focus() End If

If txt_id.Text = "" Then Me.Data_proveedores.DataSource = Nothing End If

End Sub

Private Sub txt_nombre_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txt_nombre.KeyPress Validname(Me.txt_nombre, e, 45, False) If e.KeyChar = Chr(45) Then e.Handled = True End If

'#####################validacion ######################## nonrepeat(Me.txt_nombre, True) If txt_nombre.Text = "" Then llenar_data() End If

End Sub

Private Sub txt_nombre_MouseCaptureChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txt_nombre.MouseCaptureChanged

'averiguar pa que sirve Me.txt_nombre.SelectionStart = Me.txt_nombre.TextLength() End Sub

Private Sub txt_nombre_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txt_nombre.TextChanged

Me.KeyPreview = True 'desde aqui es para llenar y cargar los datos del data grid conexion.Open() Me.Data_proveedores.RowHeadersVisible = False 'A partir de aca Dim da01 As New MySqlDataAdapter Dim dt1 As New DataTable 'Dim dt1 As New DataTable 'Pa crear una tabla con los nombres de los usuarios Dim dN1 As New DataSet Dim DV1 As New DataView Dim Data As New DataView

Page 10: codigos de algunas pantallas

'Actualiza el DataGrid de Busqueda Using conexion = New MySql.Data.MySqlClient.MySqlConnection(StrConexion) conexion.Open()

sqlstr = "select pv.Id_proveedor, pv.Nombre_proveedor, pv.Contacto, Pv.Email, Pv.Plazo_pago, pv.Fecha_ingreso from proveedores as pv order by pv.Nombre_proveedor"

Dim da1 As New MySqlDataAdapter(sqlstr, conexion) Dim ds1 As New DataSet da1.Fill(ds1) Datav1.Table = Nothing Datav1.Table = ds1.Tables(0)

'Cada vez que cambie Data se actualiza el datagrid de la forma de manera automatica Data_proveedores.DataSource = Datav1 conexion.Close() ''El DataGridView se llama Data y deben asignar el siguiente ''valor en sus propiedades SelectionMode = FullRowSelect Data_proveedores.SelectionMode = DataGridViewSelectionMode.FullRowSelect Data_proveedores.ReadOnly = True

End Using

Data_proveedores.Columns.Item(0).HeaderText = "Id Proveedor" Data_proveedores.Columns.Item(0).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter Data_proveedores.Columns.Item(0).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft

'Friend WithEvents Column1 As System.Windows.Forms.DataGridViewComboBoxColumn ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Data_proveedores.Columns.Item(1).HeaderText = "Nombre proveedor" Data_proveedores.Columns.Item(1).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter Data_proveedores.Columns.Item(1).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Data_proveedores.Columns.Item(2).HeaderText = "Contacto" Data_proveedores.Columns.Item(2).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter Data_proveedores.Columns.Item(2).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Data_proveedores.Columns.Item(3).HeaderText = "Email"

Page 11: codigos de algunas pantallas

Data_proveedores.Columns.Item(3).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter Data_proveedores.Columns.Item(3).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft '''''''''''''''''''''''''''''''''''''

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Data_proveedores.Columns.Item(4).HeaderText = "Plazo pago" Data_proveedores.Columns.Item(4).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight Data_proveedores.Columns.Item(4).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Data_proveedores.Columns.Item(5).HeaderText = "Fecha ingreso" Data_proveedores.Columns.Item(5).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter Data_proveedores.Columns.Item(5).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

'para las columnas

Data_proveedores.Columns.Item(0).Width = 80 ''Id proveedor Data_proveedores.Columns.Item(1).Width = 175 ''nombre proveedor Data_proveedores.Columns.Item(2).Width = 175 ''Contacto Data_proveedores.Columns.Item(3).Width = 175 ''Email Data_proveedores.Columns.Item(4).Width = 80 ''Plazo pago Data_proveedores.Columns.Item(5).Width = 80 ''Fecha ingreso 'Data_proveedores.Columns.Item(6).Width = 80 ''SALDO

conexion.Close()

'' ''para auto completar de nombre empledo

txt_nombre.AutoCompleteMode = AutoCompleteMode.SuggestAppend txt_nombre.AutoCompleteSource = AutoCompleteSource.CustomSource sqlstr = "SELECT DISTINCT Nombre_proveedor FROM proveedores ORDER By Nombre_proveedor ASC" AutoCompletar(Me.txt_nombre, sqlstr)

'ojo con el error

nonrepeat(Me.txt_nombre, True)

Page 12: codigos de algunas pantallas

Using conexion = New MySql.Data.MySqlClient.MySqlConnection(StrConexion)

Dim datoss As String = Me.txt_nombre.Text

Datav1.RowFilter = String.Format("Nombre_proveedor Like '{0}%'", datoss)

End Using

Dim filasgridd As Integer = Data_proveedores.Rows.Count

If filasgridd = 1 And txt_nombre.Text <> "" Then MsgBox("Este nombre del proveedor no se encuentra registrado", MsgBoxStyle.Information + MsgBoxStyle.OkOnly, "AVISO") txt_nombre.Text = Nothing End If

End Sub

Private Sub Data_proveedores_BindingContextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Data_proveedores.BindingContextChanged

End Sub

Private Sub Data_proveedores_DataSourceChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Data_proveedores.DataSourceChanged If Data_proveedores.RowCount = 0 Then llenar_data() End If

End Sub

Private Sub Data_proveedores_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Data_proveedores.DoubleClick 'al darle doble click y no hay datos tira un error para solucionarlo hay que verificar si hay lineas

' si hay filas entonces se hace el proceso If Data_proveedores.RowCount > 0 Then

editar_proveedor.Textid.Text = Data_proveedores.CurrentRow.Cells(0).Value editar_proveedor.TextNombre.Text = Data_proveedores.CurrentRow.Cells(1).Value editar_proveedor.TextContacto.Text = Data_proveedores.CurrentRow.Cells(2).Value editar_proveedor.TextEmail.Text = Data_proveedores.CurrentRow.Cells(3).Value editar_proveedor.TextPlazo_pago.Text = Data_proveedores.CurrentRow.Cells(4).Value

Page 13: codigos de algunas pantallas

editar_proveedor.TextFecha_ingreso.Text = Data_proveedores.CurrentRow.Cells(5).Value 'editar_proveedor.TextSaldo.Text = Data_proveedores.CurrentRow.Cells(6).Value

'oculta el formulario actual Me.Visible = False

'para mostrarse enfrente de todos los formularios (ShowDialog()) editar_proveedor.ShowDialog() txt_nombre.Clear() txt_id.Clear()

'muestra el formulario actual Me.Visible = True End If End Sub

Private Sub proveedores_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing

If e.CloseReason = CloseReason.UserClosing Then

Dim respexit respexit = MsgBox("¿Desea salir de la pantalla?", MsgBoxStyle.Question + MsgBoxStyle.OkCancel, "Abandonar pantalla") If respexit = vbCancel Then e.Cancel = True End If End If

End Sub

Private Sub frmproveedores_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load llenar_data() End Sub

Private Sub Data_proveedores_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles Data_proveedores.CellContentClick

End Sub

Private Sub Data_proveedores_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Data_proveedores.SelectionChanged

End Sub

Page 14: codigos de algunas pantallas

End Class

Imports MySql.Data.MySqlClientImports MySql.Data

Public Class nuevo_proveedor

Public idpr As String Public num_fact As Integer

Private Sub tsbGuardar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsbGuardar.Click 'validacion para no permitir datos repetidos en id y nombre Dim objConn As New MySql.Data.MySqlClient.MySqlConnection objConn = New MySql.Data.MySqlClient.MySqlConnection(StrConexion) objConn.Open()

If Textid.Text = "" Or Textnombre.Text = "" Then MsgBox("Es obligatorio ingresar el Id del proveedor y su nombre de Provedor", , MsgBoxStyle.Exclamation) Exit Sub End If

If Me.Textid.Text.Length < 14 Or Me.Textid.Text.Length > 15 Then If Textid.Text.Length < 14 Or Textid.Text.Length > 15 Then MsgBox("El Id del proveedor tiene que ser de 14 dígitos ", MsgBoxStyle.Critical) Textid.Clear() Textid.Focus() Exit Sub End If End If

Page 15: codigos de algunas pantallas

Dim sql_comprobar As MySqlCommand

'########_________comprobar el rtn Dim cadena_rtn As String = "SELECT COUNT(id_proveedor) FROM proveedores WHERE id_proveedor = " & Textid.Text & ""

sql_comprobar = New MySqlCommand(cadena_rtn, objConn)

'si la consulta del rtn es cero entonces no existe el rtn y pasa a comprobar el nombre 'si la consulta del rtn no es cero osea es mayor que cero ya existe el rtn If sql_comprobar.ExecuteScalar > 0 Then MsgBox("El RTN ya existe") Textid.Clear() Textid.Focus() 'Salimos del codigo para evitar que se ejecute lo de abajo. Exit Sub End If

'#########________comprobar el nombre Dim cadena_nombre As String = "SELECT COUNT(Nombre_proveedor) FROM proveedores WHERE Nombre_proveedor = '" & Textnombre.Text & "'"

sql_comprobar = New MySqlCommand(cadena_nombre, objConn)

'si la consulta del rtn es cero entonces no existe el nombre y pasa a comprobar el telefono 'si la consulta del rtn no es cero osea es mayor que cero ya existe el nombre If sql_comprobar.ExecuteScalar > 0 Then MsgBox("El nombre de proveedor ya existe") Textnombre.Clear() Textnombre.Focus() 'Salimos del codigo para evitar que se ejecute lo de abajo. Exit Sub End If

'comprobar el telefono Dim cadena_telefono As String = "SELECT COUNT(No_telefono) FROM telefono_proveedor WHERE No_telefono = '" & MaskedTelefono.Text & "' and Id_tipo_telefono = 1"

sql_comprobar = New MySqlCommand(cadena_telefono, objConn)

'si la consulta del rtn es cero entonces no existe el nombre y pasa a comprobar el telefono 'si la consulta del rtn no es cero osea es mayor que cero ya existe el nombre If sql_comprobar.ExecuteScalar > 0 Then MsgBox("El numero de Telefono ya existe") MaskedTelefono.Clear() MaskedTelefono.Focus() 'Salimos del codigo para evitar que se ejecute lo de abajo.

Page 16: codigos de algunas pantallas

Exit Sub End If

'comprobar el fax Dim cadena_fax As String = "SELECT COUNT(No_telefono) FROM telefono_proveedor WHERE No_telefono = '" & MaskedFax.Text & "' and Id_tipo_telefono = 2"

sql_comprobar = New MySqlCommand(cadena_fax, objConn)

'si la consulta del rtn es cero entonces no existe el nombre y pasa a comprobar el telefono fax If sql_comprobar.ExecuteScalar > 0 Then MsgBox("El numero de Telefono Fax ya existe") MaskedFax.Clear() MaskedFax.Focus() 'Salimos del codigo para evitar que se ejecute lo de abajo. Exit Sub End If

'#################TERMINO AREA DE COMPROBACION ###################

'#########################validaciones para tipo de telefono#########################################################

If Me.MaskedTelefono.Text.Length < 8 Then If MaskedTelefono.Text.Length < 8 Then MsgBox("El numero de Telefono tiene que ser de ocho digitos ", MsgBoxStyle.Critical) MaskedTelefono.Clear() MaskedTelefono.Focus() Exit Sub End If End If

'validacion para el numero de fax

If Me.MaskedFax.Text.Length < 8 Then If MaskedFax.Text.Length < 8 Then MsgBox("El numero de Fax tiene que ser de ocho digitos ", MsgBoxStyle.Critical) MaskedFax.Clear() MaskedFax.Focus() Exit Sub End If End If

'validacion para el numero de celular

If Me.MaskedCelular.Text.Length < 8 Then If MaskedCelular.Text.Length < 8 Then

Page 17: codigos de algunas pantallas

MsgBox("El numero de Celular tiene que ser de ocho digitos ", MsgBoxStyle.Critical) MaskedCelular.Clear() MaskedCelular.Focus() Exit Sub End If End If

'#########################PARA GUARDAR#########################################################

Try MaskedCelular.TextMaskFormat = MaskFormat.ExcludePromptAndLiterals MaskedFax.TextMaskFormat = MaskFormat.ExcludePromptAndLiterals MaskedTelefono.TextMaskFormat = MaskFormat.ExcludePromptAndLiterals

'con la funcion SELECT CURDATE() exclusiva de mysql se obtiene la fecha actual del sistema Dim guardar_proveedor As New MySqlCommand("INSERT INTO proveedores (Id_proveedor, Nombre_proveedor, Contacto, Email, Plazo_Pago, Fecha_Ingreso) VALUES('" & Textid.Text & "', '" & Textnombre.Text & "', '" & Textcontacto.Text & "','" & Textemail.Text & "','" & Textplazopag.Text & "', (SELECT CURDATE()))", objConn) Dim cadena = "INSERT INTO banco_proveedor (Nombre_Banco, id_proveedor, No_cuenta) VALUES('" & cb_bancos.Text & "', '" & Textid.Text & "', '" & Textcuenta.Text & "')" Dim cadena2 = "INSERT INTO telefono_proveedor (Id_Proveedor, No_telefono, Id_tipo_telefono) VALUES('" & Textid.Text & "', '" & MaskedTelefono.Text & "', 1)" Dim cadena3 = "INSERT INTO telefono_proveedor (Id_Proveedor, No_telefono, Id_tipo_telefono) VALUES('" & Textid.Text & "', '" & MaskedCelular.Text & "', 3)" Dim cadena4 = "INSERT INTO telefono_proveedor (Id_Proveedor, No_telefono, Id_tipo_telefono) VALUES('" & Textid.Text & "', '" & MaskedFax.Text & "', 2)" Dim guardar_banco As New MySqlCommand(cadena, objConn) Dim guardar_telefono As New MySqlCommand(cadena2, objConn) Dim guardar_celular As New MySqlCommand(cadena3, objConn) Dim guardar_fax As New MySqlCommand(cadena4, objConn)

guardar_proveedor.ExecuteNonQuery() guardar_banco.ExecuteNonQuery() guardar_telefono.ExecuteNonQuery() guardar_celular.ExecuteNonQuery() guardar_fax.ExecuteNonQuery() MsgBox("Información guardada correctamente", MsgBoxStyle.Information, "Proveedores") Me.Close()

Page 18: codigos de algunas pantallas

Catch ex As Exception MsgBox("Información no guardada. " & ex.Message, MsgBoxStyle.Critical, "ERROR....") End Try 'Exit Sub Try Catch ex As Exception MsgBox(ex.Message) End Try LIMPIAR()

End Sub

Public Sub bancos() Dim objconn As New MySql.Data.MySqlClient.MySqlConnection(StrConexion) objconn.Open() Try Dim tablabancos As New DataTable

Dim consulta_bancos As New MySqlDataAdapter("SELECT nombre_banco from banco", objconn)

consulta_bancos.Fill(tablabancos)

For i = 0 To tablabancos.Rows.Count - 1

cb_bancos.Items.Add((tablabancos.Rows(i).Item(0))) Next Catch ex As Exception MsgBox(ex.Message) End Try objconn.Close()

End Sub

Private Sub tsbSalir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsbSalir.Click Me.Close()

End Sub

Private Sub nuevo_proveedor_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'cb_bancos.Items.Clear()

bancos()

'VER SI AHI ESTA BIEN PARA LA HORA DEL SISTEMA

'agregar la fecha del servidor Dim objConn As New MySql.Data.MySqlClient.MySqlConnection

Page 19: codigos de algunas pantallas

objConn = New MySql.Data.MySqlClient.MySqlConnection(StrConexion) objConn.Open()

Dim fechadb As New MySqlClient.MySqlCommand("SELECT CURDATE()", objConn) Maskedfechaingreso.Text = fechadb.ExecuteScalar objConn.Close()

End Sub

Sub LIMPIAR() Textid.Clear() Textnombre.Clear() Textcontacto.Clear() Textemail.Clear() MaskedCelular.Clear() Textemail.Clear()

MaskedFax.Clear() MaskedTelefono.Clear() Textcuenta.Clear() Textplazopag.Clear() Maskedfechaingreso.Clear() cb_bancos = Nothing

End Sub

Sub DESBLOQUEAR_BOTONES() tsbGuardar.Enabled = True Textnombre.Enabled = True Textcontacto.Enabled = True MaskedCelular.Enabled = True Textemail.Enabled = True Textcuenta.Enabled = True cb_bancos.Enabled = True MaskedFax.Enabled = True Textid.Enabled = True MaskedTelefono.Enabled = True Maskedfechaingreso.Enabled = True Textplazopag.Enabled = True 'Textsaldo.Enabled = True Textcuenta.Enabled = True 'Textcuenta2.Enabled = True End Sub

Sub BLOQUEAR_BOTONES()

tsbGuardar.Enabled = False Textnombre.Enabled = False Textcontacto.Enabled = False MaskedCelular.Enabled = False Textemail.Enabled = False Textcuenta.Enabled = False cb_bancos.Enabled = False MaskedFax.Enabled = False

Page 20: codigos de algunas pantallas

Textid.Enabled = False MaskedTelefono.Enabled = False Maskedfechaingreso.Enabled = False Textplazopag.Enabled = False Textcuenta.Enabled = False 'Textcuenta2.Enabled = False

End Sub

Private Sub Textid_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Textid.KeyPress 'revisar si hace algo If InStr(1, "1234567890" & Chr(8), e.KeyChar) = 0 Then If e.KeyChar = ChrW(Keys.Enter) Then e.Handled = False End If e.KeyChar = "" MsgBox("SOLO SE ACEPTAN NUMEROS") End If End Sub

Private Sub Texttelefono_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs)

If InStr(1, "1234567890" & Chr(8), e.KeyChar) = 0 Then If e.KeyChar = ChrW(Keys.Enter) Then e.Handled = False End If e.KeyChar = "" MsgBox("SOLO SE ACEPTAN NUMEROS") End If

'OJO EN DONDE VA ESTE ERROR

End Sub

Private Sub Textnombre_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Textnombre.KeyPress Validname(Me.Textnombre, e, 45, False) If e.KeyChar = Chr(45) Then e.Handled = True End If

'#####################alidacion ######################## nonrepeat(Me.Textnombre, True)

End Sub

Page 21: codigos de algunas pantallas

Private Sub Textcontacto_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Textcontacto.KeyPress Validname(Me.Textcontacto, e, 45, False) If e.KeyChar = Chr(45) Then e.Handled = True End If

'#####################alidacion ######################## nonrepeat(Me.Textcontacto, True) End Sub

Private Sub Textfax_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) 'revisar si hace algo If InStr(1, "1234567890" & Chr(8), e.KeyChar) = 0 Then If e.KeyChar = ChrW(Keys.Enter) Then e.Handled = False End If e.KeyChar = "" MsgBox("SOLO SE ACEPTAN NUMEROS") End If End Sub

Private Sub Textcelular_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) 'revisar si hace algo If InStr(1, "1234567890" & Chr(8), e.KeyChar) = 0 Then If e.KeyChar = ChrW(Keys.Enter) Then e.Handled = False End If e.KeyChar = "" MsgBox("SOLO SE ACEPTAN NUMEROS") End If End Sub

Private Sub Textcuenta_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Textcuenta.KeyPress 'revisar si hace algo If InStr(1, "1234567890" & Chr(8), e.KeyChar) = 0 Then If e.KeyChar = ChrW(Keys.Enter) Then e.Handled = False End If e.KeyChar = "" MsgBox("SOLO SE ACEPTAN NUMEROS") End If

End Sub Private Sub Textplazopag_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Textplazopag.KeyPress 'revisar si hace algo If InStr(1, "1234567890" & Chr(8), e.KeyChar) = 0 Then If e.KeyChar = ChrW(Keys.Enter) Then e.Handled = False End If e.KeyChar = ""

Page 22: codigos de algunas pantallas

MsgBox("SOLO SE ACEPTAN NUMEROS") End If

'If Textcuenta.Text = "0" Then ' If e.KeyChar = ChrW(Keys.Enter) Then ' e.Handled = False ' End If ' e.KeyChar = "" ' MsgBox("No se puede guardar el numero de cuenta porque el valor es cero") 'Else 'End If

End Sub

Private Sub Textemail_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Textemail.KeyPress If Len(Textemail.Text) > 2 Then

If InStr(Textemail.Text, "@") = 0 Then If InStr(1, "0123456789.-_@" & "abcdefghijklmnñopqrstuvwxyz" & "ABCDEFGHIJKLMNÑOPQRSTUVWXYZ" & Chr(8), e.KeyChar) = 0 Then e.KeyChar = "" End If Else If InStr(1, "0123456789.-_" & "abcdefghijklmnñopqrstuvwxyz" & "ABCDEFGHIJKLMNÑOPQRSTUVWXYZ" & Chr(8), e.KeyChar) = 0 Then e.KeyChar = "" End If End If Else If InStr(1, "0123456789.-_" & "abcdefghijklmnñopqrstuvwxyz" & "ABCDEFGHIJKLMNÑOPQRSTUVWXYZ" & Chr(8), e.KeyChar) = 0 Then e.KeyChar = "" End If End If

'#####################alidacion ######################## nonrepeat(Me.Textemail, True)

End Sub

Private Sub Textemail_Validated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Textemail.Validated

Page 23: codigos de algunas pantallas

If Len(Textemail.Text) = 0 Then Exit Sub End If Textemail.Text = LCase(Textemail.Text)

If Textemail.Text = "" Then MsgBox("Debe ingresar un correo valido") Textemail.Focus() Else Dim captura_dominio As String Dim posicion_dominio As Integer

If Len(Textemail.Text) > 11 Then If InStr(Textemail.Text, "@") > 2 Then If InStr(Textemail.Text, "@.") = 0 Then

'Se captura las ultimas letras osea el dominio posicion_dominio = Len(Textemail.Text) - 3 captura_dominio = Mid(Textemail.Text, posicion_dominio)

'compara los dominios If captura_dominio = ".com" Or captura_dominio = ".net" Or captura_dominio = ".edu" Or captura_dominio = ".gov" Or captura_dominio = ".mil" Or captura_dominio = ".org" Or Mid(Textemail.Text, posicion_dominio + 1) = ".es" Or Mid(Textemail.Text, posicion_dominio + 1) = ".hn" Or Mid(Textemail.Text, posicion_dominio + 1) = ".cr" Or Mid(Textemail.Text, posicion_dominio + 1) = ".sv" Or Mid(Textemail.Text, posicion_dominio + 1) = ".pa" Or Mid(Textemail.Text, posicion_dominio + 1) = ".gt" Or Mid(Textemail.Text, posicion_dominio + 1) = ".ni" Then

Exit Sub Else MsgBox("Debe ingresar un dominio .com, .es, .hn ingrese un correo valido ejemplo: [email protected]") Textemail.Focus() End If Else MsgBox("No puede ingresar @. ingrese un correo valido ejemplo: [email protected]") Textemail.Focus() End If Else MsgBox("Falta la @ ingrese un correo valido ejemplo: [email protected]") Textemail.Focus() End If Else MsgBox("Ingrese un correo valido ejemplo: [email protected]") Textemail.Focus() End If End If End Sub

Page 24: codigos de algunas pantallas

''Private Sub Textbanco_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) '' Validname(Me.Textbanco, e, 45, False) '' If e.KeyChar = Chr(45) Then '' e.Handled = True '' End If

'' '#####################Validacion ######################## '' nonrepeat(Me.Textbanco, True) ''End Sub

Private Sub nuevo_proveedor_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing

If e.CloseReason = CloseReason.UserClosing Then

Dim respexit respexit = MsgBox("¿Desea salir de la pantalla?", MsgBoxStyle.Question + MsgBoxStyle.OkCancel, "Abandonar pantalla") If respexit = vbCancel Then e.Cancel = True End If End If

End Sub

Private Sub LinkLabel1_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked Adicion_num_tel.Show() End Sub

#Region "VALIDACIONES PARA EVITAR COLOCAR NUMEROS INCORRECTOS EN EL CELULAR, TELEFONO Y FAX"

Private Sub MaskedCelular_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles MaskedCelular.KeyPress

MaskedCelular.TextMaskFormat = MaskFormat.ExcludePromptAndLiterals If Len(MaskedCelular.Text) = 0 Then If InStr(1, "983", e.KeyChar) = 0 Then e.KeyChar = Nothing MsgBox("Solo puede iniciar con un digito que empiece con 9, 8 o 3") End If End If End Sub

Private Sub MaskedTelefono_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles MaskedTelefono.KeyPress MaskedTelefono.TextMaskFormat = MaskFormat.ExcludePromptAndLiterals

Page 25: codigos de algunas pantallas

If Len(MaskedTelefono.Text) = 0 Then If Chr(50) <> e.KeyChar Then e.KeyChar = Nothing MsgBox("Solo puede iniciar con un digito que empiece con 2") 'mensaje de que solo pude ingresar 2 End If End If

If Len(MaskedTelefono.Text) = 1 Then If InStr(1, "245678", e.KeyChar) = 0 Then e.KeyChar = "" 'mensaje de ue solo puede ingresar ... End If End If

End Sub

Private Sub MaskedFax_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles MaskedFax.KeyPress MaskedFax.TextMaskFormat = MaskFormat.ExcludePromptAndLiterals If Len(MaskedFax.Text) = 0 Then If Chr(50) <> e.KeyChar Then e.KeyChar = Nothing MsgBox("Solo puede iniciar con un digito que empiece con 2") End If End If

If Len(MaskedFax.Text) = 1 Then If InStr(1, "245678", e.KeyChar) = 0 Then e.KeyChar = "" End If End If End Sub

#End Region

End Class

Page 26: codigos de algunas pantallas

Imports MySql.Data.MySqlClient

Public Class editar_proveedor

Public Sub combo_bancos() Dim objconn As New MySql.Data.MySqlClient.MySqlConnection(StrConexion) objconn.Open() Try Dim tablabancos As New DataTable

Dim consulta_bancos As New MySqlDataAdapter("SELECT nombre_banco from banco", objconn)

consulta_bancos.Fill(tablabancos)

For i = 0 To tablabancos.Rows.Count - 1

cb_bancos.Items.Add((tablabancos.Rows(i).Item(0))) Next Catch ex As Exception MsgBox(ex.Message) End Try objconn.Close() End Sub Private Sub tsbGuardar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsbGuardar.Click

' ''OJO PA GUARDAR 'validacion para no permitir datos repetidos en id

Page 27: codigos de algunas pantallas

Dim objConn As New MySql.Data.MySqlClient.MySqlConnection objConn = New MySql.Data.MySqlClient.MySqlConnection(StrConexion) objConn.Open()

If TextNombre.Text = "" Then MsgBox("Es obligatorio ingresar el nombre del proveedor", , MsgBoxStyle.Exclamation) Exit Sub End If

'VALIDACION(BUENA) If Me.Textid.Text.Length < 14 Or Me.Textid.Text.Length > 15 Then If Textid.Text.Length < 14 Or Textid.Text.Length > 15 Then MsgBox("El Id del proveedor tiene que ser de 14 dígitos ", MsgBoxStyle.Critical) Textid.Clear() Textid.Focus() Exit Sub End If End If

If Me.TextTelefono.Text.Length < 8 Then If TextTelefono.Text < 8 Then MsgBox("El numero de Telefono tiene que ser de ocho digitos ", MsgBoxStyle.Critical) TextTelefono.Clear() TextTelefono.Focus() Exit Sub End If End If

'validacion para el numero de fax

If Me.TextFax.Text.Length < 8 Then If TextFax.Text.Length < 8 Then MsgBox("El numero de Fax tiene que ser de ocho digitos ", MsgBoxStyle.Critical) TextFax.Clear() TextFax.Focus() Exit Sub End If End If

'validacion para el numero de celular

If Me.TextCelular.Text.Length < 8 Then If TextCelular.Text.Length < 8 Then MsgBox("El numero de Celular tiene que ser de ocho digitos ", MsgBoxStyle.Critical) TextCelular.Clear() TextCelular.Focus() Exit Sub End If

Page 28: codigos de algunas pantallas

End If

'FALTA VALIDACIONES EN NUMERO DE TELEFONO COPIAR DE PANTALLA NUEVO

actualizar()

End Sub

Public Sub actualizar()

Try

Dim objConn As New MySql.Data.MySqlClient.MySqlConnection(StrConexion) Dim cadena = "UPDATE proveedores SET Nombre_proveedor= '" & TextNombre.Text & "', contacto= '" & TextContacto.Text & "', Email= '" & TextEmail.Text & "', Plazo_pago= '" & TextPlazo_pago.Text & "' WHERE Id_Proveedor= '" & Me.Textid.Text & "'" Dim adaptador As MySqlCommand objConn.Open() adaptador = New MySqlCommand(cadena, objConn) adaptador.ExecuteNonQuery() actualizar_telefonos() actualizar_banco()

MsgBox("La Información se actualizo correctamente", MsgBoxStyle.Information, "Proveedores") Me.Close()

Catch ex As Exception MsgBox("Información no se actualizo. " & ex.Message, MsgBoxStyle.Critical, "ERROR....") End Try Try Catch ex As Exception MsgBox(ex.Message) End Try

End Sub

Public Sub actualizar_telefonos()

Try

Dim objConn As New MySql.Data.MySqlClient.MySqlConnection(StrConexion) Dim cadena = "UPDATE telefono_proveedor SET No_telefono = '" & TextTelefono.Text & "' WHERE telefono_proveedor.Id_Proveedor= '" & Me.Textid.Text & "' and Id_tipo_telefono = 1" Dim cadena1 = "UPDATE telefono_proveedor SET No_telefono = '" & TextFax.Text & "' WHERE telefono_proveedor.Id_Proveedor= '" & Me.Textid.Text & "' and Id_tipo_telefono = 2"

Page 29: codigos de algunas pantallas

Dim cadena2 = "UPDATE telefono_proveedor SET No_telefono = '" & TextCelular.Text & "' WHERE telefono_proveedor.Id_Proveedor= '" & Me.Textid.Text & "' and Id_tipo_telefono = 3"

Dim adaptador As MySqlCommand objConn.Open() adaptador = New MySqlCommand(cadena, objConn) adaptador.ExecuteNonQuery()

adaptador = New MySqlCommand(cadena1, objConn) adaptador.ExecuteNonQuery()

adaptador = New MySqlCommand(cadena2, objConn) adaptador.ExecuteNonQuery()

'MsgBox("La Información se actualizo correctamente", MsgBoxStyle.Information, "Proveedores") 'Me.Close()

Catch ex As Exception MsgBox("Información no se actualizo. " & ex.Message, MsgBoxStyle.Critical, "ERROR....") End Try Try Catch ex As Exception MsgBox(ex.Message) End Try

End Sub

Public Sub actualizar_banco()

Try

Dim objConn As New MySql.Data.MySqlClient.MySqlConnection(StrConexion) Dim cadena = "UPDATE banco_proveedor SET Nombre_Banco = '" & cb_bancos.Text & "', No_cuenta= '" & TextCuenta.Text & "' WHERE Id_proveedor= '" & Me.Textid.Text & "'" Dim adaptador As MySqlCommand objConn.Open() adaptador = New MySqlCommand(cadena, objConn) adaptador.ExecuteNonQuery() 'MsgBox("La Información se actualizo correctamente", MsgBoxStyle.Information, "Proveedores") 'Me.Close()

Catch ex As Exception MsgBox("Información no se actualizo. " & ex.Message, MsgBoxStyle.Critical, "ERROR....") End Try Try Catch ex As Exception MsgBox(ex.Message)

Page 30: codigos de algunas pantallas

End Try

End Sub

Private Sub editar_proveedor_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load combo_bancos() numero_telefono() 'numero_Celular() 'numero_Fax() banco() no_cuenta() Textid.Enabled = True Textid.ReadOnly = True

End Sub Public Sub numero_telefono() Dim objConn As New MySql.Data.MySqlClient.MySqlConnection(StrConexion)

Dim cadena = "Select No_telefono from telefono_proveedor where Id_Proveedor= '" & Me.Textid.Text & "' And Id_tipo_telefono = 1" 'telefono Dim cadena2 = "Select No_telefono from telefono_proveedor where Id_Proveedor= '" & Me.Textid.Text & "' and Id_tipo_telefono = 3" 'celular Dim cadena3 = "Select No_telefono from telefono_proveedor where Id_Proveedor= '" & Me.Textid.Text & "' and Id_tipo_telefono = 2" 'fax

objConn.Open() Dim sql_consulta As MySqlCommand

Try 'obtenemos el telefono sql_consulta = New MySqlCommand(cadena, objConn) TextTelefono.Text = sql_consulta.ExecuteScalar Catch ex As Exception

End Try

Try 'obtenemos el celular sql_consulta = New MySqlCommand(cadena2, objConn) TextCelular.Text = sql_consulta.ExecuteScalar Catch ex As Exception MsgBox(ex.Message) End Try

Try 'obtenemos el fax sql_consulta = New MySqlCommand(cadena3, objConn) TextFax.Text = sql_consulta.ExecuteScalar Catch ex As Exception

Page 31: codigos de algunas pantallas

End Try

End Sub

Public Sub banco()

Try

Dim objConn As New MySql.Data.MySqlClient.MySqlConnection(StrConexion) Dim cadena = "Select Nombre_Banco from Banco_proveedor where Id_Proveedor= '" & Me.Textid.Text & "'" Dim adaptador As MySqlCommand objConn.Open() adaptador = New MySqlCommand(cadena, objConn) adaptador.ExecuteScalar() Me.cb_bancos.SelectedText = adaptador.ExecuteScalar Catch ex As Exception MsgBox(ex.Message)

End Try

End Sub

Public Sub no_cuenta()

Try

Dim objConn As New MySql.Data.MySqlClient.MySqlConnection(StrConexion) Dim cadena = "Select No_cuenta from Banco_proveedor where Id_Proveedor= '" & Me.Textid.Text & "'" Dim adaptador As MySqlCommand objConn.Open() adaptador = New MySqlCommand(cadena, objConn) adaptador.ExecuteScalar() Me.TextCuenta.Text = adaptador.ExecuteScalar Catch ex As Exception MsgBox(ex.Message)

End Try

End Sub

Private Sub TextNombre_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextNombre.KeyPress Validname(Me.TextNombre, e, 45, False) If e.KeyChar = Chr(45) Then e.Handled = True End If

'#####################alidacion ######################## nonrepeat(Me.TextNombre, True)

Page 32: codigos de algunas pantallas

End Sub

Private Sub TextContacto_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextContacto.KeyPress Validname(Me.TextContacto, e, 45, False) If e.KeyChar = Chr(45) Then e.Handled = True End If

'#####################alidacion ######################## nonrepeat(Me.TextContacto, True)

End Sub

Private Sub TextTelefono_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextTelefono.KeyPress 'revisar si hace algo If InStr(1, "1234567890" & Chr(8), e.KeyChar) = 0 Then If e.KeyChar = ChrW(Keys.Enter) Then e.Handled = False End If e.KeyChar = "" MsgBox("SOLO SE ACEPTAN NUMEROS") End If

If Len(TextTelefono.Text) = 0 Then If Chr(50) <> e.KeyChar Then e.KeyChar = Nothing MsgBox("Solo puede iniciar con un digito que empiece con 2") 'mensaje de que solo pude ingresar 2 End If End If

If Len(TextTelefono.Text) = 1 Then If InStr(1, "245678", e.KeyChar) = 0 Then e.KeyChar = "" 'mensaje de ue solo puede ingresar ... End If End If

End Sub

Private Sub TextCelular_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextCelular.KeyPress

'revisar si hace algo If InStr(1, "1234567890" & Chr(8), e.KeyChar) = 0 Then If e.KeyChar = ChrW(Keys.Enter) Then e.Handled = False End If e.KeyChar = "" MsgBox("SOLO SE ACEPTAN NUMEROS")

Page 33: codigos de algunas pantallas

End If

If Len(TextCelular.Text) = 0 Then If InStr(1, "983", e.KeyChar) = 0 Then e.KeyChar = Nothing MsgBox("Solo puede iniciar con un digito que empiece con 9, 8 o 3") End If End If End Sub

Private Sub TextFax_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextFax.KeyPress 'revisar si hace algo If InStr(1, "1234567890" & Chr(8), e.KeyChar) = 0 Then If e.KeyChar = ChrW(Keys.Enter) Then e.Handled = False End If e.KeyChar = "" MsgBox("SOLO SE ACEPTAN NUMEROS") End If

If Len(TextFax.Text) = 0 Then If Chr(50) <> e.KeyChar Then e.KeyChar = Nothing MsgBox("Solo puede iniciar con un digito que empiece con 2") End If End If

If Len(TextFax.Text) = 1 Then If InStr(1, "245678", e.KeyChar) = 0 Then e.KeyChar = "" End If End If End Sub

Private Sub TextCuenta_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextCuenta.KeyPress 'revisar si hace algo If InStr(1, "1234567890" & Chr(8), e.KeyChar) = 0 Then If e.KeyChar = ChrW(Keys.Enter) Then e.Handled = False End If e.KeyChar = "" MsgBox("SOLO SE ACEPTAN NUMEROS") End If

If Len(TextCuenta.Text) = 0 Then If InStr(1, "123456789", e.KeyChar) = 0 Then

Page 34: codigos de algunas pantallas

e.KeyChar = Nothing MsgBox("no se puede iniciar con un valor de cero") End If End If End Sub

Private Sub TextPlazo_pago_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextPlazo_pago.KeyPress 'revisar si hace algo If InStr(1, "1234567890" & Chr(8), e.KeyChar) = 0 Then If e.KeyChar = ChrW(Keys.Enter) Then e.Handled = False End If e.KeyChar = "" MsgBox("SOLO SE ACEPTAN NUMEROS") End If

If Len(TextPlazo_pago.Text) = 0 Then If InStr(1, "123456789", e.KeyChar) = 0 Then e.KeyChar = Nothing MsgBox("no se puede iniciar con un valor de cero") End If End If

End Sub

Private Sub TextEmail_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextEmail.KeyPress If Len(TextEmail.Text) > 2 Then

If InStr(TextEmail.Text, "@") = 0 Then If InStr(1, "0123456789.-_@" & "abcdefghijklmnñopqrstuvwxyz" & "ABCDEFGHIJKLMNÑOPQRSTUVWXYZ" & Chr(8), e.KeyChar) = 0 Then e.KeyChar = "" End If Else If InStr(1, "0123456789.-_" & "abcdefghijklmnñopqrstuvwxyz" & "ABCDEFGHIJKLMNÑOPQRSTUVWXYZ" & Chr(8), e.KeyChar) = 0 Then e.KeyChar = "" End If End If Else If InStr(1, "0123456789.-_" & "abcdefghijklmnñopqrstuvwxyz" & "ABCDEFGHIJKLMNÑOPQRSTUVWXYZ" & Chr(8), e.KeyChar) = 0 Then e.KeyChar = "" End If End If

'#####################alidacion ########################

Page 35: codigos de algunas pantallas

nonrepeat(Me.TextEmail, True)

End Sub

Private Sub TextEmail_Validated(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextEmail.Validated If Len(TextEmail.Text) = 0 Then Exit Sub End If

TextEmail.Text = LCase(TextEmail.Text)

If TextEmail.Text = "" Then MsgBox("Debe ingresar un correo valido") TextEmail.Focus() Else Dim captura_dominio As String Dim posicion_dominio As Integer

If Len(TextEmail.Text) > 11 Then If InStr(TextEmail.Text, "@") > 2 Then If InStr(TextEmail.Text, "@.") = 0 Then

'Se captura las ultimas letras osea el dominio posicion_dominio = Len(TextEmail.Text) - 3 captura_dominio = Mid(TextEmail.Text, posicion_dominio)

'compara los dominios If captura_dominio = ".com" Or captura_dominio = ".net" Or captura_dominio = ".edu" Or captura_dominio = ".gov" Or captura_dominio = ".mil" Or captura_dominio = ".org" Or Mid(TextEmail.Text, posicion_dominio + 1) = ".es" Or Mid(TextEmail.Text, posicion_dominio + 1) = ".hn" Or Mid(TextEmail.Text, posicion_dominio + 1) = ".cr" Or Mid(TextEmail.Text, posicion_dominio + 1) = ".sv" Or Mid(TextEmail.Text, posicion_dominio + 1) = ".pa" Or Mid(TextEmail.Text, posicion_dominio + 1) = ".gt" Or Mid(TextEmail.Text, posicion_dominio + 1) = ".ni" Then

Exit Sub Else MsgBox("Debe ingresar un dominio .com, .es, .hn ingrese un correo valido ejemplo: [email protected]") TextEmail.Focus() End If Else MsgBox("No puede ingresar @. ingrese un correo valido ejemplo: [email protected]") TextEmail.Focus() End If Else MsgBox("Fala la @ ingrese un correo valido ejemplo: [email protected]") TextEmail.Focus()

Page 36: codigos de algunas pantallas

End If Else MsgBox("Ingrese un correo valido ejemplo: [email protected]") TextEmail.Focus() End If End If End Sub

Private Sub editar_proveedor_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing

If e.CloseReason = CloseReason.UserClosing Then

Dim respexit respexit = MsgBox("¿Desea salir de la pantalla?", MsgBoxStyle.Question + MsgBoxStyle.OkCancel, "Abandonar pantalla") If respexit = vbCancel Then e.Cancel = True Else cb_bancos.Items.Clear() End If

End If

End Sub

Private Sub tsbSalir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsbSalir.Click Me.Close() End Sub

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

End Sub

Private Sub LinkLabel1_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked edit_num_tel.Show() End Sub

Private Sub GroupBox3_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GroupBox3.Enter

End SubEnd Class

Page 37: codigos de algunas pantallas

PANTALLA EDITAR

Private Sub edit_num_tel_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim cadena = "select Id_tipo_telefono , No_telefono from telefono_proveedor where Id_Proveedor= '" & editar_proveedor.Textid.Text & "'" Dim objconn As New MySql.Data.MySqlClient.MySqlConnection(StrConexion) Dim comando As New MySqlDataAdapter(cadena, objconn) Dim dt As New DataTable comando.Fill(dt) dt.AcceptChanges() 'Dim tipo As String 'For i = 0 To dt.Rows.Count - 1

' If dt.Rows(i).Item(0) = 1 Then ' dt.Rows(i).Item(0) = "Fijo" ' End If

'Next DataGridView1.DataSource = dt 'For j = 0 To DataGridView1.RowCount - 1 ' dt.AcceptChanges() ' If DataGridView1.Rows(j).Cells(0).Value = 1 Then ' DataGridView1.Rows(j).Cells(0).Value = "Fijo" ' End If 'Next

End Sub

Private Sub tsbSalir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsbSalir.Click If MsgBox("Esta seguro que sesea salir?", MsgBoxStyle.YesNo, "Desea Salir?") = MsgBoxResult.Yes Then Me.Close() End If End Sub

Private Sub tsbGuardar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsbGuardar.Click

'If Me.DataGridView1.Text.Length < 8 Then ' If DataGridView1.Text < 8 Then ' MsgBox("El numero de Telefono tiene que ser de ocho digitos ", MsgBoxStyle.Critical) ' Exit Sub ' End If

Page 38: codigos de algunas pantallas

'End If

actualizar()

End Sub

Public Sub actualizar() Dim objconn As New MySql.Data.MySqlClient.MySqlConnection(StrConexion) Dim numero As Integer Dim numero1 As Integer Dim numero2 As Integer objconn.Open()

For i = 0 To DataGridView1.RowCount - 2 numero = DataGridView1.Rows(i).Cells(0).Value numero1 = DataGridView1.Rows(i).Cells(1).Value numero2 = DataGridView1.Rows(i).Cells(2).Value 'Dim cadena = "Update telefono_proveedor set No_telefono='" & numero & "', Id_tipo_telefono='" & DataGridView1.Rows(i).Cells(0).Value & "'" codigo original Dim cadena = "UPDATE telefono_proveedor SET No_telefono = '" & numero & "' WHERE Id_tipo_telefono = 1" & DataGridView1.Rows(i).Cells(0).Value & "'" Dim cadena1 = "UPDATE telefono_proveedor SET No_telefono = '" & numero1 & "' WHERE Id_tipo_telefono = 2" & DataGridView1.Rows(i).Cells(1).Value & "'" Dim cadena2 = "UPDATE telefono_proveedor SET No_telefono = '" & numero2 & "' WHERE Id_tipo_telefono = 3" & DataGridView1.Rows(i).Cells(2).Value & "'"

Dim comando As New MySqlCommand(cadena, objconn) cadena.ExecuteNonQuery()

Dim comando1 As New MySqlCommand(cadena1, objconn) cadena1.ExecuteNonQuery()

Dim comando2 As New MySqlCommand(cadena2, objconn) cadena2.ExecuteNonQuery()

'Dim adaptador As MySqlCommand ''objconn.Open() 'adaptador = New MySqlCommand(cadena, objconn) 'adaptador.ExecuteNonQuery()

'adaptador = New MySqlCommand(cadena1, objconn) 'adaptador.ExecuteNonQuery()

'adaptador = New MySqlCommand(cadena2, objconn) 'adaptador.ExecuteNonQuery()

Page 39: codigos de algunas pantallas

Next MsgBox("Datos guardados", MsgBoxStyle.Information, "Info") objconn.Close()

Try Catch ex As Exception MsgBox(ex.Message) End Try

End Sub

Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick

End Sub

Private Sub DataGridView1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles DataGridView1.KeyPress 'If InStr(1, "1234567890" & Chr(8), e.KeyChar) = 0 Then ' If e.KeyChar = ChrW(Keys.Enter) Then ' e.Handled = False ' End If ' e.KeyChar = "" ' MsgBox("SOLO SE ACEPTAN NUMEROS") 'End If

End Sub

MODULO DE VALIDACIONES

Module ModuloValidaciones 'Public objConn = New MySql.Data.MySqlClient.MySqlConnection(StrConexion) Dim sqlStr As String

'1er paso de la validacion del nombre

'Validacion de los nombres '1ra parte validacion identidad 'Validacion del RNE y la tarjeta de identidad

Page 40: codigos de algunas pantallas

Function Numer(ByVal v As Integer, ByRef e As System.Windows.Forms.KeyPressEventArgs) As Boolean If v < 48 Or v > 57 Then ' Si es Backspace o número con decimal If v = 8 Or v = 13 Then Numer = True Else Numer = False 'Inhabilita teclas que no son las pedidas e.KeyChar = ChrW(0) MsgBox("Debe Ingresar Sólo Números", MsgBoxStyle.Information, "Cuidado") End If Else Numer = True End If End Function Public Sub ValidRNE(ByVal TextIdent As MaskedTextBox) If Len(TextIdent.Text) = 15 Then

'Validar el depto If Val(Mid(TextIdent.Text, 1, 2)) = 0 Or Val(Mid(TextIdent.Text, 1, 2)) > 18 Then MsgBox("Los Dos Primeros Digitos Tienen Que Estar Entre 01 y 18", vbInformation, "Aviso") TextIdent.Text = Nothing SendKeys.Send("{BACKSPACE}") Exit Sub End If

'Validar el numero de municipio segun el depto Dim depto As Integer = Val(Mid(TextIdent.Text, 1, 2)) Select Case depto Case 1 If Val(Mid(TextIdent.Text, 3, 4)) = 0 Or Val(Mid(TextIdent.Text, 3, 4)) > 9 Then MsgBox("El Tercer y Cuarto Digito Tiene Que Estar Estar Entre 01 y 9 ", vbInformation, "Aviso") TextIdent.Text = Nothing SendKeys.Send("{BACKSPACE}") Exit Sub End If Case 2 If Val(Mid(TextIdent.Text, 3, 4)) = 0 Or Val(Mid(TextIdent.Text, 3, 4)) > 11 Then MsgBox("El Tercer y Cuarto Digito Tiene Que Estar Estar Entre 01 y 11 ", vbInformation, "Aviso") TextIdent.Text = Nothing SendKeys.Send("{BACKSPACE}") Exit Sub End If Case 3 If Val(Mid(TextIdent.Text, 3, 4)) = 0 Or Val(Mid(TextIdent.Text, 3, 4)) > 21 Then MsgBox("El Tercer y Cuarto Digito Tiene Que Estar Estar Entre 01 y 21 ", vbInformation, "Aviso") TextIdent.Text = Nothing

Page 41: codigos de algunas pantallas

SendKeys.Send("{BACKSPACE}") Exit Sub End If Case 4 If Val(Mid(TextIdent.Text, 3, 4)) = 0 Or Val(Mid(TextIdent.Text, 3, 4)) > 23 Then MsgBox("El Tercer y Cuarto Digito Tiene Que Estar Estar Entre 01 y 23 ", vbInformation, "Aviso") TextIdent.Text = Nothing SendKeys.Send("{BACKSPACE}") Exit Sub End If Case 5 If Val(Mid(TextIdent.Text, 3, 4)) = 0 Or Val(Mid(TextIdent.Text, 3, 4)) > 12 Then MsgBox("El Tercer y Cuarto Digito Tiene Que Estar Estar Entre 01 y 12 ", vbInformation, "Aviso") TextIdent.Text = Nothing SendKeys.Send("{BACKSPACE}") Exit Sub End If Case 6 If Val(Mid(TextIdent.Text, 3, 4)) = 0 Or Val(Mid(TextIdent.Text, 3, 4)) > 16 Then MsgBox("El Tercer y Cuarto Digito Tiene Que Estar Estar Entre 01 y 16 ", vbInformation, "Aviso") TextIdent.Text = Nothing SendKeys.Send("{BACKSPACE}") Exit Sub End If Case 7 If Val(Mid(TextIdent.Text, 3, 4)) = 0 Or Val(Mid(TextIdent.Text, 3, 4)) > 19 Then MsgBox("El Tercer y Cuarto Digito Tiene Que Estar Estar Entre 01 y 19 ", vbInformation, "Aviso") TextIdent.Text = Nothing SendKeys.Send("{BACKSPACE}") Exit Sub End If Case 8 If Val(Mid(TextIdent.Text, 3, 4)) = 0 Or Val(Mid(TextIdent.Text, 3, 4)) > 28 Then MsgBox("El Tercer y Cuarto Digito Tiene Que Estar Estar Entre 01 y 28 ", vbInformation, "Aviso") TextIdent.Text = Nothing SendKeys.Send("{BACKSPACE}") Exit Sub End If Case 9 If Val(Mid(TextIdent.Text, 3, 4)) = 0 Or Val(Mid(TextIdent.Text, 3, 4)) > 6 Then MsgBox("El Tercer y Cuarto Digito Tiene Que Estar Estar Entre 01 y 6 ", vbInformation, "Aviso") TextIdent.Text = Nothing SendKeys.Send("{BACKSPACE}") Exit Sub End If

Page 42: codigos de algunas pantallas

Case 10 If Val(Mid(TextIdent.Text, 3, 4)) = 0 Or Val(Mid(TextIdent.Text, 3, 4)) > 17 Then MsgBox("El Tercer y Cuarto Digito Tiene Que Estar Estar Entre 01 y 17 ", vbInformation, "Aviso") TextIdent.Text = Nothing SendKeys.Send("{BACKSPACE}") Exit Sub End If Case 11 If Val(Mid(TextIdent.Text, 3, 4)) = 0 Or Val(Mid(TextIdent.Text, 3, 4)) > 4 Then MsgBox("El Tercer y Cuarto Digito Tiene Que Estar Estar Entre 01 y 4 ", vbInformation, "Aviso") TextIdent.Text = Nothing SendKeys.Send("{BACKSPACE}") Exit Sub End If Case 12 If Val(Mid(TextIdent.Text, 3, 4)) = 0 Or Val(Mid(TextIdent.Text, 3, 4)) > 19 Then MsgBox("El Tercer y Cuarto Digito Tiene Que Estar Estar Entre 01 y 19 ", vbInformation, "Aviso") TextIdent.Text = Nothing SendKeys.Send("{BACKSPACE}") Exit Sub End If Case 13 If Val(Mid(TextIdent.Text, 3, 4)) = 0 Or Val(Mid(TextIdent.Text, 3, 4)) > 28 Then MsgBox("El Tercer y Cuarto Digito Tiene Que Estar Estar Entre 01 y 28 ", vbInformation, "Aviso") TextIdent.Text = Nothing SendKeys.Send("{BACKSPACE}") Exit Sub End If Case 14 If Val(Mid(TextIdent.Text, 3, 4)) = 0 Or Val(Mid(TextIdent.Text, 3, 4)) > 16 Then MsgBox("El Tercer y Cuarto Digito Tiene Que Estar Estar Entre 01 y 16 ", vbInformation, "Aviso") TextIdent.Text = Nothing SendKeys.Send("{BACKSPACE}") Exit Sub End If Case 15 If Val(Mid(TextIdent.Text, 3, 4)) = 0 Or Val(Mid(TextIdent.Text, 3, 4)) > 23 Then MsgBox("El Tercer y Cuarto Digito Tiene Que Estar Estar Entre 01 y 23 ", vbInformation, "Aviso") TextIdent.Text = Nothing SendKeys.Send("{BACKSPACE}") Exit Sub End If Case 16 If Val(Mid(TextIdent.Text, 3, 4)) = 0 Or Val(Mid(TextIdent.Text, 3, 4)) > 28 Then

Page 43: codigos de algunas pantallas

MsgBox("El Tercer y Cuarto Digito Tiene Que Estar Estar Entre 01 y 28 ", vbInformation, "Aviso") TextIdent.Text = Nothing SendKeys.Send("{BACKSPACE}") Exit Sub End If Case 17 If Val(Mid(TextIdent.Text, 3, 4)) = 0 Or Val(Mid(TextIdent.Text, 3, 4)) > 9 Then MsgBox("El Tercer y Cuarto Digito Tiene Que Estar Estar Entre 01 y 9 ", vbInformation, "Aviso") TextIdent.Text = Nothing SendKeys.Send("{BACKSPACE}") Exit Sub End If Case 18 If Val(Mid(TextIdent.Text, 3, 4)) = 0 Or Val(Mid(TextIdent.Text, 3, 4)) > 11 Then MsgBox("El Tercer y Cuarto Digito Tiene Que Estar Estar Entre 01 y 11 ", vbInformation, "Aviso") TextIdent.Text = Nothing SendKeys.Send("{BACKSPACE}") Exit Sub End If Case Else MsgBox("El Tercer y Cuarto Digito Tiene no debe ser mayor de 28 ", vbInformation, "Aviso") TextIdent.Text = Nothing SendKeys.Send("{BACKSPACE}") End Select

''Consulta del anio 'sqlStr = "SELECT Anio FROM anio " 'Dim da = New MySqlDataAdapter(sqlStr, objConn) 'Dim ds = New DataSet 'da.Fill(ds) 'Dim dr As DataRow 'dr = ds.Tables(0).Rows(0) 'Dim anio = dr.Item("Anio").ToString 'ds.Dispose()

'Validar el anio 'If Val(Mid(TextIdent.Text, 6, 9)) < anio - 70 Or Val(Mid(TextIdent.Text, 6, 9)) > anio Then ' MsgBox("Revise el año introducido ya que no puede ser mayor a: " & anio & " y menor que: " & anio - 70, vbInformation, "Aviso") ' TextIdent.Text = Nothing ' SendKeys.Send("{BACKSPACE}") ' Exit Sub 'End If

'No ceros los ultimos 4 digitos If Val(Mid(TextIdent.Text, 11, 15)) = 0 Then MsgBox("Los últimos 5 digitos no pueden ser todos 0", vbInformation, "Aviso") TextIdent.Text = Nothing SendKeys.Send("{BACKSPACE}")

Page 44: codigos de algunas pantallas

Exit Sub End If End If End Sub

Public Sub Validname(ByVal Textbox As TextBox, ByVal e As System.Windows.Forms.KeyPressEventArgs, ByVal NumeroMaxLetras As Integer, ByVal You As Boolean) If Asc(e.KeyChar) = 27 Or e.KeyChar = ChrW(0) Then Exit Sub End If Static anteriorespacio As Boolean Static nespacio As Integer Dim tamanio As Integer

If Asc(e.KeyChar) = 32 Then ' No se acepta espacio al inicio de text If Trim(Textbox.Text) = "" And Asc(e.KeyChar) = 32 Then e.KeyChar = ChrW(0) Else nespacio = nespacio + 1 'Solo se acepta un espacio entre palabras If nespacio > 1 Then e.KeyChar = ChrW(0) Else 'No puede ir una palabra con menos de dos letras tamanio = Len(Trim(Textbox.Text)) If tamanio = 1 Then If You = True Then If (e.KeyChar <> ChrW(121)) Or (e.KeyChar <> ChrW(111)) Or (e.KeyChar <> ChrW(117)) Or (e.KeyChar <> ChrW(97)) Then e.KeyChar = ChrW(0) nespacio = 0 End If Else e.KeyChar = ChrW(0) nespacio = 0 End If Else If Textbox.Text(tamanio - 2) <> Chr(32) Then anteriorespacio = True nespacio = 0 Else If You = True Then If (Textbox.Text(tamanio - 1) <> ChrW(89)) And (Textbox.Text(tamanio - 1) <> ChrW(85)) And (Textbox.Text(tamanio - 1) <> ChrW(79)) And (Textbox.Text(tamanio - 1) <> ChrW(65)) Then e.KeyChar = ChrW(0) nespacio = 0 'anteriorespacio = True End If Else e.KeyChar = ChrW(0) nespacio = 0 anteriorespacio = True

Page 45: codigos de algunas pantallas

End If End If End If End If End If Else

'Primera Letra de cada palabra mayuscula If Mayuscula(Asc(e.KeyChar)) Or Minuscula(Asc(e.KeyChar)) Or Especial(Asc(e.KeyChar)) Then

If Trim(Textbox.Text) = "" Or anteriorespacio Then REM Convierte a Mayuscula e.KeyChar = UCase(e.KeyChar) nespacio = 0 Else REM Convierte a Minuscula e.KeyChar = LCase(e.KeyChar) nespacio = 0 End If anteriorespacio = False Else MsgBox("Debe de Ingresar sólo Letras", MsgBoxStyle.Information, "Cuidado") e.KeyChar = ChrW(0) End If End If 'Maximo 10 letras por palabra MaximoLetras(Textbox, e, NumeroMaxLetras) End Sub '*********************************************************************** '3er paso de la validacion del nombre 'Funcion que inhabilita las flechas de desplazamiento Public Sub InhabFlechas(ByVal e As System.Windows.Forms.KeyEventArgs) Select Case e.KeyCode Case Keys.Right e.Handled = True Case Keys.Left e.Handled = True Case Keys.Up e.Handled = True Case Keys.Down e.Handled = True End Select End Sub 'FUNCION PARA BLOQUEAR DOS LETRAS REPETIDAS Public Sub nonrepeat(ByVal TextBox As TextBox, ByVal cc As Boolean) Static tamanio As Integer Dim i, j As Integer Dim cadena As String = "" tamanio = Len(TextBox.Text) If cc <> True Then For i = 0 To tamanio - 1 'No se aceptan mas de 2 letras iguales consecutivamente si son distintas ' de las excepciones: a,b,e,l,m,n,o,r,s,t,f

Page 46: codigos de algunas pantallas

If (tamanio - 1 > 0) And (i < tamanio - 1) And (Trim(TextBox.Text) <> "") Then

If Asc(TextBox.Text(i)) <> 97 And Asc(TextBox.Text(i)) <> 65 _ And (Asc(TextBox.Text(i)) <> 98 And Asc(TextBox.Text(i)) <> 66) _ And (Asc(TextBox.Text(i)) <> 101 And Asc(TextBox.Text(i)) <> 69) _ And (Asc(TextBox.Text(i)) <> 102 And Asc(TextBox.Text(i)) <> 70) _ And (Asc(TextBox.Text(i)) <> 108 And Asc(TextBox.Text(i)) <> 76) _ And (Asc(TextBox.Text(i)) <> 109 And Asc(TextBox.Text(i)) <> 77) _ And (Asc(TextBox.Text(i)) <> 110 And Asc(TextBox.Text(i)) <> 78) _ And (Asc(TextBox.Text(i)) <> 111 And Asc(TextBox.Text(i)) <> 79) _ And (Asc(TextBox.Text(i)) <> 114 And Asc(TextBox.Text(i)) <> 82) _ And (Asc(TextBox.Text(i)) <> 115 And Asc(TextBox.Text(i)) <> 83) _ And (Asc(TextBox.Text(i)) <> 116 And Asc(TextBox.Text(i)) <> 84) _ Then If UCase(TextBox.Text(i)) = UCase(TextBox.Text(i + 1)) Then

For j = 0 To tamanio - 1 If j <> i + 1 Then cadena = cadena & TextBox.Text(j) End If Next TextBox.Text = cadena TextBox.SelectionStart = Len(TextBox.Text) tamanio = Len(TextBox.Text) Exit For End If

End If

End If Next Else For i = 0 To tamanio - 1 'No se aceptan mas de 2 letras iguales consecutivamente si son distintas ' de las excepciones: a,b,c,e,l,m,n,o,r,s,t If (tamanio - 1 > 0) And (i < tamanio - 1) And (Trim(TextBox.Text) <> "") Then

If Asc(TextBox.Text(i)) <> 97 And Asc(TextBox.Text(i)) <> 65 _ And (Asc(TextBox.Text(i)) <> 98 And Asc(TextBox.Text(i)) <> 66) _

Page 47: codigos de algunas pantallas

And (Asc(TextBox.Text(i)) <> 99 And Asc(TextBox.Text(i)) <> 67) _ And (Asc(TextBox.Text(i)) <> 101 And Asc(TextBox.Text(i)) <> 69) _ And (Asc(TextBox.Text(i)) <> 102 And Asc(TextBox.Text(i)) <> 70) _ And (Asc(TextBox.Text(i)) <> 108 And Asc(TextBox.Text(i)) <> 76) _ And (Asc(TextBox.Text(i)) <> 109 And Asc(TextBox.Text(i)) <> 77) _ And (Asc(TextBox.Text(i)) <> 110 And Asc(TextBox.Text(i)) <> 78) _ And (Asc(TextBox.Text(i)) <> 111 And Asc(TextBox.Text(i)) <> 79) _ And (Asc(TextBox.Text(i)) <> 114 And Asc(TextBox.Text(i)) <> 82) _ And (Asc(TextBox.Text(i)) <> 115 And Asc(TextBox.Text(i)) <> 83) _ And (Asc(TextBox.Text(i)) <> 116 And Asc(TextBox.Text(i)) <> 84) _ Then

If UCase(TextBox.Text(i)) = UCase(TextBox.Text(i + 1)) Then

For j = 0 To tamanio - 1 If j <> i + 1 Then cadena = cadena & TextBox.Text(j) End If Next TextBox.Text = cadena TextBox.SelectionStart = Len(TextBox.Text) tamanio = Len(TextBox.Text) Exit For End If

End If

End If Next End If

tamanio = Len(TextBox.Text) For i = 0 To tamanio - 1 If (tamanio - 1 > 1) And (i < tamanio - 2) And (Trim(TextBox.Text) <> "") Then If UCase(TextBox.Text(i)) = UCase(TextBox.Text(i + 1)) Then If UCase(TextBox.Text(i)) = UCase(TextBox.Text(i + 2)) Then For j = 0 To tamanio - 1 If j <> i + 2 Then cadena = cadena & TextBox.Text(j) End If Next TextBox.Text = cadena TextBox.SelectionStart = Len(TextBox.Text)

Page 48: codigos de algunas pantallas

tamanio = Len(TextBox.Text) End If End If End If

Next '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 'FIJATE EN LA CONVERSION AQUI NO LA VAYAS A CAGAR DESPUES!!!!!!!!!!!! 'Verifica la Mayuscula al inicio de cada Palabra TextBox.Text = StrConv(TextBox.Text, VbStrConv.ProperCase) 'Asegura que no haya espacio inicial TextBox.Text = LTrim(TextBox.Text) TextBox.SelectionStart = Len(TextBox.Text) tamanio = Len(TextBox.Text) End Sub

'%%%%%%%%%%%%%%%%%%FUNCIONES CORTAS DE APOYO%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 'Verifica que las palabras tengan un maximo de 10 letras ESTA ES PARA EL NOMBRE QUE NO SEA LARGO Public Sub MaximoLetras(ByVal TextBox As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs, ByVal NumeroMaxLetras As Integer) Dim i, cuenta As Integer Dim tamanio As Integer = Len(TextBox.Text) For i = 0 To tamanio - 1 If TextBox.Text(i) <> ChrW(32) Then cuenta = cuenta + 1 If cuenta >= NumeroMaxLetras And e.KeyChar <> ChrW(32) And e.KeyChar <> ChrW(8) Then e.Handled = True 'Control del keypress End If Else e.Handled = False cuenta = 0 End If Next End Sub '*********************************************************************** 'Validacion para la Direcciòn Public Sub Dirval(ByVal Textbox) Dim v, j As Integer Dim i As Integer = 0 Dim tamanio = Len(Textbox.Text) Dim espec As Boolean = False Dim minus As Boolean = False Dim mayus As Boolean = False Dim Numero As Boolean = False Dim texte As String = ""

For i = 0 To tamanio - 1 v = Asc(Textbox.Text(i)) If v = 8 Or v = 13 Or v = 95 Or v = 46 Or v = 32 Or v = 34 Or v = 35 _

Page 49: codigos de algunas pantallas

Or v = 44 Or v = 225 Or v = 193 Or v = 209 Or v = 233 Or v = 237 Or v = 243 Or _ v = 250 Or v = 241 Or v = 209 Or v = 252 Or v = 220 Or v = 205 Or v = 211 Or v = 218 Then If tamanio = 1 Then espec = False Else espec = True End If End If If (v > 96 And v < 123) Or v = 241 Then minus = True End If If (v > 64 And v < 91) Or v = 209 Then mayus = True End If If v > 47 And v < 58 Then Numero = True End If If mayus = False And minus = False And Numero = False And espec = False Then For j = 0 To tamanio - 1 If i <> j Then texte = texte & Textbox.Text(j) End If Next Textbox.Text = texte tamanio = Len(Textbox.Text) Exit For End If espec = False minus = False mayus = False Numero = False Next Textbox.Text = StrConv(Textbox.Text, VbStrConv.ProperCase) 'Posiciona el cursor al final del texbox Textbox.SelectionStart = Textbox.TextLength

End Sub

'No se admiten palabras de una sola letra excepto los casos especiales Function Pal1Letra(ByVal PalaText As String, ByVal Textboxx As TextBox) PalaText = PalaText.Replace("B ", "B") PalaText = PalaText.Replace("C ", "C") PalaText = PalaText.Replace("D ", "D")

PalaText = PalaText.Replace("F ", "F") PalaText = PalaText.Replace("G ", "G") PalaText = PalaText.Replace("H ", "H") PalaText = PalaText.Replace("I ", "I") PalaText = PalaText.Replace("J ", "J") PalaText = PalaText.Replace("K ", "K") PalaText = PalaText.Replace("L ", "L") PalaText = PalaText.Replace("M ", "M")

Page 50: codigos de algunas pantallas

PalaText = PalaText.Replace("N ", "N") PalaText = PalaText.Replace("Ñ ", "Ñ")

PalaText = PalaText.Replace("P ", "P") PalaText = PalaText.Replace("Q ", "Q") PalaText = PalaText.Replace("R ", "R") PalaText = PalaText.Replace("S ", "S") PalaText = PalaText.Replace("T ", "T")

PalaText = PalaText.Replace("V ", "V") PalaText = PalaText.Replace("W ", "W") PalaText = PalaText.Replace("X ", "X")

PalaText = PalaText.Replace("Z ", "Z") If Textboxx.TextLength = 2 Then PalaText = PalaText.Replace("Y ", "Y") PalaText = PalaText.Replace("U ", "U") PalaText = PalaText.Replace("O ", "O") PalaText = PalaText.Replace("A ", "A") PalaText = PalaText.Replace("E ", "E") End If

PalaText = PalaText.Replace(" B ", " B") PalaText = PalaText.Replace(" C ", " C") PalaText = PalaText.Replace(" D ", " D") PalaText = PalaText.Replace(" F ", " F") PalaText = PalaText.Replace(" G ", " G") PalaText = PalaText.Replace(" H ", " H") PalaText = PalaText.Replace(" I ", " I") PalaText = PalaText.Replace(" J ", " J") PalaText = PalaText.Replace(" K ", " K") PalaText = PalaText.Replace(" L ", " L") PalaText = PalaText.Replace(" M ", " M") PalaText = PalaText.Replace(" N ", " N") PalaText = PalaText.Replace(" Ñ ", " Ñ") PalaText = PalaText.Replace(" P ", " P") PalaText = PalaText.Replace(" Q ", " Q") PalaText = PalaText.Replace(" R ", " R") PalaText = PalaText.Replace(" S ", " S") PalaText = PalaText.Replace(" T ", " T") PalaText = PalaText.Replace(" V ", " V") PalaText = PalaText.Replace(" W ", " W") PalaText = PalaText.Replace(" X ", " X") PalaText = PalaText.Replace(" Z ", " Z")

Return PalaText End Function 'Identifica si la letra ingrsada es Minuscula Function Minuscula(ByVal v As Integer) As Boolean If v >= 97 And v <= 122 Then Minuscula = True Else Minuscula = False End If End Function

'Identifica si la letra ingrsada es Mayuscula

Page 51: codigos de algunas pantallas

Function Mayuscula(ByVal v As Integer) As Boolean If v >= 65 And v <= 90 Then 'FALTA VERIFICAR Mayuscula = True Else Mayuscula = False End If End Function

'Identifica si es un simbolo Especial el ingresado Function Especial(ByVal v As Integer) As Boolean If v = 13 Or v = 32 Or v = 8 Or v = 225 Or v = 193 Or v = 209 Or v = 233 Or v = 237 Or v = 243 _ Or v = 250 Or v = 241 Or v = 201 Or v = 252 Or v = 220 Or v = 205 Or v = 211 Or v = 218 Then Especial = True Else Especial = False End If End Function

'VALDACION PARA NUMEROS TELEFONICOS 'Solo se aceptan Números en el txt Function Numero(ByVal v As Integer, ByRef e As System.Windows.Forms.KeyPressEventArgs) As Boolean If v < 48 Or v > 57 Then ' Si es Backspace o número con decimal If v = 8 Or v = 13 Then Numero = True Else Numero = False 'Inhabilita teclas que no son las pedidas e.KeyChar = ChrW(0) MsgBox("Debe Ingresar Sólo Números", MsgBoxStyle.Information, "Cuidado") End If Else Numero = True End If End Function 'Validacion para correos electronicos Public Sub Funcmail(ByVal Textbox As Object) Dim v, j As Integer Dim i As Integer = 0 Dim tamanio = Len(Textbox.Text) Dim espec As Boolean = False Dim minus As Boolean = False Dim mayus As Boolean = False Dim Numero As Boolean = False Dim texte As String = ""

For i = 0 To tamanio - 1 v = Asc(Textbox.Text(i)) If v = 8 Or v = 13 Or v = 95 Or v = 64 Or v = 46 Then If tamanio = 1 Then espec = False Else espec = True

Page 52: codigos de algunas pantallas

End If End If If (v > 96 And v < 123) Or v = 241 Then minus = True End If If (v > 64 And v < 91) Or v = 209 Then mayus = True End If If v > 47 And v < 58 Then Numero = True End If If mayus = False And minus = False And Numero = False And espec = False Then For j = 0 To tamanio - 1 If i <> j Then texte = texte & Textbox.Text(j) End If Next Textbox.Text = texte tamanio = Len(Textbox.Text) Exit For End If espec = False minus = False mayus = False Numero = False Next 'Posiciona el cursor al final del texbox Textbox.SelectionStart = Textbox.TextLength End Sub

'Last Added Function cont_espacios(ByVal cadena As String, ByVal textbox As TextBox) As Integer Dim i As Integer Dim num As Integer

For i = 1 To Len(cadena) If InStr(Mid(cadena, i, 1), " ") <> 0 Then num = num + 1 End If Next cont_espacios = num

If cont_espacios < 1 Then textbox.Focus() End If End Function

Function cont_espacios_DIR(ByVal cadena As String, ByVal textbox As TextBox) As Integer Dim i As Integer Dim num As Integer

For i = 1 To Len(cadena) If InStr(Mid(cadena, i, 1), " ") <> 0 Then num = num + 1

Page 53: codigos de algunas pantallas

End If Next cont_espacios_DIR = num

If cont_espacios_DIR < 1 Then textbox.Focus() End If End Function