⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.pas

📁 DBDesigner 4 is a database design system that integrates database design, modelling, creation and ma
💻 PAS
📖 第 1 页 / 共 4 页
字号:
unit Main;



//----------------------------------------------------------------------------------------------------------------------

//

// 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 MainDM.pas

// ---------------

// Version 1.1, 14.05.2003, Mike

// Description

//   the main file of the plugin, handles all the UI

//

// Changes:

//   Version 1.1, 14.05.2003, Mike

//     added

//   Version 1.0, 12.01.2003, Ulli

//     initial version

//

//----------------------------------------------------------------------------------------------------------------------



interface



uses

  SysUtils, Types, Classes, Variants, QTypes, QGraphics, QControls, QForms, 

  QDialogs, QStdCtrls, Qt, QExtCtrls, QCheckLst, QComCtrls, EERModel,

  QButtons, Weboutput, EditorView, QFileCtrls, DialogDirectorySelect, Layer,

  QMenus;



type

  TMainForm = class(TForm)

    Label19: TLabel;

    Label21: TLabel;

    Label22: TLabel;

    FormHeightEd: TEdit;

    FormXEd: TEdit;

    FormYEd: TEdit;

    FormWidthEd: TEdit;

    PageControl: TPageControl;

    GridTabSheet: TTabSheet;

    CreateBtn: TSpeedButton;

    ModelOptionsTabSheet: TTabSheet;

    LayoutLbl: TLabel;

    FieldsVisibleCheckListBox: TCheckListBox;

    Label7: TLabel;

    Group2ComboBox: TComboBox;

    Label1: TLabel;

    ViewComboBox: TComboBox;

    Label8: TLabel;

    GroupBox1: TGroupBox;

    GridGroupBox: TGroupBox;

    FormOptionsTabSheet: TTabSheet;

    Form_FieldsVisibleCheckListBox: TCheckListBox;

    Label9: TLabel;

    Form_ViewComboBox: TComboBox;

    Form_GroupComboBox: TComboBox;

    Label10: TLabel;

    Label11: TLabel;

    GroupBox2: TGroupBox;

    GroupBox3: TGroupBox;

    HeadingLbl: TLabel;

    HeadingEd: TEdit;

    DatabaseSettings: TGroupBox;

    LangComboBox: TComboBox;

    LanguageLbl: TLabel;

    PasswordEd: TEdit;

    UsernameEd: TEdit;

    HostnameEd: TEdit;

    DatabaseEd: TEdit;

    Hostname: TLabel;

    Username: TLabel;

    Password: TLabel;

    Database: TLabel;

    LayoutComboBox: TComboBox;

    OutputDirEd: TEdit;

    OutputDir: TLabel;

    SaveDlgBtn: TSpeedButton;

    GeneralSettings: TGroupBox;

    RowsPerPageEd: TEdit;

    RowsPerPage: TLabel;

    GroupTabSheet: TTabSheet;

    GroupsListBox: TListBox;

    Label6: TLabel;

    ViewTabSheet: TTabSheet;

    AssignmentGroupBox: TGroupBox;

    Label18: TLabel;

    ViewsFromGroupListBox: TListBox;

    UnassignedViewsListBox: TListBox;

    GroupComboBox: TComboBox;

    Label12: TLabel;

    Label13: TLabel;

    GroupManagementBox: TGroupBox;

    Label2: TLabel;

    Label3: TLabel;

    Label4: TLabel;

    Label5: TLabel;

    ViewInfoGroupBox: TGroupBox;

    Label14: TLabel;

    Label15: TLabel;

    ColnameEd: TEdit;

    CompoundColNamesCheckBox: TCheckBox;

    ColWidthEd: TEdit;

    FixedWidthCheckBox: TCheckBox;

    MainMenu1: TMainMenu;

    File1: TMenuItem;

    Help1: TMenuItem;

    CloseMI: TMenuItem;

    About1: TMenuItem;

    Bevel3: TBevel;

    TruncateCheckBox: TCheckBox;

    ColTruncateCharsEd: TEdit;

    Execute1: TMenuItem;

    PageControlTreeView: TTreeView;

    PageControlTitleShape: TShape;

    PageControlTitlePnl: TPanel;

    PageControlTitleLbl: TLabel;

    GroupBox4: TGroupBox;

    Label17: TLabel;

    AllViewsListBox: TListBox;

    ViewNameEd: TEdit;

    TablenameEd: TEdit;

    JoinTablesEd: TEdit;

    NMTablesEd: TEdit;

    WhereClauseMemo: TMemo;

    EditViewSettingsBtn: TSpeedButton;

    Label20: TLabel;

    Label23: TLabel;

    Label16: TLabel;

    Label24: TLabel;

    Label25: TLabel;

    Label26: TLabel;

    Label27: TLabel;

    CloseBtn: TSpeedButton;

    SaveBtn: TSpeedButton;

    Label28: TLabel;

    Form_ColNameEd: TEdit;

    Form_ColWidthEd: TEdit;

    Form_FixedWidthCheckBox: TCheckBox;

    Label29: TLabel;

    SaveMI: TMenuItem;

    ReportingBugs1: TMenuItem;

    N1: TMenuItem;

    CreateGrpBtn: TSpeedButton;

    DelGrpBtn: TSpeedButton;

    EditGrpBtn: TSpeedButton;

    AddRegBtn: TSpeedButton;

    EditViewBtn: TSpeedButton;

    CreateViewBtn: TSpeedButton;

    DelViewBtn: TSpeedButton;

    AddTablesBtn: TSpeedButton;

    StatusBar: TStatusBar;

    Grid_UpBtn: TSpeedButton;

    Grid_DownBtn: TSpeedButton;

    LABtn: TSpeedButton;

    RABtn: TSpeedButton;

    Form_DownBtn: TSpeedButton;

    Form_UpBtn: TSpeedButton;

    procedure FormCreate(Sender: TObject);

    procedure FormDestroy(Sender: TObject);



    //This procedure initializes the Controls based on the selected model

    procedure InitControls;

    procedure GroupComboBoxChange(Sender: TObject);

    procedure SaveDlgBtnClick(Sender: TObject);

    procedure CreateBtnClick(Sender: TObject);

    procedure PageControlChange(Sender: TObject);

    procedure HostnameEdExit(Sender: TObject);

    procedure UsernameEdExit(Sender: TObject);

    procedure PasswordEdExit(Sender: TObject);

    procedure DatabaseEdExit(Sender: TObject);

    procedure HeadingEdExit(Sender: TObject);

    procedure LayoutComboBoxChange(Sender: TObject);

    procedure RowsPerPageEdExit(Sender: TObject);

    procedure CreateGrpBtnClick(Sender: TObject);

    procedure DelGrpBtnClick(Sender: TObject);

    procedure AddRegBtnClick(Sender: TObject);

