I have the following nested tables, in SQL Server:
## Orden_Trabajo ##
ID | TITULO | FECHA_INICIO | FECHA_TERMINO | EQUIPO
---
1 | FALLA MOTOR | 1/12/17 8:00 | 2/12/17 12:00 | 100
## Tareas ##
ID | TAREA | FECHA_INICIO | FECHA_TERMINO
---
1 | DESMONTAR MOTOR | 1/12/17 8:00 | 1/12/17 12:00
2 | REPARAR MOTOR | 1/12/17 12:00 | 2/12/17 8:00
3 | MONTAR MOTOR | 2/12/17 8:00 | 2/12/17 12:00
## Tareas_Mecanicos ##
ID | TAREA | MECANICO
---
1 | 1 | ABEL
2 | 1 | BERNARDO
3 | 2 | ABEL
4 | 2 | CARLOS
5 | 2 | DANIEL
6 | 2 | EDUARDO
7 | 3 | CARLOS
8 | 3 | DANIEL
These tables have their Object Class in the system, I need to create the following report:
MANTENEDOR | TAREAS | SUMA DURACION
---
ABEL | 1,2 | 24
BERNARDO | 1 | 4
CARLOS | 2,3 | 24
DANIEL | 2,3 | 24
EDUARDO | 2 | 20
How can I get a list without repetitions from the Maintainers and capture the tasks they participated in at the same time?
With a SELECT in the database, or with ordered lists in system (C #)
I made a Class for each table, and for the report create an ordered List: Sort Order Job:
public class OrdenTrabajo{
public int IdOT;
public string Titulo;
public Datetime FechaInicio;
public Datetime FechaTermino;
public Equipo equipo;
}
Task Class:
public class Tarea{
public int IdTarea;
public string tarea;
public Datetime FechaInicio;
public Datetime FechaTermino;
public List<Mecanico> ListaMecanicos;
public double GetDuracion(){
TimeSpan ts = FechaTermino - FechaInicio;
return ts.TotalHours;
}
}
Mechanical Class:
public class Mecanico{
public int IdMecanico;
public string NombreMecanico;
}
Turn Class:
public class Turno {
public Mecanico _Mecanico;
public List<Tarea> _ListaTareas;
public AgregarTarea(Tarea tarea){
_ListaTareas.Add(tarea);
}
}
I try to make the report using a shift list and a list of mechanics as a pivot:
List<Turno> listaTurno = new List<Turno>();
List<Mecanico> listaMecanicos = new List<Mecanico>();
List<Tarea> tareas = GetListaTareasRangoFechas(fechaInicio,fechaTermino);
for (int i = 0; i < tareas.Count; i++) {
for (int j = 0; j < tareas[i].ListaMecanicos.Count; j++) {
if (!listaMantenedores.Contains(tareas[i].ListaMantenedores[j])) {
listaMecanicos.Add(tareas[i].ListaMecanicos[j]);
Turno turno = new Turno(tareas[i].ListaMecanicos[j]);
turno.AgregarTarea(tareas[i]);
listaTurno.Add(turno);
}else {
for (int k = 0; k < listaHHTurno.Count; k++) {
if(listaTurno[k]._Mecanico.IdMecanico == tareas[i].ListaMecanicos[j].IdMecanico) {
listaTurno[k].AgregarTarea(tareas[i]);
}
}
}
}
}
Then when printing the list the *** Mechanics *** are repeated and only one Task is assigned.