📄 sjbf.frm
字号:
VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
Begin VB.Form main_xtwh_sjbf
BorderStyle = 1 'Fixed Single
Caption = "备份及恢复数据库"
ClientHeight = 4695
ClientLeft = 45
ClientTop = 330
ClientWidth = 7995
LinkTopic = "Form1"
LockControls = -1 'True
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 4695
ScaleWidth = 7995
StartUpPosition = 1 '所有者中心
Begin VB.CommandButton Command3
Caption = "数据恢复"
Height = 420
Left = 2909
TabIndex = 9
Top = 4080
Width = 2175
End
Begin VB.Frame Frame2
Caption = "数据库备份文件所在路径"
Height = 3540
Left = 4020
TabIndex = 4
Top = 135
Width = 3915
Begin VB.DriveListBox Drive1
Height = 300
Left = 150
TabIndex = 7
Top = 255
Width = 3615
End
Begin VB.DirListBox Dir1
Height = 720
Left = 150
TabIndex = 6
Top = 630
Width = 3615
End
Begin VB.FileListBox File1
Height = 2070
Left = 150
Pattern = "*.bak"
TabIndex = 5
Top = 1380
Width = 3615
End
End
Begin VB.Frame Frame1
Caption = "备份卡列表"
Height = 3540
Left = 45
TabIndex = 2
Top = 135
Width = 3915
Begin MSComctlLib.ListView ListView1
Height = 3180
Left = 135
TabIndex = 3
Top = 270
Width = 3690
_ExtentX = 6509
_ExtentY = 5609
Sorted = -1 'True
LabelWrap = -1 'True
HideSelection = -1 'True
AllowReorder = -1 'True
_Version = 393217
Icons = "ImageList1"
SmallIcons = "ImageList1"
ForeColor = -2147483640
BackColor = -2147483643
BorderStyle = 1
Appearance = 1
NumItems = 0
End
End
Begin VB.CommandButton Command2
Caption = "&E 退出"
Height = 420
Left = 5587
TabIndex = 1
Top = 4080
Width = 2175
End
Begin VB.CommandButton Command1
Caption = "数据备份"
Height = 420
Left = 232
TabIndex = 0
Top = 4080
Width = 2175
End
Begin MSComctlLib.ImageList ImageList1
Left = -135
Top = 825
_ExtentX = 1005
_ExtentY = 1005
BackColor = -2147483643
ImageWidth = 32
ImageHeight = 32
MaskColor = 12632256
_Version = 393216
BeginProperty Images {2C247F25-8591-11D1-B16A-00C0F0283628}
NumListImages = 4
BeginProperty ListImage1 {2C247F27-8591-11D1-B16A-00C0F0283628}
Picture = "sjbf.frx":0000
Key = ""
EndProperty
BeginProperty ListImage2 {2C247F27-8591-11D1-B16A-00C0F0283628}
Picture = "sjbf.frx":005E
Key = ""
EndProperty
BeginProperty ListImage3 {2C247F27-8591-11D1-B16A-00C0F0283628}
Picture = "sjbf.frx":00BC
Key = ""
EndProperty
BeginProperty ListImage4 {2C247F27-8591-11D1-B16A-00C0F0283628}
Picture = "sjbf.frx":011A
Key = ""
EndProperty
EndProperty
End
Begin VB.Label Label1
BackStyle = 0 'Transparent
ForeColor = &H00FF0000&
Height = 420
Left = 75
TabIndex = 8
Top = 3720
Width = 7890
End
End
Attribute VB_Name = "main_xtwh_sjbf"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim itmX, key As String '声明字符串变量
Dim a As Integer '声明整型变量
Dim Mydatabase
Dim Cna As New ADODB.Connection
Dim Cnb As New ADODB.Connection
Private Sub Command3_Click()
If ListView1.SelectedItem.Text <> "" Then
'恢复数据库
Set Cnb = New ADODB.Connection
Cnb.Open "Provider=MSDASQL.1;Persist Security Info=False;Data Source=Nbooks"
SQL = "BACKUP LOG books TO DISK = '" + File1.Path + "\" + CStr(Format(Now, "yyyy年m月dd日")) + "备份日志(可删除)'" & _
Chr(13) & Chr(10) & "alter database books set MULTI_USER" & Chr(13) & Chr(10) & _
"use master RESTORE DATABASE books FROM DISK ='" + File1.Path + "\" + ListView1.SelectedItem.Text + "'" & Chr(13) & Chr(10) & _
"use books alter database books set MULTI_USER"
' Cnb.Execute SQL
' Debug.Print SQL
' SQL = "alter database books set MULTI_USER"
' Cnb.Execute SQL
' Debug.Print SQL
' SQL = "use master RESTORE DATABASE books FROM DISK ='" + File1.Path + "\" + ListView1.SelectedItem.text + "'"
' Cnb.Execute SQL
' Debug.Print SQL
' SQL = "use books alter database books set MULTI_USER"
Debug.Print SQL
Cnb.Execute SQL
Cnb.Close
MsgBox "数据库已还原。", , "提示"
Else
MsgBox "请选择还原文件。", , "提示"
Cna.Close
End If
Call Form_Load
End Sub
Private Sub Form_Load()
'添加数据备份卡到列表中
ListView1.ListItems.Clear
If File1.ListCount <> 0 Then
a = 0
Do While a <= File1.ListCount - 1
File1.ListIndex = a
key = File1.FileName
If Right(key, 3) = "bak" Then
Set itmX = ListView1.ListItems.Add(, , key, 1)
End If
a = a + 1
Loop
End If
End Sub
Private Sub Dir1_Change()
File1.Path = Dir1.Path
Form_Load '调用Form_Load过程
Label1.Caption = Dir1.Path & "\" & File1.FileName
End Sub
Private Sub Drive1_Change()
Dir1.Path = Drive1.Drive
End Sub
Private Sub File1_Click()
Label1.Caption = Dir1.Path & "\" & File1.FileName '获取路径
End Sub
Private Sub Command1_Click()
Dim SQL As String
'备份数据库
Set Cna = New ADODB.Connection
Cna.Open "Provider=MSDASQL.1;Persist Security Info=False;Data Source=Nbooks"
SQL = "Backup DATABASE books to DISK='" + File1.Path + "\" + CStr(Format(Now, "yyyy年m月dd日")) + ".bak '"
Cna.Execute SQL
MsgBox "备份完成。", , "提示"
File1.Refresh
Cna.Close
End Sub
Private Sub Command2_Click()
Unload Me
End Sub
Private Sub Form_Unload(Cancel As Integer)
MsgBox "请重新启动应用程序", , ""
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -