unit ServerMethodsUnit1;
interface
uses
  System.SysUtils, System.Classes, Datasnap.DSServer, Datasnap.DSAuth,
  Data.DBXInterBase, Data.FMTBcd, Data.DB, Data.SqlExpr, Datasnap.Provider;

type
  TMyServerMethods = class(TDSServerModule)
    SQLConnection1: TSQLConnection;
    sqlEmployees: TSQLDataSet;
    dspEmployees: TDataSetProvider;
    sqlDepartments: TSQLDataSet;
    dspEmployeeDepartment: TDataSetProvider;
    dsDepartments: TDataSource;
    sqlDepartment: TSQLDataSet;
    dspDepartments: TDataSetProvider;
    SqLEmployee: TSQLDataSet;
    procedure AS_dspEmployeesBeforeGetRecords(Sender: TObject;
      var OwnerData: OleVariant);
    procedure AS_dspEmployeeDepartmentGetTableName(Sender: TObject;
      DataSet: TDataSet; var TableName: WideString);
    procedure AS_DSServerModuleCreate(Sender: TObject);
    procedure AS_DSServerModuleDestroy(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    function EchoString(Value: string): string;
    [TRoleAuth('admin')]
    function ReverseString(Value: string): string;
    function ServerTime: TDateTime; // new
    function Add33(const X1,X2,X3,X4,X5,X6,X7,X8,X9,X10,
      X11,X12,X13,X14,X15,X16,X17,X18,X19,X20,
      X21,X22,X23,X24,X25,X26,X27,X28,X29,X30,
      X31,X32,X33: Integer): Integer; // new
  public
    function GetEmployees: TDataSet;
  end;

implementation
uses
  System.StrUtils,
  CodeSiteLogging,
  Variants;

{$R *.dfm}

procedure TMyServerMethods.AS_dspEmployeeDepartmentGetTableName(Sender: TObject;
  DataSet: TDataSet; var TableName: WideString);
begin
  TableName := 'EMPLOYEE';
end;

procedure TMyServerMethods.AS_dspEmployeesBeforeGetRecords(Sender: TObject;
  var OwnerData: OleVariant);
//var
//  EMP_NO: Variant;
Begin
//  EMP_NO := OwnerData;
//  if not VarIsNull(EMP_NO) and not VarIsEmpty(EMP_NO) then
//    with Sender as TDataSetProvider do
//    begin
//      DataSet.Active := True; // just in case
//      CodeSite.Send('TDataSetProvider EMP_NO = ' + EMP_NO);
//      DataSet.Locate('EMP_NO', EMP_NO, []);
//      DataSet.Next // start at next record
//    end
end;

procedure TMyServerMethods.AS_DSServerModuleCreate(Sender: TObject);
begin
  CodeSite.Send('TMyServerMethods.DSServerModuleCreate');
end;

procedure TMyServerMethods.AS_DSServerModuleDestroy(Sender: TObject);
begin
  CodeSite.Send('TMyServerMethods.DSServerModuleDestroy');
end;

function TMyServerMethods.EchoString(Value: string): string;
begin
  CodeSite.Send('EchoString ' + value);
  Result := Value
end;

function TMyServerMethods.ReverseString(Value: string): string;
begin
  CodeSite.Send('ReverseString ' + value);
  Result := System.StrUtils.ReverseString(Value)
end;

function TMyServerMethods.ServerTime: TDateTime;
begin
  Result := Now;
  CodeSite.Send('ServerTime ' + DateTimeToStr(Now));
end;

function TMyServerMethods.Add33(const X1, X2, X3, X4, X5, X6, X7, X8, X9, X10,
  X11, X12, X13, X14, X15, X16, X17, X18, X19, X20, X21, X22, X23, X24, X25,
  X26, X27, X28, X29, X30, X31, X32, X33: Integer): Integer;
begin
  Result := X1+X2+X3+X4+X5+X6+X7+X8+X9+X10+ X11+X12+X13+X14+X15+X16+X17+
            X18+X19+X20+X21+X22+X23+X24+X25+X26+X27+X28+X29+X30+X31+X32+X33
end;

function TMyServerMethods.GetEmployees: TDataSet;
begin
  CodeSite.EnterMethod('GetEmployees'); // HIRE_DATE,
  sqlEmployee.CommandText := 'SELECT EMP_NO, FIRST_NAME, LAST_NAME, DEPT_NO, JOB_COUNTRY FROM EMPLOYEE';
  if not sqlEmployee.Active then // make sure data can be retrieved
  begin
    CodeSite.Send('not Active');
    sqlEmployee.Open // open dataset
  end
  else sqlEmployee.First; // in case it already was open
  CodeSite.Send('Result');
  Result := sqlEmployee;
  CodeSite.ExitMethod('GetEmployees');
end;

end.

