Advertisement
UsernameHere1

Untitled

Feb 21st, 2024
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 3.71 KB | None | 0 0
  1. Imports System.IO 'imports input and output functions
  2. Public Class Backup 'backup form
  3.     Private Sub saveBackup(ByVal originalfile As String)
  4.         Dim record As String 'record from file
  5.         Dim startupPath As String 'location where program is running
  6.         startupPath = Application.StartupPath
  7.         Dim backupFileLocation As String 'location of backup file to write to
  8.         backupFileLocation = startupPath & "\Backups\" & originalfile
  9.         If Dir(backupFileLocation) = "" Then 'create a new file in the backup folder for the file
  10.             Dim sw1 As New StreamWriter(backupFileLocation, True) 'create mew file with stream writer
  11.             sw1.Close() 'close stream writer
  12.             MsgBox("New file created") 'notify user
  13.         End If
  14.         Dim sw2 As New StreamWriter(backupFileLocation, False) 'delete current data stored in backup file
  15.         sw2.Close() 'close stream writer
  16.         Dim sr As New StreamReader(originalfile) 'stream reader of original file
  17.         While sr.Peek() >= 0 'while there are records to file
  18.             record = sr.ReadLine 'read record from original file
  19.             Dim sw3 As New StreamWriter(backupFileLocation, True) 'add records from original file into blank backup file
  20.             sw3.WriteLine(record) 'write record to backup file
  21.             sw3.Close() 'close stream writer
  22.         End While
  23.         sr.Close() 'close stream reader
  24.     End Sub
  25.     Private Sub Backup_Load(sender As Object, e As EventArgs) Handles MyBase.Load 'when form loads
  26.         Me.CenterToScreen() 'center form to screen
  27.         Me.BackColor = Color.FromArgb(247, 220, 143) 'set background to yellow as only admins can access this
  28.         Dim startupPath As String 'location program is running
  29.         startupPath = Application.StartupPath
  30.         pbx_logo.ImageLocation = startupPath & "\PennardLibraryLogo.png" 'set image locations
  31.         pbx_back.ImageLocation = startupPath & "\Arrow.png"
  32.     End Sub
  33.     Private Sub pbx_back_Click(sender As Object, e As EventArgs) Handles pbx_back.Click
  34.         Dim MainMenu As New MainMenu 'new instance of main menu form
  35.         MainMenu.Show() 'show new form
  36.         Me.Close()  'close current form
  37.     End Sub
  38.     Private Sub pbx_back_MouseHover(sender As Object, e As EventArgs) Handles pbx_back.MouseHover
  39.         Dim startupPath As String 'location program is running
  40.         startupPath = Application.StartupPath
  41.         pbx_back.ImageLocation = startupPath & "\ArrowRollover.png" 'rollover
  42.     End Sub
  43.  
  44.     Private Sub pbx_back_MouseLeave(sender As Object, e As EventArgs) Handles pbx_back.MouseLeave
  45.         Dim startupPath As String 'location program is running
  46.         startupPath = Application.StartupPath
  47.         pbx_back.ImageLocation = startupPath & "\Arrow.png" 'original image
  48.     End Sub
  49.  
  50.     Private Sub btn_books_Click(sender As Object, e As EventArgs) Handles btn_books.Click
  51.         saveBackup("books.txt") 'save backup for books
  52.     End Sub
  53.  
  54.     Private Sub btn_loginData_Click(sender As Object, e As EventArgs) Handles btn_loginData.Click
  55.         saveBackup("loginData.txt") 'save backup for login data
  56.     End Sub
  57.  
  58.     Private Sub btn_borrowingData_Click(sender As Object, e As EventArgs) Handles btn_borrowingData.Click
  59.         saveBackup("borrowingData.txt") 'save backup for borrowing data
  60.     End Sub
  61.  
  62.     Private Sub btn_individualBorrowings_Click(sender As Object, e As EventArgs) Handles btn_individualBorrowings.Click
  63.         saveBackup("individualBorrowings.txt") 'save backup for individual borrowings
  64.     End Sub
  65.  
  66.     Private Sub btn_customerData_Click(sender As Object, e As EventArgs) Handles btn_customerData.Click
  67.         saveBackup("customerData.txt") 'save backup for customer data
  68.     End Sub
  69. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement