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

📄 frmdatalogin.frm

📁 FLA-502控制、标定、分析用
💻 FRM
字号:
VERSION 5.00
Begin VB.Form frmDataLogin 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "数据库连接设置:"
   ClientHeight    =   5355
   ClientLeft      =   45
   ClientTop       =   435
   ClientWidth     =   8745
   ControlBox      =   0   'False
   KeyPreview      =   -1  'True
   LinkTopic       =   "Form1"
   LockControls    =   -1  'True
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   5355
   ScaleWidth      =   8745
   StartUpPosition =   2  '屏幕中心
   Begin VB.ComboBox cbInitial 
      Height          =   300
      Left            =   3240
      TabIndex        =   17
      Text            =   "cbInitial"
      Top             =   3930
      Width           =   2715
   End
   Begin VB.CommandButton CmdExit 
      Caption         =   "退出(&X)"
      Height          =   450
      Left            =   6330
      TabIndex        =   6
      Top             =   4680
      Width           =   1400
   End
   Begin VB.CommandButton CmdOk 
      Caption         =   "确定(&N)"
      Height          =   450
      Left            =   4770
      TabIndex        =   5
      Top             =   4680
      Width           =   1400
   End
   Begin VB.Frame Frame2 
      Height          =   30
      Left            =   240
      TabIndex        =   14
      Top             =   4410
      Width           =   8295
   End
   Begin VB.TextBox txtPassWord 
      Height          =   330
      IMEMode         =   3  'DISABLE
      Left            =   3240
      PasswordChar    =   "*"
      TabIndex        =   4
      Text            =   "Text3"
      Top             =   3450
      Width           =   2715
   End
   Begin VB.TextBox txtUserID 
      Height          =   330
      Left            =   3240
      TabIndex        =   3
      Top             =   2940
      Width           =   2715
   End
   Begin VB.OptionButton Option2 
      Caption         =   "使用SQL Server身份验证"
      Height          =   210
      Left            =   2190
      TabIndex        =   2
      Top             =   2475
      Width           =   2415
   End
   Begin VB.Frame Frame1 
      Height          =   30
      Left            =   1410
      TabIndex        =   11
      Top             =   1770
      Width           =   7125
   End
   Begin VB.OptionButton Option1 
      Caption         =   "使用Windows身份验证"
      Height          =   210
      Left            =   2190
      TabIndex        =   1
      Top             =   1950
      Width           =   2415
   End
   Begin VB.TextBox txtServerName 
      Height          =   330
      Left            =   2640
      TabIndex        =   0
      Text            =   "Text1"
      Top             =   1260
      Width           =   2715
   End
   Begin VB.PictureBox Picture1 
      Align           =   1  'Align Top
      BackColor       =   &H00FFFFFF&
      BorderStyle     =   0  'None
      Height          =   1035
      Left            =   0
      ScaleHeight     =   1035
      ScaleWidth      =   8745
      TabIndex        =   7
      Top             =   0
      Width           =   8745
      Begin VB.Line Line1 
         BorderColor     =   &H00808080&
         X1              =   30
         X2              =   9150
         Y1              =   1020
         Y2              =   1020
      End
      Begin VB.Label Label2 
         AutoSize        =   -1  'True
         BackStyle       =   0  'Transparent
         Caption         =   "请在下面的对话框中录你系统需要连接的SQL Server数据库信息!"
         Height          =   180
         Left            =   2040
         TabIndex        =   9
         Top             =   630
         Width           =   5220
      End
      Begin VB.Label Label1 
         AutoSize        =   -1  'True
         BackStyle       =   0  'Transparent
         Caption         =   "SQL  Server数据库连接设置:"
         BeginProperty Font 
            Name            =   "宋体"
            Size            =   10.5
            Charset         =   134
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   210
         Left            =   1170
         TabIndex        =   8
         Top             =   180
         Width           =   3120
      End
      Begin VB.Image Image1 
         Height          =   720
         Left            =   180
         Picture         =   "frmDataLogin.frx":0000
         Top             =   150
         Width           =   720
      End
   End
   Begin VB.Label Label7 
      AutoSize        =   -1  'True
      Caption         =   "数据库(&D):"
      Height          =   180
      Left            =   2190
      TabIndex        =   16
      Top             =   3990
      Width           =   990
   End
   Begin VB.Label Label6 
      AutoSize        =   -1  'True
      Caption         =   "连接"
      Height          =   180
      Left            =   900
      TabIndex        =   15
      Top             =   1710
      Width           =   360
   End
   Begin VB.Label Label5 
      AutoSize        =   -1  'True
      Caption         =   "密码(&P):"
      Height          =   180
      Left            =   2190
      TabIndex        =   13
      Top             =   3495
      Width           =   720
   End
   Begin VB.Label Label4 
      AutoSize        =   -1  'True
      Caption         =   "登录名(&L):"
      Height          =   180
      Left            =   2190
      TabIndex        =   12
      Top             =   3000
      Width           =   900
   End
   Begin VB.Label Label3 
      AutoSize        =   -1  'True
      Caption         =   "服务器名称:"
      Height          =   180
      Left            =   1440
      TabIndex        =   10
      Top             =   1350
      Width           =   1080
   End
End
Attribute VB_Name = "frmDataLogin"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private m_ConnObj As clsDataConn
Private m_iDialogResult As Integer
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Private Sub cbInitial_GotFocus()
    DoEvents
    SendKeys "{F4}"
End Sub

Private Sub CmdExit_Click()
    m_iDialogResult = 0
    Unload Me
End Sub

Private Sub CmdOK_Click()
    Dim Dn As ADODB.Connection
    Dim szConnStr As String
    Dim szLgDownConnstr As String
On Error GoTo ErrHandle
    Err.Clear
    szConnStr = GetConnectionString()
    'szLgDownConnstr = GetLgDownConnectionString()
    Set Dn = New ADODB.Connection
    Dn.Open szConnStr
    If Err.Number <> 0 Then
        MsgBox "SQL Server数据库连接不正确,请检查是否设置有误!", vbInformation + vbOKOnly, "提示“"
        Exit Sub
    Else
        Dn.Close
        Call m_ConnObj.WriteConnectionString(szConnStr, szLgDownConnstr)
    End If
    Set Dn = Nothing
    Err.Clear
    m_iDialogResult = 1
    Unload Me
    Set frmDataLogin = Nothing
    Exit Sub
ErrHandle:
    Call ShowErrorMsg(Err)
End Sub

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = 13 Then
        SendKeys "{Tab}"
    End If
End Sub

Private Sub Form_Load()
    txtServerName.Text = ""
    txtPassWord.Text = ""
    txtUserID.Text = ""
    Option1.Value = True
    Set m_ConnObj = New clsDataConn
End Sub

Private Sub Option1_Click()
    If Option1.Value = True Then
        txtUserID.Text = ""
        txtPassWord.Text = ""
        txtUserID.Enabled = False
        txtPassWord.Enabled = False
        txtUserID.BackColor = Me.BackColor
        txtPassWord.BackColor = Me.BackColor
    End If
    'Call TestConnection
End Sub

Private Sub Option2_Click()
    If Option2.Value = True Then
        txtUserID.Text = ""
        txtPassWord.Text = ""
        txtUserID.Enabled = True
        txtPassWord.Enabled = True
        txtUserID.BackColor = RGB(255, 255, 255)
        txtPassWord.BackColor = RGB(255, 255, 255)
    End If
    'Call TestConnection
End Sub

Private Sub txtPassWord_GotFocus()
    txtPassWord.SelStart = 0
    txtPassWord.SelLength = Len(txtPassWord.Text)
End Sub

Private Sub txtPassWord_LostFocus()
    'Call TestConnection
End Sub

Private Sub txtServerName_GotFocus()
    txtServerName.SelStart = 0
    txtServerName.SelLength = Len(txtServerName.Text)
End Sub

Private Sub txtServerName_LostFocus()
    'Call TestConnection
End Sub

Private Sub txtUserID_GotFocus()
    txtUserID.SelStart = 0
    txtUserID.SelLength = Len(txtUserID.Text)
End Sub
Public Function GetDialogResult() As Integer
    GetDialogResult = m_iDialogResult
End Function
Private Sub TestConnection()
    Dim Dn As ADODB.Connection
    Dim tRs As ADODB.Recordset
    Dim szConnStr As String
    Dim szValue As String
On Error Resume Next
    cbInitial.Clear
    If Option1.Value = True Then
        szConnStr = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;"
        szConnStr = szConnStr + "Initial Catalog=master;Data Source=" + txtServerName.Text
    ElseIf Option2.Value = True Then
        szConnStr = "Provider=SQLOLEDB.1;Persist Security Info=False;Password=" + txtPassWord.Text
        szConnStr = szConnStr + ";User ID=" + txtUserID.Text
        szConnStr = szConnStr + ";Initial Catalog=master;Data Source=" + txtServerName.Text
    End If
    Set Dn = New ADODB.Connection
    Dn.CommandTimeout = 4
    Dn.Open szConnStr
    If Err.Number <> 0 Then
'        MsgBox "你设置的服务器名称不正确或登录方式不正确,请确认!", vbInformation + vbOKOnly, "提示"
        Exit Sub
    End If
    Set tRs = Dn.Execute("Select * from SysDataBases Order by Name Asc")
    If Err.Number <> 0 Then Exit Sub
    If Not (tRs.EOF And tRs.BOF) Then
        Do While Not (tRs.EOF)
            szValue = IIf(Not IsNull(tRs.Fields("name").Value), tRs.Fields("Name").Value, "")
            cbInitial.AddItem Trim(szValue)
            tRs.MoveNext
        Loop
    End If
    tRs.Close
    Set tRs = Nothing
    Dn.Close
    Set Dn = Nothing
    Err.Clear
End Sub
Private Function GetConnectionString() As String
    Dim szConnStr As String
'On Error Resume Next
    If Option1.Value = True Then
        szConnStr = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;"
        szConnStr = szConnStr + "Initial Catalog=" + Trim(cbInitial.Text) + ";Data Source=" + Trim(txtServerName.Text)
    ElseIf Option2.Value = True Then
        szConnStr = "Provider=SQLOLEDB.1;Persist Security Info=true;Password=" + Trim(txtPassWord.Text)
        szConnStr = szConnStr + ";User ID=" + Trim(txtUserID.Text)
        szConnStr = szConnStr + ";Initial Catalog=" + Trim(cbInitial.Text) + " ;Data Source=" + Trim(txtServerName.Text)
    End If
    GetConnectionString = szConnStr
End Function

Private Function GetLgDownConnectionString() As String
    Dim szConnStr As String
'On Error Resume Next
    If Option1.Value = True Then
        szConnStr = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;"
        szConnStr = szConnStr + "Initial Catalog=" + "Master1" + ";Data Source=" + Trim(txtServerName.Text)
    ElseIf Option2.Value = True Then
        szConnStr = "Provider=SQLOLEDB.1;Persist Security Info=true;Password=" + Trim(txtPassWord.Text)
        szConnStr = szConnStr + ";User ID=" + Trim(txtUserID.Text)
        szConnStr = szConnStr + ";Initial Catalog=" + "Master1" + " ;Data Source=" + Trim(txtServerName.Text)
    End If
    GetLgDownConnectionString = szConnStr
End Function

Private Sub txtUserID_LostFocus()
    Call TestConnection
End Sub

⌨️ 快捷键说明

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