コード例 #1
0
        private void btnBuscar_Click(object sender, RoutedEventArgs e)
        {
            string patente = txtPatente.Text;

            //Check whether a TextBox is empty or not
            //Trim(): remove blank spaces from left and right
            if (patente.Trim() == "")
            {
                MessageBox.Show("Se debe ingresar una patente");
                return;
            }

            //if not empty then:
            Automovil auto = _coleccion.BuscarAutomovil(patente);

            //if car doesn't exist in the collection, then:
            if (auto == null)
            {
                MessageBox.Show("No se ha encontrado la patente");
                return;
            }

            //if car exists in the collection, then we pass car's attributes
            //to the form fields (MainWindows)

            cboMarca.SelectedIndex = (int)auto.Marca;
            txtModelo.Text         = auto.Modelo;
            txtAnio.Text           = auto.Anio.ToString();
            chkNuevo.IsChecked     = auto.Nuevo;

            if (auto.Transmision == Transmisiones.Automatica)
            {
                rbtAutomatica.IsChecked = true;
            }
            else
            {
                rbtMecanica.IsChecked = true;
            }
        }