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

📄 frmrestore.frm

📁 学生管理系统,vb+acc开发的一个简单程序
💻 FRM
字号:
VERSION 5.00
Object = "{CE671F01-259E-40DA-92FE-95803E2ECBB5}#1.0#0"; "SmartXPButton.ocx"
Begin VB.Form FrmRestore 
   BackColor       =   &H00E7DFE7&
   BorderStyle     =   1  'Fixed Single
   Caption         =   "还原数据库"
   ClientHeight    =   2775
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   4470
   Icon            =   "FrmRestore.frx":0000
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   2775
   ScaleWidth      =   4470
   StartUpPosition =   2  '屏幕中心
   Begin VB.ComboBox cboFile 
      Height          =   300
      Left            =   240
      TabIndex        =   1
      Top             =   720
      Width           =   3975
   End
   Begin VB.CheckBox Check1 
      BackColor       =   &H00E7DFE7&
      Caption         =   "选择最新的备份文件"
      Height          =   375
      Left            =   240
      TabIndex        =   0
      Top             =   1440
      Width           =   2055
   End
   Begin SmartXPButton.XpButton cmdRestore 
      Height          =   495
      Left            =   1320
      TabIndex        =   2
      Top             =   2040
      Width           =   1335
      _ExtentX        =   2355
      _ExtentY        =   873
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "宋体"
         Size            =   9
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Caption         =   "还原(&R)"
      PictureSmoothBackColor=   15460844
      ButtonPicture   =   "FrmRestore.frx":08CA
   End
   Begin SmartXPButton.XpButton cmdExit 
      Cancel          =   -1  'True
      Height          =   495
      Left            =   2880
      TabIndex        =   3
      Top             =   2040
      Width           =   1335
      _ExtentX        =   2355
      _ExtentY        =   873
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "宋体"
         Size            =   9
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Caption         =   "关闭(&E)"
      PictureSmoothBackColor=   15460844
      ButtonPicture   =   "FrmRestore.frx":0C64
   End
   Begin VB.Label Label2 
      BackStyle       =   0  'Transparent
      Caption         =   "请选择备份文件,然后单击“还原”按钮,即可还原数据库。"
      Height          =   660
      Left            =   240
      TabIndex        =   4
      Top             =   120
      Width           =   3420
   End
End
Attribute VB_Name = "FrmRestore"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim cn As ADODB.Connection
Dim success As Long
Dim ret As Long           '返回值
Dim buff As String

Private Sub Check1_Click()
buff = String(255, 0)
ret = GetPrivateProfileString("BackUp", "Restore", "", buff, 256, App.Path & "\Sims.ini")
If ret = 0 Then
   MsgBox "你无权执行还原数据库的操作,请与管理员联系!", vbOKOnly + vbInformation, "还原数据库"
   Unload Me
   Exit Sub
End If

If Check1.Value = 1 Then
   buff = String(255, 0)
   ret = GetPrivateProfileString("BackUp", "NewFile", "", buff, 256, App.Path & "\Sims.ini")
   If ret <> 0 Then cboFile.Text = buff
Else
    cboFile.Text = ""
End If
End Sub

Private Sub cmdExit_Click()
success = WritePrivateProfileString("BackUp", "Restore", "", App.Path & "\Sims.ini")
Unload Me
End Sub

Private Sub cmdRestore_Click()
On Error GoTo err1

buff = String(255, 0)
ret = GetPrivateProfileString("BackUp", "Restore", "", buff, 256, App.Path & "\Sims.ini")
If ret = 0 Then
   MsgBox "你无权执行还原数据库的操作,请与管理员联系!", vbOKOnly + vbInformation, "还原数据库"
   Unload Me
   Exit Sub
End If

If cboFile.Text <> "" Then
    cn.Execute ("use master")
    cn.Execute "restore database [Sims_four] from disk='" & App.Path & "\BackUP\" & cboFile.Text & "'"
    MsgBox "数据库还原成功!", vbOKOnly + vbInformation, "还原数据库"
    cboFile.Text = ""
    Check1.Value = 0
Else
    MsgBox "请选择备份文件!", vbOKOnly + vbInformation, "还原数据库"
End If
Exit Sub
err1:
    If Err = -2147217900 Then
        MsgBox "找不到指定的备份文件。" & vbCrLf & vbCrLf & "数据库还原失败!", vbOKOnly + vbInformation, "还原数据库"
        cboFile.Text = ""
        Check1.Value = 0
    Else
        MsgBox "未知错误,数据库还原失败!", vbOKOnly + vbInformation, "还原数据库"
    End If
End Sub

Private Sub Form_Load()
Set cn = New ADODB.Connection
With cn
    .ConnectionTimeout = 10
    .Provider = "sqloledb"
    .ConnectionString = "data source=.;initial catalog=master;user id=sa;password=;"
    .Open
End With
'******把备份文件名加入列表框*******
buff = String(255, 0)
ret = GetPrivateProfileString("BackUp", "File1", "", buff, 256, App.Path & "\Sims.ini")
If ret <> 0 Then cboFile.AddItem buff

ret = GetPrivateProfileString("BackUp", "File2", "", buff, 256, App.Path & "\Sims.ini")
If ret <> 0 Then cboFile.AddItem buff

ret = GetPrivateProfileString("BackUp", "File3", "", buff, 256, App.Path & "\Sims.ini")
If ret <> 0 Then cboFile.AddItem buff

ret = GetPrivateProfileString("BackUp", "File4", "", buff, 256, App.Path & "\Sims.ini")
If ret <> 0 Then cboFile.AddItem buff

ret = GetPrivateProfileString("BackUp", "File5", "", buff, 256, App.Path & "\Sims.ini")
If ret <> 0 Then cboFile.AddItem buff

buff = String(255, 0)
ret = GetPrivateProfileString("BackUp", "NewFile", "", buff, 256, App.Path & "\Sims.ini")
If ret = 0 Then
    Check1.Enabled = False
Else
    Check1.Enabled = True
End If
End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
success = WritePrivateProfileString("BackUp", "Restore", "", App.Path & "\Sims.ini")
End Sub

Private Sub Form_Terminate()
If cn.State = adStateOpen Then cn.Close
Set cn = Nothing
End Sub

⌨️ 快捷键说明

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