unit i_SYSPASCV;

interface

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

type
   _SYSPASCV = 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 getAPPCODEs(tmpSessionName, tmpDatabaseName: String):TQuery;overload;
      function getAPPCODEs(tmpSessionName, tmpDatabaseName, Cond:String):TQuery;overload;
      function getAPPCODE(tmpSessionName, tmpDatabaseName, Cond:String):TField;overload;
      function getAPPCODEvalue(tmpSessionName, tmpDatabaseName, Cond:String):Real;overload;
      function setAPPCODEvalue(tmpSessionName, tmpDatabaseName:String; Value:String; Cond:String):Boolean;

      function getAPPNAMEs(tmpSessionName, tmpDatabaseName: String):TQuery;overload;
      function getAPPNAMEs(tmpSessionName, tmpDatabaseName, Cond:String):TQuery;overload;
      function getAPPNAME(tmpSessionName, tmpDatabaseName, Cond:String):TField;overload;
      function getAPPNAMEvalue(tmpSessionName, tmpDatabaseName, Cond:String):String;overload;
      function setAPPNAMEvalue(tmpSessionName, tmpDatabaseName:String; Value:String; Cond:String):Boolean;

      function getAPPSQNOs(tmpSessionName, tmpDatabaseName: String):TQuery;overload;
      function getAPPSQNOs(tmpSessionName, tmpDatabaseName, Cond:String):TQuery;overload;
      function getAPPSQNO(tmpSessionName, tmpDatabaseName, Cond:String):TField;overload;
      function getAPPSQNOvalue(tmpSessionName, tmpDatabaseName, Cond:String):Real;overload;
      function setAPPSQNOvalue(tmpSessionName, tmpDatabaseName:String; Value:String; Cond:String):Boolean;
   end;

var
   admin_SYSPASCV: _SYSPASCV;

implementation

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

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

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

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

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

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

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

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


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

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

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

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

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

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

function _SYSPASCV.getAPPCODEs(tmpSessionName, tmpDatabaseName: String):TQuery;
begin
  Result := openSQL(tmpSessionName, tmpDatabaseName, Format('Select APPCODE from %s',['SYSPASCV']));
end;

function _SYSPASCV.getAPPCODEs(tmpSessionName, tmpDatabaseName, Cond:String):TQuery;
begin
  Result := openSQL(tmpSessionName, tmpDatabaseName, Format('Select APPCODE from %s where %s',['SYSPASCV', Cond]));
end;

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

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

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

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

function _SYSPASCV.setAPPCODEvalue(tmpSessionName, tmpDatabaseName: String; Value:String; Cond:String):Boolean;
begin
  Result := execSQL(tmpSessionName, tmpDatabaseName, Format('Update %s set APPCODE = %s where %s',
                           ['SYSPASCV', Value, Cond])
                   );
end;

function _SYSPASCV.getAPPNAMEs(tmpSessionName, tmpDatabaseName: String):TQuery;
begin
  Result := openSQL(tmpSessionName, tmpDatabaseName, Format('Select APPNAME from %s',['SYSPASCV']));
end;

function _SYSPASCV.getAPPNAMEs(tmpSessionName, tmpDatabaseName, Cond:String):TQuery;
begin
  Result := openSQL(tmpSessionName, tmpDatabaseName, Format('Select APPNAME from %s where %s',['SYSPASCV', Cond]));
end;

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

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

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

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

function _SYSPASCV.setAPPNAMEvalue(tmpSessionName, tmpDatabaseName: String; Value:String; Cond:String):Boolean;
begin
  Result := execSQL(tmpSessionName, tmpDatabaseName, Format('Update %s set APPNAME = %s where %s',
                           ['SYSPASCV', Value, Cond])
                   );
end;

function _SYSPASCV.getAPPSQNOs(tmpSessionName, tmpDatabaseName: String):TQuery;
begin
  Result := openSQL(tmpSessionName, tmpDatabaseName, Format('Select APPSQNO from %s',['SYSPASCV']));
end;

function _SYSPASCV.getAPPSQNOs(tmpSessionName, tmpDatabaseName, Cond:String):TQuery;
begin
  Result := openSQL(tmpSessionName, tmpDatabaseName, Format('Select APPSQNO from %s where %s',['SYSPASCV', Cond]));
end;

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

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

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

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

function _SYSPASCV.setAPPSQNOvalue(tmpSessionName, tmpDatabaseName: String; Value:String; Cond:String):Boolean;
begin
  Result := execSQL(tmpSessionName, tmpDatabaseName, Format('Update %s set APPSQNO = %s where %s',
                           ['SYSPASCV', Value, Cond])
                   );
end;
end.
