unit auxiapi;

interface

uses Sysutils, Classes, Grids, DB, emapi, uss;

{  Terminal Package Analysis Utilities  }
function PACK1100(sinComm:TSinComm; sin:TBuffer):String;
function UNPACK1100(outStr: String):TSoutComm;

{  Server Package Analysis Utilities for TRCT }
//procedure UNPACK_COMMTRCT(SRC: String;var inComm: TRinComm);
//function PACK_COMMTRCT(outComm: TRoutComm):String;

{  Server Package Analysis Utilities for TACT }
procedure UNPACK_COMMTACT(SRC: String;var inComm: TTinComm);
function PACK_COMMTACT(outComm: TToutComm):String;

{  Common Utilities for Terminal & Server }
function CalcPassword(Password: String):Longint;
function FormatInt(Src, MaxSize: Integer):String;

function PackTable(DataSet: TDataSet):String;overload;
//function unPackTable(Src: String; Parent: TComponent): TStringGrid;
procedure unPackTable(Src: String; Target: TStringGrid);
function PackTable(DataSet: TDataSet; TitleNames, TitleSize: Variant):String;overload;

implementation

procedure unPackTable(Src: String; Target: TStringGrid);
var
  tmpStr: String;
  i, j: Integer;
begin
  tmpStr := Src;

  Target.FixedCols := 0;
  Target.FixedRows := 0;

  Target.RowCount := 1 + StrToInt(Ut_OutOfPackage(tmpStr, tmpStr));
  Target.ColCount := StrToInt(Ut_OutOfPackage(tmpStr, tmpStr));
  Target.FixedRows := 1;

  For i := 0 to Target.ColCount - 1 do
  begin
     Target.Cells[i, 0] := Ut_OutOfPackage(tmpStr, tmpStr);
     Target.ColWidths[i] := StrToInt(Ut_OutOfPackage(tmpStr, tmpStr));
  end;

  For i := 1 to Target.RowCount - 1 do
  begin
     For j := 0 to Target.ColCount -1 do
     begin
       Target.Cells[j, i] := Ut_OutOfPackage(tmpStr, tmpStr);
     end;
  end;
end;
{
function unPackTable(Src: String; Parent: TComponent): TStringGrid;
var
  tmpStr: String;
  i, j: Integer;
begin
  tmpStr := Src;

  Ut_OutOfPackage(tmpStr, tmpStr);
  Ut_OutOfPackage(tmpStr, tmpStr);

  Result := TStringGrid.Create(Parent);
  Result.FixedCols := 0;
  Result.FixedRows := 0;

  Result.RowCount := 1 + StrToInt(Ut_OutOfPackage(tmpStr, tmpStr));
  Result.ColCount := StrToInt(Ut_OutOfPackage(tmpStr, tmpStr));
  Result.FixedRows := 1;

  For i := 0 to Result.ColCount - 1 do
  begin
     Result.Cells[i, 0] := Ut_OutOfPackage(tmpStr, tmpStr);
     Result.ColWidths[i] := StrToInt(Ut_OutOfPackage(tmpStr, tmpStr));
  end;

  For i := 1 to Result.RowCount - 1 do
  begin
     For j := 0 to Result.ColCount -1 do
     begin
       Result.Cells[j, i] := Ut_OutOfPackage(tmpStr, tmpStr);
     end;
  end;
end;
}
function PackTable(DataSet: TDataSet; TitleNames, TitleSize: Variant):String;
var
   tmpRow, tmpCol: Integer;
   tmpTitle, tmpFieldTitle: String;
   tmpContent, tmpFieldContent: String;
   i: Integer;
begin
   Result := '';
//   If (DataSet.FieldCount = VarArrayDimCount(TitleNames))and
//      (VarArrayDimCount(TitleNames) = VarArrayDimCount(TitleSize))
//   then
   begin
      tmpRow := 0; tmpCol := DataSet.FieldCount;

      tmpFieldTitle := '';
      For i := 0 to tmpCol - 1 do
      begin
        tmpFieldTitle := Ut_IntoPackage(tmpFieldTitle, TitleNames[i]);
        tmpFieldTitle := Ut_IntoPackage(tmpFieldTitle, TitleSize[i]);
      end;
      Result := Ut_IntoPackage(IntToStr(tmpCol), tmpFieldTitle);

      DataSet.First;
      While Not DataSet.Eof do
      begin
         tmpRow := tmpRow + 1;
         For i := 0 to tmpCol -1 do
         begin
           Result := Ut_IntoPackage(Result, DataSet.Fields[i].AsString);
         end;
         DataSet.Next;
      end;
      Result := Ut_IntoPackage(IntToStr(tmpRow), Result);
   end;
end;

function PackTable(DataSet: TDataSet):String;
var
   tmpRow, tmpCol: Integer;
   tmpFieldTitle: String;
   tmpFieldContent: String;
   i: Integer;
