public static void ReturnLibraryElement(OrdinaryUser LoggedOrdinaryUser) { int borrowingIdToReturn; Console.Clear(); Console.WriteLine(TextFileHandler.GetOrdinaryUserBorrowingsListFromFile(LoggedOrdinaryUser.UserID)); Console.Write("Który element chcesz zwrócić?[Podaj ID]: "); borrowingIdToReturn = int.Parse(Console.ReadLine()); if (TextFileHandler.CheckReturnValidation(borrowingIdToReturn, LoggedOrdinaryUser.UserID)) { TextFileHandler.ChangeBorrowingStatusToReturned(borrowingIdToReturn, LoggedOrdinaryUser.UserID); if (TextFileHandler.GetBorrowingElementType(borrowingIdToReturn, LoggedOrdinaryUser.UserID) == 1) { int bookID = TextFileHandler.GetBorrowingElementId(borrowingIdToReturn, LoggedOrdinaryUser.UserID); TextFileHandler.ChangeBookStatusToAvailable(bookID); } else if (TextFileHandler.GetBorrowingElementType(borrowingIdToReturn, LoggedOrdinaryUser.UserID) == 2) { int movieID = TextFileHandler.GetBorrowingElementId(borrowingIdToReturn, LoggedOrdinaryUser.UserID); TextFileHandler.ChangeMovieStatusToAvailable(movieID); } Console.WriteLine("Element oddano do zbioru biblioteki"); Console.ReadLine(); } else { Console.WriteLine("Podano niepoprawne ID!"); Console.ReadKey(); } }
public static void CreateNewOrdinaryUserDataFiles(OrdinaryUser newOrdinaryUser) { string newOrdinaryUsersDirectory = ordinaryUsersDirectoryPath + @"\OrdinaryUser" + newOrdinaryUser.UserID; Directory.CreateDirectory(newOrdinaryUsersDirectory); File.Create(newOrdinaryUsersDirectory + @"\Borrowings_OrdinaryUser" + newOrdinaryUser.UserID + ".txt"); }
public static void OrdinaryUserMenuView(OrdinaryUser LoggedOrdinaryUser) { int ordinaryUserMenuSelectedOptionInt = 0; OrdinaryUserMenuOption ordinaryUserMenuSelectedOption; while (true) { Console.Clear(); Console.WriteLine("1. Wyszukawiarka elementów w zbiorze"); Console.WriteLine("2. Wypożycz"); Console.WriteLine("3. Zwróć"); Console.WriteLine("4. Lista aktualnych wypożyczeń"); Console.WriteLine("5. Rozliczenie kar"); Console.WriteLine("6. Wyloguj"); Console.Write("Wybierz opcje: "); ordinaryUserMenuSelectedOptionInt = int.Parse(Console.ReadLine()); if (ordinaryUserMenuSelectedOptionInt > 0 && ordinaryUserMenuSelectedOptionInt < 6) { ordinaryUserMenuSelectedOption = (OrdinaryUserMenuOption)ordinaryUserMenuSelectedOptionInt; OrdinaryUserMenuOptionSelection(ordinaryUserMenuSelectedOption, LoggedOrdinaryUser); } else if (ordinaryUserMenuSelectedOptionInt == 6) { LogInView(); } } }
//ORDINARY USER METHODS public static OrdinaryUser CreateNewOrdinaryUser(string name, string surname, string password) { OrdinaryUser newOrdinaryUser = new OrdinaryUser(name, surname, 2, getCurrentOrdinaryUserID() + 1, password, $"OrdinaryUser{getCurrentOrdinaryUserID() + 1}"); File.AppendAllText(ordinaryUsersListPath, $"{newOrdinaryUser.UserID},{name},{surname},{2},0\n"); //Add new line to .txt file File.AppendAllText(accountsInfoPath, $"{newOrdinaryUser.Login},{password},{newOrdinaryUser.UserType},{newOrdinaryUser.UserID}\n"); CreateNewOrdinaryUserDataFiles(newOrdinaryUser); return(newOrdinaryUser); }
public static void LogInView() { Console.Clear(); Librarian LoggedLibrarian; OrdinaryUser LoggedOrdinaryUser; string userData = null; string[] userArguments; while (userData == null) { userData = GetUserDataByEnteringPasses(); } userArguments = userData.Split(','); if (byte.Parse(userArguments[3]) == 1) { LoggedLibrarian = new Librarian(name: userArguments[1], surname: userArguments[2], type: byte.Parse(userArguments[3]), id: int.Parse(userArguments[0]), password: userArguments[4], login: userArguments[5]); Console.Clear(); Console.WriteLine($"Witaj {LoggedLibrarian.Name}!"); Console.Write("kliknij aby kontynuować"); Console.ReadKey(); LibrarianMenuView(LoggedLibrarian); } else if (byte.Parse(userArguments[3]) == 2) { LoggedOrdinaryUser = new OrdinaryUser(name: userArguments[1], surname: userArguments[2], type: byte.Parse(userArguments[3]), id: int.Parse(userArguments[0]), password: userArguments[5], login: userArguments[6]); Console.Clear(); Console.WriteLine($"Witaj {LoggedOrdinaryUser.Name}!"); Console.Write("kliknij aby kontynuować"); Console.ReadKey(); OrdinaryUserMenuView(LoggedOrdinaryUser); } }
public static void BorrowALibraryElement(OrdinaryUser LoggedOrdinaryUser) { ushort id; byte type; Console.Clear(); Console.WriteLine("Wypożyczalnia"); Console.WriteLine("___________________________"); Console.Write("Podaj typ elementu:\nKsiążka: 1\nFilm: 2\n"); type = byte.Parse(Console.ReadLine()); if (type == 1) { Console.Write("Podaj ID elementu: "); id = ushort.Parse(Console.ReadLine()); if (TextFileHandler.CheckIfBookExistsById(id) && TextFileHandler.CheckIfBookStatusIsAvailable(id)) { //int availableBorrowingIdTmp = TextFileHandler.GetCurrentBorrowingID(LoggedOrdinaryUser) + 1; //LoggedOrdinaryUser.BorrowLibraryElement(DateTime.Now, id, type, availableBorrowingIdTmp); TextFileHandler.BorrowRequestAddToFile(DateTime.Now, id, type, LoggedOrdinaryUser.UserID); TextFileHandler.ChangeBookStatusToPending(id); Console.WriteLine("Element oczekuje na zatwierdzenie"); } else { Console.WriteLine("Podano błędne ID elementu!"); Console.ReadKey(); //BorrowALibraryElement(LoggedOrdinaryUser); } } else if (type == 2) { Console.Write("Podaj ID elementu: "); id = ushort.Parse(Console.ReadLine()); if (TextFileHandler.CheckIfMovieExistsById(id) && TextFileHandler.CheckIfMovieStatusIsAvailable(id)) { //int availableBorrowingIdTmp = TextFileHandler.GetCurrentBorrowingID(LoggedOrdinaryUser) + 1; //LoggedOrdinaryUser.BorrowLibraryElement(DateTime.Now, id, type, availableBorrowingIdTmp); TextFileHandler.BorrowRequestAddToFile(DateTime.Now, id, type, LoggedOrdinaryUser.UserID); TextFileHandler.ChangeMovieStatusToPending(id); Console.WriteLine("Element oczekuje na zatwierdzenie"); } else { Console.WriteLine("Podano błędne ID elementu!"); Console.ReadKey(); //BorrowALibraryElement(LoggedOrdinaryUser); } } else { Console.WriteLine("Podano zły typ elementu!"); Console.ReadKey(); BorrowALibraryElement(LoggedOrdinaryUser); } Console.ReadKey(); }
public static void OrdinaryUserMenuOptionSelection(OrdinaryUserMenuOption option, OrdinaryUser LoggedOrdinaryUser) { switch (option) { case OrdinaryUserMenuOption.SearchLibraryElement: SearchLibraryElement(); break; case OrdinaryUserMenuOption.Borrow: BorrowALibraryElement(LoggedOrdinaryUser); break; case OrdinaryUserMenuOption.Return: ReturnLibraryElement(LoggedOrdinaryUser); break; case OrdinaryUserMenuOption.GetBorrowingsList: GetAllOrdinaryUserBorrowingsList(LoggedOrdinaryUser.UserID); break; case OrdinaryUserMenuOption.SettlePenalties: break; default: break; } }