Public Class Form1
Inherits System.Windows.Forms.form
#Region "Windows Form Designer Generated Code"
Public Sub new () mybase.new ()
'This call is required for the Windows Form Designer. InitializeComponent ()
'Add any initialization after INITIALIZECOMPONENT ()
End Sub
'Form rewriting disposal to clean the component list. Protected overloads overrides sub dispose (byval disposing as boolean) ing disponation kiln (Components Is Nothing) Then components.dispose () end if endiffs) End sub
'Windows Form Designer Supply Private Components as System.comPonentModel.icontainer
'Note: The following procedure is necessary to use the Windows Form Designer to modify this process using the Windows Form Designer. 'Don't modify it using the code editor.
Friend WithEvents ProgressBar1 As System.Windows.Forms.ProgressBar Friend WithEvents Button1 As System.Windows.Forms.Button
False me.startPosition = system.windows.forms.formstartPosition.CenterScreen Me.ResumeLayout (false) End Sub
#End region
Since the trouble is not dealt with by the property ... should be improved by the public sa as string public paSserd As String Public File As String Public Database AS String Public SQLServer AS String
Public flag as boolean = TRUE
Private WitHevents PBackup As New SqldMo.Backup () Private Withevent ORESTORE As New SqldMo.restore ()
'Property SQLServername () AS String' Get 'Return Sql Server' End Get 'Set (Byval Value As String)' SQLServer = Value 'End Set' End Property
'Backup Public Function Backup (Byval DatabaseName As String, Byval Sqlserve As String, Byval Role As String, Byval Password As String, BYVAL BackFileName As String)
Me.ProgressBar1.Value = 0 me.backcolor = system.drawing.color.royalblue me.button1.text = "Backup" me.show () on Error Goto Errhandler
DIM SQLSER AS New SqldMo.sqlserver
SQLSER.CONNECT (SQLserve, Role, Password) PBackup.Database = DatabaseName
System.windows.forms.cursor.current = system.windows.forms.cursors.waitcursor
PBackup.Files = BackFileName PBackup.sqlbackup (SQLSER)
SQLSER.Disconnect () SQLSER = Nothing system.windows.Forms.cursor.current = system.windows.Forms.cursors.default exit function
Errhandler:
Msgbox ("Backup failed, please check if the source database exists, if the role permission is enough or whether the SQL Server service is opened" & chr (13) & "information:" & Err.Description) Resume Next End Function
'Restore Public Function Rstore (Byval DatabaseName As String, Byval Sqlserve As String, Byval Role As String, Byval Password As String, BYVAL RESTFILENAME AS STRING) Me.ProgressBar1.Value = 0
Me.backcolor = system.drawing.color.oliveDrab me.button1.text = "Restore" me.show () on error Goto Errhandler
DIM SQLSER AS New SqldMo.sqlserver
SQLSer.Connect (SQLServe, Role, Password)
Orentore.Database = DatabaseName Orestore.Files = RestfileName
System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor oRestore.SQLRestore (SQLSER) System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default
SQLSER.Disconnect () SQLSER = Nothing
EXIT FUNCTION
Errhandler: MsgBox ("Recovery Failed, please check if the recovery database exists, the role permission is enough or whether the SQL Server service is opened" & chr (13) & "information:" & Err.Description) Resume Next End Function
PRIVATE SUB PBACKUP_COMPLETE (Byval Message AS String) Handles PBackup.comPlete
Me.ProgressBar1.Value = 100 pBackup = Nothing me.orestore = Nothing me.close ()
End Sub Private Sub PBackup_PerCentComplete (Byval Message As "Handles PBackup.PercentComplete Me.BackColor = System.drawing.color.RoyalBlue
Me.ProgressBar1.Value = percent if percent = 100 Then
Me.ProgressBar1.Value = 100 pBackup = Nothing me.orestore = Nothing me.close ()
End if End Sub Private Sub Outue_complete (Byval Message As String) Handles Orentore.comPlete
Me.ProgressBar1.Value = 100 PBackup = Nothing Me.oRestore = Nothing Me.Close () End Sub Private Sub oRestore_PercentComplete (ByVal Message As String, ByVal Percent As Integer) Handles oRestore.PercentComplete Me.BackColor = System.Drawing.Color. OlivedRabme.ProgressBar1.Value = percentiff if percent = 100 Then
Me.ProgressBar1.Value = 100 pBackup = Nothing me.orestore = Nothing me.close () end if End Sub
Private sub button1_click (byvale) Handles button1.click if flag = true kil
Me.Backup (Me.Database, Me.Sqlserver, Me.SA, Me.Passerd, Me.File)
Else Me.rs (me.database, me.sqlserver, me.sa, me.passerd, me.file)
END IF
End Sub
END CLASS