begin
   tmpRow := 0; tmpCol := DataSet.FieldCount;

   tmpFieldTitle := Ut_IntoPackage('柜员号', '48');
   tmpFieldTitle := Ut_IntoPackage(tmpFieldTitle, '所属网点号');
   tmpFieldTitle := Ut_IntoPackage(tmpFieldTitle, '80');
   tmpFieldTitle := Ut_IntoPackage(tmpFieldTitle, '状态');
   tmpFieldTitle := Ut_IntoPackage(tmpFieldTitle, '48');
   tmpFieldTitle := Ut_IntoPackage(tmpFieldTitle, '级别');
   tmpFieldTitle := Ut_IntoPackage(tmpFieldTitle, '32');
   tmpFieldTitle := Ut_IntoPackage(tmpFieldTitle, '启用日期');
   tmpFieldTitle := Ut_IntoPackage(tmpFieldTitle, '80');
   tmpFieldTitle := Ut_IntoPackage(tmpFieldTitle, '停用日期');
   tmpFieldTitle := Ut_IntoPackage(tmpFieldTitle, '80');
   tmpFieldTitle := Ut_IntoPackage(tmpFieldTitle, '说明');
   tmpFieldTitle := Ut_IntoPackage(tmpFieldTitle, '180');

   tmpCol := 7;

   Result := Ut_IntoPackage(IntToStr(tmpCol), tmpFieldTitle);

   DataSet.First;
   While Not DataSet.Eof do
   begin
     tmpRow := tmpRow + 1;

     Result := Ut_IntoPackage(Result, DataSet.FieldByName('TELLNO').AsString);
     Result := Ut_IntoPackage(Result, DataSet.FieldByName('BRNO').AsString);
     Result := Ut_IntoPackage(Result, DataSet.FieldByName('STATUS').AsString);
     Result := Ut_IntoPackage(Result, DataSet.FieldByName('RANK').AsString);
     Result := Ut_IntoPackage(Result, DataSet.FieldByName('SIGN_DATE').AsString);
     Result := Ut_IntoPackage(Result, DataSet.FieldByName('EXPIRE_DATE').AsString);
     Result := Ut_IntoPackage(Result, DataSet.FieldByName('NOTE').AsString);

     DataSet.Next;
   end;

   Result := Ut_IntoPackage(IntToStr(tmpRow), Result);
end;



function PACK1100(sinComm:TSinComm; sin:TBuffer):String;
begin
   Result := '';
   Result := Ut_IntoPackage(Result, sinComm.SITRXSRVC);

   Result := Ut_IntoPackage(Result, sinComm.SITRXD);
   Result := Ut_IntoPackage(Result, sinComm.SITRXSQNO);
   Result := Ut_IntoPackage(Result, sinComm.SITELLER);
   Result := Ut_IntoPackage(Result, sinComm.SIBRANCH);
   Result := Ut_IntoPackage(Result, sinComm.SISYSDATE);
   Result := Ut_IntoPackage(Result, sin.FIELD00);
   Result := Ut_IntoPackage(Result, sin.FIELD01);
   Result := Ut_IntoPackage(Result, sin.FIELD02);
   Result := Ut_IntoPackage(Result, sin.FIELD03);
   Result := Ut_IntoPackage(Result, sin.FIELD04);
   Result := Ut_IntoPackage(Result, sin.FIELD05);
   Result := Ut_IntoPackage(Result, sin.FIELD06);
   Result := Ut_IntoPackage(Result, sin.FIELD07);
   Result := Ut_IntoPackage(Result, sin.FIELD08);
   Result := Ut_IntoPackage(Result, sin.FIELD09);
   Result := Ut_IntoPackage(Result, sin.FIELD10);
   Result := Ut_IntoPackage(Result, sin.FIELD11);
   Result := Ut_IntoPackage(Result, sin.FIELD12);
   Result := Ut_IntoPackage(Result, sin.FIELD13);
   Result := Ut_IntoPackage(Result, sin.FIELD14);
   Result := Ut_IntoPackage(Result, sin.FIELD15);
   Result := Ut_IntoPackage(Result, sin.FIELD16);
   Result := Ut_IntoPackage(Result, sin.FIELD17);
   Result := Ut_IntoPackage(Result, sin.FIELD18);
   Result := Ut_IntoPackage(Result, sin.FIELD19);
end;

function UNPACK1100(outStr: String):TSoutComm;
var
   tmpStr: String;
begin
   tmpStr := outStr;
   Result.SOOVERID    := Ut_OutOfPackage(tmpStr, tmpStr);
   Result.SOSTATEMENT := Ut_OutOfPackage(tmpStr, tmpStr);
   Result.SOFIELD00   := Ut_OutOfPackage(tmpStr, tmpStr);
   Result.SOFIELD01   := Ut_OutOfPackage(tmpStr, tmpStr);
   Result.SOFIELD02   := Ut_OutOfPackage(tmpStr, tmpStr);
   Result.SOFIELD03   := Ut_OutOfPackage(tmpStr, tmpStr);
   Result.SOFIELD04   := Ut_OutOfPackage(tmpStr, tmpStr);
   Result.SOFIELD05   := Ut_OutOfPackage(tmpStr, tmpStr);
   Result.SOFIELD06   := Ut_OutOfPackage(tmpStr, tmpStr);
   Result.SOFIELD07   := Ut_OutOfPackage(tmpStr, tmpStr);
   Result.SOFIELD08   := Ut_OutOfPackage(tmpStr, tmpStr);
   Result.SOFIELD09   := Ut_OutOfPackage(tmpStr, tmpStr);
   Result.SOFIELD10   := Ut_OutOfPackage(tmpStr, tmpStr);
   Result.SOFIELD11   := Ut_OutOfPackage(tmpStr, tmpStr);
   Result.SOFIELD12   := Ut_OutOfPackage(tmpStr, tmpStr);
   Result.SOFIELD13   := Ut_OutOfPackage(tmpStr, tmpStr);
   Result.SOFIELD14   := Ut_OutOfPackage(tmpStr, tmpStr);
   Result.SOFIELD15   := Ut_OutOfPackage(tmpStr, tmpStr);
   Result.SOFIELD16   := Ut_OutOfPackage(tmpStr, tmpStr);
   Result.SOFIELD17   := Ut_OutOfPackage(tmpStr, tmpStr);
   Result.SOFIELD18   := Ut_OutOfPackage(tmpStr, tmpStr);
   Result.SOFIELD19   := Ut_OutOfPackage(tmpStr, tmpStr);
end;
{*********************************************************}
{**********                E.N.D                 *********}
{********** Terminal Package Analysis Utilities **********}
{*********************************************************}
{******************************************************************}
{**********   Server Package Analysis Utilities for TRCT **********}
{**********                    B.E.G.I.N                 **********}
{******************************************************************}
{
procedure UNPACK_COMMTRCT(SRC: String;var inComm: TRinComm);
var
  tmpStr: String;
begin
  tmpStr := SRC;
  inComm.RITRXD    := Ut_OutOfPackage(src, src); // 交易代码
  inComm.RITELLER  := Ut_OutOfPackage(src, src); // 柜员号
  inComm.RIBRANCH  := Ut_OutOfPackage(src, src); // 网点号
  inComm.RISTATUS  := Ut_OutOfPackage(src, src); // 柜员状态
  inComm.RIRANK    := Ut_OutOfPackage(src, src); // 柜员级别
end;

function PACK_COMMTRCT(outComm: TRoutComm):String;
begin
   Result := '';
   Result := Ut_IntoPackage(Result, outComm.ROAVAIABLE); // 可用标志
   Result := Ut_IntoPackage(Result, outComm.ROSTATEMENT); // 情况说明
   Result := Ut_IntoPackage(Result, outComm.ROTRXSQNO); // 交易序号
   Result := Ut_IntoPackage(Result, outComm.ROLIBID); // 画面位置
   Result := Ut_IntoPackage(Result, outComm.ROWINDOWID); // 画面标识
   Result := Ut_IntoPackage(Result, outComm.ROSYSDATE); // 系统日期
   Result := Ut_IntoPackage(Result, outComm.ROTRANSRVC); // 交易服务名
end;
{******************************************************************}
{**********                      E.N.D                   **********}
{**********   Server Package Analysis Utilities for TRCT **********}
{******************************************************************}

{******************************************************************}
{**********   Server Package Analysis Utilities for TACT **********}
{**********                    B.E.G.I.N                 **********}
{******************************************************************}
procedure UNPACK_COMMTACT(SRC: String;var inComm: TTinComm);
var
  tmpStr: String;
begin
  tmpStr := SRC;
  inComm.TITRXD       := Ut_OutOfPackage(src, src); // 交易代码
  inComm.TITRXSQNO    := Ut_OutOfPackage(src, src); // 交易序号
  inComm.TITELLER     := Ut_OutOfPackage(src, src); // 柜员号
  inComm.TIBRANCH     := Ut_OutOfPackage(src, src); // 网点号
  inComm.TISTATUS     := Ut_OutOfPackage(src, src); // 柜员状态
  inComm.TIRANK       := Ut_OutOfPackage(src, src); // 柜员级别
  inComm.TISYSDATE    := Ut_OutOfPackage(src, src); // 系统日期

  inComm.TIFIELD00    := Ut_OutOfPackage(src, src); // 输入场
  inComm.TIFIELD01    := Ut_OutOfPackage(src, src); // 输入场
  inComm.TIFIELD02    := Ut_OutOfPackage(src, src); // 输入场
  inComm.TIFIELD03    := Ut_OutOfPackage(src, src); // 输入场
  inComm.TIFIELD04    := Ut_OutOfPackage(src, src); // 输入场
  inComm.TIFIELD05    := Ut_OutOfPackage(src, src); // 输入场
  inComm.TIFIELD06    := Ut_OutOfPackage(src, src); // 输入场
  inComm.TIFIELD07    := Ut_OutOfPackage(src, src); // 输入场
  inComm.TIFIELD08    := Ut_OutOfPackage(src, src); // 输入场
  inComm.TIFIELD09    := Ut_OutOfPackage(src, src); // 输入场
  inComm.TIFIELD10    := Ut_OutOfPackage(src, src); // 输入场
  inComm.TIFIELD11    := Ut_OutOfPackage(src, src); // 输入场
  inComm.TIFIELD12    := Ut_OutOfPackage(src, src); // 输入场
  inComm.TIFIELD13    := Ut_OutOfPackage(src, src); // 输入场
  inComm.TIFIELD14    := Ut_OutOfPackage(src, src); // 输入场
  inComm.TIFIELD15    := Ut_OutOfPackage(src, src); // 输入场
  inComm.TIFIELD16    := Ut_OutOfPackage(src, src); // 输入场
  inComm.TIFIELD17    := Ut_OutOfPackage(src, src); // 输入场
  inComm.TIFIELD18    := Ut_OutOfPackage(src, src); // 输入场
  inComm.TIFIELD19    := Ut_OutOfPackage(src, src); // 输入场
end;

function PACK_COMMTACT(outComm: TToutComm):String;
begin
   Result := '';
   Result := Ut_IntoPackage(Result, outComm.TOOVERID); // 可用标志
   Result := Ut_IntoPackage(Result, outComm.TOSTATEMENT); // 情况说明

   Result := Ut_IntoPackage(Result, outComm.TOFIELD00); // 返回数据场
   Result := Ut_IntoPackage(Result, outComm.TOFIELD01); // 返回数据场
   Result := Ut_IntoPackage(Result, outComm.TOFIELD02); // 返回数据场
   Result := Ut_IntoPackage(Result, outComm.TOFIELD03); // 返回数据场
   Result := Ut_IntoPackage(Result, outComm.TOFIELD04); // 返回数据场
   Result := Ut_IntoPackage(Result, outComm.TOFIELD05); // 返回数据场
   Result := Ut_IntoPackage(Result, outComm.TOFIELD06); // 返回数据场
   Result := Ut_IntoPackage(Result, outComm.TOFIELD07); // 返回数据场
   Result := Ut_IntoPackage(Result, outComm.TOFIELD08); // 返回数据场
   Result := Ut_IntoPackage(Result, outComm.TOFIELD09); // 返回数据场
   Result := Ut_IntoPackage(Result, outComm.TOFIELD10); // 返回数据场
   Result := Ut_IntoPackage(Result, outComm.TOFIELD11); // 返回数据场
   Result := Ut_IntoPackage(Result, outComm.TOFIELD12); // 返回数据场
   Result := Ut_IntoPackage(Result, outComm.TOFIELD13); // 返回数据场
   Result := Ut_IntoPackage(Result, outComm.TOFIELD14); // 返回数据场
   Result := Ut_IntoPackage(Result, outComm.TOFIELD15); // 返回数据场
   Result := Ut_IntoPackage(Result, outComm.TOFIELD16); // 返回数据场
   Result := Ut_IntoPackage(Result, outComm.TOFIELD17); // 返回数据场
   Result := Ut_IntoPackage(Result, outComm.TOFIELD18); // 返回数据场
   Result := Ut_IntoPackage(Result, outComm.TOFIELD19); // 返回数据场
end;
{******************************************************************}
{**********                      E.N.D                   **********}
{**********   Server Package Analysis Utilities for TACT **********}
{******************************************************************}
{********** Common Utilities for Terminal & Server *******}
{**********             B.E.G.I.N                *********}
{*********************************************************}
function FormatInt(Src, MaxSize: Integer):String;
begin
  Result := IntToStr(Src);
  If Length(Result) < MaxSize then
     Result := StringOfChar('0', MaxSize-Length(Result)) + Result;
end;

function CalcPassword(Password: String):Longint;
var
   i,n: Integer;
begin
   Result := 0;
   n := Length(Password);
   For i := 1 to n do
   begin
      Result := Result +
                11 * Ord(Password[i])*Ord(Password[i])*i +
                 3 * Ord(Password[i])*i*i + i*1997;
   end;
end;
{*********************************************************}
{**********                E.N.D                 *********}
{********** Common Utilities for Terminal & Server *******}
{*********************************************************}
end.
