unit i_SYSPASCT;

interface

uses
   DB, DBTables, Sysutils, { Variants, } i_ebss;

type
   _SYSPASCT = class(_ebss)
   public
      function getAllRows(tmpSessionName, tmpDatabaseName: String):TQuery;overload;
      function getAllRows(tmpSessionName, tmpDatabaseName, Cond:String):TQuery;overload;

      function getSomeColumns(tmpSessionName, tmpDatabaseName, ColumnNames:String):TQuery;overload;
      function getSomeColumns(tmpSessionName, tmpDatabaseName, ColumnNames, Cond:String):TQuery;overload;
      function setSomeColumns(tmpSessionName, tmpDatabaseName: String;FieldNames, Values: Variant) :Boolean;

      function Insert(tmpSessionName, tmpDatabaseName:String;Values: Variant):Boolean;
      function Delete(tmpSessionName, tmpDatabaseName, Cond:String):Boolean;
      function Empty(tmpSessionName, tmpDatabaseName: String):Boolean;

      function getWORKDATEs(tmpSessionName, tmpDatabaseName: String):TQuery;overload;
      function getWORKDATEs(tmpSessionName, tmpDatabaseName, Cond:String):TQuery;overload;
      function getWORKDATE(tmpSessionName, tmpDatabaseName, Cond:String):TField;overload;
      function getWORKDATEvalue(tmpSessionName, tmpDatabaseName, Cond:String):String;overload;
      function setWORKDATEvalue(tmpSessionName, tmpDatabaseName:String; Value:String; Cond:String):Boolean;

      function getJOURNALIs(tmpSessionName, tmpDatabaseName: String):TQuery;overload;
      function getJOURNALIs(tmpSessionName, tmpDatabaseName, Cond:String):TQuery;overload;
      function getJOURNALI(tmpSessionName, tmpDatabaseName, Cond:String):TField;overload;
      function getJOURNALIvalue(tmpSessionName, tmpDatabaseName, Cond:String):Real;overload;
      function setJOURNALIvalue(tmpSessionName, tmpDatabaseName:String; Value:String; Cond:String):Boolean;

      function getTRXSEQNOs(tmpSessionName, tmpDatabaseName: String):TQuery;overload;
      function getTRXSEQNOs(tmpSessionName, tmpDatabaseName, Cond:String):TQuery;overload;
      function getTRXSEQNO(tmpSessionName, tmpDatabaseName, Cond:String):TField;overload;
      function getTRXSEQNOvalue(tmpSessionName, tmpDatabaseName, Cond:String):Real;overload;
      function setTRXSEQNOvalue(tmpSessionName, tmpDatabaseName:String; Value:String; Cond:String):Boolean;
   end;

var
   admin_SYSPASCT: _SYSPASCT;

implementation

function _SYSPASCT.getAllRows(tmpSessionName, tmpDatabaseName: String):TQuery;
begin
   Result := openSQL(tmpSessionName, tmpDatabaseName, Format('Select * from %s', ['SYSPASCT']));
end;

function _SYSPASCT.getAllRows(tmpSessionName, tmpDatabaseName, Cond:String):TQuery;
begin
   Result := openSQL(tmpSessionName, tmpDatabaseName, Format('Select * from %s where %s',['SYSPASCT', Cond]));
end;

function _SYSPASCT.getSomeColumns(tmpSessionName, tmpDatabaseName, ColumnNames:String):TQuery;
begin
   Result := openSQL(tmpSessionName, tmpDatabaseName, Format('Select %s from %s',[ColumnNames, 'SYSPASCT']));
end;

function _SYSPASCT.getSomeColumns(tmpSessionName, tmpDatabaseName, ColumnNames, Cond:String):TQuery;
begin
   Result := openSQL(tmpSessionName, tmpDatabaseName, Format('Select %s from %s where %s',[ColumnNames, 'SYSPASCT', Cond]));
end;

function _SYSPASCT.setSomeColumns(tmpSessionName, tmpDatabaseName: String;FieldNames, Values: Variant) :Boolean;
var
   i,n: Integer;
   NamesCount, ValuesCount:Integer;
   tmpSQL: String;
begin
   Result := False;

   NamesCount := VarArrayHighBound(FieldNames, 1);
   ValuesCount := VarArrayHighBound(Values, 1);

   If NamesCount = ValuesCount then
   begin
      n := NamesCount;

      tmpSQL := Format('Update %s set ',['SYSPASCT']);

      For i:= 0 to n do
      begin
         tmpSQL := tmpSQL + Format('%s = %s',[FieldNames[i], Values[i]]);
         If i < n then
         begin
            tmpSQL := tmpSQL +', ';
         end;
      end;
      Result := execSQL(tmpSessionName, tmpDatabaseName, tmpSQL);
   end;
end;

function _SYSPASCT.Insert(tmpSessionName, tmpDatabaseName: String;Values: Variant):Boolean;
var
   i,n: Integer;
   ValueCount: Integer;
   tmpSQL: String;
begin
   Result := False;

   ValueCount := VarArrayHighBound(Values, 1);

   If ValueCount > 0 then
   begin
      n := ValueCount;

      tmpSQL := Format('Insert into %s values(',['SYSPASCT']);

      For i:= 0 to n do
      begin
         tmpSQL := tmpSQL + Format('%s',[Values[i]]);
         If i < n then
         begin
            tmpSQL := tmpSQL +', ';
         end;
      end;
      tmpSQL := tmpSQL + ')';

      Result := execSQL(tmpSessionName, tmpDatabaseName, tmpSQL);
   end;
end;

