📄 form1.frm
字号:
VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
Begin VB.Form Form1
BorderStyle = 1 'Fixed Single
Caption = "数据库操作"
ClientHeight = 3810
ClientLeft = 45
ClientTop = 330
ClientWidth = 6975
Icon = "Form1.frx":0000
LinkTopic = "Form1"
MaxButton = 0 'False
ScaleHeight = 3810
ScaleWidth = 6975
StartUpPosition = 2 '屏幕中心
Begin VB.Frame fraB
BorderStyle = 0 'None
Height = 1305
Left = 30
TabIndex = 10
Top = 2490
Width = 6945
Begin VB.CommandButton cmdDone
Caption = "备份数据库"
BeginProperty Font
Name = "宋体"
Size = 12
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Index = 0
Left = 990
TabIndex = 12
Top = 720
Width = 2085
End
Begin VB.CommandButton cmdDone
Caption = "恢复数据库"
BeginProperty Font
Name = "宋体"
Size = 12
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Index = 1
Left = 3720
TabIndex = 11
Top = 720
Width = 2085
End
Begin MSComctlLib.ProgressBar pbPrg
Height = 435
Left = 1350
TabIndex = 13
Top = 90
Width = 5505
_ExtentX = 9710
_ExtentY = 767
_Version = 393216
BorderStyle = 1
Appearance = 0
Scrolling = 1
End
Begin VB.Label lblPrg
Alignment = 2 'Center
Caption = "100%"
BeginProperty Font
Name = "宋体"
Size = 12
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 255
Left = 720
TabIndex = 15
Top = 150
Width = 615
End
Begin VB.Label lblDone
Alignment = 2 'Center
Caption = "进度"
BeginProperty Font
Name = "宋体"
Size = 12
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H00C00000&
Height = 255
Left = 120
TabIndex = 14
Top = 150
Width = 615
End
End
Begin Project1.sqlSDBC sqlSDBC1
Left = 6510
Top = 90
_ExtentX = 741
_ExtentY = 741
End
Begin VB.Frame Frame1
Caption = "恢复数据库"
Height = 795
Index = 1
Left = 90
TabIndex = 6
Top = 1590
Width = 6825
Begin VB.TextBox txtFileName
Height = 345
Index = 1
Left = 1170
TabIndex = 8
Text = "c:\DBback.bak"
Top = 240
Width = 5505
End
Begin VB.CommandButton cmdOpen
Caption = "浏览"
Height = 345
Index = 1
Left = 5520
TabIndex = 7
Top = 240
Visible = 0 'False
Width = 1005
End
Begin VB.Label Label3
Caption = "恢复文件:"
Height = 315
Index = 1
Left = 240
TabIndex = 9
Top = 330
Width = 1125
End
End
Begin VB.TextBox txtDBName
BackColor = &H00FFFFFF&
Height = 345
Left = 1170
TabIndex = 2
Text = "Hostadmin"
Top = 180
Width = 3615
End
Begin VB.Frame Frame1
Caption = "备份数据库"
Height = 795
Index = 0
Left = 90
TabIndex = 0
Top = 690
Width = 6825
Begin VB.CommandButton cmdOpen
Caption = "浏览"
Height = 345
Index = 0
Left = 5520
TabIndex = 5
Top = 240
Visible = 0 'False
Width = 1005
End
Begin VB.TextBox txtFileName
Height = 345
Index = 0
Left = 1170
TabIndex = 4
Text = "c:\DBback.bak"
Top = 240
Width = 5505
End
Begin VB.Label Label3
Caption = "备份文件:"
Height = 315
Index = 0
Left = 240
TabIndex = 3
Top = 330
Width = 1125
End
End
Begin VB.Label Label2
Caption = "数据库名:"
Height = 285
Left = 180
TabIndex = 1
Top = 240
Width = 915
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Type AppSetType
dbName As String
BackupFile As String
RestoreFile As String
End Type
Dim AppSet As AppSetType
Private Const bFun = 1 '1备份恢复 2备份 3恢复
Private Const dbName = "UnitedHost"
Private Const bFixDBName = True
Private Sub cmdDone_Click(Index As Integer)
Dim sDB As String
Dim sFileName As String
Dim sDone As String
sDB = Trim(txtDBName.Text)
If sDB = "" Then
MsgBox "请选择数据库"
Exit Sub
End If
sFileName = Trim(txtFileName(Index).Text)
If sFileName = "" Then
MsgBox "请选择文件名"
Exit Sub
End If
If Index = 1 And Dir(sFileName, vbNormal) = "" Then
MsgBox "请选择有效的恢复文件"
Exit Sub
End If
If Index = 0 Then
sDone = "备份"
Else
sDone = "恢复"
End If
If MsgBox("是否要 " & sDone & " 数据库?", vbQuestion + vbYesNo) = vbNo Then Exit Sub
Me.MousePointer = vbHourglass
cmdDone(0).Enabled = False
cmdDone(1).Enabled = False
sqlSDBC1.ConnectToSQLServer "(Local)", "sa", ""
AppSet.dbName = sDB
lblDone.Caption = sDone
If Index = 0 Then
sqlSDBC1.BackupDatabaseToFile sDB, sFileName
AppSet.BackupFile = sFileName
AppSet.RestoreFile = Trim(txtFileName(1).Text)
Else
sqlSDBC1.DeleteDatabase "UnitedHost"
sqlSDBC1.RestoreDatabaseFromFile sDB, sFileName
AppSet.BackupFile = Trim(txtFileName(0).Text)
AppSet.RestoreFile = sFileName
End If
If sqlSDBC1.ErrorNum <> 0 Then
MsgBox lblDone.Caption & "发生错误:" & sqlSDBC1.ErrorDes
Else
Call SaveSet
MsgBox lblDone.Caption & "完成"
End If
'sqlSDBC1.DisconnectFromSQLServer
Call txtFileName_Change(0)
Call txtFileName_Change(1)
Me.MousePointer = vbDefault
End Sub
Private Sub Form_Load()
Dim lY As Long
lblPrg.Caption = "0%"
pbPrg.Value = 0
Call LoadSet
txtDBName.Text = AppSet.dbName
txtFileName(0).Text = AppSet.BackupFile
txtFileName(1).Text = AppSet.RestoreFile
App.Title = Me.Caption
lY = 690
If bFun = 1 Or bFun = 2 Then
'有备份功能
lY = lY + 900
End If
If bFun = 1 Or bFun = 3 Then
'有恢复功能
Frame1(1).Top = lY
lY = lY + 900
End If
fraB.Top = lY
If bFun <> 1 Then Me.Height = Me.Height - 900
If bFun = 2 Then cmdDone(1).Visible = False: cmdDone(0).Left = (fraB.Width - cmdDone(0).Width) / 2
If bFun = 3 Then cmdDone(0).Visible = False: cmdDone(1).Left = (fraB.Width - cmdDone(1).Width) / 2
If bFixDBName And Trim(dbName) <> "" Then
txtDBName.Text = Trim(dbName)
txtDBName.Locked = True
txtDBName.BackColor = &HE0E0E0
End If
End Sub
Private Sub sqlSDBC1_BackUpPercent(Message As String, Percent As Long)
If pbPrg.Value <> Percent Then
pbPrg.Value = Percent
pbPrg.Refresh
lblPrg.Caption = Percent & "%"
lblPrg.Refresh
End If
End Sub
Private Sub sqlSDBC1_RestorePercent(Message As String, Percent As Long)
If pbPrg.Value <> Percent Then
pbPrg.Value = Percent
pbPrg.Refresh
lblPrg.Caption = Percent & "%"
lblPrg.Refresh
End If
End Sub
Private Sub LoadSet()
Dim sLine As String
Dim sKey As String, sValue As String
Dim K As Integer
Dim lFn As Long
Dim sFile As String
sFile = App.Path & "\Set.txt"
If Dir(sFile, vbNormal) = "" Then
AppSet.dbName = "Hostadmin"
AppSet.BackupFile = "c:\Hostadmin_Backup.mdk"
AppSet.RestoreFile = AppSet.BackupFile
Else
lFn = FreeFile
Open sFile For Input As lFn
Do While Not EOF(lFn)
Line Input #lFn, sLine
K = InStr(1, sLine, "=")
If K > 0 Then
sKey = Trim(LCase(Mid(sLine, 1, K - 1)))
sValue = Trim(Mid(sLine, K + 1))
Select Case sKey
Case "dbname"
AppSet.dbName = sValue
Case "backupfile"
AppSet.BackupFile = sValue
Case "restorefile"
AppSet.RestoreFile = sValue
End Select
End If
Loop
If AppSet.dbName = "" Then AppSet.dbName = "hostadmin"
'If AppSet.BackupFile = "" Then AppSet.BackupFile = "c:\DBBackup.mdk"
'If AppSet.RestoreFile = "" Then AppSet.RestoreFile = "c:\DBBackup.mdk"
Close lFn
End If
Call SaveSet
End Sub
Private Sub SaveSet()
Dim sLine As String
Dim sKey As String, sValue As String
Dim K As Integer
Dim lFn As Long
Dim sFile As String
sFile = App.Path & "\Set.txt"
lFn = FreeFile
Open sFile For Output As lFn
Print #lFn, "[Options]"
sLine = "DBName=" & AppSet.dbName
Print #lFn, sLine
sLine = "BackupFile=" & AppSet.BackupFile
Print #lFn, sLine
sLine = "RestoreFile=" & AppSet.RestoreFile
Print #lFn, sLine
Close lFn
End Sub
Private Sub txtFileName_Change(Index As Integer)
txtFileName(Index).Text = Trim(txtFileName(Index).Text)
cmdDone(Index).Enabled = CBool(txtFileName(Index).Text <> "")
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -