IPFrm.pas 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. unit IPFrm;
  2. interface
  3. uses
  4. Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  5. Dialogs, StdCtrls, CslButton, IniFiles, ComCtrls, ScPageControl, jpeg,
  6. ExtCtrls, JimPages;
  7. type
  8. TIPForm = class(TForm)
  9. jpsIP: TJimPages;
  10. jpsIPPageEdit: TJimPage;
  11. jpsIPPageNo: TJimPage;
  12. jpsIPPageYes: TJimPage;
  13. imgEdit: TImage;
  14. lblTitleEdit: TLabel;
  15. lblTitleEdit2: TLabel;
  16. shpIP: TShape;
  17. lblConSvr: TLabel;
  18. edtIP: TEdit;
  19. btnConSvr: TCslButton;
  20. imgNo: TImage;
  21. lblTitleNo: TLabel;
  22. lblIPNo: TLabel;
  23. lblHintNo: TLabel;
  24. btnReturn: TCslButton;
  25. imgYes: TImage;
  26. lblCompanyName: TLabel;
  27. lblTitleYes: TLabel;
  28. lblIPYes: TLabel;
  29. CslButton1: TCslButton;
  30. btnLogin: TCslButton;
  31. procedure btnConSvrClick(Sender: TObject);
  32. procedure FormCreate(Sender: TObject);
  33. procedure shpIPMouseDown(Sender: TObject; Button: TMouseButton;
  34. Shift: TShiftState; X, Y: Integer);
  35. procedure btnReturnClick(Sender: TObject);
  36. procedure btnLoginClick(Sender: TObject);
  37. procedure CslButton1Click(Sender: TObject);
  38. private
  39. { Private declarations }
  40. public
  41. { Public declarations }
  42. function HasIP: Boolean;
  43. procedure ConnectSever;
  44. end;
  45. implementation
  46. uses ConstUnit, PHPWebDm;
  47. {$R *.dfm}
  48. { TIPForm }
  49. procedure TIPForm.ConnectSever;
  50. var sIP, sN: string;
  51. iResult: Integer;
  52. ini: TIniFile;
  53. begin
  54. sIP := Trim(edtIP.Text);
  55. if sIP = '' then Exit;
  56. if Pos('http://', sIP) =1 then
  57. Delete(sIP, 1, 7);
  58. ini := TIniFile.Create(ExtractFilePath(Application.ExeName) + 'Cloud.ini');
  59. try
  60. ini.WriteString('URL', 'Server', sIP);
  61. ini.WriteString('URL', 'CompanyName', sN);
  62. ini.WriteString('URL', 'LoginCloudURL', 'http://' + sIP);
  63. PHPWeb.LoginCloudURL := 'http://' + sIP;
  64. finally
  65. ini.Free;
  66. end;
  67. iResult := PHPWeb.ConnectServer(sIP, sN);
  68. if iResult = 1 then
  69. begin
  70. jpsIP.ActivePage := jpsIPPageYes;
  71. lblIPYes.Caption := sIP;
  72. lblIPYes.Update;
  73. lblCompanyName.Caption := sN;
  74. lblCompanyName.Update;
  75. G_Server := sIP;
  76. G_CompanyName := sN;
  77. end
  78. else
  79. begin
  80. jpsIP.ActivePage := jpsIPPageNo;
  81. lblIPNo.Caption := sIP;
  82. lblIPNo.Update;
  83. end;
  84. end;
  85. function TIPForm.HasIP: Boolean;
  86. var ini: TIniFile;
  87. begin
  88. ini := TIniFile.Create(ExtractFilePath(Application.ExeName) + 'Cloud.ini');
  89. try
  90. G_Server := Trim(ini.ReadString('URL', 'Server', ''));
  91. Result := G_Server <> '';
  92. if Result then
  93. begin
  94. G_ServerType := ini.ReadString('URL', 'ServerType', '');
  95. G_CompanyName := ini.ReadString('URL', 'CompanyName', '');
  96. G_MeasureURL := 'http://' + G_Server + ini.ReadString('URL', 'MeasureURL', '');
  97. end;
  98. finally
  99. ini.Free;
  100. end;
  101. end;
  102. procedure TIPForm.btnConSvrClick(Sender: TObject);
  103. begin
  104. lblConSvr.Visible := True;
  105. Application.ProcessMessages;
  106. Screen.Cursor := crHourGlass;
  107. try
  108. ConnectSever;
  109. finally
  110. lblConSvr.Visible := False;
  111. Screen.Cursor := crDefault;
  112. end;
  113. end;
  114. procedure TIPForm.FormCreate(Sender: TObject);
  115. begin
  116. Caption := G_ProductName;
  117. lblTitleEdit.Caption := G_ProductName;
  118. lblTitleNo.Caption := G_ProductName;
  119. lblTitleYes.Caption := G_ProductName;
  120. end;
  121. procedure TIPForm.shpIPMouseDown(Sender: TObject; Button: TMouseButton;
  122. Shift: TShiftState; X, Y: Integer);
  123. begin
  124. edtIP.SetFocus;
  125. end;
  126. procedure TIPForm.btnReturnClick(Sender: TObject);
  127. begin
  128. jpsIP.ActivePage := jpsIPPageEdit;
  129. end;
  130. procedure TIPForm.btnLoginClick(Sender: TObject);
  131. begin
  132. ModalResult := mrOk;
  133. end;
  134. procedure TIPForm.CslButton1Click(Sender: TObject);
  135. begin
  136. jpsIP.ActivePage := jpsIPPageEdit;
  137. end;
  138. end.