Exemplo n.º 1
0
        private void handleAddApartment()
        {
            /// <summary>
            /// Handler for add appartment operation
            /// </summary>

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

            errorMessage.AddRange(modelValidator.validateApartment(noApartmentTextbox, surfaceTextbox));

            try {
                if (errorMessage.Count != 0)
                {
                    throw new ArgumentException();
                }
                int noApartment = Convert.ToInt32(noApartmentTextbox.Text);
                int surface     = Convert.ToInt32(surfaceTextbox.Text);
                this.service.addApartment(noApartment, "fara", 0, surface);

                errorMessageLabel.Text      = "Apartamentul a fost adaugat.";
                errorMessageLabel.ForeColor = Color.DarkGreen;
            } catch (ArgumentException) {
                errorMessageLabel.Text      = "";
                errorMessageLabel.ForeColor = Color.DarkRed;
                foreach (String error in errorMessage)
                {
                    errorMessageLabel.Text += error;
                }
            };
        }
Exemplo n.º 2
0
        private void handleModifyApartment()
        {
            /// <summary>
            /// Handler for apartment modify
            /// </summary>

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

            errorMessage.AddRange(modelValidator.validateApartment(apartmentsGridView, modifyApartmentGrid));

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

                int    oldNoApartment = Convert.ToInt32(apartmentsGridView.Rows[index].Cells[0].Value.ToString());
                String oldOwner       = apartmentsGridView.Rows[index].Cells[1].Value.ToString();
                int    oldNoResidents = Convert.ToInt32(apartmentsGridView.Rows[index].Cells[2].Value.ToString());
                int    oldSurface     = Convert.ToInt32(apartmentsGridView.Rows[index].Cells[3].Value.ToString());

                int    newNoApartment = Convert.ToInt32(modifyApartmentGrid.Rows[0].Cells[0].Value.ToString());
                String newOwner       = modifyApartmentGrid.Rows[0].Cells[1].Value.ToString();
                int    newNoResidents = Convert.ToInt32(modifyApartmentGrid.Rows[0].Cells[2].Value.ToString());
                int    newSurface     = Convert.ToInt32(modifyApartmentGrid.Rows[0].Cells[3].Value.ToString());

                Apartment oldApartment = new Apartment(oldNoApartment, oldOwner, oldNoResidents, oldSurface);
                Apartment newApartment = new Apartment(newNoApartment, newOwner, newNoResidents, newSurface);

                this.service.updateApartment(oldApartment, newApartment);

                errorMessageLabel.Text      = "Apartamentul a fost modificat.";
                errorMessageLabel.ForeColor = Color.DarkGreen;
            } catch (AggregateException) {
                errorMessageLabel.Text      = "";
                errorMessageLabel.ForeColor = Color.DarkRed;
                foreach (String error in errorMessage)
                {
                    errorMessageLabel.Text += error;
                }
            }
        }