unit i_SYSPATRX;

interface

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

type
   _SYSPATRX = 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 getCODEs(tmpSessionName, tmpDatabaseName: String):TQuery;overload;
      function getCODEs(tmpSessionName, tmpDatabaseName, Cond:String):TQuery;overload;
      function getCODE(tmpSessionName, tmpDatabaseName, Cond:String):TField;overload;
      function getCODEvalue(tmpSessionName, tmpDatabaseName, Cond:String):Real;overload;
      function setCODEvalue(tmpSessionName, tmpDatabaseName:String; Value:String; Cond:String):Boolean;

      function getSLEVELs(tmpSessionName, tmpDatabaseName: String):TQuery;overload;
      function getSLEVELs(tmpSessionName, tmpDatabaseName, Cond:String):TQuery;overload;
      function getSLEVEL(tmpSessionName, tmpDatabaseName, Cond:String):TField;overload;
      function getSLEVELvalue(tmpSessionName, tmpDatabaseName, Cond:String):Real;overload;
      function setSLEVELvalue(tmpSessionName, tmpDatabaseName:String; Value:String; Cond:String):Boolean;

      function getZONENOs(tmpSessionName, tmpDatabaseName: String):TQuery;overload;
      function getZONENOs(tmpSessionName, tmpDatabaseName, Cond:String):TQuery;overload;
      function getZONENO(tmpSessionName, tmpDatabaseName, Cond:String):TField;overload;
      function getZONENOvalue(tmpSessionName, tmpDatabaseName, Cond:String):Real;overload;
      function setZONENOvalue(tmpSessionName, tmpDatabaseName:String; Value:String; Cond:String):Boolean;

      function getBRCHNOs(tmpSessionName, tmpDatabaseName: String):TQuery;overload;
      function getBRCHNOs(tmpSessionName, tmpDatabaseName, Cond:String):TQuery;overload;
      function getBRCHNO(tmpSessionName, tmpDatabaseName, Cond:String):TField;overload;
      function getBRCHNOvalue(tmpSessionName, tmpDatabaseName, Cond:String):Real;overload;
      function setBRCHNOvalue(tmpSessionName, tmpDatabaseName:String; Value:String; Cond:String):Boolean;

      function getSCRIPTs(tmpSessionName, tmpDatabaseName: String):TQuery;overload;
      function getSCRIPTs(tmpSessionName, tmpDatabaseName, Cond:String):TQuery;overload;
      function getSCRIPT(tmpSessionName, tmpDatabaseName, Cond:String):TField;overload;
      function getSCRIPTvalue(tmpSessionName, tmpDatabaseName, Cond:String):String;overload;
      function setSCRIPTvalue(tmpSessionName, tmpDatabaseName:String; Value:String; Cond:String):Boolean;

      function getSTATUSs(tmpSessionName, tmpDatabaseName: String):TQuery;overload;
      function getSTATUSs(tmpSessionName, tmpDatabaseName, Cond:String):TQuery;overload;
      function getSTATUS(tmpSessionName, tmpDatabaseName, Cond:String):TField;overload;
      function getSTATUSvalue(tmpSessionName, tmpDatabaseName, Cond:String):Real;overload;
      function setSTATUSvalue(tmpSessionName, tmpDatabaseName:String; Value:String; Cond:String):Boolean;

      function getPOSIs(tmpSessionName, tmpDatabaseName: String):TQuery;overload;
      function getPOSIs(tmpSessionName, tmpDatabaseName, Cond:String):TQuery;overload;
      function getPOSI(tmpSessionName, tmpDatabaseName, Cond:String):TField;overload;
      function getPOSIvalue(tmpSessionName, tmpDatabaseName, Cond:String):String;overload;
      function setPOSIvalue(tmpSessionName, tmpDatabaseName:String; Value:String; Cond:String):Boolean;

      function getGWIDs(tmpSessionName, tmpDatabaseName: String):TQuery;overload;
      function getGWIDs(tmpSessionName, tmpDatabaseName, Cond:String):TQuery;overload;
      function getGWID(tmpSessionName, tmpDatabaseName, Cond:String):TField;overload;
      function getGWIDvalue(tmpSessionName, tmpDatabaseName, Cond:String):String;overload;
      function setGWIDvalue(tmpSessionName, tmpDatabaseName:String; Value:String; Cond:String):Boolean;

      function getSRVCs(tmpSessionName, tmpDatabaseName: String):TQuery;overload;
      function getSRVCs(tmpSessionName, tmpDatabaseName, Cond:String):TQuery;overload;
      function getSRVC(tmpSessionName, tmpDatabaseName, Cond:String):TField;overload;
      function getSRVCvalue(tmpSessionName, tmpDatabaseName, Cond:String):String;overload;
      function setSRVCvalue(tmpSessionName, tmpDatabaseName:String; Value:String; Cond:String):Boolean;
   end;

