SetGuestFrm.pas 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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, []);
  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('%sapi/client/tender/%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. end;
  118. 0:
  119. begin
  120. Application.MessageBox(PChar(PHPWeb.PageError('无法查询到关注人')),
  121. '警告', MB_OK + MB_ICONWARNING);
  122. Exit;
  123. end;
  124. end;
  125. finally
  126. Screen.Cursor := crDefault;
  127. end;
  128. end;
  129. function TSetGuestForm.HasGuest(AID: Integer): Boolean;
  130. begin
  131. Result := False;
  132. cdsGuest.First;
  133. while not cdsGuest.Eof do
  134. begin
  135. if cdsGuestID.AsInteger = AID then
  136. begin
  137. Result := True;
  138. Break;
  139. end;
  140. cdsGuest.Next;
  141. end;
  142. end;
  143. procedure TSetGuestForm.SetOwner(const Value: TObject);
  144. begin
  145. FOwner := Value;
  146. end;
  147. procedure TSetGuestForm.zgGuestCellGetFont(Sender: TObject; ACoord: TPoint;
  148. AFont: TFont);
  149. begin
  150. if ACoord.X = Col(zaGuest, 'Operate') then
  151. AFont.Color := clBlue;
  152. end;
  153. procedure TSetGuestForm.zgGuestMouseDown(Sender: TObject;
  154. Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  155. var s, sURL: string;
  156. vArr: array of string;
  157. begin
  158. if zgGuest.CurCol = Col(zaGuest, 'Operate') then
  159. begin
  160. s := Format('确定要取消用户“%s”对该标段的关注吗?', [cdsGuestName.AsString]);
  161. if Application.MessageBox(PChar(s), '询问', MB_YESNO + MB_ICONQUESTION) = ID_No then
  162. Exit;
  163. Screen.Cursor := crHourGlass;
  164. vArr := VarArrayOf(['msg']);
  165. try
  166. sURL := PHPWeb.MeasureURL + '/api/client/tender/concernaudit/del'; // AAAAAA 取消关注人
  167. case PHPWeb.Search(sURL, ['tenderid', 'uid'], [InttoStr(FwebID), cdsGuestID.AsString], vArr) of
  168. 1:
  169. begin
  170. cdsGuest.Delete;
  171. end;
  172. -1:
  173. begin
  174. Application.MessageBox(PChar(PHPWeb.NetError('无法取消关注人')),
  175. '警告', MB_OK + MB_ICONWARNING);
  176. Exit;
  177. end;
  178. 0:
  179. begin
  180. Application.MessageBox(PChar(PHPWeb.PageError('无法取消关注人')),
  181. '警告', MB_OK + MB_ICONWARNING);
  182. Exit;
  183. end;
  184. end;
  185. finally
  186. Screen.Cursor := crDefault;
  187. end;
  188. end;
  189. end;
  190. end.