unit uDBGridSort;
{< this unit contains sort methods of components}

interface

uses
  System.SysUtils, System.Classes;

type
  TDBGridSort = class(TDataModule)
  private
    { Private declarations }


    FNameSortDirectionToggle:Boolean;
    FFileSizeSortDirectionToggle:Boolean;
    FCreationDateTimeSortDirectionToggle:Boolean;
    FChangesDateTimeSortDirectionToggle:Boolean;
    FLastAccessDateTimeSortDirectionToggle:Boolean;


  public
    { Public declarations }

    constructor Create(AOwner: TComponent); override;

    procedure DBGridSortColumns(Afieldname: string);
    {< Sort on columns click }

    procedure DBGridSortComboboxes(ASortParam, ASortDirection: integer);
    {< Sort and depends on Sort Params of Comboboxes }

  end;

//var
//  DBGridSort: TDBGridSort;

implementation

{%CLASSGROUP 'Vcl.Controls.TControl'}

{$R *.dfm}


uses uVisualFrame;
var VisualFrame_HTTP:TVisualFrame_HTTP;

{ TDBGridSort }

constructor TDBGridSort.Create(AOwner: TComponent);
begin
  inherited;


      if (AOwner is TVisualFrame_HTTP)  then
      VisualFrame_HTTP:=(AOwner as TVisualFrame_HTTP);


end;

procedure TDBGridSort.DBGridSortColumns(Afieldname: string);
begin


   with VisualFrame_HTTP do begin


       if Afieldname='Name' then


              begin

                     if FNameSortDirectionToggle then
                       begin

                       FDTable.IndexFieldNames:='Name';
                       FDTable.Close;
                       FDTable.Open;

                       FNameSortDirectionToggle:=False;

                       end else

                       begin

                       FDTable.IndexFieldNames:='Name:D';
                       FDTable.Close;
                       FDTable.Open;

                       FNameSortDirectionToggle:=true;

                       end;


               end;





      if Afieldname='FileSizeCalc' then

      begin

                     if FFileSizeSortDirectionToggle then
                       begin

                       FDTable.IndexFieldNames:='fileSize';
                       FDTable.Close;
                       FDTable.Open;

                       FFileSizeSortDirectionToggle:=False;

                       end else

                       begin

                       FDTable.IndexFieldNames:='fileSize:D';
                       FDTable.Close;
                       FDTable.Open;

                       FFileSizeSortDirectionToggle:=true;

                       end;


               end;



                                    // creationDateTime
           if Afieldname='creationDateTime' then

           begin

                             if FCreationDateTimeSortDirectionToggle then
                               begin

                               FDTable.IndexFieldNames:='creationDateTime';
                               FDTable.Close;
                               FDTable.Open;

                               FCreationDateTimeSortDirectionToggle:=False;

                               end else

                               begin

                               FDTable.IndexFieldNames:='creationDateTime:D';
                               FDTable.Close;
                               FDTable.Open;

                               FCreationDateTimeSortDirectionToggle:=true;

                               end;


                       end;



          if Afieldname='changesDateTime' then


            begin

                             if FChangesDateTimeSortDirectionToggle then
                               begin

                               FDTable.IndexFieldNames:='changesDateTime';
                               FDTable.Close;
                               FDTable.Open;

                               FChangesDateTimeSortDirectionToggle:=False;

                               end else

                               begin

                               FDTable.IndexFieldNames:='changesDateTime:D';
                               FDTable.Close;
                               FDTable.Open;

                               FChangesDateTimeSortDirectionToggle:=true;

                               end;


                       end;





           // lastAccessDateTime

           if Afieldname='lastAccessDateTime' then

            begin

                             if FLastAccessDateTimeSortDirectionToggle then
                               begin

                               FDTable.IndexFieldNames:='lastAccessDateTime';
                               FDTable.Close;
                               FDTable.Open;

                               FLastAccessDateTimeSortDirectionToggle:=False;

                               end else

                               begin

                               FDTable.IndexFieldNames:='lastAccessDateTime:D';
                               FDTable.Close;
                               FDTable.Open;

                               FLastAccessDateTimeSortDirectionToggle:=true;

                               end;


                       end;




   end;


end;


procedure TDBGridSort.DBGridSortComboboxes(ASortParam: Integer; ASortDirection:integer);

 var i:integer;

begin
//

   with VisualFrame_HTTP do begin


        case ASortParam of

         // name
         0: begin

             case ASortDirection of

              0: begin
              //

                   FDTable.IndexFieldNames:='Name';
                   FDTable.Close;
                   FDTable.Open;

              end;


              1: begin
              //

                   FDTable.IndexFieldNames:='Name:D';
                   FDTable.Close;
                   FDTable.Open;


              end;

             end;


         end;


         // fileSize
         1: begin

             case ASortDirection of

              0: begin
              //

                   FDTable.IndexFieldNames:='fileSize';
                   FDTable.Close;
                   FDTable.Open;

              end;


              1: begin
              //

                   FDTable.IndexFieldNames:='fileSize:D';
                   FDTable.Close;
                   FDTable.Open;


              end;

             end;


         end;




          // creationDateTime
         2: begin

             case ASortDirection of

              0: begin
              //

                   FDTable.IndexFieldNames:='creationDateTime';
                   FDTable.Close;
                   FDTable.Open;

              end;


              1: begin
              //

                   FDTable.IndexFieldNames:='creationDateTime:D';
                   FDTable.Close;
                   FDTable.Open;


              end;

             end;


         end;






         // changesDateTime

         3: begin

             case ASortDirection of

              0: begin
              //

                   FDTable.IndexFieldNames:='changesDateTime';
                   FDTable.Close;
                   FDTable.Open;

              end;


              1: begin
              //

                   FDTable.IndexFieldNames:='changesDateTime:D';
                   FDTable.Close;
                   FDTable.Open;


              end;

             end;


         end;







         // lastAccessDateTime

         4: begin

             case ASortDirection of

              0: begin
              //

                   FDTable.IndexFieldNames:='lastAccessDateTime';
                   FDTable.Close;
                   FDTable.Open;

              end;


              1: begin
              //

                   FDTable.IndexFieldNames:='lastAccessDateTime:D';
                   FDTable.Close;
                   FDTable.Open;


              end;

             end;


         end;










        end;


   end;
end;


end.
