unit uEditorCalendarioConFiltro;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, uEditorCalendarioBase, dxPSGlbl, dxPSUtl, dxPSEngn, dxPrnPg,
  dxBkgnd, dxWrap, dxPrnDev, dxPSCompsProvider, dxPSFillPatterns,
  dxPSEdgePatterns, dxPrnDlg, dxPSCore, dxPScxCommon, dxPScxScheduler2Lnk,
  DB, uDADataTable, cxSchedulerStorage, cxSchedulerDBStorage,
  dxLayoutLookAndFeels, JvAppStorage, JvAppRegistryStorage,
  JvComponentBase, JvFormPlacement, ImgList, PngImageList, StdActns,
  ActnList, ComCtrls, TBX, TB2Item, TB2Dock, TB2Toolbar, pngimage,
  ExtCtrls, JvExControls, JvComponent, JvNavigationPane;

type
  IEditorCalendarioConFiltro = interface(IEditorCalendarioBase)
  ['{81ED9B0E-6F65-4B7D-884F-192AE45A7708}']
  end;

  TfEditorCalendarioConFiltro = class(TfEditorCalendarioBase, IEditorCalendarioConFiltro)
    actVerTodos: TAction;
    procedure actVerTodosExecute(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure JvFormStorageSavePlacement(Sender: TObject);
  protected
    NombreLista: String;
    procedure CargarLista; virtual;
  public
    destructor destroy; override;
  end;

var
  fEditorCalendarioConFiltro: TfEditorCalendarioConFiltro;

implementation
{$R *.dfm}

uses uViewCalendarioConFiltro;

procedure TfEditorCalendarioConFiltro.actVerTodosExecute(Sender: TObject);
var
  I: Integer;
begin
  with (ViewCitas as IViewCalendarioConFiltro).Resources do
  begin
    Items.BeginUpdate;
    try
      for I := 0 to Items.Count - 1 do
      begin
        Items[I].Checked := True;
        TcxSchedulerStorageResourceItem(Items[I].ItemObject).Visible := True;
      end;
    finally
      Items.EndUpdate;
    end;
  end;
end;

procedure TfEditorCalendarioConFiltro.CargarLista;
var
  I: Integer;
  cadena: String;
begin
  cadena := JvFormStorage.ReadString(NombreLista, '');

  with (ViewCitas as IViewCalendarioConFiltro).Resources do
  begin
    Items.BeginUpdate;
    try
      Items.Clear;

      for I := 0 to ViewCitas.Calendario.Storage.ResourceCount - 1 do
      begin
        with Items.Add do
        begin
          ImageIndex := 0;
          Text := ViewCitas.Calendario.Storage.ResourceNames[I];
          Checked := ViewCitas.Calendario.Storage.Resources.ResourceItems[I].Visible;
          ItemObject := ViewCitas.Calendario.Storage.Resources.ResourceItems[I];
        end;
      end;
    finally
      Items.EndUpdate;
    end;

    for I := 0 to Items.Count - 1 do
      if (Length(cadena) > 0) and (Pos('#' + IntToStr(i) + '#', cadena) = 0) then
      begin
        Items[i].Checked := False;
        (Items[i].ItemObject as TcxSchedulerStorageResourceItem).Visible := False;
      end;
  end;
end;

destructor TfEditorCalendarioConFiltro.destroy;
begin
  inherited;
end;

procedure TfEditorCalendarioConFiltro.FormShow(Sender: TObject);
begin
  inherited FormShow(Sender);

  try
    ViewCitas.Calendario.BeginUpdate;
    CargarLista;
  finally;
    ViewCitas.Calendario.EndUpdate;
  end;

  actSemana.Execute;
end;

procedure TfEditorCalendarioConFiltro.JvFormStorageSavePlacement(
  Sender: TObject);
var
  i : integer;
  cadena : string;
begin
  inherited;
  with (ViewCitas as IViewCalendarioConFiltro).Resources do
  begin
    cadena := '#';
    for i := 0 to Items.Count - 1 do
      if Items[i].Checked then
        cadena := cadena + IntToStr(i) + '#';
    JvFormStorage.WriteString(NombreLista, cadena);
  end;
end;

end.
