Ver Mensaje Individual
  #13  
Antiguo 05-11-2008
[maeyanes] maeyanes is offline
Capo de los Capos
 
Registrado: may 2003
Ubicación: Campeche, México
Posts: 2.732
Reputación: 24
maeyanes Va por buen camino
Hola...

Si te entendí bien, lo que tu código debe hacer es algo así:

Código:
+--------+----------+---------+---------+---------+---------+---------+
| Numero | Pregunta | Opcion1 | Opcion2 | Opcion3 | Opcion4 | Opcion5 |
+--------+----------+---------+---------+---------+---------+---------+
| 1      | Sección  |         |         |         |         |         |
+--------+----------+---------+---------+---------+---------+---------+
| 1.1    | ¿Como es.|    1    |    2    |         |         |    5    |
+--------+----------+---------+---------+---------+---------+---------+
| 1.2    | ¿Cual es.|    1    |         |    3    |         |    5    |
+--------+----------+---------+---------+---------+---------+---------+    
| 1.3    | ¿Donde...|    1    |    2    |    3    |         |         |
+--------+----------+---------+---------+---------+---------+---------+
| 2      | Sección  |         |         |         |         |         |
+--------+----------+---------+---------+---------+---------+---------+
| 2.1    | ¿Como es.|    1    |    2    |         |         |    5    |
+--------+----------+---------+---------+---------+---------+---------+
| 2.2    | ¿Cual es.|    1    |         |    3    |         |    5    |
+--------+----------+---------+---------+---------+---------+---------+    
| 2.3    | ¿Donde...|    1    |    2    |    3    |         |         |
+--------+----------+---------+---------+---------+---------+---------+
Si lo anterior es cierto, prueba con este código:

Código Delphi [-]
procedure TForm1.BitBtnGenerarClick(Sender: TObject);
var
  X: Integer;
  Valor: Integer;
  Evalua: string;
  
begin
   //Obtiene la clave del combo evaluacion
  Evalua := copy(cmbEvaluacion.Text, 0, Pos('-', cmbEvaluacion.Text) - 1);
  //OBTIENE LA VERSION
  Query1.Close;
  Query1.SQL.Text := Format('select det_version from det_evaluacion ' +
    'where det_eval = ''%s''', [Evalua]);
  Query1.Open;
  lblVersion.Caption := Query1.FieldByName('det_version').AsString;
  //OBTIENE LA SECCION
  Query1.Close;
  Query1.SQL.Text := Format('select * from det_evaluacion ' +
    'where det_eval = ''%s'' and det_tipo = 0 and ' +
    'det_valor = 0 order by det_clave', [Evalua]);
  Query1.Open;
  // sgEvaluacion debe tener solo la línea de encabezados, esto es: RowCount = 1
  X := 1;
  while not Query1.Eof do
  begin      
    sgEvaluacion.RowCount := X + 1; // Agregamos línea para sección
    // Agregamos la clave y la descripción de la sección
    sgEvaluacion.Cells[0, X] := Query1.FieldByName('det_pregunta').AsString;
    sgEvaluacion.Cells[1, X] := Query1.FieldByName('det_pregunta').AsString;
    // Buscamos las preguntas
    Query2.Close;
    Query2.SQL.Text := Format('select * from det_evaluacion ' + 
      'where det_eval = ''%s'' and det_tipo = 1 and ' +
      'det_clave like ''%s.%%'' and det_valor = 0 ' +
      'order by det_clave', [Evalua, Query1.FieldByName['det_clave'].AsString]);
    Query2.Open;
    while not Eof do
    begin
      Inc(X);
      sgEvaluacion.RowCount := X + 1; // Agregamos otra línea para pregunta
      sgEvaluacion.Cells[0, X] := Query2.FieldByName('det_clave').AsString;
       sgEvaluacion.Cells[1, X] := Query2.FieldByName('det_pregunta').AsString;
      // Buscamos las respuestas de la pregunta actual
      Query3.Close;
      Query3.SQL.Text := Format('select det_valor from det_evaluacion ' +
        'where det_eval = ''%s'' and det_clave like ''%s.%%'' and '
        'det_tipo = 2 order by det_valor asc', [Evalua, 
        Query1.FieldByName('det_clave'].AsString]);
      Query3.Open;
      while not Query3.Eof do
      begin
        Valor := Query3.FieldByName('det_valor').AsInteger;
        sgEvaluacion.Cells[Valor + 1, X] := IntToStr(Valor);
        Query3.Next;
      end;
      sgEvaluacion.Cells[7, X] := 'Resultado';
      Query2.Next
    end;
    Inc(X); // Incrementamos X para obtener la siguiente sección
    Query1.next
  end
end;


Saludos...
Responder Con Cita