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

📄 frmset.vb

📁 The Management Information System of Library using .NET
💻 VB
字号:
Imports System.IO
Public Class frmSet
    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 Label1 As System.Windows.Forms.Label
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents Label3 As System.Windows.Forms.Label
    Friend WithEvents TextBox1 As library.mytextbox
    Friend WithEvents TextBox2 As library.mytextbox
    Friend WithEvents TextBox3 As library.mytextbox
    Friend WithEvents TextBox4 As library.mytextbox
    Friend WithEvents Label4 As System.Windows.Forms.Label
    Friend WithEvents btnSet As System.Windows.Forms.Button
    Friend WithEvents btnExit As System.Windows.Forms.Button
    Friend WithEvents btnTest As System.Windows.Forms.Button
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(frmSet))
        Me.Label1 = New System.Windows.Forms.Label
        Me.Label2 = New System.Windows.Forms.Label
        Me.Label3 = New System.Windows.Forms.Label
        Me.TextBox1 = New library.mytextbox
        Me.TextBox2 = New library.mytextbox
        Me.TextBox3 = New library.mytextbox
        Me.TextBox4 = New library.mytextbox
        Me.Label4 = New System.Windows.Forms.Label
        Me.btnSet = New System.Windows.Forms.Button
        Me.btnExit = New System.Windows.Forms.Button
        Me.btnTest = New System.Windows.Forms.Button
        Me.SuspendLayout()
        '
        'Label1
        '
        Me.Label1.Location = New System.Drawing.Point(20, 24)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(56, 24)
        Me.Label1.TabIndex = 0
        Me.Label1.Text = "服务器:"
        '
        'Label2
        '
        Me.Label2.Location = New System.Drawing.Point(20, 72)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(56, 24)
        Me.Label2.TabIndex = 1
        Me.Label2.Text = "数据库:"
        '
        'Label3
        '
        Me.Label3.Location = New System.Drawing.Point(20, 120)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(56, 24)
        Me.Label3.TabIndex = 2
        Me.Label3.Text = "用户名:"
        '
        'TextBox1
        '
        Me.TextBox1.Location = New System.Drawing.Point(92, 24)
        Me.TextBox1.Name = "TextBox1"
        Me.TextBox1.Size = New System.Drawing.Size(160, 21)
        Me.TextBox1.TabIndex = 3
        Me.TextBox1.Text = ""
        '
        'TextBox2
        '
        Me.TextBox2.Location = New System.Drawing.Point(92, 72)
        Me.TextBox2.Name = "TextBox2"
        Me.TextBox2.Size = New System.Drawing.Size(160, 21)
        Me.TextBox2.TabIndex = 4
        Me.TextBox2.Text = ""
        '
        'TextBox3
        '
        Me.TextBox3.Location = New System.Drawing.Point(92, 120)
        Me.TextBox3.Name = "TextBox3"
        Me.TextBox3.Size = New System.Drawing.Size(160, 21)
        Me.TextBox3.TabIndex = 5
        Me.TextBox3.Text = ""
        '
        'TextBox4
        '
        Me.TextBox4.Location = New System.Drawing.Point(92, 168)
        Me.TextBox4.Name = "TextBox4"
        Me.TextBox4.PasswordChar = Microsoft.VisualBasic.ChrW(42)
        Me.TextBox4.Size = New System.Drawing.Size(160, 21)
        Me.TextBox4.TabIndex = 7
        Me.TextBox4.Text = ""
        '
        'Label4
        '
        Me.Label4.Location = New System.Drawing.Point(20, 168)
        Me.Label4.Name = "Label4"
        Me.Label4.Size = New System.Drawing.Size(56, 24)
        Me.Label4.TabIndex = 6
        Me.Label4.Text = "密  码:"
        '
        'btnSet
        '
        Me.btnSet.Location = New System.Drawing.Point(28, 208)
        Me.btnSet.Name = "btnSet"
        Me.btnSet.Size = New System.Drawing.Size(56, 24)
        Me.btnSet.TabIndex = 8
        Me.btnSet.Text = "设置"
        '
        'btnExit
        '
        Me.btnExit.DialogResult = System.Windows.Forms.DialogResult.Cancel
        Me.btnExit.Location = New System.Drawing.Point(180, 208)
        Me.btnExit.Name = "btnExit"
        Me.btnExit.Size = New System.Drawing.Size(64, 24)
        Me.btnExit.TabIndex = 9
        Me.btnExit.Text = "退出"
        '
        'btnTest
        '
        Me.btnTest.Location = New System.Drawing.Point(104, 208)
        Me.btnTest.Name = "btnTest"
        Me.btnTest.Size = New System.Drawing.Size(56, 24)
        Me.btnTest.TabIndex = 11
        Me.btnTest.Text = "测试"
        '
        'frmSet
        '
        Me.AcceptButton = Me.btnSet
        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
        Me.ClientSize = New System.Drawing.Size(272, 245)
        Me.Controls.Add(Me.btnTest)
        Me.Controls.Add(Me.btnExit)
        Me.Controls.Add(Me.btnSet)
        Me.Controls.Add(Me.TextBox4)
        Me.Controls.Add(Me.Label4)
        Me.Controls.Add(Me.TextBox3)
        Me.Controls.Add(Me.TextBox2)
        Me.Controls.Add(Me.TextBox1)
        Me.Controls.Add(Me.Label3)
        Me.Controls.Add(Me.Label2)
        Me.Controls.Add(Me.Label1)
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D
        Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
        Me.MaximizeBox = False
        Me.MinimizeBox = False
        Me.Name = "frmSet"
        Me.ShowInTaskbar = False
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent
        Me.Text = "数据服务器设置"
        Me.ResumeLayout(False)

    End Sub

#End Region
    Public mycnstr As String
    Private Sub btnSet_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSet.Click
        If Me.TextBox1.Text = "" Or Me.TextBox2.Text = "" Or Me.TextBox3.Text = "" Then
            MessageBox.Show("请输入完整信息!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning)
            Exit Sub
        End If
        Dim diaResult As System.Windows.Forms.DialogResult
        diaResult = MessageBox.Show("确定要修改吗?", _
        "警告", MessageBoxButtons.OKCancel, _
        MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2)
        If diaResult = DialogResult.OK Then
            Dim q(3) As String
            q(0) = Me.TextBox1.Text.Trim
            q(1) = Me.TextBox2.Text.Trim
            q(2) = Me.TextBox3.Text.Trim
            q(3) = Me.TextBox4.Text.Trim
            Try
                Dim p As New CsetCnInfo
                p.cnstr = q
                p.setCnTofile()
                mycnstr = p.returnCnstr
                Me.DialogResult = DialogResult.OK
                Me.Close()
            Catch ex As Exception
                MessageBox.Show("更改失败!", "信息", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            End Try
        End If

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
        Me.DialogResult = DialogResult.Cancel
    End Sub

    Private Sub frmSet_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim u As New CsetCnInfo
        u.GetCnFromfile()
        Me.TextBox1.Text = u.cnstr(0)
        Me.TextBox2.Text = u.cnstr(1)
        Me.TextBox3.Text = u.cnstr(2)
        Me.TextBox4.Text = u.cnstr(3)
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTest.Click
        mycnstr = ("server=" + Me.TextBox1.Text.Trim + ";")
        mycnstr += ("database=" + Me.TextBox2.Text.Trim + ";")
        mycnstr += ("uid=" + Me.TextBox3.Text.Trim + ";")
        mycnstr += ("pwd=" + Me.TextBox4.Text.Trim)
        Dim mycn As New System.Data.SqlClient.SqlConnection(mycnstr)
        Try
            mycn.Open()
            MessageBox.Show("连接成功", "success", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Catch ex As Exception
            MessageBox.Show("连接失败", "failure", MessageBoxButtons.OK, MessageBoxIcon.Stop)
        Finally
            mycn.Close()
            If Not mycn Is Nothing Then
                mycn.Dispose()
            End If
        End Try
    End Sub
End Class

⌨️ 快捷键说明

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