private void bttnAdd_Click(object sender, EventArgs e)
        {
            try
            {
                Garage garage = new Garage();
                Vehicle vehicle = new Vehicle();
                TypeVehicle typeVehicle = new TypeVehicle();

                garage.Number = Convert.ToInt16(lblNumber.Text);
                garage.Ubication = lblUbication.Text;
                garage.State = false;
           
                vehicle.Domain = maskDomain.Text;
                vehicle.Brand = txtBrand.Text;
                vehicle.Model = txtModel.Text;
                garage.Vehicle = vehicle;

                switch (cmbTypeOfVehicle.SelectedIndex)
                {
                    case 0:
                        {
                            typeVehicle.Code = "1";
                            typeVehicle.Description = cmbTypeOfVehicle.SelectedItem.ToString();
                            break;
                        }
                    case 1:
                        {
                            typeVehicle.Code = "2";
                            typeVehicle.Description = cmbTypeOfVehicle.SelectedItem.ToString();
                            break;
                        }
                    case 2:
                        {
                            typeVehicle.Code = "3";
                            typeVehicle.Description = cmbTypeOfVehicle.SelectedItem.ToString();
                            break;
                        }
                }

                garage.Vehicle.TypeVehicle = typeVehicle;

            if (rentalCollection.IfDomainExists(maskDomain.Text))
            {
                MessageBox.Show("This domain already exists.");
            }
            else
            {
                if (radBttnHour.Checked == true)
                {
                    RentalHour rentalHour = new RentalHour();

                    rentalHour.Date = DateTime.Now;
                    rentalHour.Garage = garage;
                    rentalHour.Since = DateTime.Now;
                    rentalCollection.Add(rentalHour);
                    xmlRentals.GenerateXMLRentals(rentalCollection.GetAll());
                    clickedBttn.Text = clickedBttn.Text + " HOUR\n" + garage.Vehicle.TypeVehicle.Description + " \n" + garage.Vehicle.Domain;
                }
                else
                {
                    RentalMonth rentalMonth = new RentalMonth();
                    Movement movement = new Movement();

                    rentalMonth.Date = DateTime.Now;
                    rentalMonth.Garage = garage;
                    rentalMonth.Holder = txtOwner.Text;
                    rentalMonth.DueDate = rentalMonth.Date.AddMonths(Convert.ToInt16(numMonth.Value));
                    rentalCollection.Add(rentalMonth);
                    xmlRentals.GenerateXMLRentals(rentalCollection.GetAll());
                    movement.Concept = "MONTH: " + garage.Vehicle.TypeVehicle.Description + " " + garage.Vehicle.Domain;
                    movement.Amount = rentalMonth.CalculateAmount();
                    movement.Date = DateTime.Now;
                    movement.ItsIncome = true;
                    movement.User = user;
                    movement.CashCount = null;
                    movementCollection.Add(movement);
                    xmlMovements.GenerateXMLMovements(movementCollection.GetAll());
                    MessageBox.Show("You have to charge " + movement.Amount + " to your client.");
                    clickedBttn.Text = clickedBttn.Text + " MONTH\n" + garage.Vehicle.TypeVehicle.Description + " \n" + garage.Vehicle.Domain;
                }

                garageCollection.Add(garage);

                clickedBttn.BackColor = Color.Red;
                Close();
            }
        }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
}
예제 #2
0
        private void FormMenu_Load(object sender, EventArgs e)
        {
            try
            {
                cashCountCollection.AddCashCountList(xmlCashCounts.GetCashCounts());
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            xmlCashCounts.GenerateXMLCashCounts(cashCountCollection.GetAll());

            try
            {
                rentalCollection.AddRentalsList(xmlRentals.GetRentals());
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            xmlRentals.GenerateXMLRentals(rentalCollection.GetAll());

            try
            {
                movementCollection.AddMovementsList(xmlMovements.GetMovements());
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            xmlMovements.GenerateXMLMovements(movementCollection.GetAll());

            int amountAlerts = 0;

            BindData();
            DataGridViewColumn Column = dgvIncomes.Columns[3];

            Column.Visible = false;
            Column         = dgvOutcomes.Columns[3];
            Column.Visible = false;



            try
            {
                foreach (Rental rental in xmlRentals.GetRentals())
                {
                    if (rental.Garage.State == false)
                    {
                        garageCollection.Add(rental.Garage);
                        if (rental is RentalMonth)
                        {
                            RentalMonth rentalMonth = (RentalMonth)rental;
                            TimeSpan    dateAux     = rentalMonth.DueDate - DateTime.Today;
                            if (dateAux.TotalDays <= 5)
                            {
                                alerts.Add(rentalMonth);
                                amountAlerts = amountAlerts + 1;
                            }
                        }
                    }
                }

                foreach (Button button in groupGarages.Controls)
                {
                    Rental rental = rentalCollection.SearchRentByNumber(Convert.ToInt16(button.Text));

                    if (rental != null)
                    {
                        if (rental.Garage.State == false)
                        {
                            button.BackColor = Color.Red;
                            if (rental is RentalHour)
                            {
                                button.Text = button.Text + " HOUR\n" + rental.Garage.Vehicle.TypeVehicle.Description + " \n" + rental.Garage.Vehicle.Domain;
                            }
                            else
                            {
                                button.Text = button.Text + " MONTH\n" + rental.Garage.Vehicle.TypeVehicle.Description + " \n" + rental.Garage.Vehicle.Domain;
                            }
                            rental = null;
                        }
                    }
                }

                if (amountAlerts > 0)
                {
                    MessageBox.Show("¡ " + amountAlerts + " alquileres a punto de terminar! Revisar ¡Alertas! para más información.");
                }
            }
            catch
            {
                MessageBox.Show("¡Error cargando cocheras. Avisar a administrador! (Error 001 - XML)");
            }
        }