unit uDataBaseInitialTableFilling;

interface

uses
  System.SysUtils, System.Classes;

type
  TDataBaseInitialTableFillling = class(TDataModule)
  private

    procedure FillFileTypeTable;
    procedure FillFileExtensionsTable;
    function IsFileTypeInDB(FileTypeName: string): Boolean;
    function IsFileExtensionInDB(AFileExtension: String): boolean;
    { Private declarations }
  public
    { Public declarations }

    constructor Create(AOwner: TComponent); override;


    procedure InitialTablesFilling;

  end;

//var
//  DataBaseInitialTableFillling: TDataBaseInitialTableFillling;

implementation

{%CLASSGROUP 'Vcl.Controls.TControl'}

{$R *.dfm}

uses uDataBaseUnitServer;

var DataBaseUnitServer:TDataBaseUnitServer;


{ TDataBaseInitialTableFillling }

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

  if (AOwner is TDataBaseUnitServer) then
  DataBaseUnitServer:=(AOwner as TDataBaseUnitServer);

end;



procedure TDataBaseInitialTableFillling.InitialTablesFilling;
begin

  FillFileTypeTable;
  FillFileExtensionsTable;

end;


procedure TDataBaseInitialTableFillling.FillFileTypeTable;



begin
  //FileType

with DataBaseUnitServer do begin

  with qInsertFileType do

    begin


      if not IsFileTypeInDB('Picture') then
      begin
        Params.ParamValues['FileType'] := 'Picture';
        ExecSQL;
      end;

      if not IsFileTypeInDB('Video') then
      begin
        Params.ParamValues['FileType'] := 'Video';
        ExecSQL;
      end;

      if not IsFileTypeInDB('Audio') then
      begin
        Params.ParamValues['FileType'] := 'Audio';
        ExecSQL;
      end;



      if not IsFileTypeInDB('Other') then
      begin
        Params.ParamValues['FileType'] := 'Other';
        ExecSQL;
      end;

             if not IsFileTypeInDB('ForbiddenExtensions') then
      begin
        Params.ParamValues['FileType'] := 'ForbiddenExtensions';
        ExecSQL;
      end;

    end;

  end;

end;



procedure TDataBaseInitialTableFillling.FillFileExtensionsTable;



begin
  //FileType


with DataBaseUnitServer do begin

        with qInsertFileExtension do

          begin

            //PictureExtensions

            if not IsFileExtensionInDB('.jpg') then
            begin
              Params.ParamValues['FileType'] := 'Picture';
              Params.ParamValues['FileExtension'] := '.jpg';
              ExecSQL;
            end;

            if not IsFileExtensionInDB('.jpeg') then

            begin
              Params.ParamValues['FileType'] := 'Picture';
              Params.ParamValues['FileExtension'] := '.jpeg';
              ExecSQL;
            end;


             if not IsFileExtensionInDB('.png') then

            begin
              Params.ParamValues['FileType'] := 'Picture';
              Params.ParamValues['FileExtension'] := '.png';
              ExecSQL;
            end;


               if not IsFileExtensionInDB('.tiff') then

            begin
              Params.ParamValues['FileType'] := 'Picture';
              Params.ParamValues['FileExtension'] := '.tiff';
              ExecSQL;
            end;


                // VideoExtensions

                    if not IsFileExtensionInDB('.avi') then

                    begin
                      Params.ParamValues['FileType'] := 'Video';
                      Params.ParamValues['FileExtension'] := '.avi';
                      ExecSQL;
                    end;



                    if not IsFileExtensionInDB('.mp4') then

                    begin
                      Params.ParamValues['FileType'] := 'Video';
                      Params.ParamValues['FileExtension'] := '.mp4';
                      ExecSQL;
                    end;



            // Audio Extensions


                   if not IsFileExtensionInDB('.mp3') then

                    begin
                      Params.ParamValues['FileType'] := 'Audio';
                      Params.ParamValues['FileExtension'] := '.mp3';
                      ExecSQL;
                    end;



                    if not IsFileExtensionInDB('.wav') then

                    begin
                      Params.ParamValues['FileType'] := 'Audio';
                      Params.ParamValues['FileExtension'] := '.wav';
                      ExecSQL;
                    end;


             // Forbidden Extensions
                              if not IsFileExtensionInDB('.exe') then

                    begin
                      Params.ParamValues['FileType'] := 'ForbiddenExtensions';
                      Params.ParamValues['FileExtension'] := '.exe';
                      ExecSQL;
                    end;



                    if not IsFileExtensionInDB('.php') then

                    begin
                      Params.ParamValues['FileType'] := 'ForbiddenExtensions';
                      Params.ParamValues['FileExtension'] := '.php';
                      ExecSQL;
                    end;



          end;


    end;


end;



function TDataBaseInitialTableFillling.IsFileTypeInDB(FileTypeName:string):Boolean;


begin

Result:=False;

    with DataBaseUnitServer do begin



         with qSelectFileType do begin


         Open();


           while not EOF  do begin

           if FileTypeName=FieldByName('FileType').AsString then

            begin
            Result:=true;
            Break;
            end;

           Next();
           end;



         Close();



         end;



    end;

end;



function TDataBaseInitialTableFillling.IsFileExtensionInDB(AFileExtension:String):boolean;
begin
//
Result:=False;

  with DataBaseUnitServer do begin

     with qSelectFileExtension do begin


     Open();


       while not EOF  do begin

       if AFileExtension=FieldByName('FileExtension').AsString then

        begin
        Result:=true;
        Break;
        end;

       Next();
       end;



     Close();



     end;


  end;

end;


end.
