private void Window_Loaded(object sender, RoutedEventArgs e) { logSystem = new LogSystem(); if (!File.Exists(CUtilities.SAVE_FILE_NAME)) { File.Create(CUtilities.SAVE_FILE_NAME); } admin = new CAdminPacientes(); admin.Cargar(); CUtilities.FillListView(lV_Pacientes, admin.GetListaPacientes()); CUtilities.FillListView(lV_AsistPacientes, admin.GetListaPacientes()); cB_Ingreso_Sangre.SelectedIndex = 0; cB_Dia.SelectedIndex = 0; cB_Mes.SelectedIndex = 0; cB_Rep_Dia.SelectedIndex = 0; cB_Rep_Dia2.SelectedIndex = 0; cB_Rep_Mes.SelectedIndex = 0; cB_Rep_Mes2.SelectedIndex = 0; cB_AsistPacientes_Dia.SelectedIndex = 0; cB_AsistPacientes_Mes.SelectedIndex = 0; cB_Rep_FechaAsist_Day.SelectedIndex = 0; cB_Rep_FechaAsist_Month.SelectedIndex = 0; }
private void btn_Ingresar_Click(object sender, RoutedEventArgs e) { try { // conseguir datos del paciente de controles string nombre = tB_Ingreso_Nombre.Text; string apellido = tB_Ingreso_Apellido.Text; string razon = tB_Ingreso_Razon.Text; string dpi = tB_DPI.Text; int dia = cB_Dia.SelectedIndex + 1; int mes = cB_Mes.SelectedIndex + 1; // validar fecha de nacimiento int year = Math.Min(int.Parse(tB_Year.Text), DateTime.UtcNow.Year); List <CAsistencia> asis = new List <CAsistencia>(); CAsistencia a = new CAsistencia(DateTime.UtcNow.ToShortDateString(), tB_AsistPacientes_Observaciones.Text); asis.Add(a); DateTime fechaNac = new DateTime(year, mes, dia); ETipoDeSangre sangre = (ETipoDeSangre)cB_Ingreso_Sangre.SelectedIndex; // validar datos if (string.IsNullOrEmpty(nombre) || string.IsNullOrEmpty(apellido) || sangre == ETipoDeSangre.Cualquiera || string.IsNullOrEmpty(dpi) || string.IsNullOrEmpty(tB_Year.Text)) { MessageBox.Show("Revisa los datos.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } else { // ingresar paciente CPaciente p = new CPaciente(nombre, apellido, dpi, fechaNac, razon, sangre, asis); admin.AgregarPaciente(p); CUtilities.FillListView(lV_Pacientes, admin.GetListaPacientes()); CUtilities.FillListView(lV_AsistPacientes, admin.GetListaPacientes()); logSystem.Loggear(ETipoLog.NuevoPaciente, p); MessageBox.Show("El paciente ha sido agregado.", "Info", MessageBoxButton.OK, MessageBoxImage.Information); // limpiar campos de ingreso tB_Ingreso_Nombre.Text = string.Empty; tB_Ingreso_Apellido.Text = string.Empty; tB_DPI.Text = string.Empty; tB_Year.Text = string.Empty; cB_Dia.SelectedIndex = 0; cB_Mes.SelectedIndex = 0; cB_Ingreso_Sangre.SelectedIndex = 0; tB_Ingreso_Razon.Text = string.Empty; } } catch (Exception ex) { MessageBox.Show("Error al agregar paciente - " + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }