unit i_SYSPAZON;

interface

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

type
   _SYSPAZON = 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 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 getTYPEs(tmpSessionName, tmpDatabaseName: String):TQuery;overload;
      function getTYPEs(tmpSessionName, tmpDatabaseName, Cond:String):TQuery;overload;
      function getTYPE(tmpSessionName, tmpDatabaseName, Cond:String):TField;overload;
      function getTYPEvalue(tmpSessionName, tmpDatabaseName, Cond:String):Real;overload;
      function setTYPEvalue(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 getREMARKSs(tmpSessionName, tmpDatabaseName: String):TQuery;overload;
      function getREMARKSs(tmpSessionName, tmpDatabaseName, Cond:String):TQuery;overload;
      function getREMARKS(tmpSessionName, tmpDatabaseName, Cond:String):TField;overload;
      function getREMARKSvalue(tmpSessionName, tmpDatabaseName, Cond:String):String;overload;
      function setREMARKSvalue(tmpSessionName, tmpDatabaseName:String; Value:String; Cond:String):Boolean;
   end;

var
   admin_SYSPAZON: _SYSPAZON;

implementation

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

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

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

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

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

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

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

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


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

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

function _SYSPAZON.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 _SYSPAZON.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 _SYSPAZON.setZONENOvalue(tmpSessionName, tmpDatabaseName: String; Value:String; Cond:String):Boolean;
begin
  Result := execSQL(tmpSessionName, tmpDatabaseName, Format('Update %s set ZONENO = %s where %s',
                           ['SYSPAZON', Value, Cond])
                   );
end;

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

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

function _SYSPAZON.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 _SYSPAZON.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 _SYSPAZON.setBRCHNOvalue(tmpSessionName, tmpDatabaseName: String; Value:String; Cond:String):Boolean;
begin
  Result := execSQL(tmpSessionName, tmpDatabaseName, Format('Update %s set BRCHNO = %s where %s',
                           ['SYSPAZON', Value, Cond])
                   );
end;

function _SYSPAZON.getTYPEs(tmpSessionName, tmpDatabaseName: String):TQuery;
begin
  Result := openSQL(tmpSessionName, tmpDatabaseName, Format('Select TYPE from %s',['SYSPAZON']));
end;

function _SYSPAZON.getTYPEs(tmpSessionName, tmpDatabaseName, Cond:String):TQuery;
begin
  Result := openSQL(tmpSessionName, tmpDatabaseName, Format('Select TYPE from %s where %s',['SYSPAZON', Cond]));
end;

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

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

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

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

function _SYSPAZON.setTYPEvalue(tmpSessionName, tmpDatabaseName: String; Value:String; Cond:String):Boolean;
begin
  Result := execSQL(tmpSessionName, tmpDatabaseName, Format('Update %s set TYPE = %s where %s',
                           ['SYSPAZON', Value, Cond])
                   );
end;

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

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

function _SYSPAZON.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 _SYSPAZON.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 _SYSPAZON.setSTATUSvalue(tmpSessionName, tmpDatabaseName: String; Value:String; Cond:String):Boolean;
begin
  Result := execSQL(tmpSessionName, tmpDatabaseName, Format('Update %s set STATUS = %s where %s',
                           ['SYSPAZON', Value, Cond])
                   );
end;

function _SYSPAZON.getREMARKSs(tmpSessionName, tmpDatabaseName: String):TQuery;
begin
  Result := openSQL(tmpSessionName, tmpDatabaseName, Format('Select REMARKS from %s',['SYSPAZON']));
end;

function _SYSPAZON.getREMARKSs(tmpSessionName, tmpDatabaseName, Cond:String):TQuery;
begin
  Result := openSQL(tmpSessionName, tmpDatabaseName, Format('Select REMARKS from %s where %s',['SYSPAZON', Cond]));
end;

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

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

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

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

function _SYSPAZON.setREMARKSvalue(tmpSessionName, tmpDatabaseName: String; Value:String; Cond:String):Boolean;
begin
  Result := execSQL(tmpSessionName, tmpDatabaseName, Format('Update %s set REMARKS = %s where %s',
                           ['SYSPAZON', Value, Cond])
                   );
end;
end.
