Este documento contiene el código para una aplicación que gestiona proveedores en una base de datos MySQL. Define clases y métodos para conectarse a la base de datos, realizar consultas SQL, mostrar datos de proveedores en una tabla, y permitir la edición y creación de nuevos registros de proveedores. Los métodos llenan la tabla con datos de proveedores al cargar el formulario o buscar por ID de proveedor.
1. Imports MySql
Imports MySql.Data
Imports MySql.Data.MySqlClient
Imports MySql.Data.MySqlClient.MySqlCommand
PublicClass frmproveedores
Public idpr AsString
Public num_proveedor AsInteger
Dim Datav1 AsNew DataView ' para auto completar el los texbox de busqueda
Dim sqlstr AsString
Dim conexion AsNew MySql.Data.MySqlClient.MySqlConnection(StrConexion)
Dim cmd AsNew MySqlCommand
PrivateSub tsbEditar_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs)
'APLICACION CORRECTA
editar_proveedor.Show()
EndSub
PrivateSub 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()
'muestra el formulario actual
2. Me.Visible = True
EndSub
'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)
' ' 'End Try
3. ' ' '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
PublicSub 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 AsNew MySqlDataAdapter(query, objConn)
Dim dt AsNew DataTable
llenar.Fill(dt)
Data_proveedores.DataSource = dt
Catch ex As Exception
MsgBox(ex.Message)
EndTry
5. Data_proveedores.Columns.Item(4).Width = 80
Data_proveedores.Columns.Item(5).Width = 80
EndSub
Sub LIMPIAR()
txt_id.Clear()
txt_nombre.Clear()
Data_proveedores.Rows.Clear()
EndSub
Sub BLOQUEAR_BOTONES()
tsbNuevo.Enabled = False
EndSub
Sub DESBLOQUEAR_BOTONES()
tsbNuevo.Enabled = True
EndSub
PrivateSub 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")
EndSub
PrivateSub RadioButton1_CheckedChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged
If RadioButton1.Checked = TrueThen
txt_nombre.Visible = False
txt_id.Visible = True
txt_nombre.Text = Nothing
txt_id.Focus()
EndIf
EndSub
PrivateSub RadioButton2_CheckedChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles RadioButton2.CheckedChanged
If RadioButton2.Checked = TrueThen
txt_id.Visible = False
txt_nombre.Visible = True
txt_id.Text = Nothing
txt_nombre.Focus()
EndIf
EndSub
PrivateSub txt_id_KeyPress(ByVal sender AsObject, 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
EndIf
6. e.KeyChar = ""
MsgBox("SOLO SE ACEPTAN NUMEROS")
EndIf
EndSub
PrivateSub 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 AsNew MySqlDataAdapter
Dim dt1 AsNew DataTable
'Dim dt1 As New DataTable 'Pa crear una tabla con los nombres de los
usuarios
Dim dN1 AsNew DataSet
Dim DV1 AsNew DataView
Dim Data AsNew 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 AsNew MySqlDataAdapter(sqlstr, conexion)
Dim ds1 AsNew 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
EndUsing
Catch ex As Exception
EndTry
Data_proveedores.Columns.Item(0).HeaderText = "Id Proveedor"
8. '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 AsString = Me.txt_id.Text
EndUsing
Dim filasgrid AsInteger = Data_proveedores.Rows.Count
Dim resultado AsInteger
Using conexion = New MySql.Data.MySqlClient.MySqlConnection(StrConexion)
conexion.Open()
Dim consulta AsNew MySqlCommand("SELECT COUNT(Id_Proveedor) FROM
Proveedores WHERE Id_Proveedor LIKE '"& txt_id.Text &"%'", conexion)
resultado = consulta.ExecuteScalar
conexion.Close()
EndUsing
If resultado = 0 Then
MsgBox("Este Id del proveedor no se encuentra registrado",
MsgBoxStyle.Information + MsgBoxStyle.OkOnly, "AVISO")
txt_id.Clear()
txt_id.Focus()
EndIf
If txt_id.Text = ""Then
Me.Data_proveedores.DataSource = Nothing
EndIf
EndSub
PrivateSub txt_nombre_KeyPress(ByVal sender AsObject, 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
EndIf
'#####################validacion ########################
nonrepeat(Me.txt_nombre, True)
If txt_nombre.Text = ""Then
9. llenar_data()
EndIf
EndSub
PrivateSub txt_nombre_MouseCaptureChanged(ByVal sender AsObject, ByVal e
As System.EventArgs) Handles txt_nombre.MouseCaptureChanged
'averiguar pa que sirve
Me.txt_nombre.SelectionStart = Me.txt_nombre.TextLength()
EndSub
PrivateSub 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 AsNew MySqlDataAdapter
Dim dt1 AsNew DataTable
'Dim dt1 As New DataTable 'Pa crear una tabla con los nombres de los
usuarios
Dim dN1 AsNew DataSet
Dim DV1 AsNew DataView
Dim Data AsNew DataView
'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 AsNew MySqlDataAdapter(sqlstr, conexion)
Dim ds1 AsNew 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
EndUsing
Data_proveedores.Columns.Item(0).HeaderText = "Id Proveedor"
Data_proveedores.Columns.Item(0).HeaderCell.Style.Alignment =
DataGridViewContentAlignment.MiddleCenter
11. 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)
Using conexion = New MySql.Data.MySqlClient.MySqlConnection(StrConexion)
Dim datoss AsString = Me.txt_nombre.Text
Datav1.RowFilter = String.Format("Nombre_proveedor Like
'{0}%'", datoss)
EndUsing
Dim filasgridd AsInteger = 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
EndIf
EndSub
PrivateSub Data_proveedores_BindingContextChanged(ByVal sender AsObject,
ByVal e As System.EventArgs) Handles
Data_proveedores.BindingContextChanged
EndSub
PrivateSub Data_proveedores_DataSourceChanged(ByVal sender AsObject,
ByVal e As System.EventArgs) Handles Data_proveedores.DataSourceChanged
If Data_proveedores.RowCount = 0 Then
llenar_data()
EndIf
EndSub
12. PrivateSub Data_proveedores_DoubleClick(ByVal sender AsObject, 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
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
EndIf
EndSub
PrivateSub proveedores_FormClosing(ByVal sender AsObject, ByVal e As
System.Windows.Forms.FormClosingEventArgs) HandlesMe.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
EndIf
EndIf
EndSub
13. PrivateSub frmproveedores_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) HandlesMyBase.Load
llenar_data()
EndSub
PrivateSub Data_proveedores_CellContentClick(ByVal sender As
System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs)
Handles Data_proveedores.CellContentClick
EndSub
PrivateSub Data_proveedores_SelectionChanged(ByVal sender AsObject, ByVal
e As System.EventArgs) Handles Data_proveedores.SelectionChanged
EndSub
EndClass
Imports MySql.Data.MySqlClient
Imports MySql.Data
PublicClass nuevo_proveedor
Public idpr AsString
Public num_fact AsInteger
PrivateSub 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 AsNew MySql.Data.MySqlClient.MySqlConnection
objConn = New MySql.Data.MySqlClient.MySqlConnection(StrConexion)
14. objConn.Open()
If Textid.Text = ""Or Textnombre.Text = ""Then
MsgBox("Es obligatorio ingresar el Id del proveedor y su nombre de
Provedor", , MsgBoxStyle.Exclamation)
ExitSub
EndIf
IfMe.Textid.Text.Length < 14 OrMe.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()
ExitSub
EndIf
EndIf
Dim sql_comprobar As MySqlCommand
'########_________comprobar el rtn
Dim cadena_rtn AsString = "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.
ExitSub
EndIf
'#########________comprobar el nombre
Dim cadena_nombre AsString = "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.
ExitSub
EndIf
15. 'comprobar el telefono
Dim cadena_telefono AsString = "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.
ExitSub
EndIf
'comprobar el fax
Dim cadena_fax AsString = "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.
ExitSub
EndIf
'#################TERMINO AREA DE COMPROBACION ###################
'#########################validaciones para tipo de
telefono#########################################################
IfMe.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()
ExitSub
EndIf
EndIf
16. 'validacion para el numero de fax
IfMe.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()
ExitSub
EndIf
EndIf
'validacion para el numero de celular
IfMe.MaskedCelular.Text.Length < 8 Then
If MaskedCelular.Text.Length < 8 Then
MsgBox("El numero de Celular tiene que ser de ocho
digitos ", MsgBoxStyle.Critical)
MaskedCelular.Clear()
MaskedCelular.Focus()
ExitSub
EndIf
EndIf
'#########################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 AsNew 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)"
17. Dim cadena4 = "INSERT INTO telefono_proveedor (Id_Proveedor, No_telefono,
Id_tipo_telefono) VALUES('"& Textid.Text &"', '"& MaskedFax.Text &"', 2)"
Dim guardar_banco AsNew MySqlCommand(cadena, objConn)
Dim guardar_telefono AsNew MySqlCommand(cadena2, objConn)
Dim guardar_celular AsNew MySqlCommand(cadena3, objConn)
Dim guardar_fax AsNew 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()
Catch ex As Exception
MsgBox("Información no guardada. "& ex.Message, MsgBoxStyle.Critical,
"ERROR....")
EndTry
'Exit Sub
Try
Catch ex As Exception
MsgBox(ex.Message)
EndTry
LIMPIAR()
EndSub
PublicSub bancos()
Dim objconn AsNew MySql.Data.MySqlClient.MySqlConnection(StrConexion)
objconn.Open()
Try
Dim tablabancos AsNew DataTable
Dim consulta_bancos AsNew 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)
EndTry
objconn.Close()
EndSub
PrivateSub tsbSalir_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles tsbSalir.Click
Me.Close()
18. EndSub
PrivateSub nuevo_proveedor_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) HandlesMyBase.Load
'cb_bancos.Items.Clear()
bancos()
'VER SI AHI ESTA BIEN PARA LA HORA DEL SISTEMA
'agregar la fecha del servidor
Dim objConn AsNew MySql.Data.MySqlClient.MySqlConnection
objConn = New MySql.Data.MySqlClient.MySqlConnection(StrConexion)
objConn.Open()
Dim fechadb AsNew MySqlClient.MySqlCommand("SELECT CURDATE()", objConn)
Maskedfechaingreso.Text = fechadb.ExecuteScalar
objConn.Close()
EndSub
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
EndSub
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
19. 'Textcuenta2.Enabled = True
EndSub
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
Textid.Enabled = False
MaskedTelefono.Enabled = False
Maskedfechaingreso.Enabled = False
Textplazopag.Enabled = False
Textcuenta.Enabled = False
'Textcuenta2.Enabled = False
EndSub
PrivateSub Textid_KeyPress(ByVal sender AsObject, 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
EndIf
e.KeyChar = ""
MsgBox("SOLO SE ACEPTAN NUMEROS")
EndIf
EndSub
PrivateSub Texttelefono_KeyPress(ByVal sender AsObject, 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
EndIf
e.KeyChar = ""
MsgBox("SOLO SE ACEPTAN NUMEROS")
EndIf
'OJO EN DONDE VA ESTE ERROR
EndSub
20. PrivateSub Textnombre_KeyPress(ByVal sender AsObject, 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
EndIf
'#####################alidacion ########################
nonrepeat(Me.Textnombre, True)
EndSub
PrivateSub Textcontacto_KeyPress(ByVal sender AsObject, 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
EndIf
'#####################alidacion ########################
nonrepeat(Me.Textcontacto, True)
EndSub
PrivateSub Textfax_KeyPress(ByVal sender AsObject, 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
EndIf
e.KeyChar = ""
MsgBox("SOLO SE ACEPTAN NUMEROS")
EndIf
EndSub
PrivateSub Textcelular_KeyPress(ByVal sender AsObject, 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
EndIf
e.KeyChar = ""
MsgBox("SOLO SE ACEPTAN NUMEROS")
EndIf
EndSub
PrivateSub Textcuenta_KeyPress(ByVal sender AsObject, 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
EndIf
e.KeyChar = ""
21. MsgBox("SOLO SE ACEPTAN NUMEROS")
EndIf
EndSub
PrivateSub Textplazopag_KeyPress(ByVal sender AsObject, 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
EndIf
e.KeyChar = ""
MsgBox("SOLO SE ACEPTAN NUMEROS")
EndIf
'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
EndSub
PrivateSub Textemail_KeyPress(ByVal sender AsObject, 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 = ""
EndIf
Else
If InStr(1, "0123456789.-
_"&"abcdefghijklmnñopqrstuvwxyz"&"ABCDEFGHIJKLMNÑOPQRSTUVWXYZ"& Chr(8),
e.KeyChar) = 0 Then
e.KeyChar = ""
EndIf
EndIf
Else
If InStr(1, "0123456789.-
_"&"abcdefghijklmnñopqrstuvwxyz"&"ABCDEFGHIJKLMNÑOPQRSTUVWXYZ"& Chr(8),
e.KeyChar) = 0 Then
e.KeyChar = ""
22. EndIf
EndIf
'#####################alidacion ########################
nonrepeat(Me.Textemail, True)
EndSub
PrivateSub Textemail_Validated(ByVal sender AsObject, ByVal e As
System.EventArgs) Handles Textemail.Validated
If Len(Textemail.Text) = 0 Then
ExitSub
EndIf
Textemail.Text = LCase(Textemail.Text)
If Textemail.Text = ""Then
MsgBox("Debe ingresar un correo valido")
Textemail.Focus()
Else
Dim captura_dominio AsString
Dim posicion_dominio AsInteger
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
ExitSub
Else
MsgBox("Debe ingresar un dominio .com, .es,
.hn ingrese un correo valido ejemplo: juan@hotmail.com")
Textemail.Focus()
EndIf
Else
MsgBox("No puede ingresar @. ingrese un correo
valido ejemplo: juan@hotmail.com")
Textemail.Focus()
EndIf
Else
23. MsgBox("Falta la @ ingrese un correo valido ejemplo:
juan@hotmail.com")
Textemail.Focus()
EndIf
Else
MsgBox("Ingrese un correo valido ejemplo:
juan@hotmail.com")
Textemail.Focus()
EndIf
EndIf
EndSub
''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
PrivateSub nuevo_proveedor_FormClosing(ByVal sender AsObject, ByVal e As
System.Windows.Forms.FormClosingEventArgs) HandlesMe.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
EndIf
EndIf
EndSub
PrivateSub LinkLabel1_LinkClicked(ByVal sender As System.Object, ByVal e
As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles
LinkLabel1.LinkClicked
Adicion_num_tel.Show()
EndSub
#Region"VALIDACIONES PARA EVITAR COLOCAR NUMEROS INCORRECTOS EN EL
CELULAR, TELEFONO Y FAX"
PrivateSub MaskedCelular_KeyPress(ByVal sender AsObject, 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
24. MsgBox("Solo puede iniciar con un digito que empiece con 9, 8 o 3")
EndIf
EndIf
EndSub
PrivateSub MaskedTelefono_KeyPress(ByVal sender AsObject, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles MaskedTelefono.KeyPress
MaskedTelefono.TextMaskFormat =
MaskFormat.ExcludePromptAndLiterals
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
EndIf
EndIf
If Len(MaskedTelefono.Text) = 1 Then
If InStr(1, "245678", e.KeyChar) = 0 Then
e.KeyChar = ""
'mensaje de ue solo puede ingresar ...
EndIf
EndIf
EndSub
PrivateSub MaskedFax_KeyPress(ByVal sender AsObject, 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")
EndIf
EndIf
If Len(MaskedFax.Text) = 1 Then
If InStr(1, "245678", e.KeyChar) = 0 Then
e.KeyChar = ""
EndIf
EndIf
EndSub
#EndRegion
EndClass
25. Imports MySql.Data.MySqlClient
PublicClass editar_proveedor
PublicSub combo_bancos()
Dim objconn AsNew MySql.Data.MySqlClient.MySqlConnection(StrConexion)
objconn.Open()
Try
Dim tablabancos AsNew DataTable
Dim consulta_bancos AsNew 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)
EndTry
objconn.Close()
EndSub
PrivateSub 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
Dim objConn AsNew MySql.Data.MySqlClient.MySqlConnection
26. objConn = New MySql.Data.MySqlClient.MySqlConnection(StrConexion)
objConn.Open()
If TextNombre.Text = ""Then
MsgBox("Es obligatorio ingresar el nombre del proveedor", ,
MsgBoxStyle.Exclamation)
ExitSub
EndIf
'VALIDACION(BUENA)
IfMe.Textid.Text.Length < 14 OrMe.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()
ExitSub
EndIf
EndIf
IfMe.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()
ExitSub
EndIf
EndIf
'validacion para el numero de fax
IfMe.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()
ExitSub
EndIf
EndIf
'validacion para el numero de celular
IfMe.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()
ExitSub
EndIf
EndIf
27. 'FALTA VALIDACIONES EN NUMERO DE TELEFONO COPIAR DE PANTALLA NUEVO
actualizar()
EndSub
PublicSub actualizar()
Try
Dim objConn AsNew 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....")
EndTry
Try
Catch ex As Exception
MsgBox(ex.Message)
EndTry
EndSub
PublicSub actualizar_telefonos()
Try
Dim objConn AsNew 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"
Dim cadena2 = "UPDATE telefono_proveedor SET No_telefono = '"&
TextCelular.Text &"' WHERE telefono_proveedor.Id_Proveedor=
'"&Me.Textid.Text &"' and Id_tipo_telefono = 3"
28. 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....")
EndTry
Try
Catch ex As Exception
MsgBox(ex.Message)
EndTry
EndSub
PublicSub actualizar_banco()
Try
Dim objConn AsNew 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....")
EndTry
Try
Catch ex As Exception
MsgBox(ex.Message)
EndTry
EndSub
29. PrivateSub editar_proveedor_Load(ByVal sender As System.Object, ByVal e
As System.EventArgs) HandlesMyBase.Load
combo_bancos()
numero_telefono()
'numero_Celular()
'numero_Fax()
banco()
no_cuenta()
Textid.Enabled = True
Textid.ReadOnly = True
EndSub
PublicSub numero_telefono()
Dim objConn AsNew 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
EndTry
Try
'obtenemos el celular
sql_consulta = New MySqlCommand(cadena2, objConn)
TextCelular.Text = sql_consulta.ExecuteScalar
Catch ex As Exception
MsgBox(ex.Message)
EndTry
Try
'obtenemos el fax
sql_consulta = New MySqlCommand(cadena3, objConn)
TextFax.Text = sql_consulta.ExecuteScalar
Catch ex As Exception
EndTry
EndSub
PublicSub banco()
30. Try
Dim objConn AsNew 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)
EndTry
EndSub
PublicSub no_cuenta()
Try
Dim objConn AsNew 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)
EndTry
EndSub
PrivateSub TextNombre_KeyPress(ByVal sender AsObject, 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
EndIf
'#####################alidacion ########################
nonrepeat(Me.TextNombre, True)
EndSub
PrivateSub TextContacto_KeyPress(ByVal sender AsObject, 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
EndIf
31. '#####################alidacion ########################
nonrepeat(Me.TextContacto, True)
EndSub
PrivateSub TextTelefono_KeyPress(ByVal sender AsObject, 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
EndIf
e.KeyChar = ""
MsgBox("SOLO SE ACEPTAN NUMEROS")
EndIf
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
EndIf
EndIf
If Len(TextTelefono.Text) = 1 Then
If InStr(1, "245678", e.KeyChar) = 0 Then
e.KeyChar = ""
'mensaje de ue solo puede ingresar ...
EndIf
EndIf
EndSub
PrivateSub TextCelular_KeyPress(ByVal sender AsObject, 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
EndIf
e.KeyChar = ""
MsgBox("SOLO SE ACEPTAN NUMEROS")
EndIf
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")
EndIf
EndIf
32. EndSub
PrivateSub TextFax_KeyPress(ByVal sender AsObject, 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
EndIf
e.KeyChar = ""
MsgBox("SOLO SE ACEPTAN NUMEROS")
EndIf
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")
EndIf
EndIf
If Len(TextFax.Text) = 1 Then
If InStr(1, "245678", e.KeyChar) = 0 Then
e.KeyChar = ""
EndIf
EndIf
EndSub
PrivateSub TextCuenta_KeyPress(ByVal sender AsObject, 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
EndIf
e.KeyChar = ""
MsgBox("SOLO SE ACEPTAN NUMEROS")
EndIf
If Len(TextCuenta.Text) = 0 Then
If InStr(1, "123456789", e.KeyChar) = 0 Then
e.KeyChar = Nothing
MsgBox("no se puede iniciar con un valor de cero")
EndIf
EndIf
EndSub
PrivateSub TextPlazo_pago_KeyPress(ByVal sender AsObject, 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
33. EndIf
e.KeyChar = ""
MsgBox("SOLO SE ACEPTAN NUMEROS")
EndIf
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")
EndIf
EndIf
EndSub
PrivateSub TextEmail_KeyPress(ByVal sender AsObject, 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 = ""
EndIf
Else
If InStr(1, "0123456789.-
_"&"abcdefghijklmnñopqrstuvwxyz"&"ABCDEFGHIJKLMNÑOPQRSTUVWXYZ"& Chr(8),
e.KeyChar) = 0 Then
e.KeyChar = ""
EndIf
EndIf
Else
If InStr(1, "0123456789.-
_"&"abcdefghijklmnñopqrstuvwxyz"&"ABCDEFGHIJKLMNÑOPQRSTUVWXYZ"& Chr(8),
e.KeyChar) = 0 Then
e.KeyChar = ""
EndIf
EndIf
'#####################alidacion ########################
nonrepeat(Me.TextEmail, True)
EndSub
PrivateSub TextEmail_Validated(ByVal sender AsObject, ByVal e As
System.EventArgs) Handles TextEmail.Validated
If Len(TextEmail.Text) = 0 Then
ExitSub
EndIf
34. TextEmail.Text = LCase(TextEmail.Text)
If TextEmail.Text = ""Then
MsgBox("Debe ingresar un correo valido")
TextEmail.Focus()
Else
Dim captura_dominio AsString
Dim posicion_dominio AsInteger
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
ExitSub
Else
MsgBox("Debe ingresar un dominio .com, .es,
.hn ingrese un correo valido ejemplo: juan@hotmail.com")
TextEmail.Focus()
EndIf
Else
MsgBox("No puede ingresar @. ingrese un correo
valido ejemplo: juan@hotmail.com")
TextEmail.Focus()
EndIf
Else
MsgBox("Fala la @ ingrese un correo valido ejemplo:
juan@hotmail.com")
TextEmail.Focus()
EndIf
Else
MsgBox("Ingrese un correo valido ejemplo:
juan@hotmail.com")
TextEmail.Focus()
EndIf
EndIf
EndSub
PrivateSub editar_proveedor_FormClosing(ByVal sender AsObject, ByVal e As
System.Windows.Forms.FormClosingEventArgs) HandlesMyBase.FormClosing
35. 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()
EndIf
EndIf
EndSub
PrivateSub tsbSalir_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles tsbSalir.Click
Me.Close()
EndSub
PrivateSub TextFax_TextChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs)
EndSub
PrivateSub LinkLabel1_LinkClicked(ByVal sender As System.Object, ByVal e
As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles
LinkLabel1.LinkClicked
edit_num_tel.Show()
EndSub
PrivateSub GroupBox3_Enter(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles GroupBox3.Enter
EndSub
EndClass
PANTALLA EDITAR
PrivateSub edit_num_tel_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) HandlesMyBase.Load
Dim cadena = "select Id_tipo_telefono , No_telefono from
telefono_proveedor where Id_Proveedor= '"& editar_proveedor.Textid.Text
&"'"
Dim objconn AsNew MySql.Data.MySqlClient.MySqlConnection(StrConexion)
Dim comando AsNew MySqlDataAdapter(cadena, objconn)
36. Dim dt AsNew 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
EndSub
PrivateSub 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()
EndIf
EndSub
PrivateSub 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
'End If
actualizar()
EndSub
PublicSub actualizar()
Dim objconn AsNew MySql.Data.MySqlClient.MySqlConnection(StrConexion)
Dim numero AsInteger
Dim numero1 AsInteger
Dim numero2 AsInteger
objconn.Open()
37. 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 AsNew MySqlCommand(cadena, objconn)
cadena.ExecuteNonQuery()
Dim comando1 AsNew MySqlCommand(cadena1, objconn)
cadena1.ExecuteNonQuery()
Dim comando2 AsNew 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()
Next
MsgBox("Datos guardados", MsgBoxStyle.Information, "Info")
objconn.Close()
Try
Catch ex As Exception
MsgBox(ex.Message)
EndTry
EndSub
PrivateSub DataGridView1_CellContentClick(ByVal sender As System.Object,
ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles
DataGridView1.CellContentClick
38. EndSub
PrivateSub DataGridView1_KeyPress(ByVal sender AsObject, 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
EndSub
MODULO DE VALIDACIONES
Module ModuloValidaciones
'Public objConn = New MySql.Data.MySqlClient.MySqlConnection(StrConexion)
Dim sqlStr AsString
'1er paso de la validacion del nombre
'Validacion de los nombres
'1ra parte validacion identidad
'Validacion del RNE y la tarjeta de identidad
Function Numer(ByVal v AsInteger, ByRef e As
System.Windows.Forms.KeyPressEventArgs) AsBoolean
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")
EndIf
Else
Numer = True
EndIf
EndFunction
PublicSub ValidRNE(ByVal TextIdent As MaskedTextBox)
If Len(TextIdent.Text) = 15 Then
39. '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}")
ExitSub
EndIf
'Validar el numero de municipio segun el depto
Dim depto AsInteger = Val(Mid(TextIdent.Text, 1, 2))
SelectCase 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}")
ExitSub
EndIf
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}")
ExitSub
EndIf
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
SendKeys.Send("{BACKSPACE}")
ExitSub
EndIf
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}")
ExitSub
EndIf
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}")
40. ExitSub
EndIf
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}")
ExitSub
EndIf
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}")
ExitSub
EndIf
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}")
ExitSub
EndIf
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}")
ExitSub
EndIf
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}")
ExitSub
EndIf
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}")
ExitSub
EndIf
Case 12
41. 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}")
ExitSub
EndIf
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}")
ExitSub
EndIf
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}")
ExitSub
EndIf
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}")
ExitSub
EndIf
Case 16
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}")
ExitSub
EndIf
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}")
ExitSub
EndIf
Case 18
If Val(Mid(TextIdent.Text, 3, 4)) = 0 Or Val(Mid(TextIdent.Text, 3, 4)) >
11 Then
42. MsgBox("El Tercer y Cuarto Digito Tiene Que Estar Estar Entre 01 y 11 ",
vbInformation, "Aviso")
TextIdent.Text = Nothing
SendKeys.Send("{BACKSPACE}")
ExitSub
EndIf
CaseElse
MsgBox("El Tercer y Cuarto Digito Tiene no debe ser mayor de 28 ",
vbInformation, "Aviso")
TextIdent.Text = Nothing
SendKeys.Send("{BACKSPACE}")
EndSelect
''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}")
ExitSub
EndIf
EndIf
EndSub
PublicSub Validname(ByVal Textbox As TextBox, ByVal e As
System.Windows.Forms.KeyPressEventArgs, ByVal NumeroMaxLetras AsInteger,
ByVal You AsBoolean)
If Asc(e.KeyChar) = 27 Or e.KeyChar = ChrW(0) Then
ExitSub
EndIf
Static anteriorespacio AsBoolean
Static nespacio AsInteger
Dim tamanio AsInteger
If Asc(e.KeyChar) = 32 Then
' No se acepta espacio al inicio de text
43. 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 = TrueThen
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
EndIf
Else
e.KeyChar = ChrW(0)
nespacio = 0
EndIf
Else
If Textbox.Text(tamanio - 2) <> Chr(32) Then
anteriorespacio = True
nespacio = 0
Else
If You = TrueThen
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
EndIf
Else
e.KeyChar = ChrW(0)
nespacio = 0
anteriorespacio = True
EndIf
EndIf
EndIf
EndIf
EndIf
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
44. EndIf
anteriorespacio = False
Else
MsgBox("Debe de Ingresar sólo Letras",
MsgBoxStyle.Information, "Cuidado")
e.KeyChar = ChrW(0)
EndIf
EndIf
'Maximo 10 letras por palabra
MaximoLetras(Textbox, e, NumeroMaxLetras)
EndSub
'***********************************************************************
'3er paso de la validacion del nombre
'Funcion que inhabilita las flechas de desplazamiento
PublicSub InhabFlechas(ByVal e As System.Windows.Forms.KeyEventArgs)
SelectCase 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
EndSelect
EndSub
'FUNCION PARA BLOQUEAR DOS LETRAS REPETIDAS
PublicSub nonrepeat(ByVal TextBox As TextBox, ByVal cc AsBoolean)
Static tamanio AsInteger
Dim i, j AsInteger
Dim cadena AsString = ""
tamanio = Len(TextBox.Text)
If cc <>TrueThen
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
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)
EndIf
45. Next
TextBox.Text = cadena
TextBox.SelectionStart = Len(TextBox.Text)
tamanio = Len(TextBox.Text)
ExitFor
EndIf
EndIf
EndIf
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) _
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)
EndIf
Next
TextBox.Text = cadena
TextBox.SelectionStart = Len(TextBox.Text)
tamanio = Len(TextBox.Text)
ExitFor
EndIf
EndIf
EndIf
Next
EndIf
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
46. For j = 0 To tamanio - 1
If j <> i + 2 Then
cadena = cadena & TextBox.Text(j)
EndIf
Next
TextBox.Text = cadena
TextBox.SelectionStart = Len(TextBox.Text)
tamanio = Len(TextBox.Text)
EndIf
EndIf
EndIf
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)
EndSub
'%%%%%%%%%%%%%%%%%%FUNCIONES CORTAS DE
APOYO%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'Verifica que las palabras tengan un maximo de 10 letras ESTA ES PARA EL
NOMBRE QUE NO SEA LARGO
PublicSub MaximoLetras(ByVal TextBox AsObject, ByVal e As
System.Windows.Forms.KeyPressEventArgs, ByVal NumeroMaxLetras AsInteger)
Dim i, cuenta AsInteger
Dim tamanio AsInteger = 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
EndIf
Else
e.Handled = False
cuenta = 0
EndIf
Next
EndSub
'***********************************************************************
'Validacion para la Direcciòn
PublicSub Dirval(ByVal Textbox)
Dim v, j AsInteger
Dim i AsInteger = 0
Dim tamanio = Len(Textbox.Text)
Dim espec AsBoolean = False
Dim minus AsBoolean = False
Dim mayus AsBoolean = False
Dim Numero AsBoolean = False
Dim texte AsString = ""
47. 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 _
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
EndIf
EndIf
If (v > 96 And v < 123) Or v = 241 Then
minus = True
EndIf
If (v > 64 And v < 91) Or v = 209 Then
mayus = True
EndIf
If v > 47 And v < 58 Then
Numero = True
EndIf
If mayus = FalseAnd minus = FalseAnd Numero = FalseAnd espec = FalseThen
For j = 0 To tamanio - 1
If i <> j Then
texte = texte & Textbox.Text(j)
EndIf
Next
Textbox.Text = texte
tamanio = Len(Textbox.Text)
ExitFor
EndIf
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
EndSub
'No se admiten palabras de una sola letra excepto los casos especiales
Function Pal1Letra(ByVal PalaText AsString, 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")
48. 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")
EndIf
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
EndFunction
'Identifica si la letra ingrsada es Minuscula
Function Minuscula(ByVal v AsInteger) AsBoolean
If v >= 97 And v <= 122 Then
Minuscula = True
Else
Minuscula = False
EndIf
EndFunction
'Identifica si la letra ingrsada es Mayuscula
49. Function Mayuscula(ByVal v AsInteger) AsBoolean
If v >= 65 And v <= 90 Then'FALTA VERIFICAR
Mayuscula = True
Else
Mayuscula = False
EndIf
EndFunction
'Identifica si es un simbolo Especial el ingresado
Function Especial(ByVal v AsInteger) AsBoolean
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
EndIf
EndFunction
'VALDACION PARA NUMEROS TELEFONICOS
'Solo se aceptan Números en el txt
Function Numero(ByVal v AsInteger, ByRef e As
System.Windows.Forms.KeyPressEventArgs) AsBoolean
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")
EndIf
Else
Numero = True
EndIf
EndFunction
'Validacion para correos electronicos
PublicSub Funcmail(ByVal Textbox AsObject)
Dim v, j AsInteger
Dim i AsInteger = 0
Dim tamanio = Len(Textbox.Text)
Dim espec AsBoolean = False
Dim minus AsBoolean = False
Dim mayus AsBoolean = False
Dim Numero AsBoolean = False
Dim texte AsString = ""
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
50. EndIf
EndIf
If (v > 96 And v < 123) Or v = 241 Then
minus = True
EndIf
If (v > 64 And v < 91) Or v = 209 Then
mayus = True
EndIf
If v > 47 And v < 58 Then
Numero = True
EndIf
If mayus = FalseAnd minus = FalseAnd Numero = FalseAnd espec = FalseThen
For j = 0 To tamanio - 1
If i <> j Then
texte = texte & Textbox.Text(j)
EndIf
Next
Textbox.Text = texte
tamanio = Len(Textbox.Text)
ExitFor
EndIf
espec = False
minus = False
mayus = False
Numero = False
Next
'Posiciona el cursor al final del texbox
Textbox.SelectionStart = Textbox.TextLength
EndSub
'Last Added
Function cont_espacios(ByVal cadena AsString, ByVal textbox As TextBox)
AsInteger
Dim i AsInteger
Dim num AsInteger
For i = 1 To Len(cadena)
If InStr(Mid(cadena, i, 1), " ") <> 0 Then
num = num + 1
EndIf
Next
cont_espacios = num
If cont_espacios < 1 Then
textbox.Focus()
EndIf
EndFunction
Function cont_espacios_DIR(ByVal cadena AsString, ByVal textbox As
TextBox) AsInteger
Dim i AsInteger
Dim num AsInteger
For i = 1 To Len(cadena)
If InStr(Mid(cadena, i, 1), " ") <> 0 Then
num = num + 1
EndIf