📄 main_sjbf.frm
字号:
VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
Begin VB.Form main_sjbf
BorderStyle = 1 'Fixed Single
Caption = "系统维护--【数据备份与数据恢复】"
ClientHeight = 4965
ClientLeft = 45
ClientTop = 330
ClientWidth = 8250
Icon = "main_sjbf.frx":0000
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 4965
ScaleWidth = 8250
StartUpPosition = 1 '所有者中心
Begin VB.Frame Frame2
Caption = "请选择数据库路径"
Height = 3540
Left = 4020
TabIndex = 6
Top = 480
Width = 4065
Begin VB.DriveListBox Drive1
Height = 300
Left = 150
TabIndex = 9
Top = 255
Width = 3750
End
Begin VB.DirListBox Dir1
Height = 720
Left = 150
TabIndex = 8
Top = 630
Width = 3750
End
Begin VB.FileListBox File1
Height = 2070
Left = 150
Pattern = "*.mc"
TabIndex = 7
Top = 1380
Width = 3750
End
End
Begin VB.Frame Frame1
Caption = "备份卡列表"
Height = 3540
Left = 45
TabIndex = 4
Top = 480
Width = 3915
Begin MSComctlLib.ListView ListView1
Height = 3180
Left = 120
TabIndex = 5
Top = 240
Width = 3690
_ExtentX = 6509
_ExtentY = 5609
Sorted = -1 'True
LabelWrap = 0 'False
HideSelection = -1 'True
HoverSelection = -1 'True
_Version = 393217
Icons = "ImageList1"
SmallIcons = "ImageList1"
ForeColor = -2147483640
BackColor = -2147483643
BorderStyle = 1
Appearance = 1
NumItems = 1
BeginProperty ColumnHeader(1) {BDD1F052-858B-11D1-B16A-00C0F0283628}
Object.Width = 2540
EndProperty
End
End
Begin VB.OptionButton Option2
Caption = "数据恢复"
Height = 300
Left = 5835
TabIndex = 3
Top = 90
Width = 1740
End
Begin VB.OptionButton Option1
Caption = "数据备份"
Height = 300
Left = 4080
TabIndex = 2
Top = 90
Width = 1740
End
Begin VB.CommandButton CmdEnd
Caption = "退出"
Height = 420
Left = 4245
TabIndex = 1
Top = 4455
Width = 1830
End
Begin VB.CommandButton CmdBackup
Caption = "数据备份或数据恢复"
Height = 420
Left = 2415
TabIndex = 0
Top = 4455
Width = 1830
End
Begin MSComctlLib.ImageList ImageList1
Left = 3075
Top = -60
_ExtentX = 1005
_ExtentY = 1005
BackColor = -2147483643
ImageWidth = 32
ImageHeight = 32
MaskColor = 12632256
_Version = 393216
BeginProperty Images {2C247F25-8591-11D1-B16A-00C0F0283628}
NumListImages = 2
BeginProperty ListImage1 {2C247F27-8591-11D1-B16A-00C0F0283628}
Picture = "main_sjbf.frx":000C
Key = ""
EndProperty
BeginProperty ListImage2 {2C247F27-8591-11D1-B16A-00C0F0283628}
Picture = "main_sjbf.frx":08E8
Key = ""
EndProperty
EndProperty
End
Begin VB.Label Label2
BackStyle = 0 'Transparent
Caption = "请选择数据备份或数据恢复选项"
ForeColor = &H000000FF&
Height = 300
Left = 75
TabIndex = 11
Top = 120
Width = 2580
End
Begin VB.Label Label1
BackStyle = 0 'Transparent
ForeColor = &H000000FF&
Height = 375
Left = 60
TabIndex = 10
Top = 4050
Width = 8025
End
End
Attribute VB_Name = "main_sjbf"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim StrCnn As New Connection '定义连接
Dim itmX As ListItem '定义一个ListItem对象
Dim key, list, sql As String '定义字符串变量
Private Sub Form_Load()
Option1.Value = True '设置Option1的值为真
End Sub
Private Sub Form_Unload(Cancel As Integer)
frm_main.Enabled = True '设置frm_main窗体有效
End Sub
Private Sub Dir1_Change()
File1.Path = Dir1.Path
'添加数据备份卡到列表中
ListView1.ListItems.Clear
If File1.ListCount <> 0 Then
a = 0 '给变量a设置初值
Do While File1.ListIndex < File1.ListCount - 1
File1.ListIndex = a '赋值给变量a
key = File1.FileName
Set itmX = ListView1.ListItems.Add(, , key, 1)
a = a + 1
Loop
End If
Label1.Caption = Dir1.Path & "\" & File1.FileName '赋值给Label1.Caption
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 ListView1_Click()
On Error Resume Next
Label1.Caption = Dir1.Path & "\" & ListView1.SelectedItem '获得路径
End Sub
Private Sub CmdBackup_Click()
Set cnn = Nothing
Dim S
If Option1.Value = True Then
'备份数据库
S = Dir1.Path & "\" & Date & ".MC"
If Label1.Caption = S Then
MsgBox "数据备份卡已存在!"
Else
StrCnn.Open "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=XYGLXT"
'数据备份语句
sql = "backup DATABASE XYGLXT TO disk='" & S & "'"
StrCnn.Execute (sql) '执行SQL语句
StrCnn.Close
MsgBox "数据库备份成功!"
key = Date & ".MC"
Set itmX = ListView1.ListItems.Add(, , key, 1)
End If
End If
If Option2.Value = True Then
'恢复指定路径下的数据库
If File1.ListCount <> 0 Then
If Label1.Caption <> "" Then
StrCnn.Open "Provider=MSDASQL.1;Persist Security Info=False;User ID=sa;Data Source=Backup"
'强行将数据库设置为单用户访问模式
sql = "ALTER DATABASE XYGLXT set single_user with rollback immediate"
StrCnn.Execute (sql)
'数据恢复
sql = "RESTORE DATABASE XYGLXT from disk='" & Label1.Caption & "'"
StrCnn.Execute (sql) '执行SQL语句
StrCnn.Close
MsgBox "数据库恢复成功!"
Else
MsgBox "请选择要恢复的数据备份卡!"
End If
Else
MsgBox "请选择要恢复的数据备份卡!"
End If
End If
End Sub
Private Sub CmdEnd_Click()
frm_main.Show
Unload Me
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -