public Ticket GetTicketByTicketId(int ticketId) { Ticket aTicket = new Ticket(); //check if it is a single ticket var singleTickets = Persister.ReadFromBinaryFile <List <Ticket> >(@_location + "_tickets.txt"); foreach (var ticket in singleTickets) { if (ticket.GetTicketId() == ticketId) { return(ticket); } } //check if it is a timed ticket var timedTickets = Persister.ReadFromBinaryFile <List <Ticket> >(@"Tickets.txt"); foreach (var ticket in timedTickets) { if (ticket.GetTicketId() == ticketId) { return(ticket); } } //not used return(aTicket); }
public void AddTicketToList(Ticket ticket) { ticket.InitialiseTicketId(); _validTicketList = Persister.ReadFromBinaryFile <List <Ticket> >(@_location + "_tickets.txt"); _validTicketList.Add(ticket); Persister.WriteToBinaryFile(@_location + "_tickets.txt", _validTicketList, false); }
/// <summary> /// a method that loops through all of the accounts and checks them against the accountId parameter and then uses the command stored in the x parameter to decide what to return from the account /// </summary> /// <typeparam name="T"></typeparam> /// <param name="accountId"></param> /// <param name="x"></param> /// <returns>depending on the x parameter: balance, cardId, fullName, username or the payment digits </returns> public T GetXByAccountId <T>(int accountId, string x) { var accs = Persister.ReadFromBinaryFile <List <CustomerAccount> >(@"Accounts.txt"); foreach (var account in accs) { if (accountId == account._accountId) { switch (x) { case "balance": return((T)Convert.ChangeType(account._balance, typeof(T))); case "cardid": return((T)Convert.ChangeType(account._cardId, typeof(T))); case "fullname": return((T)Convert.ChangeType(account._fullName, typeof(T))); case "username": return((T)Convert.ChangeType(account._username, typeof(T))); case "paymentoptions": return((T)Convert.ChangeType(account.GetSavedPaymentDigits(), typeof(T))); case "savedpaymentmethods": return((T)Convert.ChangeType(_savedPaymentMethods, typeof(T))); } } } return(default(T)); }
public void RemoveTimedTicketFromList(Ticket ticket) { var tickets = Persister.ReadFromBinaryFile <List <Ticket> >(@"Tickets.txt"); tickets.Remove(ticket); Persister.WriteToBinaryFile(@"Tickets.txt", tickets, false); }
/// <summary> /// Constructor for the scanner class that takes two parameters /// </summary> /// <param name="location"></param> /// <param name="entry"></param> public Scanner(Station location, bool entry) { _location = location; _entry = entry; _accounts = new AccountList(Persister.ReadFromBinaryFile <List <CustomerAccount> >(@"Accounts.txt")); _aBarrier = new Barrier(); _routeList = new RouteList(); }
/// <summary> /// A method that calls InitialiseTicketId() and then reads existing tickets into a list of the ticket class and then adds the ticket to the list and writes the list to the file. /// </summary> public void SerialiseTickets() { InitialiseTicketId(); var tickets = Persister.ReadFromBinaryFile <List <Ticket> >(@"Tickets.txt"); tickets.Add(this); Persister.WriteToBinaryFile(@"Tickets.txt", tickets, false); }
public Station(string Location) { _location = Location; if (File.Exists(@_location + "_tickets.txt")) { _validTicketList = Persister.ReadFromBinaryFile <List <Ticket> >(@_location + "_tickets.txt"); } else { _validTicketList = new List <Ticket>(); } }
public Station(DepartureList departureList, string location) { _departureList = departureList; _location = location; if (File.Exists(@_location + "_tickets.txt")) { _validTicketList = Persister.ReadFromBinaryFile <List <Ticket> >(@_location + "_tickets.txt"); } else { _validTicketList = new List <Ticket>(); } }
public void RemoveTicketFromList(Ticket ticket) { _validTicketList = Persister.ReadFromBinaryFile <List <Ticket> >(@_location + "_tickets.txt"); foreach (var tick in _validTicketList) { if (tick.GetTicketId() == ticket.GetTicketId()) { _validTicketList.Remove(tick); break; } } Persister.WriteToBinaryFile(@_location + "_tickets.txt", _validTicketList, false); }
/// <summary> /// This method gets the valid user account and calls the update balance method to add the amount they wish to top up to their account balance. /// </summary> /// <param name="accountId">The account ID of which account to top up.</param> /// <param name="topup">How much the user wishes to top up.</param> public void UpdateData(int accountId, decimal topup) { var accs = Persister.ReadFromBinaryFile <List <CustomerAccount> >(@"Accounts.txt"); foreach (var account in accs) { if (accountId == account.GetAccountId()) { account.UpdateBalance(topup); } } _listOfAccounts = accs; SaveCustomerData(); }
public void TicketSetup() { selectedStartStation = "Birmingham"; selectedEndStation = "Birmingham"; Ticket ticket = new Ticket(); ticket.InitialiseTicketId(); ticket.InitialiseTickets(); List<Station> stationList = Persister.ReadFromBinaryFile<List<Station>>(@"Stations.txt"); foreach (var station in stationList) { station.InitialiseTicketList(ticket); } //StationList _stations = new StationList(); //_stations = new StationList(stationList); }
/// <summary> /// This function logs out a user from the system. /// </summary> /// <param name="accountId">The user ID to log out.</param> /// <returns>returns -1 to show the user has been logged out. </returns> public int LogoutAdmin(int accountId) { var accs = Persister.ReadFromBinaryFile <List <AdminAccount> >(@"AdminAccounts.txt"); foreach (var account in accs) { if (account._accountId == accountId) { account._loginStatus = false; var temp = new AccountList(accs); temp.SaveAdminData(); return(-1); } } return(-1); }
/// <summary> /// Updates a single account in the listOfAccounts and then saves the listOfAccounts to file /// Used in various locations to allow easy updating of any attribute of an account. /// </summary> /// <param name="accountT">CustomerAccount to be updated</param> public void UpdateAccount(CustomerAccount accountT) { if (File.Exists(@"Accounts.txt")) { var accs = Persister.ReadFromBinaryFile <List <CustomerAccount> >(@"Accounts.txt"); for (int i = 0; i < accs.Count; i++) { if (accountT.GetId() == accs[i].GetAccountId()) { accs[i] = accountT; break; } } _listOfAccounts = accs; SaveCustomerData(); } }
/// <summary> /// This function takes the username and password entered by the user. /// It then calls the function to read the Accounts file; this then verifies the entered details /// against the stored details. If both match, it returns the accountId. /// </summary> /// <param name="username">A string containing the username the user entered when attempting to log in.</param> /// <param name="password">A string containing the password the user entered when attempting to log in.</param> /// <returns>If successful, the accountId, else -1 to signal a failure.</returns> public int VerifyLogin(string username, string password) { if (username.StartsWith("admin")) { var accs = Persister.ReadFromBinaryFile <List <AdminAccount> >(@"AdminAccounts.txt"); foreach (var account in accs) { if (account._username == username && account._password == password) { if (account._loginStatus) { return(-2); } account._loginStatus = true; var temp = new AccountList(accs); temp.SaveAdminData(); return(account._accountId); } } return(-1); } else { var accs = Persister.ReadFromBinaryFile <List <CustomerAccount> >(@"Accounts.txt"); foreach (var account in accs) { if (account._username == username && account._password == password) { if (account._loginStatus) { return(-2); } account._loginStatus = true; var temp = new AccountList(accs); temp.SaveCustomerData(); return(account._accountId); } } return(-1); } }
public T GetXByAccountId <T>(int accountId, string x) { var accs = Persister.ReadFromBinaryFile <List <AdminAccount> >(@"AdminAccounts.txt"); foreach (var account in accs) { if (accountId == account._accountId) { switch (x) { case "routes": return((T)Convert.ChangeType(account._routes, typeof(T))); case "fullname": return((T)Convert.ChangeType(account._fullName, typeof(T))); case "username": return((T)Convert.ChangeType(account._username, typeof(T))); } } } return(default(T)); }
private StationList LoadStations(StationList _stations) { List<Station> stationsTemp = Persister.ReadFromBinaryFile<List<Station>>(@"Stations.txt"); _stations = new StationList(stationsTemp); return _stations; }
private void LoadStations() { List <Station> stationsTemp = Persister.ReadFromBinaryFile <List <Station> >(@"Stations.txt"); _stations = new StationList(stationsTemp); }
public void LoadAdminData() { _listOfAdminAccounts = Persister.ReadFromBinaryFile <List <AdminAccount> >(@"AdminAccounts.txt"); }
/// <summary> /// A method that calls the private Persister.ReadFromBinaryFile method with the required parameters /// </summary> public void LoadCustomerData() { _listOfAccounts = Persister.ReadFromBinaryFile <List <CustomerAccount> >(@"Accounts.txt"); }
/// <summary> /// a method that reads in a ticket from file and then returns the ticketId + 1 /// </summary> /// <returns>the _ticketId integer + 1</returns> public int GetNewTicketId() { var ticket = Persister.ReadFromBinaryFile <Ticket>(@"LastTicket.txt"); return(ticket.TicketId() + 1); }