2016-08-01 10:08:42 +00:00
|
|
|
{* ***** BEGIN LICENSE BLOCK ***** *}
|
|
|
|
{* Version: MPL 1.1 *}
|
|
|
|
{* *}
|
|
|
|
{* The contents of this file are subject to the Mozilla Public License *}
|
|
|
|
{* Version 1.1 (the "License"); you may not use this file except in *}
|
|
|
|
{* compliance with the License. You may obtain a copy of the License at *}
|
|
|
|
{* http://www.mozilla.org/MPL/ *}
|
|
|
|
{* *}
|
|
|
|
{* Software distributed under the License is distributed on an "AS IS" basis, *}
|
|
|
|
{* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License *}
|
|
|
|
{* for the specific language governing rights and limitations under the *}
|
|
|
|
{* License. *}
|
|
|
|
{* *}
|
|
|
|
{* The Original Code is TurboPower Visual PlanIt *}
|
|
|
|
{* *}
|
|
|
|
{* The Initial Developer of the Original Code is TurboPower Software *}
|
|
|
|
{* *}
|
|
|
|
{* Portions created by TurboPower Software Inc. are Copyright (C) 2002 *}
|
|
|
|
{* TurboPower Software Inc. All Rights Reserved. *}
|
|
|
|
{* *}
|
|
|
|
{* Contributor(s): *}
|
|
|
|
{* *}
|
|
|
|
{* ***** END LICENSE BLOCK ***** *}
|
|
|
|
|
|
|
|
unit ExVpRptSetup;
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
2016-08-01 10:15:48 +00:00
|
|
|
SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
|
2017-05-21 21:30:07 +00:00
|
|
|
StdCtrls, ComCtrls, EditBtn, ExtCtrls,
|
2016-08-01 10:08:42 +00:00
|
|
|
|
|
|
|
VpBaseDS, VpPrtFmtCBox;
|
|
|
|
|
|
|
|
type
|
|
|
|
TReportDataRec = record
|
|
|
|
StartDate, EndDate : TDateTime;
|
|
|
|
Format : string;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{ TfrmReportSetup }
|
|
|
|
|
|
|
|
TfrmReportSetup = class(TForm)
|
|
|
|
btnOK: TButton;
|
|
|
|
btnCancel: TButton;
|
|
|
|
lblStartDate: TLabel;
|
|
|
|
lblEndDate: TLabel;
|
|
|
|
lblFormat: TLabel;
|
|
|
|
edStartDate: TDateEdit;
|
|
|
|
edEndDate: TDateEdit;
|
2017-05-21 21:30:07 +00:00
|
|
|
Panel1: TPanel;
|
|
|
|
ButtonPanel: TPanel;
|
2017-05-21 12:02:22 +00:00
|
|
|
PrintFormatCombo: TVpPrintFormatComboBox;
|
2016-08-01 10:08:42 +00:00
|
|
|
procedure FormCreate(Sender: TObject);
|
|
|
|
procedure FormShow(Sender: TObject);
|
|
|
|
private
|
|
|
|
procedure PositionControls;
|
|
|
|
procedure SetCaptions;
|
|
|
|
function GetControlLink: TVpControlLink;
|
|
|
|
procedure SetControlLink(const Value: TVpControlLink);
|
|
|
|
function GetDate(Index: Integer): TDateTime;
|
|
|
|
procedure SetDate(Index: Integer; Value: TDateTime);
|
|
|
|
procedure SaveData(out ReportData: TReportDataRec);
|
|
|
|
public
|
|
|
|
{ Public declarations }
|
|
|
|
function Execute(var ReportData: TReportDataRec) : Boolean;
|
|
|
|
property ControlLink : TVpControlLink
|
|
|
|
read GetControlLink write SetControlLink;
|
|
|
|
property StartDate : TDateTime index 1
|
|
|
|
read GetDate write SetDate;
|
|
|
|
property EndDate : TDateTime index 2
|
|
|
|
read GetDate write SetDate;
|
|
|
|
end;
|
|
|
|
|
|
|
|
var
|
|
|
|
frmReportSetup: TfrmReportSetup;
|
|
|
|
ReportData: TReportDataRec = (StartDate: 0; EndDate: 0; Format: '');
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
2016-08-01 10:15:48 +00:00
|
|
|
{$R *.lfm}
|
2016-08-01 10:08:42 +00:00
|
|
|
|
|
|
|
uses
|
2017-05-21 12:02:22 +00:00
|
|
|
Math, LCLIntf, LCLType,
|
|
|
|
VpSR, VpMisc;
|
2016-08-01 10:08:42 +00:00
|
|
|
|
|
|
|
{ TfrmReportSetup }
|
|
|
|
|
|
|
|
function TfrmReportSetup.Execute(var ReportData: TReportDataRec) : Boolean;
|
|
|
|
begin
|
|
|
|
StartDate := ReportData.StartDate;
|
|
|
|
EndDate := ReportData.EndDate;
|
2017-05-21 12:02:22 +00:00
|
|
|
PrintFormatCombo.ItemIndex := ControlLink.Printer.Find(ReportData.Format);
|
2016-08-01 10:08:42 +00:00
|
|
|
|
|
|
|
Result := ShowModal = mrOk;
|
|
|
|
|
|
|
|
if Result then
|
|
|
|
SaveData(ReportData);
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TfrmReportSetup.FormCreate(Sender: TObject);
|
|
|
|
begin
|
|
|
|
SetCaptions;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TfrmReportSetup.FormShow(Sender: TObject);
|
|
|
|
begin
|
|
|
|
PositionControls;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TfrmReportSetup.GetControlLink: TVpControlLink;
|
|
|
|
begin
|
2017-05-21 12:02:22 +00:00
|
|
|
Result := PrintFormatCombo.ControlLink;
|
2016-08-01 10:08:42 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TfrmReportSetup.GetDate(Index: Integer) : TDateTime;
|
|
|
|
begin
|
|
|
|
Result := 0.0;
|
|
|
|
case Index of
|
|
|
|
1: Result := edStartDate.Date;
|
|
|
|
2: Result := edEndDate.Date;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TfrmReportSetup.PositionControls;
|
|
|
|
var
|
2018-06-09 09:22:33 +00:00
|
|
|
i, w: Integer;
|
2017-05-21 12:02:22 +00:00
|
|
|
cnv: TControlCanvas;
|
2016-08-01 10:08:42 +00:00
|
|
|
begin
|
2017-05-21 12:02:22 +00:00
|
|
|
AutoSize := false;
|
2016-08-05 22:07:34 +00:00
|
|
|
|
2017-05-21 21:30:07 +00:00
|
|
|
AlignOKCancel(btnOK, btnCancel, ButtonPanel);
|
2017-05-21 12:02:22 +00:00
|
|
|
|
|
|
|
cnv := TControlCanvas.Create;
|
|
|
|
try
|
|
|
|
cnv.Control := PrintFormatCombo;
|
|
|
|
w := 0;
|
|
|
|
for i:=0 to PrintFormatCombo.Items.Count-1 do
|
|
|
|
w := Max(w, cnv.TextWidth(PrintFormatCombo.Items[i]));
|
|
|
|
inc(w, GetSystemMetrics(SM_CXVSCROLL));
|
|
|
|
edStartDate.Width := w;
|
|
|
|
// The width of the PrintFormatCombo is anchored to the edStartDate!
|
|
|
|
finally
|
|
|
|
cnv.Free;
|
|
|
|
end;
|
2016-08-05 22:07:34 +00:00
|
|
|
|
2017-05-21 12:02:22 +00:00
|
|
|
edStartDate.ButtonWidth := edStartDate.Height;
|
|
|
|
edEndDate.ButtonWidth := edEndDate.Height;
|
|
|
|
AutoSize := true;
|
2016-08-01 10:08:42 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TfrmReportSetup.SaveData(out ReportData: TReportDataRec);
|
|
|
|
begin
|
|
|
|
if (edStartDate.Text = '') and (edEndDate.Text = '') then begin
|
|
|
|
ReportData.StartDate := now;
|
|
|
|
ReportData.EndDate := now;
|
|
|
|
end else
|
|
|
|
if (edStartDate.Text = '') then begin
|
|
|
|
ReportData.EndDate := edEndDate.Date;
|
|
|
|
ReportData.StartDate := edEndDate.Date;
|
|
|
|
end else
|
|
|
|
if (edEndDate.Text = '') then begin
|
|
|
|
ReportData.StartDate := edStartDate.Date;
|
|
|
|
ReportData.EndDate := edStartDate.date;
|
|
|
|
end else
|
|
|
|
begin
|
|
|
|
ReportData.StartDate := edStartDate.Date;
|
|
|
|
ReportData.EndDate := edEndDate.Date;
|
|
|
|
end;
|
2017-05-21 12:02:22 +00:00
|
|
|
ReportData.Format := PrintFormatCombo.Text;
|
2016-08-01 10:08:42 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TfrmReportSetup.SetCaptions;
|
|
|
|
begin
|
|
|
|
Caption := RSReportSetup;
|
|
|
|
lblStartDate.Caption := RSStartTimeLbl;
|
|
|
|
lblEndDate.Caption := RSEndTimeLbl;
|
|
|
|
lblFormat.Caption := RSFormatLbl;
|
|
|
|
btnOK.Caption := RSOKBtn;
|
|
|
|
btnCancel.Caption := RSCancelBtn;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TfrmReportSetup.SetControlLink(const Value: TVpControlLink);
|
|
|
|
begin
|
2017-05-21 12:02:22 +00:00
|
|
|
PrintFormatCombo.ControlLink := Value;
|
2016-08-01 10:08:42 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TfrmReportSetup.SetDate(Index: Integer;
|
|
|
|
Value: TDateTime);
|
|
|
|
begin
|
|
|
|
case Index of
|
|
|
|
1: edStartDate.Date := Value;
|
|
|
|
2: edEndDate.Date := Value;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
end.
|
|
|
|
|