SetGuestFrm.pas 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. {*******************************************************************************
  2. 单元名称: FindUserFrm.pas
  3. 单元说明: 设置游客帐号,标段关注人。
  4. 作者时间: Chenshilong, 2017-06-19
  5. *******************************************************************************}
  6. unit SetGuestFrm;
  7. interface
  8. uses
  9. Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  10. Dialogs, StdCtrls, ZJGrid, ZjGridDBA, DB, DBClient, sdDB;
  11. type
  12. TSetGuestForm = class(TForm)
  13. btnAdd: TButton;
  14. zgGuest: TZJGrid;
  15. btnOK: TButton;
  16. zaGuest: TZjGridDBA;
  17. cdsGuest: TClientDataSet;
  18. cdsGuestID: TIntegerField;
  19. cdsGuestName: TWideStringField;
  20. cdsGuestAccount: TWideStringField;
  21. cdsGuestOperate: TWideStringField;
  22. procedure btnAddClick(Sender: TObject);
  23. procedure zgGuestCellGetFont(Sender: TObject; ACoord: TPoint;
  24. AFont: TFont);
  25. procedure zgGuestMouseDown(Sender: TObject; Button: TMouseButton;
  26. Shift: TShiftState; X, Y: Integer);
  27. private
  28. { Private declarations }
  29. FWebID: Integer;
  30. FOwner: TObject;
  31. procedure GetGuests;
  32. function Col(AGridDBA: TZjGridDBA; FieldName: string): Integer;
  33. procedure SetOwner(const Value: TObject);
  34. public
  35. { Public declarations }
  36. constructor Create(AWebID: Integer);
  37. procedure AddGuest(AID: Integer; AName, AEmail: string);
  38. function HasGuest(AID: Integer): Boolean;
  39. property Owner: TObject read FOwner write SetOwner;
  40. end;
  41. var
  42. SetGuestForm: TSetGuestForm;
  43. implementation
  44. uses FindUserFrm, PHPWebDm, CSLJson;
  45. {$R *.dfm}
  46. procedure TSetGuestForm.AddGuest(AID: Integer; AName, AEmail: string);
  47. begin
  48. cdsGuest.Append;
  49. cdsGuestID.AsInteger := AID;
  50. cdsGuestName.AsString := AName;
  51. cdsGuestAccount.AsString := AEmail;
  52. cdsGuestOperate.AsString := '取消关注';
  53. cdsGuest.Post;
  54. end;
  55. procedure TSetGuestForm.btnAddClick(Sender: TObject);
  56. var
  57. FindUserForm: TFindUserForm;
  58. begin
  59. FindUserForm := TFindUserForm.Create(self, 1, [FWebID, -1]);
  60. try
  61. FindUserForm.ShowModal;
  62. finally
  63. FindUserForm.Free;
  64. end;
  65. end;
  66. function TSetGuestForm.Col(AGridDBA: TZjGridDBA;
  67. FieldName: string): Integer;
  68. begin
  69. Result := AGridDBA.ColumnIndex(FieldName) + 1;
  70. end;
  71. constructor TSetGuestForm.Create(AWebID: Integer);
  72. var i: Integer;
  73. begin
  74. inherited Create(nil);
  75. FWebID := AWebID;
  76. GetGuests;
  77. // for test
  78. // for i := 1 to 5 do
  79. // begin
  80. // cdsGuest.Append;
  81. // cdsGuestID.AsString := IntToStr(i);
  82. // cdsGuestName.AsString := 'aaa' + IntToStr(i);
  83. // cdsGuestAccount.AsString := 'aaaa@qq.com';
  84. // cdsGuestOperate.AsString := '取消关注';
  85. // cdsGuest.Post;
  86. // end;
  87. end;
  88. procedure TSetGuestForm.GetGuests;
  89. var sURL: string;
  90. UserArr: TOVArr;
  91. i: Integer;
  92. begin
  93. Screen.Cursor := crHourGlass;
  94. try
  95. sURL := Format('%stender/%s/concernaudit/list', [PHPWeb.MeasureURL, InttoStr(FwebID)]); // AAAAAA 查询标段的关注人
  96. case PHPWeb.Search(sURL, [], [], UserArr) of
  97. 1:
  98. begin
  99. if cdsGuest.RecordCount > 0 then
  100. cdsGuest.EmptyDataSet;
  101. for i := Low(UserArr) to High(UserArr) do
  102. begin
  103. cdsGuest.Append;
  104. cdsGuestID.AsString := UserArr[i, 0];
  105. cdsGuestName.AsString := UserArr[i, 1];
  106. cdsGuestAccount.AsString := UserArr[i, 2];
  107. cdsGuestOperate.AsString := '取消关注';
  108. cdsGuest.Post;
  109. end;
  110. cdsGuest.First;
  111. end;
  112. -1:
  113. begin
  114. Application.MessageBox(PChar(PHPWeb.NetError('无法查询到关注人')),
  115. '警告', MB_OK + MB_ICONWARNING);
  116. Exit;
  117. close;
  118. end;
  119. 0:
  120. begin
  121. Application.MessageBox(PChar(PHPWeb.PageError('无法查询到关注人')),
  122. '警告', MB_OK + MB_ICONWARNING);
  123. Exit;
  124. close;
  125. end;
  126. end;
  127. finally
  128. Screen.Cursor := crDefault;
  129. end;
  130. end;
  131. function TSetGuestForm.HasGuest(AID: Integer): Boolean;
  132. begin
  133. Result := False;
  134. cdsGuest.First;
  135. while not cdsGuest.Eof do
  136. begin
  137. if cdsGuestID.AsInteger = AID then
  138. begin
  139. Result := True;
  140. Break;
  141. end;
  142. cdsGuest.Next;
  143. end;
  144. end;
  145. procedure TSetGuestForm.SetOwner(const Value: TObject);
  146. begin
  147. FOwner := Value;
  148. end;
  149. procedure TSetGuestForm.zgGuestCellGetFont(Sender: TObject; ACoord: TPoint;
  150. AFont: TFont);
  151. begin
  152. if ACoord.X = Col(zaGuest, 'Operate') then
  153. AFont.Color := clBlue;
  154. end;
  155. procedure TSetGuestForm.zgGuestMouseDown(Sender: TObject;
  156. Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  157. var s, sURL: string;
  158. vArr: array of string;
  159. begin
  160. if ((zgGuest.CurCol = Col(zaGuest, 'Operate')) and (zgGuest.CurRow <= cdsGuest.RecordCount)) then
  161. begin
  162. s := Format('确定要取消用户“%s”对该标段的关注吗?', [cdsGuestName.AsString]);
  163. if Application.MessageBox(PChar(s), '询问', MB_YESNO + MB_ICONQUESTION) = ID_No then
  164. Exit;
  165. Screen.Cursor := crHourGlass;
  166. vArr := VarArrayOf(['msg']);
  167. try
  168. sURL := PHPWeb.MeasureURL + 'tender/concernaudit/del'; // AAAAAA 取消关注人
  169. case PHPWeb.Search(sURL, ['tenderid', 'uid'], [InttoStr(FwebID), cdsGuestID.AsString], vArr) of
  170. 1:
  171. begin
  172. cdsGuest.Delete;
  173. end;
  174. -1:
  175. begin
  176. Application.MessageBox(PChar(PHPWeb.NetError('无法取消关注人')),
  177. '警告', MB_OK + MB_ICONWARNING);
  178. Exit;
  179. end;
  180. 0:
  181. begin
  182. Application.MessageBox(PChar(PHPWeb.PageError('无法取消关注人')),
  183. '警告', MB_OK + MB_ICONWARNING);
  184. Exit;
  185. end;
  186. end;
  187. finally
  188. Screen.Cursor := crDefault;
  189. end;
  190. end;
  191. end;
  192. end.