?? frmreloaddata.frm
字號:
VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "Mscomctl.ocx"
Begin VB.Form frmreloaddata
Caption = "正在恢復數據,請稍等..."
ClientHeight = 2700
ClientLeft = 60
ClientTop = 450
ClientWidth = 4635
LinkTopic = "Form1"
ScaleHeight = 2700
ScaleWidth = 4635
StartUpPosition = 2 '屏幕中心
Begin VB.Frame Frame1
Height = 2745
Left = 0
TabIndex = 0
Top = 0
Width = 4695
Begin VB.CommandButton Command4
Caption = "..."
BeginProperty Font
Name = "宋體"
Size = 7.5
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 345
Left = 3930
TabIndex = 5
Top = 1020
Width = 375
End
Begin VB.TextBox txtpathText
Height = 324
Left = 210
TabIndex = 4
Top = 1020
Width = 3705
End
Begin VB.CommandButton Command1
Caption = "開始恢復數據"
Default = -1 'True
Height = 405
Left = 510
TabIndex = 2
Top = 2160
Width = 1395
End
Begin VB.CommandButton Command2
Cancel = -1 'True
Caption = "取消恢復數據"
Height = 405
Left = 2580
TabIndex = 1
Top = 2160
Width = 1395
End
Begin MSComctlLib.ProgressBar MyBar
Height = 285
Left = 210
TabIndex = 3
Top = 1680
Width = 4125
_ExtentX = 7276
_ExtentY = 503
_Version = 393216
Appearance = 1
End
Begin VB.Label lblShowInfo
Height = 255
Left = 210
TabIndex = 8
Top = 1470
Width = 4035
End
Begin VB.Label Label3
Caption = "請輸入備份數據表所在的目錄:"
Height = 330
Left = 210
TabIndex = 7
Top = 750
Width = 3030
End
Begin VB.Label Label2
Caption = "注意:數據恢復將刪除現存的數據,而將以前備份到硬盤的數據恢復到如今庫中!"
ForeColor = &H8000000D&
Height = 435
Left = 240
TabIndex = 6
Top = 270
Width = 4095
End
End
End
Attribute VB_Name = "frmreloaddata"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Command1_Click()
m_iBeginSaveTimer = 0
Dim respond As Integer
respond = MsgBox("恢復數據將改寫全部數據庫現有數據,是否繼續?", 64 + 4, "是否確認")
If respond = 7 Then
Exit Sub
End If
If (Len(Trim(txtpathText.Text)) = 0) Then
Result = MsgBox("請指定所要備份數據的路徑!", vbOKOnly, "數據備份")
Exit Sub
Else
If (Right(Trim(txtpathText.Text), 1) <> "\") Then
txtpathText.Text = Trim(txtpathText.Text) + "\"
Else
txtpathText.Text = Trim(txtpathText.Text)
End If
If (Dir(txtpathText.Text, vbDirectory) = "") Then
Result = MsgBox("指定路徑不存在!", vbOKOnly, "數據備份")
Exit Sub
End If
End If
On Error GoTo ErrorHand
'連接數據庫
Dim strFileName As String
Dim strTableName As String
Dim sqlname As String
Dim rsColumnName As New ADODB.Recordset
Dim rs As New ADODB.Recordset
Dim rsData As New ADODB.Recordset
strFileName = Dir(Trim(txtpathText.Text) + "*.dat")
If strFileName = "" Then
MsgBox "該處不包含所要恢復數據的備份文件!", 64, "數據恢復"
MousePointer = 1
Exit Sub
End If
Dim nreccount As Long
Dim bOK As Boolean
'開始一個事務
cnnJLDB.BeginTrans
Do While strFileName <> ""
If strFileName <> "dtproperties.dat" Then
bOK = False
strTableName = Left(strFileName, Len(strFileName) - 4)
'先刪除該表的數據
sqlname = "truncate Table " + Trim(strTableName)
cnnJLDB.Execute sqlname
'然后開始備份
sqlname = "select * from sysobjects Where type = 'u' and name ='" + strTableName + "'"
rs.Open sqlname, cnnJLDB, adOpenStatic, adLockReadOnly
If Not rs.EOF Then
bOK = True
End If
rs.Close
If bOK = True Then
MousePointer = 11
'---------------------------------------------------------------------------
'根據表名確定各個域名及域類型
sqlname = "select xtype,length,name from syscolumns where id in (select id from sysobjects where name = '" + strTableName + "')"
rsColumnName.Open sqlname, cnnJLDB, adOpenStatic, adLockReadOnly
nreccount = 0
If Not rsColumnName.EOF Then
rsColumnName.MoveLast
nreccount = rsColumnName.RecordCount
rsColumnName.MoveFirst
End If
rsColumnName.Close
'將指定文件數據恢復到數據庫中
sqlname = "select * from " + Trim(strTableName)
rsData.Open sqlname, cnnJLDB, adOpenKeyset, adLockOptimistic
lblShowInfo.Caption = "正在恢復" + strTableName + "表中的數據..."
lblShowInfo.Refresh
Open Trim(txtpathText.Text) + strFileName For Binary As #1
Dim lRecordNum As Long
Dim n As Long
Get #1, , lRecordNum
If lRecordNum < 10000 Then
MyBar.Max = lRecordNum + 1
Else
MyBar.Max = lRecordNum \ 100
End If
MyBar.Value = 0
If (lRecordNum > 0) Then
For n = 1 To lRecordNum
rsData.AddNew
For nStep = 0 To nreccount - 1
Get #1, , fieldData
rsData(nStep) = fieldData
Next nStep
rsData.Update
m_iBeginSaveTimer = 0
If lRecordNum < 10000 Then
MyBar.Value = MyBar.Value + 1
Else
If n Mod 100 = 1 Then
MyBar.Value = MyBar.Value + 1
End If
End If
Next n
Close #1
Else
Close #1
End If
rsData.Close
End If
End If
'---------------------------------------------------------------------------
strFileName = Dir
Loop
lblShowInfo.Caption = "數據恢復完畢!"
lblShowInfo.Refresh
MousePointer = 1
cnnJLDB.CommitTrans
MsgBox "數據恢復完畢!", , "信息提示"
Unload Me
Exit Sub
ErrorHand:
cnnJLDB.RollbackTrans
MousePointer = 1
MsgBox "數據恢復失敗,請聯系開發人員!", 64, "數據恢復"
End Sub
Private Sub Command2_Click()
SaveSetting App.Title, "Settings", "StoreDirection", Trim(txtpathText.Text)
Unload Me
End Sub
Private Sub Command4_Click()
frmopendir.Show 1
txtpathText.Text = frmopendir.strSelDir
End Sub
Private Sub Form_Load()
m_iBeginSaveTimer = 0
m_bHaveDone = False
txtpathText.Text = GetSetting(App.Title, "Settings", "StoreDirection", "d:\temp")
End Sub
Private Sub Form_Unload(Cancel As Integer)
m_iBeginSaveTimer = 0
End Sub
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -