//Register employee algorithm: protected virtual void RegisterEmployee() { int numberOfPotentiallyRequestedEmployees; string idUserCode; List <Employee> potentialEmployees; IEnumerable <Employee> employees = UI_RequestEmployeeNames(); // requesting name and surname parameters from user if (employees == null) // Triggers when user cancels providing requested informations. { DialogBoxFactory.GetInfoBox("Rejestracja anulowana!").Show(); return; } numberOfPotentiallyRequestedEmployees = employees.Count(); switch ((numberOfPotentiallyRequestedEmployees)) { case 0: // Triggers when requested employee wasn't found. DialogBoxFactory.GetInfoBox("Rejestracja anulowana!\n\nPracownik nie istnieje w Bazie.").Show(); break; case 1: // Triggers when exactly one record was found. RegisteredEmployee.RegisterNewEmployee(employees.First(), DB_RequestEmployeesOwnedKeys(employees.First())); break; default: // Triggers when there are mor than one matching record - 2nd step verification. idUserCode = UI_RequestId("Proszę podać numer identyfikacyjny Pracownika:"); // requesting an id parameter if (idUserCode == null) // User resigned from providing employee id. { DialogBoxFactory.GetInfoBox("Rejestracja anulowana!").Show(); return; } potentialEmployees = employees.Where(e => e.Employee_Id == idUserCode).ToList(); if (potentialEmployees.Count == 0) // User provided wrong employee id. { DialogBoxFactory.GetInfoBox($"Nie znaleziono pracownika: {potentialEmployees[0].Name} {potentialEmployees[0]} o numerze ID: {idUserCode}.").Show(); return; } else if (potentialEmployees.Count > 1) // That's a scary situation. Somehow 2 identical "unique" ids was found. Well... that should not happend :) Unless someone do something bad in data base. { DialogBoxFactory.GetInfoBox("Wykryto poważny błąd bazy Danych: Duplikacja numeru identyfikacyjnego pracownika. Skontaktuj się ze swoim Administratorem.").Show(); return; } else // User provided a correct Id number. { RegisteredEmployee.RegisterNewEmployee(potentialEmployees[0], DB_RequestEmployeesOwnedKeys(potentialEmployees[0])); } break; } RaisePropertyChangedEvent(nameof(RegisteredEmployee)); // Informing the view. }
// Method finding particular key specified by user: protected virtual void ShowSpecifiedKey() { DialogBoxFactory dialogFactory = new DialogBoxFactory(); RequestDialogBox dialogBox; RoomKey key; string id; // dialog box building part: dialogFactory.HeaderMessage = "Proszę podać numer szukanego klucza."; dialogFactory.RequestedParameters = new List <string>() { "Numer Identyfikacyjny" }; dialogFactory.DefaultValuesForRequestedParameters = new List <string>(); dialogFactory.CorrespondingRules = new List <ValidationRules> { ValidationRules.StringTyped4DigitCode }; dialogBox = dialogFactory.GetRequestDialogBox(); // dialog box handling part: if ((bool)dialogBox.ShowDialog()) { id = dialogBox[0]; } else { return; } // data access part try { key = _queryProvider.GetRoomKeyByIdAsync(id).Result; } catch (Exception e) { SendTabNotification(new TabNotificationSentEventArgs() { Message = e.Message }); return; } // data validation part: if (key == null) { DialogBoxFactory.GetInfoBox($"Brak wyników. Klucz o numerze: {id} nie istnieje w Bazie.").Show(); ResetKeysCollection(); } else { ResetKeysCollection(new List <RoomKey>() { key }); } ResetPresentedDetail(); }
// Handover room key procedure algorithm: protected virtual void HandoverTheKey() { RoomKey searchedKey; string requestedKeyId = UI_RequestId("Proszę podać numer klucza:"); // requesting an id parameter if (requestedKeyId == null) // Triggers when user cancels providing requested informations. { DialogBoxFactory.GetInfoBox("Procedura anulowana!").Show(); return; } try // potential exception handler { searchedKey = _dataQueryProvider.GetRoomKeyByIdAsync(requestedKeyId).Result; } catch (Exception e) { SendTabNotification(new TabNotificationSentEventArgs() { Message = e.Message }); return; } if (searchedKey == null) // Triggers when user provided wrong key id. { DialogBoxFactory.GetInfoBox("Klucz nie został odnaleziony w Bazie.").Show(); return; } else if (searchedKey.AssignedEmployee_Id != null) // Triggers when user provided id of key which was already handovered. { DialogBoxFactory.GetInfoBox("Klucz został już wydany innemu pracownikowi.").Show(); return; } else // Triggers when user provided correct key id and key was found on gatehouse. { try // potential exception handler { _dataCommandProvider.HandOverTheRoomKeyToEmployeeAsync(searchedKey, RegisteredEmployee.GetRegisteredEmployee()).Wait(); } catch (Exception e) { SendTabNotification(new TabNotificationSentEventArgs() { Message = e.Message }); return; } DialogBoxFactory.GetInfoBox("Wydano klucz!").Show(); // Handover key operation confirmation. } RegisteredEmployee.RefreshHeldKeys(DB_RequestEmployeesOwnedKeys(RegisteredEmployee.GetRegisteredEmployee())); // Refresh information about taken keys by registered employee. RaisePropertyChangedEvent(nameof(RegisteredEmployee)); // Informing the view. }
// Retrieving key algorithm: protected virtual void TakeTheKeyBack() { string requestedKeyId = UI_RequestId("Proszę podać numer klucza:"); // Requesting the retrieved key id number. if (requestedKeyId == null) // Triggers when user cancels providing requested informations. { DialogBoxFactory.GetInfoBox("Procedura anulowana!").Show(); return; } List <RoomKey> searchedKeys = RegisteredEmployee.HeldKeys.Where(hk => hk.RoomKey_Id == requestedKeyId).ToList(); if (searchedKeys.Count == 0) // Situation where provided key wasnt previously handovered to registered employee OR id doesn't exist in database. Any way the registered employee isn't allowed to return provided key. { DialogBoxFactory.GetInfoBox($"Pracownik nie jest uprawniony do zwrotu klucza nr:\n{requestedKeyId}").Show(); return; } else if (searchedKeys.Count == 1) // Everything it's ok and employee may return key. { try // potential exception handler { _dataCommandProvider.TakeTheRoomKeyAsync(searchedKeys[0]).Wait(); } catch (Exception e) { SendTabNotification(new TabNotificationSentEventArgs() { Message = e.Message }); return; } DialogBoxFactory.GetInfoBox("Przyjęto klucz!").Show(); // Returning key fact confirmation. } else // That's a scary situation. Somehow 2 identical "unique" ids was found. Well... that should not happend :) Better call dBase Admin. { DialogBoxFactory.GetInfoBox("Wykryto poważny błąd bazy Danych: Duplikacja numeru identyfikacyjnego klucza. Skontaktuj się ze swoim Administratorem.").Show(); return; } RegisteredEmployee.RefreshHeldKeys(DB_RequestEmployeesOwnedKeys(RegisteredEmployee.GetRegisteredEmployee())); // Refresh information about taken keys by registered employee. RaisePropertyChangedEvent(nameof(RegisteredEmployee)); // Informing the view. }
// Because of fact that id numbers are considered as unique, and a fact that implemented shallow validation doesn't allow for save/update record with redundant id. This algorithm returns first unused id number to use in CU operations. protected virtual string GenerateFirstAvailable4DigitCode() { List <int> rawIds = _records.Select(r => r.GetIdNumber()).OrderBy(i => i).ToList(); string code = "EORE"; int counter = 0; for (int i = 0; i < 10000; i++) { if (counter < rawIds.Count && i == rawIds[counter]) { counter++; } else { code = i.ConvertToFourDigitStringCode(); break; } } DialogBoxFactory.GetInfoBox("Błąd Krytyczny:\nPrzekroczono limit bazy danych. Skontaktuj się ze swoim Administratorem."); // that will happen if you try to overload a data base and save to it 10000 records and then add a one more :) return(code); }
// Method showing only keys that remain on the gatehouse: protected virtual void ShowRemainingRoomKeys() { IEnumerable <RoomKey> results; try { results = _queryProvider.GetAvailableRoomKeysAsync().Result; } catch (Exception e) { SendTabNotification(new TabNotificationSentEventArgs() { Message = e.Message }); return; } if (results.Count() == 0) { DialogBoxFactory.GetInfoBox("Kolekcja jest pusta. Wszystkie klucze zostały wydane.").Show(); } ResetKeysCollection(results); ResetPresentedDetail(); }
// Method showing only currently handovered keys: protected virtual void ShowHandoveredRoomKeys() { IEnumerable <RoomKey> results; try { results = _queryProvider.GetHandoveredRoomKeysAsync().Result; } catch (Exception e) { SendTabNotification(new TabNotificationSentEventArgs() { Message = e.Message }); return; } if (results.Count() == 0) { DialogBoxFactory.GetInfoBox("Kolekcja jest pusta. Nie wydano żadnego klucza.").Show(); } ResetKeysCollection(results); ResetPresentedDetail(); }
// Method showing all keys in data base: protected virtual void ShowAllRoomKeys() { IEnumerable <RoomKey> results; try { results = _queryProvider.GetAllRoomKeysAsync().Result; } catch (Exception e) { SendTabNotification(new TabNotificationSentEventArgs() { Message = e.Message }); return; } if (results.Count() == 0) { DialogBoxFactory.GetInfoBox("Kolekcja jest pusta. Proszę skontaktować się z Administratorem bazy danych.").Show(); } ResetKeysCollection(results); ResetPresentedDetail(); }