Ver Mensaje Individual
  #12  
Antiguo 07-11-2012
Avatar de ecfisa
ecfisa ecfisa is offline
Moderador
 
Registrado: dic 2005
Ubicación: Tres Arroyos, Argentina
Posts: 10.508
Reputación: 36
ecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to behold
Hola Pablo.

Ahora viendo el gráfico pude entender lo que buscas hacer. La fecha a comparar entre las del archivo es la que esta en la fila cero del StringGrid y el nombre a buscar en la tabla está en la columna cero de la misma.

Entonces, esta es la prueba que realicé y funciona bién:
Código:
...
#include <DateUtils.hpp>
...
void __fastcall TForm1::FormCreate(TObject *Sender) {

  TStringGrid *sg = static_cast<TStringGrid*>(StringGrid1);
  TDate dt = Date();
  AnsiString s;
  sg->ColCount = 31;
  sg->Cells[0][1] = "Renuevate";
  sg->Cells[0][2] = "Navidades";
  sg->Cells[0][3] = "Ocasion";
  for(int c =DayOf(Date()); c<= DaysInMonth(Date()); c++) {
      sg->Cells[c-DayOf(Date())+1][0] = DateToStr(dt);
      dt=IncDay(dt,1);
  }
  sg->Col = 1;
  sg->Row = 1;
  /* Asignar evento OnSelectCell por código */
  sg->OnSelectCell = StringGrid1SelectCell; 
}

void __fastcall TForm1::StringGrid1DrawCell(TObject *Sender, int ACol,
      int ARow, TRect &Rect, TGridDrawState State) {
  TStringGrid *sg = static_cast<TStringGrid*>(StringGrid1);

  if (ACol > 0 && ARow > 0 && sg->Cells[ACol][ARow] != "") {
    QryTmp->Close();
    QryTmp->SQL->Clear();
    QryTmp->SQL->Add("SELECT * FROM CATALOG");
    QryTmp->SQL->Add("WHERE NOMBRE_CATALOGO = :PNOMBRE");
    QryTmp->SQL->Add("AND :PFECHA >= FECHA_DESDE AND :PFECHA <= FECHA_HASTA");
    // En columna 0 estan los nombres
    QryTmp->ParamByName("PNOMBRE")->AsString = sg->Cells[0][ARow];
    // En fila 0 estan las fechas
    QryTmp->ParamByName("PFECHA")->AsString  = sg->Cells[ACol][0];
    QryTmp->Open();
    if (!QryTmp->IsEmpty()) {
      sg->Canvas->Brush->Color = clLime;
      sg->Canvas->FillRect(Rect);
      sg->Canvas->TextOut(Rect.Left+1 ,Rect.top+1, sg->Cells[ACol][ARow]);
    }
  }
}

/* Impedir que seleccionen columna 0 o fila 0 */
void __fastcall TForm1::StringGrid1SelectCell(TObject *Sender, int ACol,
      int ARow, bool &CanSelect) {
 CanSelect = ACol > 0 && ARow > 0;
}

...

void __fastcall TForm1::FormDestroy(TObject *Sender) {
 StringGrid1->OnSelectCell = NULL;
}
La tabla que cree para la prueba tiene el siguiente formato:
Código:
NOMBRE_CATALOGO | FECHA_DESDE | FECHA_HASTA
----------------+-------------+------------
Renuevate       | 07.11.2012  | 08.11.2012
Navidades       | 09.11.2012  | 10.11.2012
Ocasion         | 08.11.2012  | 10.11.2012
Los valores son iguales a los de tu imágen.

Como verás en el resultado, el pintado considera las fechas límites de la tabla en relación a la columna y de acuerdo al nombre de la fila:


No olvides quitar el evento OnSelectCell desde el Object Inspector, lo asigno por código para que permita el posicionamiento en Col = 1, Row = 1.

Saludos.

Edito: Me olvidaba... Y si deseas que se pinten las celdas aún estando vacías, cambiá:
Código:
  if (ACol > 0 && ARow > 0 && sg->Cells[ACol][ARow] != "") {
  // por:
  if (ACol > 0 && ARow > 0) {
__________________
Daniel Didriksen

Guía de estilo - Uso de las etiquetas - La otra guía de estilo ....

Última edición por ecfisa fecha: 07-11-2012 a las 14:55:12. Razón: agregar comentario
Responder Con Cita