function _SYSPASCT.Delete(tmpSessionName, tmpDatabaseName, Cond:String):Boolean;
begin
   Result := execSQL(tmpSessionName, tmpDatabaseName, Format('Delete from %s where %s',['SYSPASCT', Cond]));
end;

function _SYSPASCT.Empty(tmpSessionName, tmpDatabaseName: String):Boolean;
begin
   Result := execSQL(tmpSessionName, tmpDatabaseName, Format('Delete from %s',['SYSPASCT']));
end;


function _SYSPASCT.getWORKDATEs(tmpSessionName, tmpDatabaseName: String):TQuery;
begin
  Result := openSQL(tmpSessionName, tmpDatabaseName, Format('Select WORKDATE from %s',['SYSPASCT']));
end;

function _SYSPASCT.getWORKDATEs(tmpSessionName, tmpDatabaseName, Cond:String):TQuery;
begin
  Result := openSQL(tmpSessionName, tmpDatabaseName, Format('Select WORKDATE from %s where %s',['SYSPASCT', Cond]));
end;

function _SYSPASCT.getWORKDATE(tmpSessionName, tmpDatabaseName, Cond:String):TField;
var
  Query: TQuery;
begin
  Result := nil;

  Query := getWORKDATEs(tmpSessionName, tmpDatabaseName, Cond);
  If Not Query.IsEmpty then
  begin
    Result := Query.FieldByName('WORKDATE');
  end;
  Query.Free;
end;

function _SYSPASCT.getWORKDATEvalue(tmpSessionName, tmpDatabaseName, Cond:String):String;
var
  Query: TQuery;
begin
  Result := 'null';

  Query := getWORKDATEs(tmpSessionName, tmpDatabaseName, Cond);
  If Not Query.IsEmpty then
  begin
    Result := Query.FieldByName('WORKDATE').AsString;
  end;
  Query.Free;
end;

function _SYSPASCT.setWORKDATEvalue(tmpSessionName, tmpDatabaseName: String; Value:String; Cond:String):Boolean;
begin
  Result := execSQL(tmpSessionName, tmpDatabaseName, Format('Update %s set WORKDATE = %s where %s',
                           ['SYSPASCT', Value, Cond])
                   );
end;

function _SYSPASCT.getJOURNALIs(tmpSessionName, tmpDatabaseName: String):TQuery;
begin
  Result := openSQL(tmpSessionName, tmpDatabaseName, Format('Select JOURNALI from %s',['SYSPASCT']));
end;

function _SYSPASCT.getJOURNALIs(tmpSessionName, tmpDatabaseName, Cond:String):TQuery;
begin
  Result := openSQL(tmpSessionName, tmpDatabaseName, Format('Select JOURNALI from %s where %s',['SYSPASCT', Cond]));
end;

function _SYSPASCT.getJOURNALI(tmpSessionName, tmpDatabaseName, Cond:String):TField;
var
  Query: TQuery;
begin
  Result := nil;

  Query := getJOURNALIs(tmpSessionName, tmpDatabaseName, Cond);
  If Not Query.IsEmpty then
  begin
    Result := Query.FieldByName('JOURNALI');
  end;
  Query.Free;
end;

function _SYSPASCT.getJOURNALIvalue(tmpSessionName, tmpDatabaseName, Cond:String):Real;
var
  Query: TQuery;
begin
  Result := -1;

  Query := getJOURNALIs(tmpSessionName, tmpDatabaseName, Cond);
  If Not Query.IsEmpty then
  begin
    Result := Query.FieldByName('JOURNALI').AsVariant;
  end;
  Query.Free;
end;

function _SYSPASCT.setJOURNALIvalue(tmpSessionName, tmpDatabaseName: String; Value:String; Cond:String):Boolean;
begin
  Result := execSQL(tmpSessionName, tmpDatabaseName, Format('Update %s set JOURNALI = %s where %s',
                           ['SYSPASCT', Value, Cond])
                   );
end;

function _SYSPASCT.getTRXSEQNOs(tmpSessionName, tmpDatabaseName: String):TQuery;
begin
  Result := openSQL(tmpSessionName, tmpDatabaseName, Format('Select TRXSEQNO from %s',['SYSPASCT']));
end;

function _SYSPASCT.getTRXSEQNOs(tmpSessionName, tmpDatabaseName, Cond:String):TQuery;
begin
  Result := openSQL(tmpSessionName, tmpDatabaseName, Format('Select TRXSEQNO from %s where %s',['SYSPASCT', Cond]));
end;

function _SYSPASCT.getTRXSEQNO(tmpSessionName, tmpDatabaseName, Cond:String):TField;
var
  Query: TQuery;
begin
  Result := nil;

  Query := getTRXSEQNOs(tmpSessionName, tmpDatabaseName, Cond);
  If Not Query.IsEmpty then
  begin
    Result := Query.FieldByName('TRXSEQNO');
  end;
  Query.Free;
end;

function _SYSPASCT.getTRXSEQNOvalue(tmpSessionName, tmpDatabaseName, Cond:String):Real;
var
  Query: TQuery;
begin
  Result := -1;

  Query := getTRXSEQNOs(tmpSessionName, tmpDatabaseName, Cond);
  If Not Query.IsEmpty then
  begin
    Result := Query.FieldByName('TRXSEQNO').AsVariant;
  end;
  Query.Free;
end;

function _SYSPASCT.setTRXSEQNOvalue(tmpSessionName, tmpDatabaseName: String; Value:String; Cond:String):Boolean;
begin
  Result := execSQL(tmpSessionName, tmpDatabaseName, Format('Update %s set TRXSEQNO = %s where %s',
                           ['SYSPASCT', Value, Cond])
                   );
end;
end.