//    procedure DelRegBtnClick(Sender: TObject);

    procedure CreateViewBtnClick(Sender: TObject);

    procedure DelViewBtnClick(Sender: TObject);

    procedure LABtnClick(Sender: TObject);

    procedure RABtnClick(Sender: TObject);

    procedure AllViewsListBoxClick(Sender: TObject);

    procedure Group2ComboBoxChange(Sender: TObject);

    procedure ViewComboBoxChange(Sender: TObject);

    procedure FieldsVisibleCheckListBoxClickCheck(Sender: TObject);

    procedure AddTablesBtnClick(Sender: TObject);

//    procedure DelTablesBtnClick(Sender: TObject);

    procedure EditViewBtnClick(Sender: TObject);

    procedure OutputDirEdExit(Sender: TObject);

    procedure Form_GroupComboBoxChange(Sender: TObject);

    procedure Form_ViewComboBoxChange(Sender: TObject);

    procedure Form_FieldsVisibleCheckListBoxClickCheck(Sender: TObject);

    procedure EditGrpBtnClick(Sender: TObject);

    procedure AllViewsListBoxDblClick(Sender: TObject);

    procedure GroupsListBoxDblClick(Sender: TObject);

    procedure CloseMIClick(Sender: TObject);

    procedure CompoundColNamesCheckBoxClick(Sender: TObject);

    procedure FieldsVisibleCheckListBoxClick(Sender: TObject);

    procedure FixedWidthCheckBoxClick(Sender: TObject);

    procedure ColWidthEdExit(Sender: TObject);

    procedure ColnameEdExit(Sender: TObject);

    procedure TruncateCheckBoxClick(Sender: TObject);

    procedure ExecuteMIClick(Sender: TObject);

    procedure ColTruncateCharsEdExit(Sender: TObject);

    procedure About1Click(Sender: TObject);

    procedure PopupBtnClick(Sender: TObject);

    procedure FormWidthEdExit(Sender: TObject);

    procedure FormHeightEdExit(Sender: TObject);

    procedure FormXEdExit(Sender: TObject);

    procedure FormYEdExit(Sender: TObject);

    procedure PageControlTreeViewChange(Sender: TObject; Node: TTreeNode);

    procedure SaveBtnClick(Sender: TObject);

    procedure CloseBtnClick(Sender: TObject);

    procedure Form_FieldsVisibleCheckListBoxClick(Sender: TObject);

    procedure Form_ColWidthEdExit(Sender: TObject);

    procedure Form_ColNameEdExit(Sender: TObject);

    procedure Form_FixedWidthCheckBoxClick(Sender: TObject);

    procedure SaveMIClick(Sender: TObject);

    procedure ReportingBugs1Click(Sender: TObject);

    procedure Grid_UpBtnClick(Sender: TObject);

    procedure Grid_DownBtnClick(Sender: TObject);

    procedure Form_UpBtnClick(Sender: TObject);

    procedure Form_DownBtnClick(Sender: TObject);

  private

    EERModel: TEERModel;     //only used for GetPlugInData and AddPluginData

    xmlFilename :String;

    function TakeSettings : Boolean;

    procedure RefreshPage(index: Integer);

    procedure RefreshGroupTab;

    procedure RefreshViewTab;

    procedure RefreshGridTab;

    procedure RefreshFormTab;

    procedure UpdateInfoFields;

    procedure RefreshColInfo;

    procedure RefreshViewInfo;

    procedure RefreshFormInfo;

    procedure RefreshFormColInfo;

    procedure UpdateTabFromOutputObject;



    //Deactivate/Activate the execute-menu entry and the execute-button 

    procedure DeactivateRun;

    procedure ActivateRun;

    function CreateViewLikeTable(table: SW_Table) : TView;

  public

    { Public declarations }

    Output  : TWeboutput;



  end;



