예제 #1
0
        private void handleAddPerson()
        {
            /// <summary>
            /// Handler for add person operation
            /// </summary>

            ModelValidator modelValidator = new ModelValidator(this.service);
            List <String>  errorMessage   = new List <String>();

            errorMessage.AddRange(modelValidator.validatePerson(personForenameTextbox, personSurnameTextbox, noApartmentTextbox, birthdateDatePicker, jobTextbox));

            try {
                if (errorMessage.Count != 0)
                {
                    throw new ArgumentException();
                }
                String surname     = personSurnameTextbox.Text;
                String forename    = personForenameTextbox.Text;
                int    noApartment = Convert.ToInt32(noApartmentTextbox.Text);
                String birthdate   = birthdateDatePicker.Value.ToString("dd/MM/yyyy");
                String job         = jobTextbox.Text;
                this.service.addPerson(forename, surname, noApartment, birthdate, job);

                errorLabel.Text      = "Persoana a fost adaugata.";
                errorLabel.ForeColor = Color.DarkGreen;
            } catch (ArgumentException) {
                errorLabel.Text      = "";
                errorLabel.ForeColor = Color.DarkRed;
                foreach (String error in errorMessage)
                {
                    errorLabel.Text += error;
                }
            };
        }
예제 #2
0
        private void handleModifyPerson()
        {
            /// <summary>
            /// Handler for person modify
            /// </summary>

            ModelValidator modelValidator = new ModelValidator(this.service);
            List <String>  errorMessage   = new List <String>();

            errorMessage.AddRange(modelValidator.validatePerson(searchedPersonGrid, modifyPersonGrid));

            try {
                if (errorMessage.Count != 0)
                {
                    throw new ArgumentException();
                }
                int index = searchedPersonGrid.CurrentCell.RowIndex;

                String oldSurname     = searchedPersonGrid.Rows[index].Cells[0].Value.ToString();
                String oldForename    = searchedPersonGrid.Rows[index].Cells[1].Value.ToString();
                int    oldNoApartment = Convert.ToInt32(searchedPersonGrid.Rows[index].Cells[2].Value.ToString());
                String oldBirthdate   = searchedPersonGrid.Rows[index].Cells[3].Value.ToString();
                String oldJob         = searchedPersonGrid.Rows[index].Cells[4].Value.ToString();

                String newSurname     = modifyPersonGrid.Rows[0].Cells[0].Value.ToString();
                String newForename    = modifyPersonGrid.Rows[0].Cells[1].Value.ToString();
                int    newNoApartment = Convert.ToInt32(modifyPersonGrid.Rows[0].Cells[2].Value.ToString());
                String newBirthdate   = modifyPersonGrid.Rows[0].Cells[3].Value.ToString();
                String newJob         = modifyPersonGrid.Rows[0].Cells[4].Value.ToString();

                Person oldPerson = new Person(oldForename, oldSurname, oldNoApartment, oldBirthdate, oldJob);
                Person newPerson = new Person(newForename, newSurname, newNoApartment, newBirthdate, newJob);

                this.service.updatePerson(oldPerson, newPerson);

                errorMessageLabel.Text      = "Persoana a fost modificata.";
                errorMessageLabel.ForeColor = Color.DarkGreen;
            } catch (ArgumentException) {
                errorMessageLabel.Text      = "";
                errorMessageLabel.ForeColor = Color.DarkRed;
                foreach (String error in errorMessage)
                {
                    errorMessageLabel.Text += error;
                }
            } catch (Exception) {
                errorMessageLabel.Text      = "Alegeti persoana de modificat.";
                errorMessageLabel.ForeColor = Color.DarkRed;
            }
        }