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

📄 form_backuprestore.frm

📁 运用VB和SQL Server实现
💻 FRM
字号:
VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "mscomctl.ocx"
Begin VB.Form Form_Backuprestore 
   Caption         =   "Form1"
   ClientHeight    =   5355
   ClientLeft      =   60
   ClientTop       =   450
   ClientWidth     =   9120
   LinkTopic       =   "Form1"
   ScaleHeight     =   5355
   ScaleWidth      =   9120
   StartUpPosition =   3  '窗口缺省
   Begin VB.CommandButton Cmdexit 
      Caption         =   "退出"
      Height          =   495
      Left            =   4800
      TabIndex        =   11
      Top             =   4800
      Width           =   2295
   End
   Begin VB.CommandButton CmdBackup 
      Caption         =   "数据备份或恢复"
      Height          =   495
      Left            =   1920
      TabIndex        =   10
      Top             =   4800
      Width           =   2295
   End
   Begin VB.OptionButton Option2 
      Caption         =   "数据恢复"
      Height          =   375
      Left            =   7320
      TabIndex        =   9
      Top             =   120
      Width           =   1455
   End
   Begin VB.OptionButton Option1 
      Caption         =   "数据备份"
      Height          =   375
      Left            =   5640
      TabIndex        =   8
      Top             =   120
      Width           =   1215
   End
   Begin VB.Frame Frame2 
      Caption         =   "选择路径"
      Height          =   3375
      Left            =   4680
      TabIndex        =   3
      Top             =   600
      Width           =   4335
      Begin VB.DirListBox Dir1 
         Height          =   720
         Left            =   240
         TabIndex        =   7
         Top             =   720
         Width           =   3975
      End
      Begin VB.FileListBox File1 
         Height          =   1530
         Left            =   240
         Pattern         =   "*.Bak"
         TabIndex        =   6
         Top             =   1560
         Width           =   3975
      End
      Begin VB.DriveListBox Drive1 
         Height          =   300
         Left            =   240
         TabIndex        =   4
         Top             =   240
         Width           =   3855
      End
   End
   Begin VB.Frame Frame1 
      Caption         =   "备份卡选项"
      Height          =   3375
      Left            =   120
      TabIndex        =   2
      Top             =   600
      Width           =   4335
      Begin MSComctlLib.ImageList ImageList1 
         Left            =   480
         Top             =   2160
         _ExtentX        =   1005
         _ExtentY        =   1005
         BackColor       =   -2147483643
         ImageWidth      =   32
         ImageHeight     =   32
         MaskColor       =   12632256
         _Version        =   393216
         BeginProperty Images {2C247F25-8591-11D1-B16A-00C0F0283628} 
            NumListImages   =   1
            BeginProperty ListImage1 {2C247F27-8591-11D1-B16A-00C0F0283628} 
               Picture         =   "Form_Backuprestore.frx":0000
               Key             =   ""
            EndProperty
         EndProperty
      End
      Begin MSComctlLib.ListView ListView1 
         Height          =   3015
         Left            =   120
         TabIndex        =   5
         Top             =   240
         Width           =   4095
         _ExtentX        =   7223
         _ExtentY        =   5318
         LabelWrap       =   -1  'True
         HideSelection   =   -1  'True
         _Version        =   393217
         Icons           =   "ImageList1"
         SmallIcons      =   "ImageList1"
         ForeColor       =   -2147483640
         BackColor       =   -2147483643
         BorderStyle     =   1
         Appearance      =   1
         NumItems        =   0
      End
   End
   Begin VB.Label Label2 
      AutoSize        =   -1  'True
      Caption         =   "请选择数据备份或数据恢复选项:"
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   12
         Charset         =   134
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H008080FF&
      Height          =   240
      Left            =   360
      TabIndex        =   1
      Top             =   120
      Width           =   3825
   End
   Begin VB.Label Label1 
      ForeColor       =   &H000000FF&
      Height          =   375
      Left            =   360
      TabIndex        =   0
      Top             =   4200
      Width           =   7815
   End
End
Attribute VB_Name = "Form_Backuprestore"
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的值为真
 Dir1_Change
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
 File1_Click
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()
 Label1.Caption = Dir1.Path & "\" & ListView1.SelectedItem     '获得路径
End Sub
Private Sub CmdBackup_Click()
 Dim S
 If Option1.Value = True Then
 '备份数据库
   S = Dir1.Path & "\" & Date & ".BAK"
   If Label1.Caption = S Then
    MsgBox "数据备份卡已存在!"
   Else
    StrCnn.Open "Provider=MSDASQL.1;Persist Security Info=False;User ID=sa;Data Source=database"
    '数据备份语句
    sql = "backup DATABASE db TO disk='" & S & "'"
    StrCnn.Execute (sql)     '执行SQL语句
    StrCnn.Close
    MsgBox "数据库备份成功!"
    key = Date & ".BAK"
    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=database"
    '数据恢复语句
    sql = "RESTORE DATABASE db 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 Cmdexit_Click()
Unload Me
End Sub

⌨️ 快捷键说明

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