Club Delphi  
    Paypal   FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Otros entornos y lenguajes > Lazarus, FreePascal, Kylix, etc.
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

 
 
Herramientas Buscar en Tema Desplegado
  #6  
Antiguo 10-07-2015
Avatar de ecfisa
ecfisa ecfisa is offline
Moderador
 
Registrado: dic 2005
Ubicación: Tres Arroyos, Argentina
Posts: 10.508
Poder: 38
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 El_Chava.

Como te comenta Neftali todo puede variar según programes la estructuración de los datos.

Te pongo una idea de tantas en que podrías realizarlo. El ejemplo hace uso del mouse tanto para la elección única como múltiple de días y usa un PopupMenu cuyos ítems ponen el día o la selección en día feriado o laboral.

Por la imágen que adjuntaste pareciera que usas 12 StringGrids, el ejemplo usa uno solo (StringGridEnero), pero es muy simple modificarlo para que funcione con los restantes.
Código Delphi [-]
...
type
  TForm1 = class(TForm)
    RadioGroup1: TRadioGroup;
    StringGridEnero: TStringGrid;
    PopupMenu1: TPopupMenu;
    pmiFeriado: TMenuItem;
    pmiLaboral: TMenuItem;
    
    btSave: TButton;
    btReset: TButton;
    btLoad: TButton;
    procedure FormCreate(Sender: TObject);
    procedure PopupItemsClick(Sender: TObject);
    procedure StringGridDrawCell(Sender: TObject; ACol, ARow: Integer;
      Rect: TRect; State: TGridDrawState);
    procedure btSaveClick(Sender: TObject);
    procedure btLoadClick(Sender: TObject);
    procedure btResetClick(Sender: TObject);
  private
    FFileName : string;
    procedure SaveStringGrid(SG: TStringGrid; const aFileName: string);
    procedure LoadStringGrid(SG: TStringGrid; const aFileName: string);
  public
  end;

var
  Form1: TForm1;

implementation

const
  NOPRN     = #144;   // caracter no imprimible, dado la forma de cargarlo que uso (CommaText) 

// Carga unos datos en el StringGrid
procedure IniciarDemo(StringGrid: TStringGrid);
var
  c, r : Integer;
begin
 with StringGrid do
  begin
    FixedCols:= 0;
    FixedRows:= 1;
    ColCount := 7;
    RowCount := 6;
    Options  := Options + [goRangeSelect] - [goEditing];
    for r := 0 to RowCount-1 do Rows[r].QuoteChar:= #0;
    Rows[0].CommaText := 'LUN,MAR,MIE,JUE,VIE,SAB,DOM';
    Rows[1].CommaText := NOPRN+','+NOPRN+','+NOPRN+',1,2,3,4';
    Rows[2].CommaText := '5,6,7,8,9,10,11';
    Rows[3].CommaText := '12,13,14,15,16,17,18';
    Rows[4].CommaText := '19,20,21,22,23,24,25';
    Rows[5].CommaText := '26,27,28,29,30,31,'+NOPRN;
    for r := FixedRows to RowCount -1 do
      for c:= FixedCols to ColCount-1 do
        Objects[c, r] := TObject(False);
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  FFileName := ExtractFilePath(Application.ExeName)+'enero.dat';
  IniciarDemo(StringGridEnero);
end;

// OnDrawCell, evento asignado a cada StringGrid
procedure TForm1.StringGridDrawCell(Sender: TObject; ACol,
  ARow: Integer; Rect: TRect; State: TGridDrawState);
const
  COLORCELL : array[Boolean] of TColor = (clWindow, clGray);
  FLAGS = DT_SINGLELINE or DT_CENTER or DT_VCENTER;
begin
  with TStringGrid(Sender) do
  begin
    if Boolean(Objects[ACol,ARow]) and (Cells[ACol,ARow] <> NOPRN) then
    begin
      Canvas.Brush.Color := COLORCELL[Boolean(Objects[ACol,ARow])];
      Canvas.FillRect(Rect);
      DrawText(Canvas.Handle, PChar(Cells[ACol, ARow]), -1, Rect, FLAGS);
    end;
  end;
end;

// PopupMenu OnClick (Feriado/Laboral). Asociado a cada StringGrid
procedure TForm1.PopupItemsClick(Sender: TObject);
var
  c,r : Integer;
begin
  with TStringGrid(PopupMenu1.PopupComponent) do
    for c := Selection.Left to Selection.Right do
      for r := Selection.Top to Selection.Bottom do
         Objects[c,r] := TObject(TMenuItem(Sender).MenuIndex = 0);
end;

// Botón Guardar
procedure TForm1.btSaveClick(Sender: TObject);
begin
  SaveStringGrid(StringGridEnero, FFileName);
end;

// Botón Reset
procedure TForm1.btResetClick(Sender: TObject);
begin
  IniciarDemo(StringGridEnero);
end;

// Botón Cargar
procedure TForm1.btLoadClick(Sender: TObject);
begin
  LoadStringGrid(StringGridEnero, FFileName);
end;

// Guardar StringGrid
procedure TForm1.SaveStringGrid(SG: TStringGrid; const aFileName: string);
var
  c, r: Integer;
  d: Byte;
  b: Boolean;
begin
  with TFileStream.Create(aFileName, fmCreate) do
  try
    for c := SG.FixedCols to SG.ColCount-1 do
      for r := SG.FixedRows to SG.RowCount-1 do
      begin
        d := StrToIntDef(SG.Cells[c, r], 0);
        WriteBuffer(d, SizeOf(Byte));
        b := Boolean(SG.Objects[c, r]);
        WriteBuffer(b, SizeOf(Boolean));
      end;
  finally
    Free;
  end;
end;

// Cargar StringGrid
procedure TForm1.LoadStringGrid(SG: TStringGrid; const aFileName: string);
var
  c, r: Integer;
  d: Byte;
  b: Boolean;
begin
  with TFileStream.Create(aFileName, fmOpenRead) do
  try
    for c := SG.FixedCols to SG.ColCount-1 do
      for r := SG.FixedRows to SG.RowCount-1 do
      begin
        ReadBuffer(d, SizeOf(Byte));
        if d = 0 then
          SG.Cells[c, r] := NOPRN
        else
          SG.Cells[c,r] := IntToStr(d);
        ReadBuffer(b, Sizeof(Boolean));
        SG.Objects[c, r] := TObject(b);
      end;
  finally
    Free;
  end;
end;

Muestra:


Saludos
__________________
Daniel Didriksen

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



Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
Validar Calendario Días Habiles mantraxer21 Varios 2 05-11-2014 21:27:29
diferencia de dias , suponiendo que los meses son de 30 dias. ingabraham Varios 30 12-09-2010 22:37:48
Sumar Columna en StringGrig carlosh2006 Varios 2 28-08-2007 03:23:53
Titulos en StringGrig CamiloU OOP 3 09-02-2006 01:07:56
Calendario. fecha de noviembre 2005 me pone 31 dias y a diciembre 30 sakuragi PHP 2 21-11-2005 18:39:59


La franja horaria es GMT +2. Ahora son las 07:30:45.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi