Class FileHandler
- Namespace
- Exercise1b.Core
- Assembly
- Exercise1b.Core.dll
En klass som hanterar filoperationer för att spara och ladda anställda, samt att lägga till och ta bort anställda från en lista. Den innehåller metoder för att lägga till en person, ta bort en person, spara personer till en fil och ladda personer från en fil. Den har också en metod för att visa informationen om den valda personen i textfälten.
public static class FileHandler
- Inheritance
-
FileHandler
- Inherited Members
Methods
AddPerson(ObservableCollection<Employee>, TextBox, TextBox, TextBox)
Metod för att lägga till en person, den tar in en lista av anställda och tre textfält som innehåller namn, födelseår och timlön.
public static bool AddPerson(ObservableCollection<Employee> employees, TextBox TextBoxNamn, TextBox TextBoxFData, TextBox TextBoxHourlyRate)
Parameters
employeesObservableCollection<Employee>TextBoxNamnTextBoxTextBoxFDataTextBoxTextBoxHourlyRateTextBox
Returns
- bool
Returns true if the person was successfully added, otherwise false.
LoadPeople(string)
Metod för att läsa in personer från en fil, den läser filen rad för rad och delar upp raden i delar för att extrahera namn, födelseår och timlön för varje anställd och sedan skapa ett nytt Employee-objekt och lägga till det i en lista som returneras i slutet.
public static ObservableCollection<Employee> LoadPeople(string filePath)
Parameters
filePathstringFilväg från vilken anställda kommer att läsas.
Returns
- ObservableCollection<Employee>
En lista med anställda som lästs från filen.
RemovePerson(ObservableCollection<Employee>, ListView, TextBox, TextBox, TextBox)
Metod för att ta bort en person, den tar in en lista av anställda, en ListView som visar listan av anställda och tre textfält som innehåller namn, födelseår och timlön.
public static void RemovePerson(ObservableCollection<Employee> employees, ListView employeeListBox, TextBox TextBoxNamn, TextBox TextBoxFData, TextBox TextBoxHourlyRate)
Parameters
employeesObservableCollection<Employee>employeeListBoxListViewTextBoxNamnTextBoxTextBoxFDataTextBoxTextBoxHourlyRateTextBox
SavePeople(ObservableCollection<Employee>, string)
Metod för att spara personer till en fil, den tar in en lista av anställda och en filväg där anställda kommer att sparas.
public static void SavePeople(ObservableCollection<Employee> list, string filePath)
Parameters
listObservableCollection<Employee>Lista på anställda som ska sparas.
filePathstringFilväg där anställda kommer att sparas.
SelectPerson(ListView, TextBox, TextBox, TextBox)
Befolkar textfälten med informationen om den valda personen i ListView, den tar in en ListView som visar listan av anställda och tre textfält som innehåller namn, födelseår och timlön.
public static void SelectPerson(ListView employeeListBox, TextBox TextBoxNamn, TextBox TextBoxFData, TextBox TextBoxHourlyRate)