private void Window_Loaded(object sender, RoutedEventArgs e) { ControlPreliminar = false; SoporteCombo.cargarEnumerador(cboTipoDocumentoIdentidad, typeof(TipoDocumentoIdentidad)); ModeloDepartamento modelodepartamento = new ModeloDepartamento(); this.cboDepartamento.ItemsSource = modelodepartamento.Listar(); this.cboDepartamento.DisplayMemberPath = "Descripcion"; this.cboDepartamento.SelectedValuePath = "Id"; ModeloTipoParentesco modelotipoparentesco = new ModeloTipoParentesco(); this.cboTipoParentesco.ItemsSource = modelotipoparentesco.Listar(); this.cboTipoParentesco.DisplayMemberPath = "Descripcion"; this.cboTipoParentesco.SelectedValuePath = "Id"; if (IdFamilia > 0) { ModeloFamilia modelofamilia = new ModeloFamilia(); Familia familia = new Familia(); familia = modelofamilia.Recuperar(IdFamilia); this.txtPaternoFamilia.Text = familia.PrimerApellido; this.txtMaternoFamilia.Text = familia.SegundoApellido; } if (IdSeleccionado == 0) { this.cboTipoDocumentoIdentidad.SelectedIndex = -1; this.dtpFechaNacimiento.SelectedDate = DateTime.Today; this.cboDepartamento.SelectedIndex = -1; this.cboTipoParentesco.SelectedIndex = -1; } else { ModeloTutor modelotutor = new ModeloTutor(); _tutor = modelotutor.Recuperar(IdSeleccionado); txtDocumentoIdentidad.Text = _tutor.DocumentoIdentidad; switch (_tutor.TipoDocumentoIdentidad) { case TipoDocumentoIdentidad.CarnetIdentidad: cboTipoDocumentoIdentidad.SelectedIndex = 0; break; case TipoDocumentoIdentidad.CertificadoNacimiento: cboTipoDocumentoIdentidad.SelectedIndex = 1; break; case TipoDocumentoIdentidad.Pasaporte: cboTipoDocumentoIdentidad.SelectedIndex = 2; break; } txtPaterno.Text = _tutor.PrimerApellido; txtMaterno.Text = _tutor.SegundoApellido; txtConyuge.Text = _tutor.TercerApellido; txtNombres.Text = _tutor.Nombres; txtNombreCompleto.Text = _tutor.NombreCompleto; dtpFechaNacimiento.SelectedDate = _tutor.FechaNacimiento; if (_tutor.Sexo == "F") { rdbFemenino.IsChecked = true; } else if (_tutor.Sexo == "M") { rdbMasculino.IsChecked = true; } if (_tutor.Defuncion == true) { chkDefuncion.IsChecked = true; } txtLugarNacimiento.Text = _tutor.LocalidadNacimiento; cboDepartamento.SelectedValue = _tutor.IdDepartamento; RecuperarProvincias(_tutor.IdDepartamento.ToString()); cboProvincia.SelectedValue = _tutor.IdProvincia; RecuperarMunicipios(_tutor.IdProvincia.ToString()); cboMunicipio.SelectedValue = _tutor.IdMunicipio; ModeloGrupoFamiliar modelogrupofamiliar = new ModeloGrupoFamiliar(); _grupofamiliar = modelogrupofamiliar.RecuperarPorTutorDeFamilia(IdFamilia, IdSeleccionado); cboTipoParentesco.SelectedValue = _grupofamiliar.IdTipoParentesco; if (TipoAccion == TipoAccion.Detalle) { cboTipoParentesco.IsEnabled = false; txtDocumentoIdentidad.IsEnabled = false; cboTipoDocumentoIdentidad.IsEnabled = false; txtPaterno.IsEnabled = false; txtMaterno.IsEnabled = false; txtConyuge.IsEnabled = false; txtNombres.IsEnabled = false; dtpFechaNacimiento.IsEnabled = false; rdbFemenino.IsEnabled = false; rdbMasculino.IsEnabled = false; chkDefuncion.IsEnabled = false; txtLugarNacimiento.IsEnabled = false; cboDepartamento.IsEnabled = false; cboProvincia.IsEnabled = false; cboMunicipio.IsEnabled = false; cmdAceptar.IsEnabled = false; } } ControlPreliminar = true; if ((TipoAccion == TipoAccion.Nuevo) || (TipoAccion == TipoAccion.Edicion)) { this.cboTipoParentesco.Focus(); } }
private void cmdAceptar_Click(object sender, RoutedEventArgs e) { ModeloGrupoFamiliar modelogrupofamiliar = new ModeloGrupoFamiliar(); GrupoFamiliar gf = new GrupoFamiliar(); gf = modelogrupofamiliar.RecuperarTitularHabilitado(IdFamilia); bool ok = false; bool OK = false; int OKM = 0; if (!(txtDocumentoIdentidad.Text.Length > 0)) { MessageBox.Show("Se requiere especificar documento de identidad.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); ok = true; } else if ((Convert.ToInt64(cboTipoDocumentoIdentidad.SelectedIndex) < 0)) { MessageBox.Show("Se requiere especificar tipo de documento de identidad.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); ok = true; } else if (!(txtPaterno.Text.Length > 0) && !(txtMaterno.Text.Length > 0)) { MessageBox.Show("Se requiere especificar apellidos.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); ok = true; } else if (!(txtNombres.Text.Length > 0)) { MessageBox.Show("Se requiere especificar nombre.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); ok = true; } else if (!(txtNombreCompleto.Text.Length > 0)) { MessageBox.Show("Se requiere especificar nombre completo.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); ok = true; } else if ((Convert.ToInt64(cboDepartamento.SelectedIndex) < 0)) { ok = true; MessageBox.Show("Se requiere especificar departamento.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } else if ((Convert.ToInt64(cboProvincia.SelectedIndex) < 0)) { MessageBox.Show("Se requiere especificar provincia.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); ok = true; } else if ((Convert.ToInt64(cboMunicipio.SelectedIndex) < 0)) { MessageBox.Show("Se requiere especificar municipio.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); ok = true; } else if (!(txtLugarNacimiento.Text.Length > 0)) { MessageBox.Show("Se requiere especificar lugar de nacimiento.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); ok = true; } if (ok == false) { if (txtPaterno.Text != txtMaternoFamilia.Text) { if (MessageBox.Show("El apellido paterno de la madre no es igual al apellido materno de la familia. ¿Desea continua?", "Advertencia", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.No) { ok = true; } } } if (gf == null) { if (ok == false) { switch (MessageBox.Show("¿Desea guardar los datos correspondiente a este madre?", "Consulta", MessageBoxButton.YesNoCancel, MessageBoxImage.Question)) { case MessageBoxResult.Yes: OKM = 1; break; case MessageBoxResult.No: OKM = 2; break; case MessageBoxResult.Cancel: OKM = 3; break; } if (OKM == 1) { DateTime FechitaDeNacimiento; DateTime FechitaActual; FechitaDeNacimiento = dtpFechaNacimiento.SelectedDate.Value; FechitaActual = DateTime.Now; FechitaActual = FechitaActual.AddYears(-16); if (FechitaDeNacimiento > FechitaActual) { if (MessageBox.Show("La fecha de nacimiento de la madre es: " + string.Format("{0:dd/MM/yyyy}", FechitaDeNacimiento) + ", lo cual a la fecha determina que es menor de edad. ¿Desea registrar ahora un nuevo titular de pago para la familia?", "Advertencia", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes) { this.Cursor = Cursors.Wait; frmTutor objTutorWindow = new frmTutor(); objTutorWindow.IdFamilia = IdFamilia; objTutorWindow.IdSeleccionado = 0; objTutorWindow.TipoAccion = TipoAccion.Nuevo; objTutorWindow.Owner = this; objTutorWindow.ShowDialog(); this.Cursor = Cursors.Arrow; if (objTutorWindow.Resultado == true) { GrupoFamiliar grupofamiliar = new GrupoFamiliar(); grupofamiliar = modelogrupofamiliar.RecuperarPorTutorDeFamilia(IdFamilia, objTutorWindow.IdSeleccionado); grupofamiliar.TitularPagoVigente = true; modelogrupofamiliar.Editar(grupofamiliar.Id, grupofamiliar); OK = true; } objTutorWindow = null; } } } } } else { switch (MessageBox.Show("¿Desea guardar los datos correspondiente a este madre?", "Consulta", MessageBoxButton.YesNoCancel, MessageBoxImage.Question)) { case MessageBoxResult.Yes: OKM = 1; break; case MessageBoxResult.No: OKM = 2; break; case MessageBoxResult.Cancel: OKM = 3; break; } } if (ok == false) { switch (OKM) { case 1: ModeloMadre modelomadre = new ModeloMadre(); _madre.DocumentoIdentidad = txtDocumentoIdentidad.Text; switch (cboTipoDocumentoIdentidad.SelectedIndex) { case 0: _madre.TipoDocumentoIdentidad = TipoDocumentoIdentidad.CarnetIdentidad; break; case 1: _madre.TipoDocumentoIdentidad = TipoDocumentoIdentidad.CertificadoNacimiento; break; case 2: _madre.TipoDocumentoIdentidad = TipoDocumentoIdentidad.Pasaporte; break; } _madre.PrimerApellido = txtPaterno.Text; _madre.SegundoApellido = txtMaterno.Text; _madre.TercerApellido = txtConyuge.Text; _madre.Nombres = txtNombres.Text; _madre.NombreCompleto = txtNombreCompleto.Text; _madre.FechaNacimiento = dtpFechaNacimiento.SelectedDate.Value; _madre.Defuncion = (chkDefuncion.IsChecked == true) ? true : false; _madre.Observaciones = ""; _madre.IdDepartamento = Convert.ToInt64(cboDepartamento.SelectedValue); _madre.IdProvincia = Convert.ToInt64(cboProvincia.SelectedValue); _madre.IdMunicipio = Convert.ToInt64(cboMunicipio.SelectedValue); _madre.LocalidadNacimiento = txtLugarNacimiento.Text; if (IdSeleccionado > 0) { modelomadre.Editar(IdSeleccionado, _madre); } else { modelomadre.Crear(_madre); IdSeleccionado = _madre.Id; _grupofamiliar.IdFamilia = IdFamilia; _grupofamiliar.IdMadre = _madre.Id; _grupofamiliar.TipoGrupoFamiliar = TipoGrupoFamiliar.Madre; if (gf == null) { if (OK == false) { _grupofamiliar.TitularPagoVigente = true; } } modelogrupofamiliar.Crear(_grupofamiliar); } Resultado = true; this.Close(); break; case 3: IdSeleccionado = 0; Resultado = false; this.Close(); break; } } }