📄 weboutput.pas
字号:
//----------------------------------------------------------------------------------------------------------------------
//
// This file is part of the SimpleWebFront-DBDesigner4-Plugin.
// Copyright (C) 2003 Bayer Ulrich
//
// The SimpleWebFront-DBDesigner4-Plugin 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.
//
// SimpleWebFront-DBDesigner4-Plugin 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 Weboutput;
interface
uses Classes,Contnrs, Layer, QGraphics, SWF_XML_Binding, SysUtils;
type
ETemplateFileException = class(Exception);
//a class symbolyzing a Group
//*************Class TGroup**************************
//***************************************************
TGroup = class(TObject)
private
FName: string; //the name of the group
FshowOnLine, FshowInColumn : Integer; //the position on the index-webpage
Views: TObjectList; //the views associated with this group
FViewsAsPopup : Boolean; //show views in a browser popup-window or in the same window?
public
property Name: String read FName write FName;
property ShowOnLine :Integer read FshowOnLine write FshowOnLine;
property ShowInColumn :Integer read FshowInColumn write FshowInColumn;
property ViewsAsPopup :Boolean read FViewsAsPopup write FViewsAsPopup;
constructor Create(Groupname: String; lineNumber,columnNumber: Integer; viewsAsPopup: Boolean); overload;
destructor Destroy; override;
//function SaveToString() :String;
// class function LoadFromString(s :String) :TGroup;
procedure SaveToXMLNode(node :IXMLSWF_GroupType);
class function LoadFromXMLNode(node :IXMLSWF_GroupType) :TGroup;
end;
//TView represents an sql view
//*************Class TView***************************
//***************************************************
TView = class(TObject)
private
FFormHeight, FFormWidth : Integer;
FFormX,FFormY : Integer;
FGridPopupHeight, FGridPopupWidth: Integer;
FGridPopupX, FGridPopupY : Integer;
FName: String;
FWhereClause: String;
FTable : SW_Table;
FRowsPerPage: Integer;
FUseCompoundColNames : Boolean;
FIcon : TPicture;
FIconFilename: String;
FOrderBy : String;
FJoinTables, FNMTables : TObjectList; //a list of SW_Table objects
GridSortedColumnList,FormSortedColumnList: TStringList;
//returns the Columns from all tables in a stringlist consisting of (name,SW_Column) pairs
procedure GetColumns(stringList: TStringList); overload;
class procedure GetColumns(stringList: TStringList; view:TView);overload;
//This constructor is meant for internal use only; used by LoadFromString
constructor Create(); overload;
function RelationsValid() : Boolean;
class function FindColumnInView(obj_id: Integer; view: TView) : SW_Column;
public
property FormHeight : Integer read FFormHeight write FFormHeight;
property FormWidth : Integer read FFormWidth write FFormWidth;
property FormX : Integer read FFormX write FFormX;
property FormY : Integer read FFormY write FFormY;
property GridPopupHeight : Integer read FGridPopupHeight write FGridPopupHeight;
property GridPopupWidth: Integer read FGridPopupWidth write FGridPopupWidth;
property GridPopupX : Integer read FGridPopupX write FGridPopupX;
property GridPopupY : Integer read FGridPopupY write FGridPopupY;
property Name : String read FName write FName;
property WhereClause :String read FWhereClause write FWhereClause;
property Table: SW_Table read FTable write FTable;
property RowsPerPage: Integer read FRowsPerPage write FRowsPerPage;
property UseCompoundColNames: Boolean read FUseCompoundColNames write FUseCompoundColNames;
property Icon: TPicture read FIcon;
property JoinTables: TObjectList read FJoinTables;
property NMTables :TObjectList read FNMTables;
property IconFilename: STring read FIconFilename write FIconFilename;
property OrderBy : String read FOrderBy write FOrderBy;
//methods
constructor Create(Viewname, WhereClause :String; Table : SW_Table;
JoinTables, NMTables: TObjectList; IconImage:TPicture;
IconFilename,OrderBy:String;RowsPerPage: Integer = 20); overload;
destructor Destroy; override;
//returns the Columns from all tables in a stringlist consisting of (name,SW_Column) pairs
//moreover the stringlist is ordered after the way the columns shall appear on the GridList
procedure GetGridSortedColumns(stringList: TStringList);
//returns the Columns from all tables in a stringlist consisting of (name,SW_Column) pairs
//moreover the stringlist is ordered after the way the columns shall appear on the Form
procedure GetFormSortedColumns(stringList: TStringList);
procedure ExchangeGridSortedColumns(ind1, ind2 :Integer);
procedure ExchangeFormSortedColumns(ind1, ind2 :Integer);
procedure RebuildSortColumns();
function OneGridColVisible() : Boolean;
//function GetSelectStatement() : String;
procedure SaveToXMLNode(node :IXMLSWF_ViewType);
class function LoadFromXMLNode(node :IXMLSWF_ViewType) :TView;
end;
//TWeboutput is the base class for all output classes
//*************Class TWEBOUTPUT**********************
//***************************************************
TWebOutput = class(TObject)
private
//fields
GroupList : TObjectList; //a list of TGroup-objects
UnassignedViewsList : TObjectList; //contains all views that are not assigned to a view yet
Fhostname,Fusername,Fpassword,Fdatabasename : String; //db-connection settings
Fheading, FsaveDir,Flayout : String;
fdirDoesntExist :Boolean;
procedure SetSaveDir(s: String);
public
property dirDoesntExist: Boolean read FDirdoesntExist;
property Hostname: String read FHostname write FHostname;
property Username: STring read FUsername write FUsername;
property Password: STring read FPassword write FPassword;
property Databasename: String read FDatabasename write FDatabasename;
property Heading: String read FHeading write FHeading;
property SaveDir: String read FSaveDir write SetSaveDir;
property Layout: String read FLayout write FLayout;
//methods
constructor Create;
destructor Destroy; override;
//group/view management functions
//procedure AddGroup(Groupname: String; lineNumber, columnNumber: Integer);
procedure AddGroup(group : TGroup);
procedure DeleteGroup(group: TGroup); //removes the specified object from the list and frees it
function GroupPositionFree(lineNo, ColNo : Integer) : Boolean;
function GetGroupAtPosition(lineNo, ColNo : Integer) : TGroup;
//adds the view to the unassignedviewsList
procedure AddView(view: TView); overload;
procedure DeleteView(view: TView);
procedure AssignViewToGroup(group :TGroup; view :TView);
procedure UnassignViewFromGroup(group :TGroup; view :TView);
//returns all groups in a StringList that contains strings paired with objects
procedure GetGroupNames(stringList : TStringList);
procedure GetViewNamesFromGroup(group :TGroup ; stringList :TStringList);
procedure GetViewNames(stringList :TStringList);
procedure GetUnassignedViewNames(stringList : TStringList);
//returns true if all necessary settings for creating the pages have been made
function InputComplete() : Boolean;
//procedure SaveToStringList(stringList :TStringList);
//procedure LoadFromStringList(stringList :TStringList);
procedure LoadFromXMLNode(node :IXMLSWF_DataType);
procedure SaveToXMLNode(node :IXMLSWF_DataType);
//makes the output file(s)
procedure Run(); virtual; abstract;
end;
//this class implements the output for php-files
//*************Class TPHPOUTPUT**********************
//***************************************************
TPHPOutput = class (TWeboutput)
private
procedure CreateIncludeFile();
procedure CreateIndexFile(IndexTemplateFilename: string);
procedure CreateFrameFiles(FrameTemplateFilename: String);
procedure CreateGridFiles(GridTemplateFilename :String);
procedure CreateSQLfiles(SQLTemplateFilename :string);
procedure CreateUpdateFiles(UpdateTemplateFilename :string);
procedure CreateInsertFiles(InsertTemplateFilename :string);
procedure CreateSearchFiles(SearchTemplateFilename: string);
function MakeMainIndex() : String; //index
function MakeKey(table : SW_Table) : String; overload;
function MakeKey(tables : TObjectList) : String; overload;
function MakeDataTypes(table: SW_Table) : String; overload;
function MakeDataTypes(tables: TObjectList) : String; overload;
function MakeDataTypeParams(table: SW_Table) : String; overload;
function MakeDataTypeParams(tables: TObjectList) : String; overload;
function MakeDispCols(table: SW_Table; option : Integer) : String; overload;
function MakeDispCols(tables :TObjectList; option :Integer) : String; overload;
function MakeTableNames(tables: TObjectList) : String;
function MakeConnectionTables(mainTable: SW_Table; nmTables: TObjectList) : String;
procedure SaveIcons();
function MakeColumnCaptions(view: TView) : String;
function MakeFormColumnCaptions(view: TView) : String;
function MakeColumnWidths(view :TView) : String;
function MakeFormColumnWidths(view :TView) : String;
function MakeColumnTruncChars(view :TView) : String;
function MakeKeyMapping(view: TView) : String;
function MakeImageNames() :String;
function MakeDefaultValues(table: SW_Table) : String;
function MakeNotNull(table: SW_Table) : String;
function MakeSortedSelectClause(view: TView) :String;
function MakeColumnOrder(view: TView) :String;
function MakeGridColumnOrder(view: TView) :String;
public
procedure Run(); override;
end;
implementation
uses QForms,Main, MainDM, StrUtils, QDialogs, IniFiles, SplitFns, StringConstants, QControls;
//The tokens denote character sequences that will be expanded in the php-code.
const SELECT_TOKEN = '/*[[SELECT]]*/';
WHERE_CONSTRAINT_TOKEN = '/*[[WHERE_CONSTRAINT]]*/';
INCLUDE_TOKEN = '/*[[INCLUDE]]*/';
VIEWNAME_TOKEN = '/*[[VIEWNAME]]*/';
HEADING_TOKEN = '/*[[HEADING]]*/';
INDEX_TOKEN = '/*[[INDEX]]*/';
FILENAME_TOKEN = '/*[[FILENAME]]*/';
GRID_FILENAME_TOKEN = '/*[[FILENAME_GRID]]*/';
FRAME_FILENAME_TOKEN = '/*[[FILENAME_FRAME]]*/';
IMAGES_TOKEN = '/*[[IMAGE_NAMES]]*/';
SORTED_SELECT_CLAUSE_TOKEN = '/*[[SORTED_SELECT_CLAUSE]]*/';
COLUMNS_ORDER_TOKEN = '/*[[COLUMNS_ORDER]]*/';
TABLENAME_TOKEN = '/*[[TABLENAME]]*/';
DATATYPES_TOKEN = '/*[[DATATYPES]]*/';
DATATYPE_PARAMS_TOKEN = '/*[[DATATYPE_PARAMS]]*/';
TABLEKEY_TOKEN = '/*[[TABLEKEY]]*/';
TABLEDISPCOLS_TOKEN = '/*[[TABLEDISPCOLS]]*/';
MAIN_DEFAULT_VALUE_TOKEN = '/*[[MAIN_DEFAULT_VALUE]]*/';
MAIN_NOT_NULL_TOKEN = '/*[[MAIN_NOTNULL]]*/';
JOINTABLENAME_TOKEN = '/*[[JOINTABLENAMES]]*/';
JOINTABLEKEY_TOKEN = '/*[[JOINTABLES_KEY]]*/';
JOINTABLEDISPCOLS_TOKEN = '/*[[JOINTABLES_DISPCOLS]]*/';
NMTABLENAME_TOKEN = '/*[[NMTABLENAMES]]*/';
NMTABLEKEY_TOKEN = '/*[[NMTABLES_KEY]]*/';
NMTABLEDATATYPES_TOKEN = '/*[[NMTABLES_DATATYPES]]*/';
NMTABLEDATATYPE_PARAMS_TOKEN = '/*[[NMTABLES_DATATYPE_PARAMS]]*/';
NMTABLEDISPCOLS_TOKEN = '/*[[NMTABLES_DISPCOLS]]*/';
CONNECTIONTABLENAME_TOKEN = '/*[[CONNECTIONTABLENAMES]]*/';
KEY_MAPPING_TOKEN = '/*[[KEY_MAPPING]]*/';
//these tokens are recognized in the grid-file only
ROWSPP_TOKEN = '/*[[ROWSPERPAGE]]*/';
GRID_AS_POPUP_TOKEN = '/*[[GRID_AS_POPUP]]*/';
FORMHEIGHT_TOKEN = '/*[[FORMHEIGHT]]*/';
FORMWIDTH_TOKEN = '/*[[FORMWIDTH]]*/';
FORMX_TOKEN = '/*[[FORMX]]*/';
FORMY_TOKEN = '/*[[FORMY]]*/';
COLUMN_CAPTIONS_TOKEN = '/*[[COLUMN_CAPTIONS]]*/';
COLUMN_WIDTHS_TOKEN = '/*[[COLUMN_WIDTHS]]*/';
COLUMN_TRUNC_TOKEN = '/*[[COLUMN_TRUNCATE_CHARS]]*/';
{$IFDEF MSWINDOWS}
EOL = #13#10; //Carriage Return + Newline
{$ELSEIF LINUX}
EOL = #10; //only newline
{$IFEND}
//*************************************************************
//**Implementations for TGroup*********************************
//*************************************************************
constructor TGroup.Create(Groupname: String; lineNumber, columnNumber: Integer; viewsAsPopup: Boolean);
begin
inherited Create();
Name:= Groupname;
Views := TObjectList.Create();
showOnLine := lineNumber;
showInColumn := columnNumber;
FViewsAsPopup := viewsAsPopup;
end;
destructor TGroup.Destroy;
begin
Views.Free();
end;
procedure TGroup.SaveToXMLNode(node :IXMLSWF_GroupType);
var i : Integer;
xmlView :IXMLSWF_ViewType;
view: TView;
begin
node.Name := self.FName;
node.ShowOnLine := ShowOnLine;
node.ShowInColumn := ShowInColumn;
node.ViewsAsPopup := self.FViewsAsPopup;
for i:= 0 to Views.Count-1 do
begin
xmlView := node.SWF_Views.Add;
view := TView(Views[i]);
view.SaveToXMLNode(xmlView);
end;
end;
class function TGroup.LoadFromXMLNode(node :IXMLSWF_GroupType) :TGroup;
var views : IXMLSWF_ViewsType;
view: IXMLSWF_ViewType;
i : Integer;
grpName : string;
lineNo,colNo : Integer;
ViewsAsPopup : Boolean;
tmpGrp :TGroup;
viewList :TObjectList;
realView :TView;
begin
grpName := node.Name;
lineNo := node.ShowOnLine;
colNo:= node.ShowInColumn;
ViewsAsPopup := node.ViewsAsPopup;
views := node.SWF_Views;
viewList := TObjectList.Create;
for I:=0 to views.Count-1 do
begin
view:= views[i];
realView := TView.LoadFromXMLNode(view);
if (realView <> nil) then //if one of the tables of the view doesn't exist
viewList.Add(realView);
end;
TmpGrp := Create(grpName,lineNo,colNo, ViewsAspopup);
TmpGrp.Views := ViewList;
LoadFromXMLNode := TmpGrp;
end;
//*************************************************************
//**Implementations for TView**********************************
//*************************************************************
procedure TView.SaveToXMLNode(node :IXMLSWF_ViewType);
var i :Integer;
tmpTable :SW_Table;
xmlTable : IXMLSWF_TableType;
stream : TMemoryStream;
gs, fs : STring;
begin
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -