365 lines
16 KiB
VB.net
365 lines
16 KiB
VB.net
Public Class frmConfiguracion
|
|
Inherits System.Windows.Forms.Form
|
|
Dim objConexion As New ConexionNET
|
|
#Region " Código generado por el Diseñador de Windows Forms "
|
|
|
|
Public Sub New()
|
|
MyBase.New()
|
|
|
|
'El Diseñador de Windows Forms requiere esta llamada.
|
|
InitializeComponent()
|
|
|
|
'Agregar cualquier inicialización después de la llamada a InitializeComponent()
|
|
|
|
End Sub
|
|
|
|
'Form reemplaza a Dispose para limpiar la lista de componentes.
|
|
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
|
|
If disposing Then
|
|
If Not (components Is Nothing) Then
|
|
components.Dispose()
|
|
End If
|
|
End If
|
|
MyBase.Dispose(disposing)
|
|
End Sub
|
|
|
|
'Requerido por el Diseñador de Windows Forms
|
|
Private components As System.ComponentModel.IContainer
|
|
|
|
'NOTA: el Diseñador de Windows Forms requiere el siguiente procedimiento
|
|
'Puede modificarse utilizando el Diseñador de Windows Forms.
|
|
'No lo modifique con el editor de código.
|
|
Friend WithEvents TabControl1 As System.Windows.Forms.TabControl
|
|
Friend WithEvents TabPage1 As System.Windows.Forms.TabPage
|
|
Friend WithEvents lblServidorBD As System.Windows.Forms.Label
|
|
Friend WithEvents cboServidorDB As System.Windows.Forms.ComboBox
|
|
Friend WithEvents txtServidorDB As System.Windows.Forms.TextBox
|
|
Friend WithEvents lblServidor As System.Windows.Forms.Label
|
|
Friend WithEvents lblBaseDatos As System.Windows.Forms.Label
|
|
Friend WithEvents txtBaseDatos As System.Windows.Forms.TextBox
|
|
Friend WithEvents txtUsuario As System.Windows.Forms.TextBox
|
|
Friend WithEvents lblUsuario As System.Windows.Forms.Label
|
|
Friend WithEvents Label1 As System.Windows.Forms.Label
|
|
Friend WithEvents btnGrabar As System.Windows.Forms.Button
|
|
Friend WithEvents btnProbar As System.Windows.Forms.Button
|
|
Friend WithEvents txtPassword As System.Windows.Forms.TextBox
|
|
Friend WithEvents SqlConnection1 As System.Data.SqlClient.SqlConnection
|
|
Friend WithEvents SqlDataAdapter1 As System.Data.SqlClient.SqlDataAdapter
|
|
Friend WithEvents SqlSelectCommand1 As System.Data.SqlClient.SqlCommand
|
|
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
|
|
Me.TabControl1 = New System.Windows.Forms.TabControl
|
|
Me.TabPage1 = New System.Windows.Forms.TabPage
|
|
Me.btnProbar = New System.Windows.Forms.Button
|
|
Me.btnGrabar = New System.Windows.Forms.Button
|
|
Me.txtPassword = New System.Windows.Forms.TextBox
|
|
Me.Label1 = New System.Windows.Forms.Label
|
|
Me.txtUsuario = New System.Windows.Forms.TextBox
|
|
Me.lblUsuario = New System.Windows.Forms.Label
|
|
Me.txtBaseDatos = New System.Windows.Forms.TextBox
|
|
Me.lblBaseDatos = New System.Windows.Forms.Label
|
|
Me.txtServidorDB = New System.Windows.Forms.TextBox
|
|
Me.lblServidor = New System.Windows.Forms.Label
|
|
Me.cboServidorDB = New System.Windows.Forms.ComboBox
|
|
Me.lblServidorBD = New System.Windows.Forms.Label
|
|
Me.SqlConnection1 = New System.Data.SqlClient.SqlConnection
|
|
Me.SqlDataAdapter1 = New System.Data.SqlClient.SqlDataAdapter
|
|
Me.SqlSelectCommand1 = New System.Data.SqlClient.SqlCommand
|
|
Me.TabControl1.SuspendLayout()
|
|
Me.TabPage1.SuspendLayout()
|
|
Me.SuspendLayout()
|
|
'
|
|
'TabControl1
|
|
'
|
|
Me.TabControl1.Controls.AddRange(New System.Windows.Forms.Control() {Me.TabPage1})
|
|
Me.TabControl1.Location = New System.Drawing.Point(8, 8)
|
|
Me.TabControl1.Name = "TabControl1"
|
|
Me.TabControl1.SelectedIndex = 0
|
|
Me.TabControl1.Size = New System.Drawing.Size(488, 176)
|
|
Me.TabControl1.TabIndex = 0
|
|
'
|
|
'TabPage1
|
|
'
|
|
Me.TabPage1.Controls.AddRange(New System.Windows.Forms.Control() {Me.btnProbar, Me.btnGrabar, Me.txtPassword, Me.Label1, Me.txtUsuario, Me.lblUsuario, Me.txtBaseDatos, Me.lblBaseDatos, Me.txtServidorDB, Me.lblServidor, Me.cboServidorDB, Me.lblServidorBD})
|
|
Me.TabPage1.Font = New System.Drawing.Font("Verdana", 9.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
|
|
Me.TabPage1.Location = New System.Drawing.Point(4, 22)
|
|
Me.TabPage1.Name = "TabPage1"
|
|
Me.TabPage1.Size = New System.Drawing.Size(480, 150)
|
|
Me.TabPage1.TabIndex = 0
|
|
Me.TabPage1.Text = "Nombre Servidor"
|
|
'
|
|
'btnProbar
|
|
'
|
|
Me.btnProbar.Location = New System.Drawing.Point(384, 88)
|
|
Me.btnProbar.Name = "btnProbar"
|
|
Me.btnProbar.Size = New System.Drawing.Size(80, 33)
|
|
Me.btnProbar.TabIndex = 11
|
|
Me.btnProbar.Text = "&Probar"
|
|
Me.btnProbar.Visible = False
|
|
'
|
|
'btnGrabar
|
|
'
|
|
Me.btnGrabar.Location = New System.Drawing.Point(384, 40)
|
|
Me.btnGrabar.Name = "btnGrabar"
|
|
Me.btnGrabar.Size = New System.Drawing.Size(80, 32)
|
|
Me.btnGrabar.TabIndex = 10
|
|
Me.btnGrabar.Text = "&Grabar"
|
|
'
|
|
'txtPassword
|
|
'
|
|
Me.txtPassword.Location = New System.Drawing.Point(160, 112)
|
|
Me.txtPassword.Name = "txtPassword"
|
|
Me.txtPassword.PasswordChar = Microsoft.VisualBasic.ChrW(42)
|
|
Me.txtPassword.Size = New System.Drawing.Size(208, 22)
|
|
Me.txtPassword.TabIndex = 9
|
|
Me.txtPassword.Text = ""
|
|
'
|
|
'Label1
|
|
'
|
|
Me.Label1.Font = New System.Drawing.Font("Verdana", 9.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
|
|
Me.Label1.Location = New System.Drawing.Point(16, 112)
|
|
Me.Label1.Name = "Label1"
|
|
Me.Label1.Size = New System.Drawing.Size(144, 16)
|
|
Me.Label1.TabIndex = 8
|
|
Me.Label1.Text = "Password:"
|
|
Me.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight
|
|
Me.Label1.ForeColor = System.Drawing.Color.MidnightBlue
|
|
'
|
|
'txtUsuario
|
|
'
|
|
Me.txtUsuario.Location = New System.Drawing.Point(160, 88)
|
|
Me.txtUsuario.Name = "txtUsuario"
|
|
Me.txtUsuario.Size = New System.Drawing.Size(208, 22)
|
|
Me.txtUsuario.TabIndex = 7
|
|
Me.txtUsuario.Text = ""
|
|
'
|
|
'lblUsuario
|
|
'
|
|
Me.lblUsuario.Font = New System.Drawing.Font("Verdana", 9.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
|
|
Me.lblUsuario.Location = New System.Drawing.Point(16, 88)
|
|
Me.lblUsuario.Name = "lblUsuario"
|
|
Me.lblUsuario.Size = New System.Drawing.Size(144, 16)
|
|
Me.lblUsuario.TabIndex = 6
|
|
Me.lblUsuario.Text = "Usuario:"
|
|
Me.lblUsuario.TextAlign = System.Drawing.ContentAlignment.MiddleRight
|
|
Me.lblUsuario.ForeColor = System.Drawing.Color.MidnightBlue
|
|
'
|
|
'txtBaseDatos
|
|
'
|
|
Me.txtBaseDatos.Location = New System.Drawing.Point(160, 64)
|
|
Me.txtBaseDatos.Name = "txtBaseDatos"
|
|
Me.txtBaseDatos.Size = New System.Drawing.Size(208, 22)
|
|
Me.txtBaseDatos.TabIndex = 5
|
|
Me.txtBaseDatos.Text = ""
|
|
'
|
|
'lblBaseDatos
|
|
'
|
|
Me.lblBaseDatos.Font = New System.Drawing.Font("Verdana", 9.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
|
|
Me.lblBaseDatos.Location = New System.Drawing.Point(16, 64)
|
|
Me.lblBaseDatos.Name = "lblBaseDatos"
|
|
Me.lblBaseDatos.Size = New System.Drawing.Size(144, 16)
|
|
Me.lblBaseDatos.TabIndex = 4
|
|
Me.lblBaseDatos.Text = "Base de Datos:"
|
|
Me.lblBaseDatos.TextAlign = System.Drawing.ContentAlignment.MiddleRight
|
|
Me.lblBaseDatos.ForeColor = System.Drawing.Color.MidnightBlue
|
|
'
|
|
'txtServidorDB
|
|
'
|
|
Me.txtServidorDB.Location = New System.Drawing.Point(160, 40)
|
|
Me.txtServidorDB.Name = "txtServidorDB"
|
|
Me.txtServidorDB.Size = New System.Drawing.Size(208, 22)
|
|
Me.txtServidorDB.TabIndex = 3
|
|
Me.txtServidorDB.Text = ""
|
|
'
|
|
'lblServidor
|
|
'
|
|
Me.lblServidor.Font = New System.Drawing.Font("Verdana", 9.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
|
|
Me.lblServidor.Location = New System.Drawing.Point(16, 40)
|
|
Me.lblServidor.Name = "lblServidor"
|
|
Me.lblServidor.Size = New System.Drawing.Size(144, 16)
|
|
Me.lblServidor.TabIndex = 2
|
|
Me.lblServidor.Text = "Nombre Servidor:"
|
|
Me.lblServidor.TextAlign = System.Drawing.ContentAlignment.MiddleRight
|
|
Me.lblServidor.ForeColor = System.Drawing.Color.MidnightBlue
|
|
'
|
|
'cboServidorDB
|
|
'
|
|
Me.cboServidorDB.Location = New System.Drawing.Point(160, 16)
|
|
Me.cboServidorDB.Name = "cboServidorDB"
|
|
Me.cboServidorDB.Size = New System.Drawing.Size(208, 22)
|
|
Me.cboServidorDB.TabIndex = 1
|
|
Me.cboServidorDB.Text = "<Seleccione Servidor DB>"
|
|
'
|
|
'lblServidorBD
|
|
'
|
|
Me.lblServidorBD.Font = New System.Drawing.Font("Verdana", 9.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
|
|
Me.lblServidorBD.Location = New System.Drawing.Point(16, 16)
|
|
Me.lblServidorBD.Name = "lblServidorBD"
|
|
Me.lblServidorBD.Size = New System.Drawing.Size(144, 16)
|
|
Me.lblServidorBD.TabIndex = 0
|
|
Me.lblServidorBD.Text = "Tipo de Servidor:"
|
|
Me.lblServidorBD.TextAlign = System.Drawing.ContentAlignment.MiddleRight
|
|
Me.lblServidorBD.ForeColor = System.Drawing.Color.MidnightBlue
|
|
'
|
|
'SqlConnection1
|
|
'
|
|
Me.SqlConnection1.ConnectionString = "data source=(local);initial catalog=Minds_test;password=t3qu!la;persist security " & _
|
|
"info=True;user id=sa;workstation id=CONDORLAP;packet size=4096"
|
|
'
|
|
'SqlDataAdapter1
|
|
'
|
|
Me.SqlDataAdapter1.SelectCommand = Me.SqlSelectCommand1
|
|
Me.SqlDataAdapter1.TableMappings.AddRange(New System.Data.Common.DataTableMapping() {New System.Data.Common.DataTableMapping("Table", "Table", New System.Data.Common.DataColumnMapping() {New System.Data.Common.DataColumnMapping("Column1", "Column1")})})
|
|
'
|
|
'SqlSelectCommand1
|
|
'
|
|
Me.SqlSelectCommand1.CommandText = "SELECT COUNT(*) AS Expr1 FROM Usuarios"
|
|
Me.SqlSelectCommand1.Connection = Me.SqlConnection1
|
|
'
|
|
'frmConfiguracion
|
|
'
|
|
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
|
|
Me.ClientSize = New System.Drawing.Size(526, 195)
|
|
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.TabControl1})
|
|
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D
|
|
Me.Name = "frmConfiguracion"
|
|
Me.Text = "Configuración de Propiedades"
|
|
Me.TabControl1.ResumeLayout(False)
|
|
Me.TabPage1.ResumeLayout(False)
|
|
Me.ResumeLayout(False)
|
|
|
|
End Sub
|
|
|
|
#End Region
|
|
|
|
Private Sub frmConfiguracion_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
|
|
cboServidorDB.Items.Add("SQL Server")
|
|
cboServidorDB.Items.Add("Oracle")
|
|
cboServidorDB.Items.Add("MS Access")
|
|
Try
|
|
Dim MySettings(,) As String
|
|
Dim n As Integer
|
|
' obtiene los datos del registro
|
|
MySettings = GetAllSettings("MINDS", "Conexion")
|
|
|
|
objConexion.MDServidor = MySettings(0, 1)
|
|
objConexion.Servidor = MySettings(1, 1)
|
|
objConexion.BaseDatos = MySettings(2, 1)
|
|
objConexion.Usuario = MySettings(3, 1)
|
|
objConexion.Password = DesEncripta(MySettings(4, 1))
|
|
Catch
|
|
Select Case Err.Number
|
|
Case Is = 91
|
|
Case Else
|
|
MsgBox(Err.Number & ": " & Err.Description, MsgBoxStyle.Critical)
|
|
End
|
|
End Select
|
|
End Try
|
|
Me.cboServidorDB.Text = objConexion.MDServidor
|
|
Me.txtBaseDatos.Text = objConexion.BaseDatos
|
|
Me.txtServidorDB.Text = objConexion.Servidor
|
|
Me.txtUsuario.Text = objConexion.Usuario
|
|
Me.txtPassword.Text = objConexion.Password
|
|
End Sub
|
|
|
|
Private Sub btnGrabar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGrabar.Click
|
|
If Valida_C() = True Then
|
|
Dim SERVIDOR As String
|
|
'Graba en el registro
|
|
' Microsoft.VisualBasic.
|
|
SaveSetting("MIndsAgro", "Conexion", "TipoServidorMD", objConexion.MDServidor)
|
|
SaveSetting("MIndsAgro", "Conexion", "Servidor", objConexion.Servidor)
|
|
SaveSetting("MIndsAgro", "Conexion", "BaseDatos", objConexion.BaseDatos)
|
|
SaveSetting("MIndsAgro", "Conexion", "Usuario", objConexion.Usuario)
|
|
SaveSetting("MIndsAgro", "Conexion", "Password", Encripta(objConexion.Password))
|
|
|
|
MsgBox("Configuración Guardada", MsgBoxStyle.Information)
|
|
'fin de grabación
|
|
btnProbar.Visible = True
|
|
End If
|
|
End Sub
|
|
|
|
Private Sub txtServidorDB_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtServidorDB.TextChanged
|
|
objConexion.Servidor = txtServidorDB.Text.ToString
|
|
End Sub
|
|
|
|
Private Sub txtBaseDatos_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtBaseDatos.TextChanged
|
|
objConexion.BaseDatos = txtBaseDatos.Text.ToString
|
|
End Sub
|
|
|
|
Private Sub txtUsuario_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtUsuario.TextChanged
|
|
objConexion.Usuario = txtUsuario.Text.ToString
|
|
End Sub
|
|
|
|
Private Sub txtPassword_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtPassword.TextChanged
|
|
If Me.txtPassword.Text.Length = 0 Then
|
|
txtPassword.Text = ""
|
|
End If
|
|
objConexion.Password = txtPassword.Text.ToString
|
|
End Sub
|
|
|
|
Private Sub cboServidorDB_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboServidorDB.SelectedIndexChanged
|
|
objConexion.MDServidor = cboServidorDB.Text.ToString
|
|
End Sub
|
|
Function Valida_C() As Boolean
|
|
Valida_C = False
|
|
If objConexion.MDServidor = "" Then
|
|
MsgBox("Es necesario ingresar el tipo de Servidor de BD a conectar", MsgBoxStyle.Information)
|
|
Me.cboServidorDB.Focus()
|
|
Exit Function
|
|
End If
|
|
|
|
If objConexion.Servidor = "" Then
|
|
MsgBox("Es necesario ingresar el Nombre del Servidor de BD a conectar", MsgBoxStyle.Information)
|
|
txtServidorDB.Focus()
|
|
Exit Function
|
|
End If
|
|
If objConexion.BaseDatos = "" Then
|
|
MsgBox("Es necesario ingresar el Nombre de la base de datos conectar", MsgBoxStyle.Information)
|
|
txtBaseDatos.Focus()
|
|
Exit Function
|
|
End If
|
|
If objConexion.Usuario = "" Then
|
|
MsgBox("Es necesario ingresar el Nombre del USUARIO de BD a ser conectado", MsgBoxStyle.Information)
|
|
txtUsuario.Focus()
|
|
Exit Function
|
|
End If
|
|
If objConexion.Password = "" Then
|
|
MsgBox("Es necesario ingresar el PASSWORD correspondiente al USUARIO de BD a ser conectado", MsgBoxStyle.Information)
|
|
txtPassword.Focus()
|
|
Exit Function
|
|
End If
|
|
Valida_C = True
|
|
End Function
|
|
|
|
Private Sub btnProbar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnProbar.Click
|
|
Dim CnEjemplo As New SqlClient.SqlConnection
|
|
Dim AdpEjemplo As New SqlClient.SqlDataAdapter
|
|
Dim tblEjemplo As New DataSet
|
|
Dim i As Integer
|
|
Dim strConexion As String
|
|
btnProbar.Visible = False
|
|
Try
|
|
If objConexion.MDServidor = "SQL Server" Then
|
|
strConexion = "data source=" & objConexion.Servidor & ";initial catalog=" & objConexion.BaseDatos & ";password=" & objConexion.Password & ";persist security info=True;user id=" & objConexion.Usuario & ";workstation id=;packet size=4096"
|
|
End If
|
|
''' Prueba la cadena de conexión
|
|
CnEjemplo.ConnectionString = strConexion
|
|
CnEjemplo.Open()
|
|
AdpEjemplo.SelectCommand = New SqlClient.SqlCommand("SELECT COUNT(*) FROM USUARIO")
|
|
AdpEjemplo.SelectCommand.Connection = CnEjemplo
|
|
AdpEjemplo.Fill(tblEjemplo, "Ejemplo")
|
|
i = tblEjemplo.Tables(0).Rows(0).Item(0)
|
|
'MsgBox("Número de Usuarios Registrados: " & i, MsgBoxStyle.Information)
|
|
MsgBox("Conexión a la Base de datos exitosa")
|
|
tblEjemplo = Nothing
|
|
AdpEjemplo = Nothing
|
|
CnEjemplo.Close()
|
|
CnEjemplo = Nothing
|
|
Catch
|
|
MsgBox(Err.Number & ": " & Err.Description & Chr(13) & "Fallo la conexion....Verifique sus propiedades", MsgBoxStyle.Critical)
|
|
End Try
|
|
End Sub
|
|
|
|
End Class
|
|
|