SetGuestFrm.pas 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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. procedure GetGuests;
  31. function Col(AGridDBA: TZjGridDBA; FieldName: string): Integer;
  32. public
  33. { Public declarations }
  34. constructor Create(AWebID: Integer);
  35. procedure AddGuest(AID: Integer; AName, AEmail: string);
  36. function HasGuest(AID: Integer): Boolean;
  37. end;
  38. var
  39. SetGuestForm: TSetGuestForm;
  40. implementation
  41. uses FindUserFrm, PHPWebDm, CSLJson;
  42. {$R *.dfm}
  43. procedure TSetGuestForm.AddGuest(AID: Integer; AName, AEmail: string);
  44. begin
  45. cdsGuest.Append;
  46. cdsGuestID.AsInteger := AID;
  47. cdsGuestName.AsString := AName;
  48. cdsGuestAccount.AsString := AEmail;
  49. cdsGuestOperate.AsString := '取消关注';
  50. cdsGuest.Post;
  51. end;
  52. procedure TSetGuestForm.btnAddClick(Sender: TObject);
  53. var
  54. FindUserForm: TFindUserForm;
  55. begin
  56. FindUserForm := TFindUserForm.Create(self, 1, []);
  57. try
  58. FindUserForm.ShowModal;
  59. finally
  60. FindUserForm.Free;
  61. end;
  62. end;
  63. function TSetGuestForm.Col(AGridDBA: TZjGridDBA;
  64. FieldName: string): Integer;
  65. begin
  66. Result := AGridDBA.ColumnIndex(FieldName) + 1;
  67. end;
  68. constructor TSetGuestForm.Create(AWebID: Integer);
  69. var i: Integer;
  70. begin
  71. inherited Create(nil);
  72. FWebID := AWebID;
  73. // GetGuests;
  74. // for test
  75. for i := 1 to 5 do
  76. begin
  77. cdsGuest.Append;
  78. cdsGuestID.AsString := IntToStr(i);
  79. cdsGuestName.AsString := 'aaa' + IntToStr(i);
  80. cdsGuestAccount.AsString := 'aaaa@qq.com';
  81. cdsGuestOperate.AsString := '取消关注';
  82. cdsGuest.Post;
  83. end;
  84. end;
  85. procedure TSetGuestForm.GetGuests;
  86. var sURL: string;
  87. UserArr: TOVArr;
  88. i: Integer;
  89. begin
  90. Screen.Cursor := crHourGlass;
  91. try
  92. sURL := 'xxxxxx'; // AAAAAA 查询标段的关注人
  93. case PHPWeb.Search(PHPWeb.MeasureURL + sURL, ['WebID'], [InttoStr(FwebID)], UserArr) of
  94. 1:
  95. begin
  96. if cdsGuest.RecordCount > 0 then
  97. cdsGuest.EmptyDataSet;
  98. for i := Low(UserArr) to High(UserArr) do
  99. begin
  100. cdsGuest.Append;
  101. cdsGuestID.AsString := UserArr[i, 0];
  102. cdsGuestName.AsString := UserArr[i, 1];
  103. cdsGuestAccount.AsString := UserArr[i, 2];
  104. cdsGuestOperate.AsString := '取消关注';
  105. cdsGuest.Post;
  106. end;
  107. cdsGuest.First;
  108. end;
  109. -1:
  110. begin
  111. Application.MessageBox(PChar(PHPWeb.NetError('无法查询到关注人')),
  112. '警告', MB_OK + MB_ICONWARNING);
  113. Exit;
  114. end;
  115. 0:
  116. begin
  117. Application.MessageBox(PChar(PHPWeb.PageError('无法查询到关注人')),
  118. '警告', MB_OK + MB_ICONWARNING);
  119. Exit;
  120. end;
  121. end;
  122. finally
  123. Screen.Cursor := crDefault;
  124. end;
  125. end;
  126. function TSetGuestForm.HasGuest(AID: Integer): Boolean;
  127. begin
  128. Result := False;
  129. cdsGuest.First;
  130. while not cdsGuest.Eof do
  131. begin
  132. if cdsGuestID.AsInteger = AID then
  133. begin
  134. Result := True;
  135. Break;
  136. end;
  137. cdsGuest.Next;
  138. end;
  139. end;
  140. procedure TSetGuestForm.zgGuestCellGetFont(Sender: TObject; ACoord: TPoint;
  141. AFont: TFont);
  142. begin
  143. if ACoord.X = Col(zaGuest, 'Operate') then
  144. AFont.Color := clBlue;
  145. end;
  146. procedure TSetGuestForm.zgGuestMouseDown(Sender: TObject;
  147. Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  148. var s: string;
  149. begin
  150. if zgGuest.CurCol = Col(zaGuest, 'Operate') then
  151. begin
  152. s := Format('确定要取消用户“%s”对该标段的关注吗?', [cdsGuestName.AsString]);
  153. if Application.MessageBox(PChar(s), '询问', MB_YESNO + MB_ICONQUESTION) = ID_No then
  154. Exit;
  155. // do
  156. end;
  157. end;
  158. end.