public static void GenerateSpecificUserSummary(int userID) { List <Reservation> userPastReservations = ReservationCalendar.GetSpecificUserPastReservations(userID); List <string> output = new List <string>(); string currentlyLoggedUsername = CurrentlyLoggedUser.GetSpecificUserUsername(); string filePath = $"{currentlyLoggedUsername}Summary.txt"; string firstLine = $"Reservation summary for client {currentlyLoggedUsername}:"; output.Add(firstLine); int totalSpentSum = 0; int totalRentDays = 0; foreach (var reservation in userPastReservations) { DateTime pickUp = Convert.ToDateTime(reservation.rentedFrom); DateTime dropOff = Convert.ToDateTime(reservation.rentedTo); int numberOfRentDays = (dropOff.Date - pickUp.Date).Days; int oneReservationSum = CarList.getSpecificCarRentPrice(reservation.carId) * numberOfRentDays; totalSpentSum += oneReservationSum; totalRentDays += numberOfRentDays; output.Add($"Car {CarList.getSpecificCarName(reservation.carId)} rented from {reservation.rentedFrom} to {reservation.rentedTo} ({numberOfRentDays} days)" + $" for total of {oneReservationSum}PLN"); } string lastLine = $"Total sum spent: {totalSpentSum}PLN, total rent days: {totalRentDays}"; output.Add(lastLine); File.WriteAllLines(filePath, output); }
private void Login_Button_Click(object sender, RoutedEventArgs e) { string inputPassword = password.Password; string inputUsername = username.Text; bool switcher = true; if (string.IsNullOrEmpty(inputUsername)) { System.Windows.MessageBox.Show("Username box is empty"); switcher = false; } else if (string.IsNullOrEmpty(inputPassword)) { System.Windows.MessageBox.Show("Password box is empty"); switcher = false; } if (switcher) { if (AdminList.isOnTheList(inputUsername, inputPassword)) { System.Windows.MessageBox.Show("You are successfully logged in as an admin!"); Admin_ControlPanel admin_ControlPanel = new Admin_ControlPanel(this.Left, this.Top); admin_ControlPanel.Show(); Close(); } else if (UserList.isOnTheList(inputUsername, inputPassword)) { CurrentlyLoggedUser.InitilizeCurrentyLoggedUser(UserList.GetId(inputUsername, inputPassword)); System.Windows.MessageBox.Show("You are successfully logged in as an user!"); User_ControlPanel user_ControlPanel = new User_ControlPanel(this.Left, this.Top); user_ControlPanel.Show(); Close(); } else { System.Windows.MessageBox.Show("Account does not exist! Click REGISTER button in order to register."); } } }