📄 frmztsqlrestore.frm
字号:
VERSION 5.00
Object = "{3B7C8863-D78F-101B-B9B5-04021C009402}#1.2#0"; "RICHTX32.OCX"
Begin VB.Form frmZTSQLRestore
Caption = "账套恢复"
ClientHeight = 5025
ClientLeft = 60
ClientTop = 345
ClientWidth = 5595
Icon = "frmZTSQLRestore.frx":0000
LinkTopic = "Form1"
ScaleHeight = 5025
ScaleWidth = 5595
StartUpPosition = 1 '所有者中心
Begin VB.CommandButton cmdCancel
Caption = "退出(&Q)"
Height = 345
Left = 3510
TabIndex = 4
Top = 4485
Width = 1065
End
Begin VB.CommandButton cmdOK
Caption = "确定(&O)"
Height = 345
Left = 915
TabIndex = 3
Top = 4485
Width = 1065
End
Begin VB.CommandButton CmdBrowse
Caption = "浏览"
Height = 300
Left = 3960
TabIndex = 2
Top = 570
Width = 735
End
Begin VB.TextBox TxtFileName
Height = 285
Left = 1335
TabIndex = 1
Top = 570
Width = 2580
End
Begin VB.ComboBox cboZTSelect
Height = 300
Left = 1350
TabIndex = 0
Text = "cboZTSelect"
Top = 120
Width = 1995
End
Begin RichTextLib.RichTextBox RTBfile
Height = 3300
Left = 0
TabIndex = 5
Top = 1035
Width = 5505
_ExtentX = 9710
_ExtentY = 5821
_Version = 393217
ScrollBars = 3
TextRTF = $"frmZTSQLRestore.frx":0442
End
Begin VB.Label Label3
AutoSize = -1 'True
Caption = "备份文件:"
Height = 180
Left = 150
TabIndex = 7
Top = 615
Width = 900
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "账套选择:"
Height = 180
Left = 180
TabIndex = 6
Top = 210
Width = 900
End
End
Attribute VB_Name = "frmZTSQLRestore"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private WithEvents Cnn As ADODB.Connection
Attribute Cnn.VB_VarHelpID = -1
Private Sub CmdBrowse_Click()
frmServerPath.uConnection = gloSys.cnnSys
frmServerPath.Show 1, Me
If frmServerPath.OK Then
TxtFileName = frmServerPath.FileName
End If
Unload frmServerPath
End Sub
Private Sub cmdCancel_Click()
Unload Me
End Sub
Public Function CreateDirctory(ByVal sPath As String, Optional ByVal IsFile As Boolean = True)
Dim i As Integer
Dim sTempPath As String
i = InStr(1, sPath, "\")
While i > 1
sTempPath = Left$(sPath, i - 1)
If IsFile Then
If i < LenB(sPath) Then
If Dir(sTempPath, vbDirectory) = "" Then
MkDir sTempPath
End If
End If
Else
If Dir(sTempPath, vbDirectory) = "" Then
MkDir sTempPath
End If
End If
i = InStr(i + 1, sPath, "\")
Wend
End Function
Public Function SQLRestore(ByVal sDatabase As String, ByVal sFileName As String, ByVal sLogFile As String) As Boolean
CreateDirctory sLogFile
RTBfile.text = "恢复开始..."
RTBfile.text = RTBfile.text + vbCrLf + "恢复账套:" + sDatabase
RTBfile.text = RTBfile.text + vbCrLf + "用于恢复的文件:" + sFileName
RTBfile.text = RTBfile.text + vbCrLf + "恢复时间:" + Format(Date, "yyyy-MM-dd") + " " + Format(Time, "hh:mm:dd")
On Error Resume Next
Set Cnn = New ADODB.Connection
Cnn.Open gloSys.cnnSys.ConnectionString
Cnn.Execute "Restore DataBase " + sDatabase + " From Disk='" + sFileName + "'"
On Error GoTo 0
Set Cnn = Nothing
RTBfile.SaveFile sLogFile
End Function
Private Sub cmdOK_Click()
Dim sAccountID As String
'合法性检查
If cboZTSelect.text = "" Then
MsgBox "账套名不能为空!", vbOKOnly, "提示"
cboZTSelect.SetFocus
Exit Sub
End If
If TxtFileName = "" Then
MsgBox "备份文件名不能为空!", vbOKOnly, "提示"
TxtFileName.SetFocus
Exit Sub
End If
If MsgBox("是否恢复?(并覆盖数据)", vbQuestion + vbYesNo, "") = vbNo Then Exit Sub
If Trim(cboZTSelect.text) = "财务系统表" Then
sAccountID = "ykcwsysdb"
Else
sAccountID = "CWDB" & Mid(Trim(cboZTSelect.text), 1, InStr(1, Trim(cboZTSelect.text), "=") - 1)
End If
On Error GoTo ErrMessageSec:
SQLRestore sAccountID, TxtFileName, App.Path + "\RestoreLog\" + Format(Date, "yyyymmdd") + ".log"
Call SaveSetting(App.Title, "Backup", "SQLUserId", cboZTSelect.text)
Call SaveSetting(App.Title, "Backup", "SQLRestorePath", Trim$(Left(TxtFileName.text, InStrRev(TxtFileName.text, "\"))))
Exit Sub
ErrMessageSec:
MsgBox "正在恢复过程中!应用程序运行出错!", vbInformation, "提示"
End Sub
Private Sub Cnn_ExecuteComplete(ByVal RecordsAffected As Long, ByVal pError As ADODB.Error, adStatus As ADODB.EventStatusEnum, ByVal pCommand As ADODB.Command, ByVal pRecordset As ADODB.Recordset, ByVal pConnection As ADODB.Connection)
Dim i As Integer
Dim oErr As Error
If adStatus = adStatusOK Then
RTBfile.text = RTBfile.text + vbCrLf + "成功恢复。"
Else
For Each oErr In Cnn.Errors
Set oErr = Cnn.Errors(i)
RTBfile.text = RTBfile.text + vbCrLf + "错误:(" + CStr(oErr.NativeError) + ") " + vbCrLf + oErr.Description + ""
Next
RTBfile.text = RTBfile.text + vbCrLf + "恢复失败。"
Cnn.Errors.Clear
End If
End Sub
Private Sub Form_Load()
Dim rSt As New ADODB.Recordset
cboZTSelect.Clear
cboZTSelect.AddItem "财务系统表"
cboZTSelect.Refresh
With rSt
.CursorLocation = adUseClient
.Open "SELECT * FROM tSYS_Account A,tSYS_Trade B " & _
"WHERE A.TradeID=B.ID ORDER BY A.AccountID", _
gloSys.cnnSys, adOpenStatic, adLockReadOnly
If .RecordCount <> 0 Then
Do Until .EOF
cboZTSelect.AddItem .Fields("AccountID").Value & "=" & _
.Fields("AccountName").Value
.MoveNext
Loop
End If
.Close
End With
cboZTSelect.Refresh
Dim i As Integer
If g_FLAT = "SQL" Then
If GetSetting(App.Title, "Backup", "SQLUserId", "") = "ykcwsysdb" Then
cboZTSelect.text = "财务系统表"
Else
cboZTSelect.text = GetSetting(App.Title, "Backup", "SQLUserId", "")
End If
TxtFileName.text = GetSetting(App.Title, "Backup", "SQLBackupPath", "") & "" & Format(Date, "yyyymmdd") & ".dat"
End If
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -