unit txset;

interface

uses Sysutils, DB, DBTables, uss, auxiapi, txsetsub;

procedure TRANPROC_TRCT(inComm: TTinComm;var outComm: TToutComm);

implementation

uses
   i_SYSCJNL1,
   i_SYSPABCP,
   i_SYSPALVL,
   i_SYSPASCT,
   i_SYSPASCV,
   i_SYSPATEL,
   i_SYSPATRX,
   i_SYSPAZON,
   i_ebss;

procedure TRANPROC_TRCT(inComm: TTinComm;var outComm: TToutComm);
var
   syspasct: _SYSPASCT;
   syspatrx: _SYSPATRX;
   syspatel: _SYSPATEL;
   rDatabase: TDatabase;
   rSession: TSession;
   rDatabaseName, rSessionName: String;
   DataSet: TDataSet;
   CanContinue: Boolean;
   x: Integer;
   txDatabase: TDatabase;
   txSession: TSession;
   txDatabaseName, txSessionName: String;
begin
   openDatabase(txSession, txDatabase, txSessionName, txDatabaseName);

   TransactionStart(txDatabase);
   try
{ IN = 交易代码#交易序号#柜员号#地区号#网点号#柜员状态#柜员级别 #日期 }
{OUT = 可用标志#情况说明#交易序号#画面位置#画面标识#系统日期#交易标识  }
      syspasct := _SYSPASCT.Create;
      syspatrx := _SYSPATRX.Create;
      syspatel := _SYSPATEL.Create;

      CanContinue := True;

      outComm.TOOVERID    := RONORMAL;
      outComm.TOSTATEMENT   := ROSTATNORMAL;

      If CanContinue then
      begin
         DataSet := syspatrx.getAllRows(txSessionName, txDatabaseName,
//                        'ZONENO = '+IntToStr(StrToInt(inComm.TIZONENO))+ ' and ' +
//                        'BRCHNO = '+IntToStr(StrToInt(inComm.TIBRANCH))+ ' and ' +
                        'CODE = '+IntToStr(StrToInt(inComm.TITRXD)));
         If Not DataSet.IsEmpty then
         begin
            DataSet.First;
            While Not DataSet.Eof do
            begin
              If StrToInt(inComm.TIRANK) < DataSet.FieldByName('SLEVEL').AsInteger then
              begin
                 outComm.TOOVERID  := ROLOWRIGHTTEL;
                 outComm.TOSTATEMENT := ROSTATLOWRIGHTTEL;
                 CanContinue := False;
              end else begin
                 outComm.TOFIELD01 := DataSet.FieldByName('POSI').AsString; // 界面库名称
                 outComm.TOFIELD02 := DataSet.FieldByName('GWID').AsString; // 界面编号
                 outComm.TOFIELD04 := DataSet.FieldByName('SRVC').AsString; // 服务类型
                 Break;
              end;
              DataSet.Next;
            end;
         end else begin
            outComm.TOOVERID  := RONOTFOUNDTRX;
            outComm.TOSTATEMENT := ROSTATNOTFOUNDTRX;
            CanContinue := False;
         end;

         DataSet.Close;
      end;

      If CanContinue then
      begin
         DataSet := syspatel.getAllRows(txSessionName, txDatabaseName,
                        'ZONENO = '+IntToStr(StrToInt(inComm.TIZONENO))+ ' and ' +
                        'BRCHNO = '+IntToStr(StrToInt(inComm.TIBRANCH))+ ' and ' +
                        'TELLNO = '+IntToStr(StrToInt(inComm.TITELLER)));
         If Not DataSet.IsEmpty then
         begin
             If (DataSet.FieldByName('STATUS').AsInteger <> StrToInt(inComm.TISTATUS)) then
             begin { 柜员状态不一致 }
               outComm.TOOVERID  := ROWRONGTELSTU;
               outComm.TOSTATEMENT := ROSTATWRONGTELSTU;
               CanContinue := False;
             end else If DataSet.FieldByName('SLEVEL').AsInteger <> (StrToInt(inComm.TIRANK)) then
             begin
               outComm.TOOVERID  := ROWRONGTELLVL;
               outComm.TOSTATEMENT := ROSTATWRONGTELLVL;
               CanContinue := False;
//             end else If (StrToInt(inComm.TITRXD) <> 1100)and(StrToInt(inComm.TISTATUS) = 0) then
//             begin
//               outComm.TOOVERID  := ROHASNOTLOGON;
//               outComm.TOSTATEMENT := ROSTATHASNOTLOGON;
//               CanContinue := False;
//             end else If (StrToInt(inComm.TITRXD) = 1100)and(StrToInt(inComm.TISTATUS) <> 0) then
//             begin
//                 outComm.TOOVERID  := ROHASNOTLOGOUT;
//                 outComm.TOSTATEMENT := ROSTATHASNOTLOGOUT;
//                 CanContinue := False;
             end;
          end else begin
             outComm.TOOVERID  := RONOTFOUNDTEL;
             outComm.TOSTATEMENT := ROSTATNOTFOUNDTEL;
             CanContinue := False;
          end;
         DataSet.Close;
      end;

      If CanContinue then
      begin
         DataSet := syspasct.getAllRows(txSessionName, txDatabaseName);
         If Not DataSet.IsEmpty then
         begin
            DataSet.First;
            x := DataSet.FieldByName('TRXSEQNO').AsInteger + 1;
            outComm.TOFIELD00 := FormatInt(x, 9);  //  新交易序号
            outComm.TOFIELD03 := DataSet.FieldByName('WORKDATE').AsString;
                                                   //  工作日期
            syspasct.setTRXSEQNOvalue(
                                      txSessionName, txDatabaseName,
                                      IntToStr(x),'WORKDATE = '''+outComm.TOFIELD03+''''
                                      );
         end;
         DataSet.Close;
      end;

      LOG_CTL(txSessionName, txDatabaseName, inComm, outComm);

      syspasct.Free;
      syspatrx.Free;
      syspatel.Free;
   except
      TransactionRollBack(txDatabase);
      closeDatabase(txSession, txDatabase);
      outComm.TOOVERID  := ROABNORMAL;
      outComm.TOSTATEMENT := ROSTATABNORMAL;
      Exit;
   end;
   TransactionCommit(txDatabase);
   closeDatabase(txSession, txDatabase);
end;

end.