var

  MainForm: TMainForm;



const

  Version = '0.6.4.6';

  DataDir = 'Data'+PathDelim+'Plugins'+PathDelim+'SimpleWebFront'+PathDelim;







IMPLEMENTATION





uses MainDM, EERDM,EditorString, Contnrs, EditorGroup, StringConstants,

     Splash, DialogPopupSettings, SWF_XML_Binding, XMLIntf,DialogBugs;



{$R *.xfm}





procedure TMainForm.FormCreate(Sender: TObject);

var mydata: TEERPluginData;

    password, xmlString: string;

    xmlNode : IXMLSWF_DataType;

begin



  Caption:='Simple Web Front Plugin - Version '+Version+' |';



  //Create Main DataModule, containing general functions

  DMMain:=TDMMain.Create(self);

  //Create EER DateModule, containing additional functions for the EERModel

  DMEER:=TDMEER.Create(self);



  //Initialize the Forms Font

  DMMain.InitForm(self);



  xmlFilename :=ParamStr(1);



  if ( (ParamCount = 0) or NOT(FileExists(xmlFilename)) ) then //no (valid) model-file given

  begin

    MessageDlg(ArgumentError, mtError,[mbOK],0);

    Application.Terminate;

  end;



  //create the model

  //we have to do that here since the EERModel is a panel and it expects a form as a parent

  EERModel:=TEERModel.Create(self);

  EERModel.Visible:=False;

  EERModel.LoadFromFile(ParamStr(1), True, False, False, False); //Load from file, read settings and do not append to current model

  DMEER.SetCurrentWorkTool(wtPointer);   //Set the Worktool to Pointer



  Model := SW_Model.Create(EERModel);

  Output := TPHPOutput.Create;  //at the moment only PHP is supported



  InitControls;



  //Load the model data

  mydata:=EERModel.GetPluginDataById('SimpleWebFront', 0);

  if (mydata <> nil) then

  begin

    xmlString := mydata.params[0];



    xmlNode := LoadSWF_DataFromString(xmlString);



    //should be named loadFromXMLNode

    Output.LoadFromXMLNode(xmlNode);

    UpdateTabFromOutputObject;

  end;





  if (Output.InputComplete) then

    ActivateRun()

  else

    DeactivateRun();





  //Page Control Tree View

  PageControlTreeView.FullExpand;

  PageControl.ActivePageIndex:=0;

  PageControlTreeView.Selected:=PageControlTreeView.Items[0];



  PageControlTitleLbl.Font.Style:=[fsBold];



  //Center Form

  Top:=(Screen.Height-Height) div 2;

  //2 Monitors

  if(Screen.Width=(Screen.Height/0.75)*2)or

    (Screen.Width=(Screen.Height*1.25)*2)then

    Left:=((Screen.Width div 2)-Width) div 2

  else

    Left:=(Screen.Width-Width) div 2;

  //2 Monitors, different resolution 1280+1152

  if(Screen.Width=1280+1152)then

    Left:=(1280-Width) div 2;



  //to support automatic testing

  if ((ParamCount = 3) and (ParamStr(3) = 'auto')) then

  begin

    password := ParamStr(2);

    Output.Password := password;

    if (Output.InputComplete = false) then

    begin

      ExitCode := 1;

      Application.Terminate;

    end;

    try

      Output.Run;

      MessageDlg(OutputSuccessful, mtInformation,[mbOK],0);

    except

      on e: Exception do ShowException(e,ExceptAddr);

    end;

    Application.Terminate;

  end;

