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;
    uqAddTaskRow: TUniQuery;
    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;
    uqTaskHeader: TUniQuery;
    uqTaskHeaderTASK_ID: TStringField;
    uqTaskHeaderPARENT_ID: TStringField;
    uqTaskHeaderTASK_NUM_1: TIntegerField;
    uqTaskHeaderTASK_NUM_2: TIntegerField;
    uqTaskHeaderTASK_NUM_3: TIntegerField;
    uqTaskHeaderTASK_NUM_4: TIntegerField;
    uqTaskHeaderTASK_NUM_5: TIntegerField;
    uqTaskHeaderTASK_NUM_6: TIntegerField;
    uqTaskHeaderPROJECT_ID: TStringField;
    uqTaskHeaderSUBJECT: TStringField;
    uqTaskHeaderPROJECT_NAME: TStringField;
    uqTaskItemCodes: TUniQuery;
    uqTaskItemCodesCODE: TStringField;
    uqTaskItemCodesCODE_DESC: TStringField;
    uqTaskItemCodesCODE_TYPE: TStringField;
    uqGetTaskRowPosition: TUniQuery;
    uqMoveTaskRowTemp: TUniQuery;
    uqShiftTaskRowsDown: TUniQuery;
    uqShiftTaskRowsUp: TUniQuery;
    uqSetTaskRowFinalPosition: TUniQuery;
    uqGetTaskMaxItemNum: TUniQuery;
    uqGetTaskRowPositionTASK_ID: TStringField;
    uqGetTaskRowPositionITEM_NUM: TSmallintField;
    uqTaskItemsTASK_ITEM_ID: TIntegerField;
    uqGetTaskRowPositionTASK_ITEM_ID: TIntegerField;
    uqDeleteTaskRow: TUniQuery;
    uqShiftTaskRowsAfterDelete: TUniQuery;
    uqShiftTaskRowsForInsert: TUniQuery;
    uqProjectReportedUsers: TUniQuery;
    uqTaskAssignedUsers: TUniQuery;
    uqAssignedInsert: TUniQuery;
    uqAssignedRename: TUniQuery;
    uqAssignedDelete: TUniQuery;
    uqRenameAssignedTo: TUniQuery;
    uqBlankAssignedTo: TUniQuery;
    uqProjectReportedUsersNAME: TStringField;
    uqTaskAssignedUsersTASK_ITEM_USER_ID: TStringField;
    uqTaskAssignedUsersTASK_ID: TStringField;
    uqTaskAssignedUsersUSER_TYPE: TStringField;
    uqTaskAssignedUsersNAME: TStringField;
    uqProjectApplications: TUniQuery;
    uqApplicationInsert: TUniQuery;
    uqApplicationRename: TUniQuery;
    uqApplicationDelete: TUniQuery;
    uqRenameTaskItemApplication: TUniQuery;
    uqBlankTaskItemApplication: TUniQuery;
    uqProjectApplicationsTASK_ITEM_APPLICATION_ID: TIntegerField;
    uqProjectApplicationsPROJECT_ID: TStringField;
    uqProjectApplicationsNAME: 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.
