unit UT0905;

interface

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

type
  TGW0905 = 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;
    Panel3: TPanel;
    Label2: TLabel;
    Edit2: TEdit;
    Edit1: TEdit;
    Label1: TLabel;
    procedure BitBtn2Click(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);
    procedure Edit1KeyPress(Sender: TObject; var Key: Char);
    procedure StringGrid1KeyPress(Sender: TObject; var Key: Char);
    procedure Edit1Exit(Sender: TObject);
    procedure Edit2Exit(Sender: TObject);
  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
  GW0905: TGW0905;
  procedure T0905(inCommArea: TSinComm; var outCommArea: TSoutComm);stdcall;

implementation

{$R *.DFM}

procedure T0905(inCommArea: TSinComm; var outCommArea: TSoutComm);stdcall;
var
   tmpGW0905: TGW0905;
begin
   tmpGW0905 := TGW0905.Create(nil);
   tmpGW0905.sinComm := inCommArea;

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

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

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

   tmpGW0905.ShowModal;

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

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

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

  Result := True;
{****************************************}
{  TO DO : Modified for Input Parameters }
{****************************************}
end;

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

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

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

procedure TGW0905.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 TGW0905.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
  GotoNextCTL(Key);
end;

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

procedure TGW0905.Edit1Exit(Sender: TObject);
begin
   If Edit1.Text = '' then
   begin
      Edit1.Text := '全部';
   end;
end;

procedure TGW0905.Edit2Exit(Sender: TObject);
begin
   If Edit2.Text = '' then
   begin
      Edit2.Text := '全部';
   end;
end;

end.
