PageRenderTime 28ms CodeModel.GetById 15ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 1ms

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