private void bttnEnd_Click(object sender, EventArgs e)
        {
            try
            {
                if (clickedBttn.Text.Substring(2, 5) == "MONTH" || clickedBttn.Text.Substring(3, 5) == "MONTH")
                {
                    clickedBttn.BackColor = Color.Chartreuse;
                    clickedBttn.Text = lblNumber.Text;
                    rentalCollection.SearchRentByNumber(Convert.ToInt16(lblNumber.Text)).Garage.State = true;
                    xmlRentals.GenerateXMLRentals(rentalCollection.GetAll());
                    Close();
                }
                else if (clickedBttn.Text.Substring(2, 4) == "HOUR" || clickedBttn.Text.Substring(3, 4) == "HOUR")
                {
                    Movement movement = new Movement();
                    Garage auxGarage = new Garage();

                    auxGarage = rentalCollection.SearchRentByNumber(Convert.ToInt16(lblNumber.Text)).Garage;

                    clickedBttn.BackColor = Color.Chartreuse;
                    clickedBttn.Text = lblNumber.Text;

                    rentalCollection.SearchRentByNumber(Convert.ToInt16(lblNumber.Text)).Garage.State = true;
                    xmlRentals.GenerateXMLRentals(rentalCollection.GetAll());
                    movement.Amount = rentalCollection.SearchRentByNumber(Convert.ToInt16(lblNumber.Text)).CalculateAmount();
                    movement.Concept = "HOUR: " + auxGarage.Vehicle.TypeVehicle.Description + " " + auxGarage.Vehicle.Domain;
                    movement.Date = DateTime.Now;
                    movement.ItsIncome = true;
                    movement.User = user;
                    movement.CashCount = null;
                    movementCollection.Add(movement);
                    xmlMovements.GenerateXMLMovements(movementCollection.GetAll());
                    garageCollection.Remove(garageCollection.SearchByNumber(Convert.ToInt16(lblNumber.Text)));
                    MessageBox.Show("You have to charge " + movement.Amount + " to your client.");
                    Close();
                }
                garageCollection.Remove(garageCollection.SearchByNumber(Convert.ToInt16(lblNumber.Text)));
            }
            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)");
            }
        }