示例#1
0
        private void sinChoferToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Agregar_Vehiculo agregar = new Agregar_Vehiculo();

            try
            {
                agregar.Size = new Size(816, 370);
                agregar.btnCargar.Location = new Point(657, 296);
                agregar.btnSalir.Location  = new Point(59, 300);
                if (agregar.ShowDialog() == DialogResult.OK)
                {
                    bool disponible = true, chofer = false;


                    string patente       = agregar.tbPatente.Text;
                    string marca         = agregar.tbMarca.Text;
                    string modelo        = agregar.tbModelo.Text;
                    string combustible   = agregar.tbtipoCombustible.Text;
                    int    capacidad     = Convert.ToInt32(agregar.tbCapacidad.Text);
                    string path          = agregar.path;
                    int    unidadDeCobro = Convert.ToInt32(agregar.tbUnidadDeCobro.Text);
                    int    kms           = Convert.ToInt32(agregar.tbKilometros.Text);

                    foreach (Vehículo v in SinChof)
                    {
                        if (v.Patente == patente)
                        {
                            throw new ApplicationException("La Patente Ya Existe!");
                        }
                    }
                    foreach (Vehículo v in ConChof)
                    {
                        if (v.Patente == patente)
                        {
                            throw new ApplicationException("La Patente Ya Existe!");
                        }
                    }
                    vehículo = new Vehículo(disponible, chofer, patente, marca, modelo, combustible, path, capacidad, unidadDeCobro, kms);



                    administracion.agregarVehiculo(vehículo);
                    administracion.GetVehículos().Sort();
                    SinChof.Clear();
                    SinChof.AddRange(administracion.GetVehículos());

                    ActualizarListboxs();
                }
            }

            catch (FormatException ex)
            {
                MessageBox.Show(ex.Message);
            }
            catch (ApplicationException er) { MessageBox.Show(er.Message); }
        }
示例#2
0
        private void conChoferToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Agregar_Vehiculo agregar = new Agregar_Vehiculo();

            try
            {
                agregar.Size = new Size(816, 706);
                agregar.btnCargar.Location = new Point(565, 636);
                agregar.btnSalir.Location  = new Point(35, 641);

                if (agregar.ShowDialog() == DialogResult.OK)
                {
                    bool disponible = true, chofer = true;


                    string patente       = agregar.tbPatente.Text;
                    string marca         = agregar.tbMarca.Text;
                    string modelo        = agregar.tbModelo.Text;
                    string combustible   = agregar.tbtipoCombustible.Text;
                    int    capacidad     = Convert.ToInt32(agregar.tbCapacidad.Text);
                    string path          = agregar.path;
                    int    unidadDeCobro = Convert.ToInt32(agregar.tbUnidadDeCobro.Text);
                    int    kms           = Convert.ToInt32(agregar.tbKilometros.Text);

                    foreach (Vehículo v in SinChof)
                    {
                        if (v.Patente == patente)
                        {
                            throw new ApplicationException("La Patente Ya Existe!");
                        }
                    }
                    foreach (Vehículo v in ConChof)
                    {
                        if (v.Patente == patente)
                        {
                            throw new ApplicationException("La Patente Ya Existe!");
                        }
                    }

                    string   nombre       = agregar.tbNombreChofer.Text;
                    int      Dni          = Convert.ToInt32(agregar.tbDniChofer.Text);
                    long     cuil         = Convert.ToInt64(agregar.tbCuit.Text);
                    string   dir          = agregar.tbDireccion.Text;
                    int      tel          = Convert.ToInt32(agregar.tbTelefono.Text);
                    DateTime fechanac     = agregar.dtpFechaNac.Value;
                    string   estadocivil  = agregar.tbEstadoCivil.Text;
                    string   nacionalidad = agregar.tbNacionalidad.Text;
                    long     carnet       = Convert.ToInt64(agregar.tbCarnet.Text);

                    foreach (Vehículo c in administracion.GetVehiculosConChofer())
                    {
                        if (((VehículoConChofer)c).UnChofer.Cuit == cuil)
                        {
                            throw new ApplicationException("El Cuit: " + cuil + " Ya Existe!");
                        }
                        if (((VehículoConChofer)c).UnChofer.Dni == Dni)
                        {
                            throw new ApplicationException("El DNI: " + Dni + " Ya Existe!");
                        }
                        if (((Chofer)((VehículoConChofer)c).UnChofer).Carnet == carnet)
                        {
                            throw new ApplicationException("El Carnet: " + carnet + " Ya Existe!");
                        }
                    }


                    persona = new Chofer(nombre, Dni, cuil, dir, tel, fechanac, estadocivil, nacionalidad, carnet);
                    ((Chofer)persona).GrabarCSV(nombreArchivoChoferes);
                    vehículo = new VehículoConChofer(disponible, chofer, patente, marca, modelo, combustible, path, capacidad, persona, unidadDeCobro, kms);


                    administracion.agregarVehiculo(vehículo);
                    administracion.GetVehiculosConChofer().Sort();
                    ConChof.Clear();
                    ConChof.AddRange(administracion.GetVehiculosConChofer());

                    ActualizarListboxs();
                }
            }
            catch (FormatException er)
            {
                MessageBox.Show(er.Message);
            }

            catch (OverflowException er) { MessageBox.Show(er.Message); }
            catch (ApplicationException er) { MessageBox.Show(er.Message); }
        }