示例#1
0
        private void btnAceptar_Click(object sender, EventArgs e)
        {
            bool error = false;

            if (txtCiudadOrigen.Text == "")
            {
                error = true;
            }

            if (txtCiudadDestino.Text == "")
            {
                error = true;
            }

            if (txtSeleccionarVehiculo.Text == "")
            {
                error = true;
            }

            if (dtpFechaViaje.Value <= DateTime.Today)
            {
                error = true;
            }

            if (cbxCantidadPasajeros.SelectedIndex == -1)
            {
                error = true;
            }

            if (cbxTipoVehiculo.SelectedIndex == -1)
            {
                error = true;
            }
            else if (cbxCantidadPasajeros.SelectedIndex != -1)
            {
                int cantPas = Convert.ToInt16(cbxCantidadPasajeros.Text);

                if ((cbxTipoVehiculo.SelectedIndex == 0) && (cantPas < 10))
                {
                    error = true;
                }

                if (cbxTipoVehiculo.SelectedIndex == 1)
                {
                    if (cantPas > 5)
                    {
                        error = true;
                    }

                    if (mskCantidadKm.Text == "")
                    {
                        error = true;
                    }
                }
                if ((cbxTipoVehiculo.SelectedIndex == 2) && (cantPas > 50))
                {
                    error = true;
                }
            }

            if (error)
            {
                MessageBox.Show("Hay campos incerrectos o sin completar.", "Advertencia", MessageBoxButtons.OK);
            }
            else
            {
                string   origen  = txtCiudadOrigen.Text;
                string   detino  = txtCiudadDestino.Text;
                DateTime fecha   = dtpFechaViaje.Value;
                int      cantPas = Convert.ToInt16(cbxCantidadPasajeros.Text);
                int      id      = Convert.ToInt16(txtSeleccionarVehiculo.Text);
                tipo = cbxTipoVehiculo.SelectedIndex;
                string tipoVh    = ((tipo == 0) ? "Avión" : (tipo == 1) ? "Auto" : "Colectivo");
                int    cantPasKm = cantPas;

                if (tipo == 1)
                {
                    cantPasKm = Convert.ToInt16(mskCantidadKm.Text);
                }

                float costo = CalcularCostoTotal(tipo, id, cantPasKm);
                Viaje = new Viaje(origen, detino, fecha, cantPas, id, tipoVh, costo);
                MessageBox.Show("Viaje registrado correctamente: el costo total es $" + costo, "Información", MessageBoxButtons.OK);

                estado = true;
                ActiveForm.Close();
            }
        }