static public EmpleadoDatabase GetDatabase() { if (instance == null) { instance = new EmpleadoDatabase(); } return(instance); }
public Form1() { InitializeComponent(); // Get plantillas Path TemplatesPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "PlantillasRH"); Directory.CreateDirectory(TemplatesPath); // Load Plantillas NombresPlantillas = Directory.EnumerateFiles(TemplatesPath, @"*.docx").Where(s => s.Last() != '#').Select <string, string>((path) => Path.GetFileName(path)).ToList(); listBoxPlantillas.DataSource = NombresPlantillas; // Load Empleados Empleados = EmpleadoDatabase.GetDatabase().GetEmpleados(); listBoxEmpleados.DataSource = Empleados; // Search plantilla textBoxBusquedaPlantilla.TextChanged += (o, e) => { string text = textBoxBusquedaPlantilla.Text; if (string.IsNullOrEmpty(text)) { listBoxPlantillas.DataSource = NombresPlantillas; } else { listBoxPlantillas.DataSource = NombresPlantillas.Where(s => s.Contains(text)).ToList(); } }; // Search Empleado textBoxBusquedaEmpleado.TextChanged += (o, e) => { string text = textBoxBusquedaEmpleado.Text; if (string.IsNullOrEmpty(text)) { listBoxEmpleados.DataSource = Empleados; } else { listBoxEmpleados.DataSource = Empleados.Where(s => s.Nombre.Contains(text) || s.RFC.Contains(text)).ToList(); } }; // Mostrar Empleado Seleccionado listBoxEmpleados.SelectedValueChanged += (o, e) => { try { var empleado = listBoxEmpleados.SelectedValue as Empleado; labelNombre.Text = empleado.Nombre; labelRFC.Text = empleado.RFC; labelEstadoCivil.Text = empleado.EstadoCivil; labelSexo.Text = empleado.Sexo; } catch { } }; }