end;



procedure TMainForm.FormDestroy(Sender: TObject);

begin

  Output.Free;

  Model.Free;

  EERModel.Free;

end;



procedure TMainForm.InitControls;

var path: string;

    successful: Integer;

    result: TSearchRec;

    oneLayoutFound :Boolean;

begin

  oneLayoutFound := false;

  

  //Always start with First Page

  PageControl.ActivePageIndex:=0;



  //deactive the button as long as the settings for submitting are not complete

  DeactivateRun();



  //prepare the layout-listbox

  {$IFDEF MSWINDOWS}

    path := IncludeTrailingPathDelimiter(ExtractFilePath(Application.ExeName))+PathDelim+DataDir+'*.*';

  {$ELSE}

    path := IncludeTrailingPathDelimiter(ExtractFilePath(Application.ExeName))+PathDelim+DataDir+'*';

  {$ENDIF}



  successful:= FindFirst(path,faDirectory,result);

  while(successful=0) do

  begin

    if (((result.Attr and faDirectory) <>0 ) and (result.Name<>'..') //if it is a directory

       and (result.Name<> '.') and (result.Name<> 'CVS') and (result.Name<> 'cvs'))  then

    begin

      oneLayoutFound := TRUE;

      LayoutComboBox.Items.Add(result.Name);       //addentry;

    end;

    successful := FindNext(result);

  end;

  FindClose(result);



  if (oneLayoutFound) then

  begin

    LayoutComboBox.ItemIndex:=0;

    LayoutComboBoxChange(self);

  end

  else

  begin

    MessageDlg(NoLayoutError, mtError,[mbOK],0);

    Application.Terminate;

  end;



end;





procedure TMainForm.CloseMIClick(Sender: TObject);

begin

  CloseBtnClick(Sender);

end;



//Produce the webfiles

procedure TMainForm.CreateBtnClick(Sender: TObject);

begin

  //unfortunately the onclick-event is processed before OnExit-Events that

  //logically happened before the click



  try

    if (TakeSettings) then //it could be that the change disallows executing again

    begin

       //check if the output-dir exists

      if (Output.dirDoesntExist) THEN

      begin

        if ( MessageDlg(OutputDirDoesntExist, mtConfirmation,[mbYes,mbNo],0) = mrYes) THEN

          ForceDirectories(Output.SaveDir)

        else

      Exit;

      end;



      Output.Run;

      //Application.ProcessMessages;

      //MessageDlg(OutputSuccessful, mtInformation,[mbOK],0,mbOk);

      //ShowMessage(Outputsuccessful);

      StatusBar.SimpleText := Outputsuccessful;

    end;

  except

    //on e:ETemplateFileException do MessageDlg(e.Message, mtError, [mbOK], 0);

    on e: Exception do ShowException(e,ExceptAddr);

  end;



end;



procedure TMainForm.ExecuteMIClick(Sender: TObject);

begin

  CreateBtnClick(Sender);

end;



procedure TMainForm.DeactivateRun;

begin

  //deactivate the 'Execute'-Entry in the Menu

  MainMenu1.Items[0].Items[0].Enabled := false;

  CreateBtn.Enabled := false;

end;



procedure TMainForm.ActivateRun;

begin

  //activate the 'Execute'-Entry in the Menu

  MainMenu1.Items[0].Items[0].Enabled := True;

  CreateBtn.Enabled := True;

end;



procedure TMainForm.RefreshPage(index: Integer);

begin

  if (index=1) then RefreshViewTab;

  if (index=2) then RefreshGroupTab;

  if (index=3) then RefreshGridTab;

  if (index=4) then RefreshFormTab;

end;









//since you can also change the pages with your mousewheel, we need that

procedure TMainForm.PageControlChange(Sender: TObject);

begin

  if(PageControl.ActivePageIndex<PageControlTreeView.Items.Count)then

    PageControlTreeView.Selected:=PageControlTreeView.Items[PageControl.ActivePageIndex];



  RefreshPage(PageControl.ActivePageIndex);

end;



//For all Edit-controls that propagate updates by the OnExit-Event

//call their event-handlers

//The return value says if all settings necessary for an execute-operation are done

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -