unit Api.Database;

interface

uses
  System.SysUtils, System.Classes, Data.DB, MemDS, DBAccess, Uni, UniProvider,
  PostgreSQLUniProvider, System.Variants, System.Generics.Collections, System.IniFiles,
  Common.Logging, Vcl.Forms, MySQLUniProvider;

type
  TApiDatabase = class(TDataModule)
    ucETaskApi: TUniConnection;
    MySQLUniProvider1: TMySQLUniProvider;
    uqUsers: TUniQuery;
    uqUsersUSER_ID: TIntegerField;
    uqUsersNAME: TStringField;
    uqUsersSTATUS: TStringField;
    uqUsersREPRESENTATIVE: TStringField;
    uqSaveTaskRow: TUniQuery;
    uqTaskItems: TUniQuery;
    uqEnsureBlankRow: TUniQuery;
    uqTaskItemsTASK_ITEM_ID: TStringField;
    uqTaskItemsTASK_ID: TStringField;
    uqTaskItemsITEM_NUM: TShortintField;
    uqTaskItemsAPPLICATION: TStringField;
    uqTaskItemsAPP_VERSION: TStringField;
    uqTaskItemsTASK_DATE: TDateField;
    uqTaskItemsSTATUS_DATE: TDateField;
    uqTaskItemsREPORTED_BY: TStringField;
    uqTaskItemsASSIGNED_TO: TStringField;
    uqTaskItemsSTATUS: TStringField;
    uqTaskItemsFIXED_VERSION: TStringField;
    uqTaskItemsFORM_SECTION: TStringField;
    uqTaskItemsISSUE: TStringField;
    uqTaskItemsNOTES: TStringField;
    procedure DataModuleCreate(Sender: TObject);
    procedure uqUsersCalcFields(DataSet: TDataSet);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  ApiDatabase: TApiDatabase;

implementation

uses
  uLibrary;
{%CLASSGROUP 'Vcl.Controls.TControl'}

{$R *.dfm}

procedure TApiDatabase.DataModuleCreate(Sender: TObject);
begin
  Logger.Log( 5, 'TApiDatabase.DataModuleCreate' );
  LoadDatabaseSettings( ucETaskApi, 'emT3XDataServer.ini' );
  try
    ucETaskApi.Connect;
  except
    on E: Exception do
    begin
      Logger.Log(2, '--TApiDatabase.DataModuleCreate -Error connecting to database: ' + E.Message);
    end;
  end;
end;

procedure TApiDatabase.uqUsersCalcFields(DataSet: TDataSet);
begin
  uqUsersREPRESENTATIVE.AsString := uqUsersNAME.AsString + '(' + uqUsersSTATUS.AsString + ')';
end;

end.
