//Boton para realizar la accion de eliminar un Transporte. private void btnEliminarTransporte_Click(object sender, RoutedEventArgs e) { try { if (string.IsNullOrEmpty(txtIdServicio.Text)) { MessageBox.Show("Debe seleccionar un campo de las tablas."); } else { trc = new TransporteCollection(); trc.EliminaTransporteC(int.Parse(txtIdServicio.Text)); txtIdServicio.Text = string.Empty; txt1.Text = string.Empty; txt2.Text = string.Empty; lblmensaje.Content = "Eliminado!"; Limpiar(); datosTransporte(); } } catch (Exception ex) { MessageBox.Show("Ha ocurrido un error, contacte al administrador: " + ex.Message, "Excepción detectada", MessageBoxButton.OK, MessageBoxImage.Warning); } }
//Metodo para mostrar los datos de Transporte. private void datosTransporte() { TransporteCollection transc = new TransporteCollection(); dtgTransporte.ItemsSource = transc.ListaTransporteC().DefaultView; dtgTransporte.Items.Refresh(); }
//Boton para realizar la accion de ingresar datos de Transporte. private void btnRegistrarTransporte_Click(object sender, RoutedEventArgs e) { try { if (cbxIdServicioTransporte.SelectedIndex == -1) { MessageBox.Show("Debe seleccionar un servicio."); } else if (string.IsNullOrEmpty(txtNombreConductor.Text) || txtNombreConductor.Text.Length < 3 && txtNombreConductor.Text.Length > 100) { MessageBox.Show("Nombre no debe estar vacío y tiene que estar entre 3 a 100 carácteres."); } else if (string.IsNullOrEmpty(txtPatente.Text) || txtPatente.Text.Length >= 9) { MessageBox.Show("El campo patente no debe estar vacío y ser mayor a 8 carácteres."); } else if (!Regex.IsMatch(txtPatente.Text, "^[a-zA-Z]{2}[-][a-zA-Z]{2}[-][0-9]{2}$")) { MessageBox.Show("El campo patente debe tener formato AA-AA-99."); } else { trc = new TransporteCollection(); int id_servicio = int.Parse(cbxIdServicioTransporte.SelectedValue.ToString()); string nombreConductor = txtNombreConductor.Text; string patente = txtPatente.Text; var insercion = trc.InsertaTransporteC(nombreConductor, patente, id_servicio); if (insercion == true) { this.Close(); } else { lblmensaje.Content = "Error de inserción."; } } } catch (Exception ex) { MessageBox.Show("Ha ocurrido un error, contacte al administrador: " + ex.Message, "Excepción detectada", MessageBoxButton.OK, MessageBoxImage.Warning); } }
//Boton para realizar la accion de actualizar datos de Transporte. private void btnActualizarTransporte_Click(object sender, RoutedEventArgs e) { try { if (string.IsNullOrEmpty(txtIdServicio.Text)) { MessageBox.Show("Debe seleccionar un campo de las tablas."); } else if (string.IsNullOrEmpty(txt1.Text) || txt1.Text.Length < 3 && txt1.Text.Length > 100) { MessageBox.Show("Nombre no debe estar vacío y tiene que estar entre 3 a 100 carácteres."); } else if (string.IsNullOrEmpty(txt2.Text) || txt2.Text.Length >= 9) { MessageBox.Show("El campo patente no debe estar vacío y ser mayor a 8 carácteres."); } else if (!Regex.IsMatch(txt2.Text, "^[a-zA-Z]{2}[-][a-zA-Z]{2}[-][0-9]{2}$")) { MessageBox.Show("El campo patente debe tener formato AA-AA-99."); } else { trc = new TransporteCollection(); trc.ActualizaTransporteC(int.Parse(txtIdServicio.Text), txt1.Text, txt2.Text); lblmensaje.Content = "Actualización correcta!"; Limpiar(); datosTransporte(); } } catch (Exception ex) { MessageBox.Show("Ha ocurrido un error, contacte al administrador: " + ex.Message, "Excepción detectada", MessageBoxButton.OK, MessageBoxImage.Warning); } }