📄 main.pas
字号:
unit Main;
//----------------------------------------------------------------------------------------------------------------------
//
// This file is part of fabFORCE DBDesigner4.
// Copyright (C) 2002 Michael G. Zinner, www.fabFORCE.net
//
// DBDesigner4 is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// DBDesigner4 is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with DBDesigner4; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
//----------------------------------------------------------------------------------------------------------------------
//
// Unit Main.pas
// -------------
// Version 1.0, 12.01.2003, Mike
// Description
// MainForm of the HTML Report Plugin
//
// Changes:
// Version 1.0, 12.01.2003, Mike
// initial version, Mike
//
//----------------------------------------------------------------------------------------------------------------------
interface
uses
SysUtils, Types, Classes, Variants, QTypes, QGraphics, QControls, QForms,
QDialogs, QStdCtrls, Qt, QExtCtrls, QCheckLst, QButtons, QMenus,
EERModel; // The EERModel module has to be added to the uses clause
type
TMainForm = class(TForm)
MenuBevel: TBevel;
MainPnl: TPanel;
SubmitBtn: TSpeedButton;
CancelBtn: TSpeedButton;
TablesLbl: TLabel;
TablesCheckListBox: TCheckListBox;
OptionsGroupBox: TGroupBox;
ListRegionsCheckBox: TCheckBox;
ListIndicesCheckBox: TCheckBox;
TableOptionsCheckBox: TCheckBox;
RegionsLbl: TLabel;
RegionsComboBox: TComboBox;
LayoutGroupBox: TGroupBox;
LayoutComboBox: TComboBox;
MainMenu: TMainMenu;
File1: TMenuItem;
ExitMI: TMenuItem;
DisplayMI: TMenuItem;
ShowControlsMI: TMenuItem;
ShowModelMI: TMenuItem;
Help1: TMenuItem;
AboutMI: TMenuItem;
TablesPopupMenu: TPopupMenu;
SelectAllMI: TMenuItem;
DeselectAllMI: TMenuItem;
SortOrderPosRBtn: TRadioButton;
SortAlphaRBtn: TRadioButton;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
//Initialize this form's controls with data from the loaded model
procedure InitControls;
procedure GetLayouts;
procedure RegionsComboBoxCloseUp(Sender: TObject);
procedure CancelBtnClick(Sender: TObject);
procedure SubmitBtnClick(Sender: TObject);
//Show About Box
procedure AboutMIClick(Sender: TObject);
//Show or Hide the Controls/the EER Model
procedure ShowControlsMIClick(Sender: TObject);
procedure TablesCheckListBoxClickCheck(Sender: TObject);
procedure SelectAllMIClick(Sender: TObject);
procedure DeselectAllMIClick(Sender: TObject);
procedure StorePluginDataInModel;
function BuildHTMLFile(layout: string): string;
function BuildHTMLTable(theTable: TEERTable; layout: string): string;
procedure SortOrderPosRBtnClick(Sender: TObject);
private
{ Private declarations }
SelectedTables: string;
lastFileName: string;
ModelFileName: string;
public
{ Public declarations }
//Public declaration of the EERModel
EERModel: TEERModel;
end;
var
MainForm: TMainForm;
implementation
//Include the MainDM and EERDM modules
uses MainDM, EERDM;
{$R *.xfm}
procedure TMainForm.FormCreate(Sender: TObject);
var i: Integer;
begin
//Create Main DataModule, containing general functions
DMMain:=TDMMain.Create(self);
//Create EER DateModule, containing additional functions for the EERModel
DMEER:=TDMEER.Create(self);
//Initialise the Forms Font (For Kylix)
DMMain.InitForm(self);
EERModel:=nil;
//if a parameter is specified, it is assumed to be a filename
for i := 1 to ParamCount do
begin
//Check if file exists
if(FileExists(ParamStr(i)))then
begin
//Create EERModel
EERModel:=TEERModel.Create(self);
//Set the Model invisible at first, so the form's controls are visible
EERModel.Visible:=False;
//Load model from file, read settings and do not append to current model
ModelFileName:=ParamStr(i);
EERModel.LoadFromFile(ModelFileName, True, False, False, False);
//Set the current worktool to Pointer
DMEER.SetCurrentWorkTool(wtPointer);
//Initialize this form's controls with data from the model
InitControls;
//Only load first file
break;
end;
end;
lastFileName:='';
end;
procedure TMainForm.FormDestroy(Sender: TObject);
begin
//Store changes to model
StorePluginDataInModel;
//Free the EERModel
EERModel.Free;
end;
procedure TMainForm.InitControls;
var thePluginData: TEERPluginData;
theTables: TList;
theTableNames: TStringList;
theRegionNames: TStringList;
i: integer;
begin
thePluginData:=EERModel.GetPluginDataByID('HTMLReport', -1);
if(thePluginData=nil)then
begin
//Get selected tables
theTables:=TList.Create;
try
EERModel.GetEERObjectList([EERTable], theTables);
SelectedTables:='';
for i:=0 to theTables.Count-1 do
SelectedTables:=SelectedTables+TEERTable(theTables[i]).ObjName+';';
finally
theTables.Free;
end;
end
else
begin
SelectedTables:=thePluginData.Params.Values['SelectedTables'];
end;
//If there are Regions
if(EERModel.GetEERObjectCount([EERRegion])>0)then
begin
//Create temporary Stringlist
theRegionNames:=TStringList.Create;
try
//Call EERModel function which will list all regions
EERModel.GetEERObjectNameList([EERRegion], theRegionNames);
theRegionNames.Sorted:=True;
//Assigned the returned Stringlist to the Listbox
RegionsComboBox.Items.Assign(theRegionNames);
finally
//Free the temporary Stringlist
theRegionNames.Free;
end;
RegionsComboBox.ItemIndex:=0;
RegionsComboBoxCloseUp(self);
end
else
begin
//if there are no regions, hide Combobox
RegionsLbl.Visible:=False;
TablesLbl.Top:=RegionsLbl.Top;
RegionsComboBox.Visible:=False;
TablesCheckListBox.Height:=TablesCheckListBox.Height+
TablesCheckListBox.Top-RegionsComboBox.Top;
TablesCheckListBox.Top:=RegionsComboBox.Top;
ListRegionsCheckBox.Enabled:=False;
ListRegionsCheckBox.Checked:=False;
//Create temporary Stringlist
theTableNames:=TStringList.Create;
try
//Call EERModel function which will list all tables
EERModel.GetEERObjectNameList([EERTable], theTableNames);
//Assigned the returned Stringlist to the Listbox
TablesCheckListBox.Items.Assign(theTableNames);
finally
//Free the temporary Stringlist
theTableNames.Free;
end;
//Select all items in the Listbox which are in the SelectedTables string
for i:=0 to TablesCheckListBox.Items.Count-1 do
if(Pos(TablesCheckListBox.Items[i]+';', SelectedTables)>0)then
TablesCheckListBox.Checked[i]:=True;
TablesCheckListBox.ItemIndex:=0;
end;
//Get Layouts
GetLayouts;
end;
procedure TMainForm.RegionsComboBoxCloseUp(Sender: TObject);
var theTables: TList;
theRegion: TEERRegion;
i: integer;
begin
theTables:=TList.Create;
try
theRegion:=EERModel.GetEERObjectByName(EERRegion, RegionsComboBox.Items[RegionsComboBox.ItemIndex]);
if(theRegion<>nil)then
begin
theRegion.GetEERObjsInRegion([EERTable], theTables);
if(SortOrderPosRBtn.Checked)then
EERModel.SortEERObjectListByOrderPos(theTables)
else
EERModel.SortEERObjectListByObjName(theTables);
TablesCheckListBox.Clear;
for i:=0 to theTables.Count-1 do
begin
TablesCheckListBox.Items.Add(TEERTable(theTables[i]).ObjName);
if(Pos(TablesCheckListBox.Items[i]+';', SelectedTables)>0)then
TablesCheckListBox.Checked[i]:=True;
end;
end;
finally
theTables.Free;
end;
end;
procedure TMainForm.TablesCheckListBoxClickCheck(Sender: TObject);
begin
if(TablesCheckListBox.Checked[TablesCheckListBox.ItemIndex])then
begin
//Add to SelectedTables if the table isn't already in the string
if(Pos(TablesCheckListBox.Items[TablesCheckListBox.ItemIndex]+';', SelectedTables)=0)then
SelectedTables:=SelectedTables+TablesCheckListBox.Items[TablesCheckListBox.ItemIndex]+';';
end
else
begin
//Delete from SelectedTables if the table is in the string
if(Pos(TablesCheckListBox.Items[TablesCheckListBox.ItemIndex]+';', SelectedTables)>0)then
SelectedTables:=DMMain.ReplaceText(SelectedTables,
TablesCheckListBox.Items[TablesCheckListBox.ItemIndex]+';', '');
end;
end;
procedure TMainForm.AboutMIClick(Sender: TObject);
begin
ShowMessage('DBDesigner 4 HTML Report Plugin'#13#10+
'Version 1.0.0.7'#13#10#13#10+
'The HTML Report Plugin generates a HTML Report of the '#13#10+
'EER Model. Different templates and options can be selected. ');
end;
procedure TMainForm.ShowControlsMIClick(Sender: TObject);
begin
//This is called from ShowControlsMI and ShowModelMI
if(EERModel=nil)then
Exit;
//Check the selected MenuItem, the other MenuItem will be unchecked automatically
TMenuItem(Sender).Checked:=True;
//Hide Model
if(Sender=ShowControlsMI)then
begin
//AutoScroll:=False;
EERModel.Visible:=False;
end
else
//Show the Model
begin
//AutoScroll:=True;
EERModel.Visible:=True;
EERModel.BringToFront;
end;
end;
procedure TMainForm.SelectAllMIClick(Sender: TObject);
var i: integer;
begin
//Select all items in the Listbox
for i:=0 to TablesCheckListBox.Items.Count-1 do
begin
TablesCheckListBox.Checked[i]:=True;
//Add to SelectedTables if the table isn't already in the string
if(Pos(TablesCheckListBox.Items[i]+';', SelectedTables)=0)then
SelectedTables:=SelectedTables+TablesCheckListBox.Items[i]+';';
end;
end;
procedure TMainForm.DeselectAllMIClick(Sender: TObject);
var i: integer;
begin
//Select all items in the Listbox
for i:=0 to TablesCheckListBox.Items.Count-1 do
begin
TablesCheckListBox.Checked[i]:=False;
//Delete from SelectedTables if the table is in the string
if(Pos(TablesCheckListBox.Items[i]+';', SelectedTables)>0)then
SelectedTables:=DMMain.ReplaceText(SelectedTables,
TablesCheckListBox.Items[i]+';', '');
end;
end;
procedure TMainForm.CancelBtnClick(Sender: TObject);
begin
//When the user presses Cancel, close the program
Close;
end;
procedure TMainForm.SubmitBtnClick(Sender: TObject);
var theSaveDialog: TSaveDialog;
RecentSaveFileAsDir: string;
ReportAsText: TStringList;
begin
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -