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

📄 frm_backup.vb

📁 一个用VB.NET做的图书管理系统,功能比较简单
💻 VB
字号:
Imports System.Data.OleDb
Imports System.DateTime
Imports System.Math
Imports System.IO
Imports System.Threading



Public Class frm_BackUp
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents TxtSourceAddress As System.Windows.Forms.TextBox
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents TxtDest As System.Windows.Forms.TextBox
    Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
    Friend WithEvents BtnBackup As System.Windows.Forms.Button
    Friend WithEvents ProgressBar1 As System.Windows.Forms.ProgressBar
    Friend WithEvents BtnExit As System.Windows.Forms.Button
    Friend WithEvents Button7 As System.Windows.Forms.Button
    Friend WithEvents BtnBrowser As System.Windows.Forms.Button
    Friend WithEvents Label3 As System.Windows.Forms.Label
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(frm_BackUp))
        Me.Label1 = New System.Windows.Forms.Label
        Me.TxtSourceAddress = New System.Windows.Forms.TextBox
        Me.Label2 = New System.Windows.Forms.Label
        Me.TxtDest = New System.Windows.Forms.TextBox
        Me.GroupBox1 = New System.Windows.Forms.GroupBox
        Me.Button7 = New System.Windows.Forms.Button
        Me.BtnBrowser = New System.Windows.Forms.Button
        Me.BtnBackup = New System.Windows.Forms.Button
        Me.ProgressBar1 = New System.Windows.Forms.ProgressBar
        Me.BtnExit = New System.Windows.Forms.Button
        Me.Label3 = New System.Windows.Forms.Label
        Me.GroupBox1.SuspendLayout()
        Me.SuspendLayout()
        '
        'Label1
        '
        Me.Label1.Location = New System.Drawing.Point(49, 30)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(120, 25)
        Me.Label1.TabIndex = 0
        Me.Label1.Text = "源地址"
        '
        'TxtSourceAddress
        '
        Me.TxtSourceAddress.Location = New System.Drawing.Point(98, 26)
        Me.TxtSourceAddress.Name = "TxtSourceAddress"
        Me.TxtSourceAddress.Size = New System.Drawing.Size(269, 21)
        Me.TxtSourceAddress.TabIndex = 1
        '
        'Label2
        '
        Me.Label2.Location = New System.Drawing.Point(38, 60)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(54, 25)
        Me.Label2.TabIndex = 2
        Me.Label2.Text = "目标地址"
        '
        'TxtDest
        '
        Me.TxtDest.Location = New System.Drawing.Point(98, 60)
        Me.TxtDest.Name = "TxtDest"
        Me.TxtDest.Size = New System.Drawing.Size(269, 21)
        Me.TxtDest.TabIndex = 3
        '
        'GroupBox1
        '
        Me.GroupBox1.Controls.Add(Me.Button7)
        Me.GroupBox1.Controls.Add(Me.BtnBrowser)
        Me.GroupBox1.Controls.Add(Me.Label2)
        Me.GroupBox1.Controls.Add(Me.TxtDest)
        Me.GroupBox1.Controls.Add(Me.TxtSourceAddress)
        Me.GroupBox1.Controls.Add(Me.Label1)
        Me.GroupBox1.Location = New System.Drawing.Point(19, 17)
        Me.GroupBox1.Name = "GroupBox1"
        Me.GroupBox1.Size = New System.Drawing.Size(432, 103)
        Me.GroupBox1.TabIndex = 4
        Me.GroupBox1.TabStop = False
        Me.GroupBox1.Text = "备份设置"
        '
        'Button7
        '
        Me.Button7.Location = New System.Drawing.Point(377, 60)
        Me.Button7.Name = "Button7"
        Me.Button7.Size = New System.Drawing.Size(37, 23)
        Me.Button7.TabIndex = 8
        Me.Button7.Text = "...."
        Me.Button7.UseVisualStyleBackColor = True
        '
        'BtnBrowser
        '
        Me.BtnBrowser.Location = New System.Drawing.Point(378, 25)
        Me.BtnBrowser.Name = "BtnBrowser"
        Me.BtnBrowser.Size = New System.Drawing.Size(37, 23)
        Me.BtnBrowser.TabIndex = 7
        Me.BtnBrowser.Text = "...."
        Me.BtnBrowser.UseVisualStyleBackColor = True
        '
        'BtnBackup
        '
        Me.BtnBackup.Location = New System.Drawing.Point(92, 223)
        Me.BtnBackup.Name = "BtnBackup"
        Me.BtnBackup.Size = New System.Drawing.Size(96, 34)
        Me.BtnBackup.TabIndex = 5
        Me.BtnBackup.Text = "备份"
        '
        'ProgressBar1
        '
        Me.ProgressBar1.Location = New System.Drawing.Point(19, 136)
        Me.ProgressBar1.Name = "ProgressBar1"
        Me.ProgressBar1.Size = New System.Drawing.Size(432, 43)
        Me.ProgressBar1.TabIndex = 6
        '
        'BtnExit
        '
        Me.BtnExit.Location = New System.Drawing.Point(273, 223)
        Me.BtnExit.Name = "BtnExit"
        Me.BtnExit.Size = New System.Drawing.Size(96, 35)
        Me.BtnExit.TabIndex = 7
        Me.BtnExit.Text = "退出"
        '
        'Label3
        '
        Me.Label3.Location = New System.Drawing.Point(68, 182)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(327, 25)
        Me.Label3.TabIndex = 8
        Me.Label3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        '
        'frm_BackUp
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
        Me.ClientSize = New System.Drawing.Size(475, 268)
        Me.Controls.Add(Me.Label3)
        Me.Controls.Add(Me.BtnExit)
        Me.Controls.Add(Me.ProgressBar1)
        Me.Controls.Add(Me.BtnBackup)
        Me.Controls.Add(Me.GroupBox1)
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
        Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
        Me.MaximizeBox = False
        Me.MinimizeBox = False
        Me.Name = "frm_BackUp"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "备份数据库"
        Me.GroupBox1.ResumeLayout(False)
        Me.GroupBox1.PerformLayout()
        Me.ResumeLayout(False)

    End Sub

#End Region
    Dim MyConnection As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Application.StartupPath & "\Library.mdb")
    Dim MyCommand As OleDbCommand
    Dim MyReader As OleDbDataReader



    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnExit.Click
        Me.Close()
    End Sub


   
    Private Sub frm_BackUp_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        MyConnection.Open()
        MyCommand = New OleDbCommand("SELECT * FROM Backup", MyConnection)
        MyReader = MyCommand.ExecuteReader()
        While MyReader.Read
            TxtSourceAddress.Text = MyReader("Source")
            TxtDest.Text = MyReader("Dest")
        End While
        MyConnection.Close()
        MyReader.Close()
    End Sub
    Sub updatePath()
        MyConnection.Open()
        MyCommand = New OleDbCommand("UPDATE Backup SET Source ='" & TxtSourceAddress.Text & "',Dest = '" & TxtDest.Text & "' ", MyConnection)
        Try
            MyCommand.ExecuteNonQuery()
        Catch c As Exception
            MsgBox(c.ToString)
        End Try
        MyConnection.Close()
        MyCommand.Dispose()
    End Sub
 


    Private Sub BtnBackup_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnBackup.Click

        updatePath()
        Label3.Text = "初始化......."
        ProgressBar1.Increment(20)
        Label3.Text = "..."
        myWait(2500)
        Label3.Text = "...."
        Label3.Text = "....."
        Label3.Text = "......"
        ProgressBar1.Increment(20)
        Dim foldername As String = Date.Now.Day.ToString + "-" + Date.Now.Month.ToString + "-" + Date.Now.Year.ToString
        Dim filename As String = Date.Now.Hour.ToString + "-" + Date.Now.Minute.ToString + "-" + Date.Now.Second.ToString
        Dim direcname = TxtDest.Text + foldername
        Dim sourcepath As String = TxtSourceAddress.Text
        myWait(2500)
        Label3.Text = "创建文件夹......."
        Label3.Text = "..."
        Label3.Text = "...."
        Label3.Text = "....."
        Label3.Text = "......"
        ProgressBar1.Increment(20)
        myWait(2500)
        If Directory.Exists(direcname) = True Then
        Else
            If Directory.Exists(direcname) = False Then
                Directory.CreateDirectory(direcname)
            End If
        End If
        ProgressBar1.Increment(20)
        Label3.Text = "备份数据库......."
        Label3.Text = "..."
        Label3.Text = "...."
        Label3.Text = "....."
        Label3.Text = "......"
        File.Copy(sourcepath, direcname + "\" + filename + ".backup")
        myWait(2500)
        ProgressBar1.Increment(20)
        Label3.Text = "备份完成......."
        MsgBox("备份完成!", MsgBoxStyle.OkOnly, "图书馆管理系统")
    End Sub



    Sub myWait(ByVal mySeconds As Integer)
        Dim myTime As Integer
        myTime = 0
        While myTime <= mySeconds
            myTime = myTime + 1
            Label3.Text = "..."
            Label3.Text = "...."
            Label3.Text = "....."
            Label3.Text = "......"
        End While
    End Sub







    Private Sub BtnBrowser_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnBrowser.Click
        Dim objOpenFile As New OpenFileDialog
        Dim filePath As String
        objOpenFile.Filter = "所有文件 (*.*)|*.*"
        If objOpenFile.ShowDialog() = Windows.Forms.DialogResult.OK And objOpenFile.FileName <> "" Then
            filePath = objOpenFile.FileName
        End If
        TxtSourceAddress.Text = filePath
    End Sub


    Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
        Dim objOpenFile As New OpenFileDialog
        Dim filePath As String
        objOpenFile.Filter = "所有文件 (*.*)|*.*"
        If objOpenFile.ShowDialog() = Windows.Forms.DialogResult.OK And objOpenFile.FileName <> "" Then
            filePath = objOpenFile.FileName
        End If
        TxtSourceAddress.Text = filePath
    End Sub



End Class

⌨️ 快捷键说明

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