/Gedemin/Tax/tax_frmAddParamsFunc_unit.pas

http://gedemin.googlecode.com/ · Pascal · 346 lines · 278 code · 44 blank · 24 comment · 18 complexity · a9de4cbbf19847457a981b09b3f5043d MD5 · raw file

  1. {++
  2. Copyright (c) 2001 by Golden Software of Belarus
  3. Module
  4. tax_frmAddParamsFunc_unit.pas
  5. Abstract
  6. Form for visual addition parameters of fiscal function.
  7. Author
  8. Dubrovnik Alexander (DAlex)
  9. Revisions history
  10. 1.00 07.02.03 DAlex Initial version.
  11. --}
  12. unit tax_frmAddParamsFunc_unit;
  13. interface
  14. uses
  15. Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  16. Spin, Buttons, StdCtrls, ExtCtrls, ImgList, ActnList, Menus, BtnEdit,
  17. tax_frmAvailableTaxFunc_unit, wiz_FunctionBlock_unit;
  18. type
  19. TParamPanel = class(TPanel)
  20. private
  21. FedtParam: TBtnEdit;
  22. FlblParam: TLabel;
  23. procedure SetedtParam(const Value: TBtnEdit);
  24. procedure SetlblParam(const Value: TLabel);
  25. public
  26. constructor Create(AOwner: TComponent); override;
  27. procedure AssignSize(Source: TParamPanel);
  28. property lblParam: TLabel read FlblParam write SetlblParam;
  29. property edtParam: TBtnEdit read FedtParam write SetedtParam;
  30. end;
  31. type
  32. TfrmAddParamsFunc = class(TForm)
  33. plnButton: TPanel;
  34. btnOk: TButton;
  35. btnCancel: TButton;
  36. pnlMain: TPanel;
  37. pnlFunction: TPanel;
  38. lblFunction: TLabel;
  39. sbParams: TScrollBox;
  40. pnlParam: TPanel;
  41. lblParam: TLabel;
  42. pmAdd: TPopupMenu;
  43. alAdd: TActionList;
  44. actAddFunction: TAction;
  45. actAddAnalytics: TAction;
  46. ilAdd: TImageList;
  47. edtParam: TBtnEdit;
  48. miAnalitics: TMenuItem;
  49. miFunction: TMenuItem;
  50. actAccount: TAction;
  51. miAccount: TMenuItem;
  52. actOk: TAction;
  53. actCancel: TAction;
  54. pnlDescr: TPanel;
  55. mmDescription: TMemo;
  56. Bevel1: TBevel;
  57. actAddValue: TAction;
  58. N1: TMenuItem;
  59. procedure actAddFunctionExecute(Sender: TObject);
  60. procedure actAddAnalyticsExecute(Sender: TObject);
  61. procedure actAccountExecute(Sender: TObject);
  62. procedure edtParamBtnOnClick(Sender: TObject);
  63. procedure actOkExecute(Sender: TObject);
  64. procedure actCancelExecute(Sender: TObject);
  65. procedure actAddValueExecute(Sender: TObject);
  66. protected
  67. FActualTaxKey: Integer;
  68. FActiveEdit: TBtnEdit;
  69. FFuncDescr: TFuncDescr;
  70. FParamPanelList: TList;
  71. FLastParamPanel: TParamPanel;
  72. FMaxHeight: Integer;
  73. function GetParamsStr: String;
  74. public
  75. constructor Create(AOwner: TComponent); override;
  76. destructor Destroy; override;
  77. procedure SetParams(const FuncMask, Description: String;
  78. const ActualTaxKey: Integer; const FuncDescr: TFuncDescr);
  79. property ParamsStr: String read GetParamsStr;
  80. end;
  81. var
  82. frmAddParamsFunc: TfrmAddParamsFunc;
  83. implementation
  84. uses
  85. tax_frmAnalytics_unit, gdc_frmAccountSel_unit, gdc_frmValueSel_unit,
  86. gdcBaseInterface;
  87. {$R *.DFM}
  88. procedure TfrmAddParamsFunc.actAddFunctionExecute(Sender: TObject);
  89. begin
  90. with TfrmAvailableTaxFunc.CreateWithParams(Self, FActualTaxKey, '') do
  91. try
  92. if ShowModal = idOk then
  93. begin
  94. FActiveEdit.SelText := SelectedFunction;
  95. end;
  96. finally
  97. Free;
  98. end;
  99. end;
  100. procedure TfrmAddParamsFunc.actAddAnalyticsExecute(Sender: TObject);
  101. begin
  102. with TfrmAnalytics.Create(nil) do
  103. try
  104. if ShowModal = idOk then
  105. begin
  106. if (FActiveEdit.Text > '') then
  107. begin
  108. FActiveEdit.Text := FActiveEdit.Text + ' + "; " + ';
  109. end;
  110. FActiveEdit.Text := FActiveEdit.Text + '"' + Analytics + '"';
  111. end;
  112. finally
  113. Free
  114. end;
  115. end;
  116. constructor TfrmAddParamsFunc.Create(AOwner: TComponent);
  117. begin
  118. inherited;
  119. if GetDeviceCaps(GetDC(Self.Handle), VERTRES) > 479 then
  120. begin
  121. FMaxHeight := GetDeviceCaps(GetDC(Self.Handle), VERTRES) - 60;
  122. end;
  123. FParamPanelList := TList.Create;
  124. end;
  125. function TfrmAddParamsFunc.GetParamsStr: String;
  126. var
  127. i: Integer;
  128. ParamPanel: TParamPanel;
  129. begin
  130. Result := '';
  131. for i := 0 to FParamPanelList.Count - 1 do
  132. if ModalResult <> idCancel then
  133. begin
  134. ParamPanel := TParamPanel(FParamPanelList[i]);
  135. with ParamPanel do
  136. begin
  137. if Result > '' then
  138. Result := Result + ', ';
  139. if Trim(edtParam.Text) = '' then
  140. Result := Result + 'Empty'
  141. else
  142. Result := Result + edtParam.Text;
  143. end;
  144. end else
  145. begin
  146. if i = 0 then
  147. Result := Result + ' '
  148. else
  149. Result := Result + ' , ';
  150. end;
  151. end;
  152. procedure TfrmAddParamsFunc.actAccountExecute(Sender: TObject);
  153. var
  154. Account: string;
  155. AccountRUID: string;
  156. begin
  157. if (MainFunction <> nil) and (FActiveEdit <> nil) then
  158. begin
  159. if MainFunction.OnClickAccount(Account, AccountRUID) then
  160. begin
  161. if CheckRUID(AccountRUID) then
  162. FActiveEdit.Text := '"' + AccountRUID + '"{' + Account + '}'
  163. else
  164. FActiveEdit.Text := AccountRUID + '{' + Account + '}'
  165. end;
  166. end;
  167. end;
  168. procedure TfrmAddParamsFunc.edtParamBtnOnClick(Sender: TObject);
  169. var
  170. Point: TPoint;
  171. begin
  172. if Sender is TEditSButton then
  173. begin
  174. FActiveEdit := TEditSButton(Sender).Edit;
  175. Point.x := 0;
  176. Point.y := TEditSButton(Sender).Height - 1;
  177. Point := TEditSButton(Sender).ClientToScreen(Point);
  178. pmAdd.Popup(Point.X, Point.Y);
  179. end;
  180. end;
  181. procedure TfrmAddParamsFunc.SetParams(const FuncMask, Description: String;
  182. const ActualTaxKey: Integer; const FuncDescr: TFuncDescr);
  183. var
  184. i: Integer;
  185. ParamPanel: TParamPanel;
  186. begin
  187. sbParams.AutoScroll := False;
  188. lblFunction.Caption := FuncMask;
  189. mmDescription.Lines.Text := Description;
  190. FActualTaxKey := ActualTaxKey;
  191. FFuncDescr := FuncDescr;
  192. if Length(FFuncDescr.ParamArray) = 0 then
  193. begin
  194. raise Exception.Create('??????? ' + FFuncDescr.Name + ' ?? ????? ??????????.');
  195. end;
  196. ParamPanel := TParamPanel.Create(Self);
  197. with ParamPanel do
  198. begin
  199. Parent := sbParams;
  200. BoundsRect := pnlParam.BoundsRect;
  201. Align := pnlParam.Align;
  202. Anchors := pnlParam.Anchors;
  203. lblParam.BoundsRect := Self.lblParam.BoundsRect;
  204. lblParam.Align := Self.lblParam.Align;
  205. lblParam.Anchors := Self.lblParam.Anchors;
  206. edtParam.AssignSize(Self.edtParam);
  207. edtParam.BtnCaption := Self.edtParam.BtnCaption;
  208. edtParam.BtnGlyph := Self.edtParam.BtnGlyph;
  209. edtParam.BtnOnClick := Self.edtParam.BtnOnClick;
  210. lblParam.Caption := FFuncDescr.ParamArray[0];
  211. end;
  212. FParamPanelList.Add(ParamPanel);
  213. FLastParamPanel := ParamPanel;
  214. for i := 1 to Length(FFuncDescr.ParamArray) - 1 do
  215. begin
  216. ParamPanel := TParamPanel.Create(Self);
  217. ParamPanel.AssignSize(FLastParamPanel);
  218. ParamPanel.Top := FLastParamPanel.Top + FLastParamPanel.Height;
  219. ParamPanel.Parent := sbParams;
  220. ParamPanel.lblParam.Caption := FFuncDescr.ParamArray[i];
  221. ParamPanel.edtParam.BtnCaption := Self.edtParam.BtnCaption;
  222. ParamPanel.edtParam.BtnGlyph := Self.edtParam.BtnGlyph;
  223. ParamPanel.edtParam.BtnOnClick := Self.edtParam.BtnOnClick;
  224. FLastParamPanel := ParamPanel;
  225. FParamPanelList.Add(ParamPanel);
  226. end;
  227. if (sbParams.Height - 22) < (FLastParamPanel.Height + FLastParamPanel.Top) then
  228. begin
  229. Self.Height := Self.Height +
  230. FLastParamPanel.Height + FLastParamPanel.Top - sbParams.Height + 20;
  231. if Self.Height > FMaxHeight then
  232. Self.Height := FMaxHeight;
  233. end;
  234. sbParams.AutoScroll := True;;
  235. end;
  236. destructor TfrmAddParamsFunc.Destroy;
  237. begin
  238. FParamPanelList.Free;
  239. inherited;
  240. end;
  241. { TParamPanel }
  242. procedure TParamPanel.AssignSize(Source: TParamPanel);
  243. begin
  244. BoundsRect := Source.BoundsRect;
  245. Align := Source.Align;
  246. Anchors := Source.Anchors;
  247. lblParam.BoundsRect := Source.lblParam.BoundsRect;
  248. lblParam.Align := Source.lblParam.Align;
  249. lblParam.Anchors := Source.lblParam.Anchors;
  250. edtParam.AssignSize(Source.edtParam);
  251. end;
  252. constructor TParamPanel.Create(AOwner: TComponent);
  253. begin
  254. inherited;
  255. BevelInner := bvNone;
  256. BevelOuter := bvNone;
  257. FlblParam := TLabel.Create(Self);
  258. FedtParam := TBtnEdit.Create(Self);
  259. FlblParam.Parent := Self;
  260. FedtParam.Parent := Self;
  261. end;
  262. procedure TParamPanel.SetedtParam(const Value: TBtnEdit);
  263. begin
  264. FedtParam := Value;
  265. end;
  266. procedure TParamPanel.SetlblParam(const Value: TLabel);
  267. begin
  268. FlblParam := Value;
  269. end;
  270. procedure TfrmAddParamsFunc.actOkExecute(Sender: TObject);
  271. begin
  272. ModalResult := mrOk;
  273. end;
  274. procedure TfrmAddParamsFunc.actCancelExecute(Sender: TObject);
  275. begin
  276. ModalResult := mrCancel;
  277. end;
  278. procedure TfrmAddParamsFunc.actAddValueExecute(Sender: TObject);
  279. begin
  280. with TfrmValueSel.Create(Self) do
  281. try
  282. if ShowModal = idOk then
  283. begin
  284. FActiveEdit.Text := 'gdcBaseManager.GetIDByRUIDString("' +
  285. gdcBaseManager.GetRUIDStringByID(iblcValue.CurrentKeyInt) + '")';
  286. end;
  287. finally
  288. Free;
  289. end
  290. end;
  291. end.