⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dbconn.vb

📁 档案管理系统
💻 VB
字号:
Public Class frmDbConn
    Inherits System.Windows.Forms.Form

#Region " Windows 窗体设计器生成的代码 "

    Public Sub New()
        MyBase.New()

        '该调用是 Windows 窗体设计器所必需的。
        InitializeComponent()

        '在 InitializeComponent() 调用之后添加任何初始化

    End Sub

    '窗体重写 dispose 以清理组件列表。
    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

    'Windows 窗体设计器所必需的
    Private components As System.ComponentModel.IContainer

    '注意: 以下过程是 Windows 窗体设计器所必需的
    '可以使用 Windows 窗体设计器修改此过程。
    '不要使用代码编辑器修改它。
    Friend WithEvents btnDbConn As System.Windows.Forms.Button
    Friend WithEvents btnCancel As System.Windows.Forms.Button
    Friend WithEvents btnDefault As System.Windows.Forms.Button
    Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
    Friend WithEvents txtServer As System.Windows.Forms.TextBox
    Friend WithEvents txtDatabase As System.Windows.Forms.TextBox
    Friend WithEvents txtUsername As System.Windows.Forms.TextBox
    Friend WithEvents txtPassword As System.Windows.Forms.TextBox
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents Label3 As System.Windows.Forms.Label
    Friend WithEvents Label4 As System.Windows.Forms.Label
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.btnDbConn = New System.Windows.Forms.Button
        Me.btnCancel = New System.Windows.Forms.Button
        Me.btnDefault = New System.Windows.Forms.Button
        Me.GroupBox1 = New System.Windows.Forms.GroupBox
        Me.txtServer = New System.Windows.Forms.TextBox
        Me.txtDatabase = New System.Windows.Forms.TextBox
        Me.txtUsername = New System.Windows.Forms.TextBox
        Me.txtPassword = New System.Windows.Forms.TextBox
        Me.Label1 = New System.Windows.Forms.Label
        Me.Label2 = New System.Windows.Forms.Label
        Me.Label3 = New System.Windows.Forms.Label
        Me.Label4 = New System.Windows.Forms.Label
        Me.GroupBox1.SuspendLayout()
        Me.SuspendLayout()
        '
        'btnDbConn
        '
        Me.btnDbConn.Location = New System.Drawing.Point(16, 184)
        Me.btnDbConn.Name = "btnDbConn"
        Me.btnDbConn.Size = New System.Drawing.Size(48, 23)
        Me.btnDbConn.TabIndex = 1
        Me.btnDbConn.Text = "连接"
        '
        'btnCancel
        '
        Me.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel
        Me.btnCancel.Location = New System.Drawing.Point(88, 184)
        Me.btnCancel.Name = "btnCancel"
        Me.btnCancel.Size = New System.Drawing.Size(48, 23)
        Me.btnCancel.TabIndex = 2
        Me.btnCancel.Text = "取消"
        '
        'btnDefault
        '
        Me.btnDefault.DialogResult = System.Windows.Forms.DialogResult.OK
        Me.btnDefault.Location = New System.Drawing.Point(88, 184)
        Me.btnDefault.Name = "btnDefault"
        Me.btnDefault.Size = New System.Drawing.Size(48, 23)
        Me.btnDefault.TabIndex = 2
        '
        'GroupBox1
        '
        Me.GroupBox1.Controls.Add(Me.txtServer)
        Me.GroupBox1.Controls.Add(Me.txtDatabase)
        Me.GroupBox1.Controls.Add(Me.txtUsername)
        Me.GroupBox1.Controls.Add(Me.txtPassword)
        Me.GroupBox1.Controls.Add(Me.Label1)
        Me.GroupBox1.Controls.Add(Me.Label2)
        Me.GroupBox1.Controls.Add(Me.Label3)
        Me.GroupBox1.Controls.Add(Me.Label4)
        Me.GroupBox1.Location = New System.Drawing.Point(16, 8)
        Me.GroupBox1.Name = "GroupBox1"
        Me.GroupBox1.Size = New System.Drawing.Size(192, 168)
        Me.GroupBox1.TabIndex = 0
        Me.GroupBox1.TabStop = False
        Me.GroupBox1.Text = "连接设置"
        '
        'txtServer
        '
        Me.txtServer.Location = New System.Drawing.Point(72, 24)
        Me.txtServer.Name = "txtServer"
        Me.txtServer.Size = New System.Drawing.Size(104, 21)
        Me.txtServer.TabIndex = 0
        Me.txtServer.Text = ""
        '
        'txtDatabase
        '
        Me.txtDatabase.Location = New System.Drawing.Point(72, 64)
        Me.txtDatabase.Name = "txtDatabase"
        Me.txtDatabase.Size = New System.Drawing.Size(104, 21)
        Me.txtDatabase.TabIndex = 1
        Me.txtDatabase.Text = ""
        '
        'txtUsername
        '
        Me.txtUsername.Location = New System.Drawing.Point(72, 96)
        Me.txtUsername.Name = "txtUsername"
        Me.txtUsername.Size = New System.Drawing.Size(104, 21)
        Me.txtUsername.TabIndex = 2
        Me.txtUsername.Text = ""
        '
        'txtPassword
        '
        Me.txtPassword.Location = New System.Drawing.Point(72, 136)
        Me.txtPassword.Name = "txtPassword"
        Me.txtPassword.Size = New System.Drawing.Size(104, 21)
        Me.txtPassword.TabIndex = 3
        Me.txtPassword.Text = ""
        '
        'Label1
        '
        Me.Label1.Location = New System.Drawing.Point(8, 24)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(48, 23)
        Me.Label1.TabIndex = 3
        Me.Label1.Text = "服务器"
        Me.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        '
        'Label2
        '
        Me.Label2.Location = New System.Drawing.Point(8, 64)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(48, 23)
        Me.Label2.TabIndex = 2
        Me.Label2.Text = "数据库"
        Me.Label2.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        '
        'Label3
        '
        Me.Label3.Location = New System.Drawing.Point(8, 96)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(48, 23)
        Me.Label3.TabIndex = 5
        Me.Label3.Text = "用户名"
        Me.Label3.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        '
        'Label4
        '
        Me.Label4.Location = New System.Drawing.Point(8, 136)
        Me.Label4.Name = "Label4"
        Me.Label4.Size = New System.Drawing.Size(48, 23)
        Me.Label4.TabIndex = 4
        Me.Label4.Text = "密码"
        Me.Label4.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        '
        'frmDbConn
        '
        Me.AcceptButton = Me.btnDbConn
        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
        Me.CancelButton = Me.btnCancel
        Me.ClientSize = New System.Drawing.Size(224, 221)
        Me.Controls.Add(Me.GroupBox1)
        Me.Controls.Add(Me.btnDbConn)
        Me.Controls.Add(Me.btnCancel)
        Me.Controls.Add(Me.btnDefault)
        Me.MaximizeBox = False
        Me.Name = "frmDbConn"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "数据库连接"
        Me.GroupBox1.ResumeLayout(False)
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private Sub btnDbConn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDbConn.Click
        Dim succ As Boolean = False

        If txtServer.Text = "" Then
            MsgBox("请输入服务器名")
        ElseIf txtDatabase.Text = "" Then
            MsgBox("请输入数据库名")
        End If

        '如果用户名跟密码都为空,则尝试用WINDOWS的集成安全性连接数据库
        If txtUsername.Text = "" And txtPassword.Text = "" Then
            If OleConn.SqlConnection(txtServer.Text, txtDatabase.Text) Then
                succ = True
            End If
        Else
            If OleConn.SqlConnection(txtServer.Text, txtDatabase.Text, txtUsername.Text, txtPassword.Text) Then
                succ = True
            End If
        End If

        If succ Then
            Server = txtServer.Text
            Database = txtDatabase.Text
            Username = txtUsername.Text
            Password = txtPassword.Text

            '保存登录设置到注册表
            SaveSetting("student", "config", "server", Server)
            SaveSetting("student", "config", "database", Database)
            SaveSetting("student", "config", "username", Username)
            SaveSetting("student", "config", "password", Password)
            '控制返回到主界面
            btnDefault.PerformClick()
        End If
    End Sub

    Private Sub frmDbConn_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        '从注册表读连接设置
        Server = GetSetting("student", "config", "server")
        Database = GetSetting("student", "config", "database")
        Username = GetSetting("student", "config", "username")
        Password = GetSetting("student", "config", "password")
        txtServer.Text = Server
        txtDatabase.Text = Database
        txtUsername.Text = Username
        txtPassword.Text = Password
    End Sub

End Class

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -