Ejemplo n.º 1
0
        // Retreieving id information from user.
        private string UI_RequestId(string message)
        {
            DialogBoxFactory dialogFactory = new DialogBoxFactory();
            RequestDialogBox dialogBox;
            string           id;

            // dialog box building part:
            dialogFactory.HeaderMessage       = message;
            dialogFactory.RequestedParameters = new List <string>()
            {
                "Numer Identyfikacyjny"
            };
            dialogFactory.DefaultValuesForRequestedParameters = new List <string>();
            dialogFactory.CorrespondingRules = new List <ValidationRules> {
                ValidationRules.StringTyped4DigitCode
            };

            dialogBox = dialogFactory.GetRequestDialogBox();
            // dialog handling:
            if ((bool)dialogBox.ShowDialog())
            {
                id = dialogBox[0];
            }
            else
            {
                return(null);
            }

            return(id);
        }
Ejemplo n.º 2
0
        //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.
        }
Ejemplo n.º 3
0
        // 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();
        }
Ejemplo n.º 4
0
        // 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.
        }
Ejemplo n.º 5
0
        protected virtual void ConfigureConnection() // Method building a request dialog box, with presented actual connection string parameters, and allows for their independent change.
        {
            string currentConnectionString = ConnectionSetting.GetCurrentConnectionString();

            string[]      connectionStringRawParams = currentConnectionString.Split(';');
            List <string> connectionStringParams    = new List <string>();

            foreach (string rawParam in connectionStringRawParams)
            {
                string param = rawParam.Substring(rawParam.IndexOf('=') + 1);
                connectionStringParams.Add(param);
            }

            DialogBoxFactory dialogBoxFactory = new DialogBoxFactory();

            dialogBoxFactory.HeaderMessage       = "Ustawienia połączenia z bazą danych:";
            dialogBoxFactory.RequestedParameters = new List <string>()
            {
                "Nazwa/Adres Serwera", "Nazwa Bazy Danych", "Login", "Hasło"
            };
            dialogBoxFactory.DefaultValuesForRequestedParameters = connectionStringParams;
            dialogBoxFactory.CorrespondingRules = new List <ValidationRules>();

            RequestDialogBox dialogBox = dialogBoxFactory.GetRequestDialogBox();

            if ((bool)dialogBox.ShowDialog())
            {
                ConnectionSetting.SetNewConnectionString(dialogBox[0], dialogBox[1], dialogBox[2], dialogBox[3]);
                if (ConnectionSetting.TestDatabaseExistance())
                {
                    ReportStatus("Konfiguracja połączenia zakończona sukcesem.");
                }
                else
                {
                    ReportStatus("Błąd konfiguracji. Nie odnaleziono bazy danych.");
                }
            }
            else
            {
                ReportStatus("Konfiguracja połączenia anulowana.");
            }
        }
Ejemplo n.º 6
0
        // Retrieving initial informations from user.
        private IEnumerable <Employee> UI_RequestEmployeeNames()
        {
            DialogBoxFactory dialogFactory = new DialogBoxFactory();
            RequestDialogBox dialogBox;
            string           name, surname;

            IEnumerable <Employee> employees;

            // dialog box building part:
            dialogFactory.HeaderMessage       = "Proszę podać Imię i Nazwisko:";
            dialogFactory.RequestedParameters = new List <string>()
            {
                "Imię", "Nazwisko"
            };
            dialogFactory.DefaultValuesForRequestedParameters = new List <string>();
            dialogFactory.CorrespondingRules = new List <ValidationRules>();

            dialogBox = dialogFactory.GetRequestDialogBox();
            // dialog handling:
            if ((bool)dialogBox.ShowDialog())
            {
                name    = dialogBox[0];
                surname = dialogBox[1];
            }
            else
            {
                return(null);
            }
            // data access part:
            try
            {
                return(employees = _dataQueryProvider.GetEmployeesByNamesAsync(name, surname).Result);
            }
            catch (Exception e)
            {
                SendTabNotification(new TabNotificationSentEventArgs()
                {
                    Message = e.Message
                });
                return(new List <Employee>());
            }
        }
Ejemplo n.º 7
0
        // 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.
        }
Ejemplo n.º 8
0
        // 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);
        }
Ejemplo n.º 9
0
        // 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();
        }
Ejemplo n.º 10
0
        // 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();
        }
Ejemplo n.º 11
0
        // 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();
        }