var
   admin_SYSPATRX: _SYSPATRX;

implementation

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

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

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

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

function _SYSPATRX.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 ',['SYSPATRX']);

      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 _SYSPATRX.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(',['SYSPATRX']);

      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 _SYSPATRX.Delete(tmpSessionName, tmpDatabaseName, Cond:String):Boolean;
begin
   Result := execSQL(tmpSessionName, tmpDatabaseName, Format('Delete from %s where %s',['SYSPATRX', Cond]));
end;

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


function _SYSPATRX.getCODEs(tmpSessionName, tmpDatabaseName: String):TQuery;
begin
  Result := openSQL(tmpSessionName, tmpDatabaseName, Format('Select CODE from %s',['SYSPATRX']));
end;

function _SYSPATRX.getCODEs(tmpSessionName, tmpDatabaseName, Cond:String):TQuery;
begin
  Result := openSQL(tmpSessionName, tmpDatabaseName, Format('Select CODE from %s where %s',['SYSPATRX', Cond]));
end;

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

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

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

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

function _SYSPATRX.setCODEvalue(tmpSessionName, tmpDatabaseName: String; Value:String; Cond:String):Boolean;
begin
  Result := execSQL(tmpSessionName, tmpDatabaseName, Format('Update %s set CODE = %s where %s',
                           ['SYSPATRX', Value, Cond])
                   );
end;

function _SYSPATRX.getSLEVELs(tmpSessionName, tmpDatabaseName: String):TQuery;
begin
  Result := openSQL(tmpSessionName, tmpDatabaseName, Format('Select SLEVEL from %s',['SYSPATRX']));
end;

function _SYSPATRX.getSLEVELs(tmpSessionName, tmpDatabaseName, Cond:String):TQuery;
begin
  Result := openSQL(tmpSessionName, tmpDatabaseName, Format('Select SLEVEL from %s where %s',['SYSPATRX', Cond]));
end;

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

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

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

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

function _SYSPATRX.setSLEVELvalue(tmpSessionName, tmpDatabaseName: String; Value:String; Cond:String):Boolean;
begin
  Result := execSQL(tmpSessionName, tmpDatabaseName, Format('Update %s set SLEVEL = %s where %s',
                           ['SYSPATRX', Value, Cond])
                   );
end;

function _SYSPATRX.getZONENOs(tmpSessionName, tmpDatabaseName: String):TQuery;
begin
  Result := openSQL(tmpSessionName, tmpDatabaseName, Format('Select ZONENO from %s',['SYSPATRX']));
end;

function _SYSPATRX.getZONENOs(tmpSessionName, tmpDatabaseName, Cond:String):TQuery;
begin
  Result := openSQL(tmpSessionName, tmpDatabaseName, Format('Select ZONENO from %s where %s',['SYSPATRX', Cond]));
end;

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

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

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

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

function _SYSPATRX.setZONENOvalue(tmpSessionName, tmpDatabaseName: String; Value:String; Cond:String):Boolean;
begin
  Result := execSQL(tmpSessionName, tmpDatabaseName, Format('Update %s set ZONENO = %s where %s',
                           ['SYSPATRX', Value, Cond])
                   );
end;

function _SYSPATRX.getBRCHNOs(tmpSessionName, tmpDatabaseName: String):TQuery;
begin
  Result := openSQL(tmpSessionName, tmpDatabaseName, Format('Select BRCHNO from %s',['SYSPATRX']));
end;

function _SYSPATRX.getBRCHNOs(tmpSessionName, tmpDatabaseName, Cond:String):TQuery;
begin
  Result := openSQL(tmpSessionName, tmpDatabaseName, Format('Select BRCHNO from %s where %s',['SYSPATRX', Cond]));
end;

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

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

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

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

function _SYSPATRX.setBRCHNOvalue(tmpSessionName, tmpDatabaseName: String; Value:String; Cond:String):Boolean;
begin
  Result := execSQL(tmpSessionName, tmpDatabaseName, Format('Update %s set BRCHNO = %s where %s',
                           ['SYSPATRX', Value, Cond])
                   );
end;

function _SYSPATRX.getSCRIPTs(tmpSessionName, tmpDatabaseName: String):TQuery;
begin
  Result := openSQL(tmpSessionName, tmpDatabaseName, Format('Select SCRIPT from %s',['SYSPATRX']));
end;

function _SYSPATRX.getSCRIPTs(tmpSessionName, tmpDatabaseName, Cond:String):TQuery;
begin
  Result := openSQL(tmpSessionName, tmpDatabaseName, Format('Select SCRIPT from %s where %s',['SYSPATRX', Cond]));
end;

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

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

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

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

function _SYSPATRX.setSCRIPTvalue(tmpSessionName, tmpDatabaseName: String; Value:String; Cond:String):Boolean;
begin
  Result := execSQL(tmpSessionName, tmpDatabaseName, Format('Update %s set SCRIPT = %s where %s',
                           ['SYSPATRX', Value, Cond])
                   );
end;

function _SYSPATRX.getSTATUSs(tmpSessionName, tmpDatabaseName: String):TQuery;
begin
  Result := openSQL(tmpSessionName, tmpDatabaseName, Format('Select STATUS from %s',['SYSPATRX']));
end;

function _SYSPATRX.getSTATUSs(tmpSessionName, tmpDatabaseName, Cond:String):TQuery;
begin
  Result := openSQL(tmpSessionName, tmpDatabaseName, Format('Select STATUS from %s where %s',['SYSPATRX', Cond]));
end;

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

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

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

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

function _SYSPATRX.setSTATUSvalue(tmpSessionName, tmpDatabaseName: String; Value:String; Cond:String):Boolean;
begin
  Result := execSQL(tmpSessionName, tmpDatabaseName, Format('Update %s set STATUS = %s where %s',
                           ['SYSPATRX', Value, Cond])
                   );
end;

function _SYSPATRX.getPOSIs(tmpSessionName, tmpDatabaseName: String):TQuery;
begin
  Result := openSQL(tmpSessionName, tmpDatabaseName, Format('Select POSI from %s',['SYSPATRX']));
end;

function _SYSPATRX.getPOSIs(tmpSessionName, tmpDatabaseName, Cond:String):TQuery;
begin
  Result := openSQL(tmpSessionName, tmpDatabaseName, Format('Select POSI from %s where %s',['SYSPATRX', Cond]));
end;

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

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

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

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

function _SYSPATRX.setPOSIvalue(tmpSessionName, tmpDatabaseName: String; Value:String; Cond:String):Boolean;
begin
  Result := execSQL(tmpSessionName, tmpDatabaseName, Format('Update %s set POSI = %s where %s',
                           ['SYSPATRX', Value, Cond])
                   );
end;

function _SYSPATRX.getGWIDs(tmpSessionName, tmpDatabaseName: String):TQuery;
begin
  Result := openSQL(tmpSessionName, tmpDatabaseName, Format('Select GWID from %s',['SYSPATRX']));
end;

function _SYSPATRX.getGWIDs(tmpSessionName, tmpDatabaseName, Cond:String):TQuery;
begin
  Result := openSQL(tmpSessionName, tmpDatabaseName, Format('Select GWID from %s where %s',['SYSPATRX', Cond]));
end;

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

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

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

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

function _SYSPATRX.setGWIDvalue(tmpSessionName, tmpDatabaseName: String; Value:String; Cond:String):Boolean;
begin
  Result := execSQL(tmpSessionName, tmpDatabaseName, Format('Update %s set GWID = %s where %s',
                           ['SYSPATRX', Value, Cond])
                   );
end;

function _SYSPATRX.getSRVCs(tmpSessionName, tmpDatabaseName: String):TQuery;
begin
  Result := openSQL(tmpSessionName, tmpDatabaseName, Format('Select SRVC from %s',['SYSPATRX']));
end;

function _SYSPATRX.getSRVCs(tmpSessionName, tmpDatabaseName, Cond:String):TQuery;
begin
  Result := openSQL(tmpSessionName, tmpDatabaseName, Format('Select SRVC from %s where %s',['SYSPATRX', Cond]));
end;

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

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

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

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

function _SYSPATRX.setSRVCvalue(tmpSessionName, tmpDatabaseName: String; Value:String; Cond:String):Boolean;
begin
  Result := execSQL(tmpSessionName, tmpDatabaseName, Format('Update %s set SRVC = %s where %s',
                           ['SYSPATRX', Value, Cond])
                   );
end;
end.
