Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports System.IO 'imports input and output functions
- Public Class Backup 'backup form
- Private Sub saveBackup(ByVal originalfile As String)
- Dim record As String 'record from file
- Dim startupPath As String 'location where program is running
- startupPath = Application.StartupPath
- Dim backupFileLocation As String 'location of backup file to write to
- backupFileLocation = startupPath & "\Backups\" & originalfile
- If Dir(backupFileLocation) = "" Then 'create a new file in the backup folder for the file
- Dim sw1 As New StreamWriter(backupFileLocation, True) 'create mew file with stream writer
- sw1.Close() 'close stream writer
- MsgBox("New file created") 'notify user
- End If
- Dim sw2 As New StreamWriter(backupFileLocation, False) 'delete current data stored in backup file
- sw2.Close() 'close stream writer
- Dim sr As New StreamReader(originalfile) 'stream reader of original file
- While sr.Peek() >= 0 'while there are records to file
- record = sr.ReadLine 'read record from original file
- Dim sw3 As New StreamWriter(backupFileLocation, True) 'add records from original file into blank backup file
- sw3.WriteLine(record) 'write record to backup file
- sw3.Close() 'close stream writer
- End While
- sr.Close() 'close stream reader
- End Sub
- Private Sub Backup_Load(sender As Object, e As EventArgs) Handles MyBase.Load 'when form loads
- Me.CenterToScreen() 'center form to screen
- Me.BackColor = Color.FromArgb(247, 220, 143) 'set background to yellow as only admins can access this
- Dim startupPath As String 'location program is running
- startupPath = Application.StartupPath
- pbx_logo.ImageLocation = startupPath & "\PennardLibraryLogo.png" 'set image locations
- pbx_back.ImageLocation = startupPath & "\Arrow.png"
- End Sub
- Private Sub pbx_back_Click(sender As Object, e As EventArgs) Handles pbx_back.Click
- Dim MainMenu As New MainMenu 'new instance of main menu form
- MainMenu.Show() 'show new form
- Me.Close() 'close current form
- End Sub
- Private Sub pbx_back_MouseHover(sender As Object, e As EventArgs) Handles pbx_back.MouseHover
- Dim startupPath As String 'location program is running
- startupPath = Application.StartupPath
- pbx_back.ImageLocation = startupPath & "\ArrowRollover.png" 'rollover
- End Sub
- Private Sub pbx_back_MouseLeave(sender As Object, e As EventArgs) Handles pbx_back.MouseLeave
- Dim startupPath As String 'location program is running
- startupPath = Application.StartupPath
- pbx_back.ImageLocation = startupPath & "\Arrow.png" 'original image
- End Sub
- Private Sub btn_books_Click(sender As Object, e As EventArgs) Handles btn_books.Click
- saveBackup("books.txt") 'save backup for books
- End Sub
- Private Sub btn_loginData_Click(sender As Object, e As EventArgs) Handles btn_loginData.Click
- saveBackup("loginData.txt") 'save backup for login data
- End Sub
- Private Sub btn_borrowingData_Click(sender As Object, e As EventArgs) Handles btn_borrowingData.Click
- saveBackup("borrowingData.txt") 'save backup for borrowing data
- End Sub
- Private Sub btn_individualBorrowings_Click(sender As Object, e As EventArgs) Handles btn_individualBorrowings.Click
- saveBackup("individualBorrowings.txt") 'save backup for individual borrowings
- End Sub
- Private Sub btn_customerData_Click(sender As Object, e As EventArgs) Handles btn_customerData.Click
- saveBackup("customerData.txt") 'save backup for customer data
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement