unit UT0904;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, Buttons, ExtCtrls, emapi, uss, auxiapi, Grids;

type
  TGW0904 = class(TForm)
    GroupBox1: TGroupBox;
    Panel2: TPanel;
    BitBtn1: TBitBtn;
    BitBtn2: TBitBtn;
    GroupBox2: TGroupBox;
    StringGrid1: TStringGrid;
    Panel1: TPanel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    Label9: TLabel;
    Label10: TLabel;
    Label11: TLabel;
    Label20: TLabel;
    Label21: TLabel;
    procedure BitBtn2Click(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);
    procedure Edit1KeyPress(Sender: TObject; var Key: Char);
    procedure StringGrid1KeyPress(Sender: TObject; var Key: Char);
  private
    { Private declarations }
    procedure GotoNextCTL(Key: Char);
    function IsReady:Boolean;
    function PACKFIELDS:TBuffer;
    function Send(Host, Port, inPackage: String):String;
  public
    { Public declarations }
    sinComm: TSinComm;
    soutComm: TSoutComm;
  end;

var
  GW0904: TGW0904;
  procedure T0904(inCommArea: TSinComm; var outCommArea: TSoutComm);stdcall;

implementation

{$R *.DFM}

procedure T0904(inCommArea: TSinComm; var outCommArea: TSoutComm);stdcall;
var
   tmpGW0904: TGW0904;
begin
   tmpGW0904 := TGW0904.Create(nil);
   tmpGW0904.sinComm := inCommArea;

   If (tmpGW0904.sinComm.SIBRANCH = '9999')and(tmpGW0904.sinComm.SITELLER = '9999') then
   begin
      tmpGW0904.Label21.Caption := '?????';
      tmpGW0904.Label5.Caption := '?????';
      tmpGW0904.Label7.Caption := '?????';

      tmpGW0904.Label9.Caption := inCommArea.SITRXSQNO;
      tmpGW0904.Label11.Caption := inCommArea.SISYSDATE;
   end else begin
      tmpGW0904.Label21.Caption := StringOfChar('0', 5 - Length(inCommArea.SIZONENO)) + inCommArea.SIZONENO;
      tmpGW0904.Label5.Caption := StringOfChar('0', 5 - Length(inCommArea.SIBRANCH)) + inCommArea.SIBRANCH;
      tmpGW0904.Label7.Caption := StringOfChar('0', 5 - Length(inCommArea.SITELLER)) + inCommArea.SITELLER;

      tmpGW0904.Label9.Caption := inCommArea.SITRXSQNO;
      tmpGW0904.Label11.Caption := inCommArea.SISYSDATE;
   end;

   tmpGW0904.ShowModal;

   outCommArea := tmpGW0904.soutComm;
   tmpGW0904.Free;
end;

procedure TGW0904.GotoNextCTL(Key: Char);
begin
  If Ord(Key) = VK_RETURN then
  begin
    Self.Perform(WM_NEXTDLGCTL,0,0);
  end;
end;

function TGW0904.IsReady:Boolean;
begin
{****************************************}
{  TO DO : Modified for Input Parameters }
{****************************************}
  BitBtn1.Enabled := False;
  BitBtn2.Enabled := False;

//  If Edit1.Text='' then
//  begin
//    ShowMessage('请输入“网点号”');
//    Edit1.SelectAll;
//    Edit1.SetFocus;
//    BitBtn1.Enabled := True;
//    BitBtn2.Enabled := True;
//    Result:=False;
//  end else begin
    Result:=True;
//  end;
{****************************************}
{  TO DO : Modified for Input Parameters }
{****************************************}
end;

procedure TGW0904.BitBtn2Click(Sender: TObject);
begin
   soutComm.SOOVERID := RONORMAL;
   soutComm.SOSTATEMENT := ROSTATNORMAL;
   Close;
end;

function TGW0904.PACKFIELDS:TBuffer;
begin
{****************************************}
{  TO DO : Modified for Input Parameters }
{****************************************}
// Result.FIELD00 := Edit1.Text;
{****************************************}
{  TO DO : Modified for Input Parameters }
{****************************************}
end;

function TGW0904.Send(Host, Port, inPackage: String):String;
begin
   try
     Netreq_Request(Host, Port, inPackage, Result);
   except
     Result := Ut_IntoPackage(ROERRORCOMMPT,ROSTATERRORCOMMPT);
   end;
end;

procedure TGW0904.BitBtn1Click(Sender: TObject);
var
  inStr, outStr: String;
begin
  If IsReady then
  begin
    If BitBtn1.Caption = '发送' then
    begin
       inStr := packTinComm(sinComm, PACKFIELDS);
       outStr := Send(sinComm.SIHOST, sinComm.SIPORT, inStr);
       soutComm.SOOVERID := Ut_OutOfPackage(outStr, outStr);
       soutComm.SOSTATEMENT := Ut_OutOfPackage(outStr, outStr);

       If soutComm.SOOVERID = SOTRANSFER then
       begin
          unPackTable(outStr, StringGrid1);
       end else begin
          ShowMessage(Format('服务器返回错误。（%s）', [soutComm.SOSTATEMENT]));
       end;

       BitBtn2.Enabled := True;
//       Edit1.SelectAll;
//       Edit1.SetFocus;
//       BitBtn1.Caption := '退出';
//    end else begin
//       soutComm.SOOVERID := RONORMAL;
//       soutComm.SOSTATEMENT := ROSTATNORMAL;
//       Close;
    end;
  end;
end;

procedure TGW0904.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
  GotoNextCTL(Key);
end;

procedure TGW0904.StringGrid1KeyPress(Sender: TObject; var Key: Char);
begin
  GotoNextCTL(Key);
end;

end.
