📄 frm_setup.frm
字号:
VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
Begin VB.Form frm_setup
BorderStyle = 1 'Fixed Single
Caption = "数据库安装程序"
ClientHeight = 2760
ClientLeft = 45
ClientTop = 330
ClientWidth = 5190
LinkTopic = "Form1"
LockControls = -1 'True
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 2760
ScaleWidth = 5190
StartUpPosition = 2 '屏幕中心
Begin VB.CommandButton Cmd_Save
Caption = "保存"
Enabled = 0 'False
Height = 345
Left = 2960
TabIndex = 13
Top = 2355
Width = 1065
End
Begin VB.CommandButton Cmd_edit
Caption = "编辑"
Height = 345
Left = 1890
TabIndex = 12
Top = 2355
Width = 1065
End
Begin VB.Frame Frame1
Caption = "配置参数"
ForeColor = &H00C000C0&
Height = 1845
Left = 120
TabIndex = 3
Top = 75
Width = 4965
Begin VB.TextBox Text5
Enabled = 0 'False
Height = 300
Left = 1245
TabIndex = 9
Top = 1410
Width = 3555
End
Begin VB.TextBox Text4
Enabled = 0 'False
Height = 300
IMEMode = 3 'DISABLE
Left = 1245
PasswordChar = "*"
TabIndex = 8
Top = 1020
Width = 3555
End
Begin VB.TextBox Text3
Enabled = 0 'False
Height = 300
Left = 1245
TabIndex = 7
Text = "sa"
Top = 645
Width = 3555
End
Begin VB.TextBox Text1
Enabled = 0 'False
Height = 300
Left = 1245
TabIndex = 4
Text = "db_Goods"
Top = 255
Width = 3555
End
Begin VB.Label Label2
Caption = "用户名密码:"
ForeColor = &H00800000&
Height = 300
Left = 165
TabIndex = 11
Top = 1110
Width = 1080
End
Begin VB.Label Label1
Caption = "登录用户名:"
ForeColor = &H00800000&
Height = 255
Left = 165
TabIndex = 10
Top = 735
Width = 1125
End
Begin VB.Label Label8
Caption = "数据库名称:"
ForeColor = &H00800000&
Height = 300
Left = 165
TabIndex = 6
Top = 350
Width = 1170
End
Begin VB.Label Label7
Caption = "服务器名称:"
ForeColor = &H00800000&
Height = 255
Left = 165
TabIndex = 5
Top = 1455
Width = 1125
End
End
Begin VB.CommandButton Cmd_Cancel
Caption = "退出"
Height = 345
Left = 4020
TabIndex = 2
Top = 2355
Width = 1065
End
Begin MSComctlLib.ProgressBar PBar1
Height = 345
Left = 120
TabIndex = 1
Top = 1980
Width = 4965
_ExtentX = 8758
_ExtentY = 609
_Version = 393216
Appearance = 1
Scrolling = 1
End
Begin VB.CommandButton Cmd_setup
Caption = "开始安装"
Height = 345
Left = 830
TabIndex = 0
Top = 2355
Width = 1065
End
End
Attribute VB_Name = "frm_setup"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private con As New ADODB.Connection
Private rs As New ADODB.Recordset
Private STR, SMDF, SMDFS, SLDF, SLDFS, ODBC_str As String
Private UserName As String
Private UserPwd As String
Dim connter As Integer '定义一个整型变量
Dim sql, workarea(4600) As String
Dim char As Byte
Dim Intext As String
Dim Intexts As String
Dim strtemp As String * 200
Dim StrName As String * 256
Dim Computer_str As String * 256
Dim db_str As String * 256
Dim Paths As String * 256
Dim YWJ, MWJ, L, L1 As String, S As String * 1, ASCIIN, i As Integer
Dim x As Integer
'提取计算机名和用户名
Private Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Private Sub Cmd_Cancel_Click()
End
End Sub
Private Sub Cmd_edit_Click()
Cmd_Save.Enabled = True
Cmd_edit.Enabled = False
Text1.Enabled = True
Text3.Enabled = True
Text4.Enabled = True
End Sub
Private Sub Cmd_Save_Click()
Dim STR As String
Cmd_Save.Enabled = False
Cmd_edit.Enabled = True
Open (App.Path & "\Setup.ini") For Output As #1
Print #1, "[DataBase]"
STR = "DBName='" & Text1.Text & "'"
Print #1, STR
STR = "UserName='" & Text3.Text & "'"
Print #1, STR
STR = "UserPwd='" & Text4.Text & "'"
Print #1, STR
STR = SMDFS
Print #1, STR
STR = SLDFS
Print #1, STR
STR = "DBServer='" & Trim(Text5.Text) & "'"
Print #1, STR
Close #1
End Sub
Private Sub Cmd_setup_Click()
Call Form_Load
If Text1.Text = "" Or Text3.Text = "" Then
MsgBox "数据库安装出现异常错误,可能原因是配制参数不完全!", 48, "数据库安装提示信息"
Exit Sub
Else
Cmd_setup.Enabled = False
On Error GoTo x '处理异常错误
Cmd_setup.Enabled = False
If UserPwd <> "" Then
con.ConnectionString = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;PWD=" & UserPwd & ""
con.Open
ElseIf UserPwd = "" Then
con.ConnectionString = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa"
con.Open
End If
Set rs = New ADODB.Recordset
'附加数据库文件
STR = "EXEC sp_attach_db @dbname = N'" + Trim(db_str) + "', @filename1 = N'" + SMDF + "', @filename2 = N'" + SLDF + "'"
rs.Open STR, con, adOpenDynamic, adLockOptimistic
PBar1.Visible = True
PBar1.Max = UBound(workarea)
PBar1.Value = PBar1.Min
For connter = LBound(workarea) To UBound(workarea)
workarea(connter) = "initial value" & connter
PBar1.Value = connter
Next connter
Open (App.Path & "\DataBase.ini") For Output As #1
Print #1, "Yes"
Close #1
MsgBox "数据库安装成功!!", , "系统提示"
Cmd_setup.Enabled = True
con.Close
Call main
Unload Me
Exit Sub
End If
x:
MsgBox "参数配置错误或者数据库已经存在!!", 48, "系统提示信息"
Cmd_setup.Enabled = True
End Sub
Private Sub Command1_Click()
Comm1.Filter = "MDF文件(*.MDF)|*.MDF"
Comm1.ShowOpen
Text4.Text = Comm1.FileName
End Sub
Private Sub Command2_Click()
Comm1.Filter = "LDF文件(*.LDF)|*.LDF"
Comm1.ShowOpen
Text5.Text = Comm1.FileName
End Sub
Private Sub Form_Load()
Dim L As Integer
Open (App.Path & "\DataBase.ini") For Input As #1
Line Input #1, Intexts
Close #1
If Intexts <> "Yes" Then
GetComputerName Computer_str, 255
Paths = Left(strtemp, L) & "\sqlsrv32.dll"
Open (App.Path & "\Setup.ini") For Input As #1
Line Input #1, Intext
Line Input #1, Intext '读入数据库名称
db_str = Mid(Intext, 9, Len(Intext) - 9)
Line Input #1, Intext
UserName = Mid(Intext, 11, Len(Intext) - 11) '读入登录用户名信息
Line Input #1, Intext
UserPwd = Mid(Intext, 10, Len(Intext) - 10) '读入用户密码信息
Line Input #1, Intext
SMDFS = Intext
SMDF = App.Path & "\" & Mid(Intext, 10, Len(Intext) - 10) '读入MDF文件名称
Line Input #1, Intext
SLDFS = Intext
SLDF = App.Path & "\" & Mid(Intext, 10, Len(Intext) - 10) '读入LDF文件名称
Close #1
GetUserName StrName, 255
Text1.Text = Trim(db_str)
Text3.Text = Trim(UserName)
Text4.Text = Trim(UserPwd)
Text5.Text = Trim(Computer_str)
ElseIf Intexts = "Yes" Then
Call main
Unload Me
End If
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -