private void CargaEstado(int idEstadoCivil) { EstadoCivil estado = new EstadoCivil(); estado.Id = idEstadoCivil; if (!estado.Read()) { throw new Exception("Error al leer estado."); } cboEstado.SelectedIndex = estado.Id - 1; }
private void btnActualiza_Click(object sender, RoutedEventArgs e) { try { if (ValidaDatosCliente()) { Cliente cliente = new Cliente() { Rut = txtRut.Text, Nombres = txtNombres.Text, Apellidos = txtApellidos.Text, FechaNacimiento = (DateTime)FechaNacimiento.SelectedDate }; Sexo sexo = new Sexo(); sexo.Id = cboSexo.SelectedIndex + 1; if (sexo.Read()) { cliente.Sexo = sexo; } else { throw new Exception("Sexo Invalido."); } EstadoCivil estado = new EstadoCivil(); estado.Id = cboEstado.SelectedIndex + 1; if (estado.Read()) { cliente.EstadoCivil = estado; } else { throw new Exception("Estado Invalido."); } if (cliente.Update()) { MessageBox.Show("Cliente actualizado", "Información", MessageBoxButton.OK, MessageBoxImage.Information); LimpiaDatos(); } } } catch (Exception ex) { MessageBox.Show(ex.Message, "Atención", MessageBoxButton.OK, MessageBoxImage.Exclamation); } }
/// <summary> /// Agrega un Cliente en la BD /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void BtnAgregar_Click(object sender, RoutedEventArgs e) { try { if (ValidaDatosCliente()) { Cliente cliente = new Cliente() { Rut = TxtRut.Text, Nombres = TxtNombres.Text, Apellidos = TxtApellidos.Text, FechaNacimiento = (DateTime)FechaNacimiento.SelectedDate }; Sexo sexo = new Sexo(); sexo.Id = CboSexo.SelectedIndex + 1; if (sexo.Read()) { cliente.Sexo = sexo; } EstadoCivil estado = new EstadoCivil(); estado.Id = CboEstadoCivil.SelectedIndex + 1; if (estado.Read()) { cliente.EstadoCivil = estado; } if (cliente.Create()) { MessageBox.Show("Cliente agregado", "Información", MessageBoxButton.OK, MessageBoxImage.Information); LimpiaDatos(); } else { MessageBox.Show("El Cliente no se pudo agregar", "Atención", MessageBoxButton.OK, MessageBoxImage.Exclamation); } } } catch (Exception ex) { MessageBox.Show(ex.Message, "Atención", MessageBoxButton.OK, MessageBoxImage.Exclamation); } }
private void btnFiltrar_Click(object sender, RoutedEventArgs e) { try { //Lee los controles de la interfaz. string rut = txtRut.Text; Sexo sexo = new Sexo(); sexo.Id = cboSexo.SelectedIndex + 1; EstadoCivil estado = new EstadoCivil(); estado.Id = cboEstado.SelectedIndex + 1; Cliente cliente = new Cliente(); //Solo Rut if (String.IsNullOrEmpty(rut) == false && !sexo.Read() && !estado.Read()) { grdClientes.ItemsSource = cliente.ReadAll(rut); } //Solo Sexo if (String.IsNullOrEmpty(rut) != false && sexo.Read() && !estado.Read()) { grdClientes.ItemsSource = cliente.ReadAllBySexo(sexo.Id); } //Solo Estado if (String.IsNullOrEmpty(rut) != false && !sexo.Read() && estado.Read()) { grdClientes.ItemsSource = cliente.ReadAllByEstadoCivil(estado.Id); } //Rut y Sexo if (String.IsNullOrEmpty(rut) == false && sexo.Read() && !estado.Read()) { grdClientes.ItemsSource = cliente.ReadAllRutSexo(rut, sexo.Id); } //Rut y Estado if (String.IsNullOrEmpty(rut) == false && !sexo.Read() && estado.Read()) { grdClientes.ItemsSource = cliente.ReadAllRutEstado(rut, estado.Id); } //Sexo y Estado if (String.IsNullOrEmpty(rut) != false && sexo.Read() && estado.Read()) { grdClientes.ItemsSource = cliente.ReadAll(sexo.Id, estado.Id); } //Rut, Sexo y Estado if (String.IsNullOrEmpty(rut) == false && sexo.Read() && estado.Read()) { grdClientes.ItemsSource = cliente.ReadAll(rut, sexo.Id, estado.Id); } //NINGUNO if (String.IsNullOrEmpty(rut) != false && !sexo.Read() && !estado.Read()) { grdClientes.ItemsSource = cliente.ReadAll(); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Atención", MessageBoxButton.OK, MessageBoxImage.Exclamation); } }