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

📄 main.pas

📁 DBDesigner 4 is a database design system that integrates database design, modelling, creation and ma
💻 PAS
📖 第 1 页 / 共 4 页
字号:
function TMainForm.TakeSettings : Boolean;

begin

  //controls of the first tab

  LayoutComboBoxChange(self);

  HeadingEdExit(self);

  OutputDirEdExit(self);

  HostnameEdExit(self);

  UsernameEdExit(self);

  PasswordEdExit(self);

  DatabaseEdExit(self);



  //grid tab

  RowsPerPageEdExit(self);

  ColnameEdExit(self);

  ColWidthEdExit(self);

  ColTruncateCharsEdExit(self);



  //form tab

  FormWidthEdExit(self);

  FormHeightEdExit(self);

  FormXEdExit(self);

  FormYEdExit(self);

  Form_ColNameEdExit(self);

  Form_ColWidthEdExit(self);



  TakeSettings := Output.InputComplete();

end;





//*****************************************

//**********Exit/Change-Events*************

//*****************************************



procedure TMainForm.HostnameEdExit(Sender: TObject);

begin

  Output.Hostname := HostnameEd.Text;

  if (Output.InputComplete) then

    ActivateRun

  else

    DeactivateRun;

end;



procedure TMainForm.UsernameEdExit(Sender: TObject);

begin

  Output.Username := UsernameEd.Text;

  if (Output.InputComplete) then

    ActivateRun

  else

    DeactivateRun;

end;



procedure TMainForm.PasswordEdExit(Sender: TObject);

begin

  Output.Password := PasswordEd.Text;

  if (Output.InputComplete) then

    ActivateRun

  else

    DeactivateRun;

end;



procedure TMainForm.DatabaseEdExit(Sender: TObject);

begin

  Output.Databasename := DatabaseEd.Text;

  if (Output.InputComplete) then

    ActivateRun

  else

    DeactivateRun;

end;



procedure TMainForm.HeadingEdExit(Sender: TObject);

begin

  Output.Heading := HeadingEd.Text;

  if (Output.InputComplete) then

    ActivateRun

  else

    DeactivateRun;

end;



procedure TMainForm.OutputDirEdExit(Sender: TObject);

begin

  Output.SaveDir := OutputDirEd.Text;



  if (Output.InputComplete) then

    ActivateRun

  else

    DeactivateRun;

end;



procedure TMainForm.LayoutComboBoxChange(Sender: TObject);

var ind: Integer;

    name: string;

begin

  ind:= LayoutComboBox.ItemIndex;

  name:=LayoutComboBox.Items[ind];

  Output.Layout := name;

  if (Output.InputComplete) then

    ActivateRun

  else

    DeactivateRun;



end;







//*****************************************

//******1st page(General Options)**********

//*****************************************



procedure TMainForm.SaveDlgBtnClick(Sender: TObject);

var OutputDirSel :TDialogDirectorySelectForm;

begin

  OutputDirSel := TDialogDirectorySelectForm.Create(nil);

  try

    if (OutputDirSel.ShowModal = mrOK) then

      OutputDirEd.Text := IncludeTrailingPathDelimiter(OutputDirSel.DirectoryTreeView.Directory);

      Output.SaveDir := OutputDirEd.Text;

  finally

    OutputDirSel.Release;

  end;

end;





procedure TMainForm.UpdateTabFromOutputObject;

var p: Integer;

begin

  HostnameEd.Text := Output.hostname;

  UsernameEd.Text := Output.username;

  PasswordEd.Text := Output.password;

  DatabaseEd.Text := Output.databasename;

  HeadingEd.Text  := Output.heading;

  OutputDirEd.Text := Output.saveDir;



  //layout

  p := LayoutComboBox.Items.IndexOf(Output.Layout);

  if (p<> -1) then LayoutComboBox.ItemIndex := p;

end;



//*****************************************

//**********2nd page(Views)****************

//*****************************************

procedure TMainForm.RefreshViewTab;

var stringList: TStringList;

begin

  stringList:= TStringList.Create;



  Output.GetViewNames(stringList);

  AllViewsListBox.Items.Assign(stringList);

  stringList.Free;



  UpdateInfoFields;



  if (Output.InputComplete) then

    ActivateRun

  else

    DeactivateRun;

end;



procedure TMainForm.UpdateInfoFields;

var ind: Integer;

    view : TView;

    i : Integer;

    str : String;

begin

  ind:=AllViewsListBox.ItemIndex;

  if (ind = -1) then

  begin

    ViewNameEd.Text    := '-';

    TableNameEd.Text   := '-';

    JoinTablesEd.Text      := '-';

    NMTablesEd.Text        := '-';

    WhereClauseMemo.Text     := '';

  end

  else

  begin

    view:= TView(AllViewsListBox.Items.Objects[ind]);

    ViewNameEd.Text:= view.Name;

    TableNameEd.Text := view.Table.Name;

    WhereClauseMemo.Text := view.WhereClause;



    //show all JoinTables

    str:= '';

    for i:=0 to view.JoinTables.Count-1 do

      str:= str + SW_Table(view.JoinTables[i]).name + ',';

    Delete(str,Length(str),1);  //delete the last comma

    JoinTablesEd.Text := str;



    //show all NMTables

    str:='';

    for i:=0 to view.NMTables.Count-1 do

      str:= str + SW_Table(view.NMTables[i]).name + ',';

    Delete(str,Length(str),1);

    NMTablesEd.Text := str;

  end;

end;



procedure TMainForm.CreateViewBtnClick(Sender: TObject);

var ViewForm : TEditorViewForm;

begin

  ViewForm := TEditorViewForm.Create(nil);

  //nil causes a new view to be created

  ViewForm.provideView(nil);

  try

    if (ViewForm.ShowModal=mrOk) then

    begin

      //add the view to the state

      Output.AddView(ViewForm.view);

      

      //update the GUI

      RefreshViewTab;

    end;

  finally

    ViewForm.Release;

  end;



end;



procedure TMainForm.DelViewBtnClick(Sender: TObject);

var ind: Integer;

begin

  ind:= AllViewsListBox.ItemIndex;

  if (ind=-1) then Exit;

  Output.DeleteView( TView(AllViewsListBox.Items.Objects[ind]) );



  RefreshViewTab;

end;



procedure TMainForm.AddTablesBtnClick(Sender: TObject);

var stringList : TStringList;

    i: Integer;

    view : TView;

begin

  stringList := TStringList.Create;

  Model.GetAllTables(stringList);



  for i:= 0 to stringList.Count-1 do

  begin

    view := CreateViewLikeTable(SW_Table(stringList.Objects[i]));

    Output.AddView(view);

  end;



  stringList.Free;

  RefreshViewTab;

end;



//creates a view representing table

function TMainForm.CreateViewLikeTable(table: SW_Table) :TView;

var thePic : TPicture;

    exeFilepath : String;

    view :TView;

begin

  //load the default icon

  thePic:=TPicture.Create;

  exeFilepath :=  IncludeTrailingPathDelimiter(ExtractFilePath(Application.ExeName));

  thePic.LoadFromFile(exeFilePath+DataDir+'Standard'+PathDelim+'icons'+PathDelim+'icons_01.png');



  view:= TView.Create(table.name, '', table, nil,nil,thePic,'icons_01.png','');

  thePic.Free;



  CreateViewLikeTable:= view;

end;



{

procedure TMainForm.DelTablesBtnClick(Sender: TObject);

var stringList : TStringList;

    i,a: Integer;

begin

  stringList := TStringList.Create;

  Model.GetAllTables(stringList);

  for i:= 0 to stringList.Count-1 do

  begin

    a:= AllViewsListBox.Items.IndexOf(stringList[i]);

    if (a <> -1) then

      Output.DeleteView(TView(AllViewsListBox.Items.Objects[a]));

  end;



  stringList.Free;

  RefreshViewTab;

end;

}



procedure TMainForm.EditViewBtnClick(Sender: TObject);

var view: TView;

    ViewEditForm : TEditorViewForm;

begin

  if (AllViewsListBox.ItemIndex=-1) then Exit;

  view:= TView(AllViewsListBox.Items.Objects[AllViewsListBox.ItemIndex]);



  ViewEditForm := TEditorViewForm.Create(nil);

  ViewEditForm.ProvideView(view);



  if (ViewEditForm.ShowModal = mrOK) then RefreshViewTab;



  ViewEditForm.Release;

end;



procedure TMainForm.AllViewsListBoxDblClick(Sender: TObject);

begin

  EditViewBtnClick(self);

end;



procedure TMainForm.AllViewsListBoxClick(Sender: TObject);

begin

  if (AllViewsListBox.ItemIndex=-1) then Exit;



  UpdateInfoFields;

end;















//*****************************************

//**********3rd page(Groups)***************

//*****************************************

//this procedure completly refills the gui-objects on this page

//with the information that

//is stored in the WebOutput class

procedure TMainForm.RefreshGroupTab;

var group: TGroup;

    stringList: TStringList;

begin

  stringList := TStringList.Create;



  Output.GetGroupNames(stringList);

  GroupsListBox.Items.Assign(stringList);

  GroupComboBox.Items.Assign(stringList);

  if (stringList.Count = 0) then

  begin

    GroupComboBox.Enabled := false;

    LABtn.Enabled := false;

    RABtn.Enabled := false;

  end

  else

  begin

    GroupComboBox.Enabled := True;

    if (GroupComboBox.ItemIndex = -1) then GroupComboBox.ItemIndex := 0;

  end;

  stringList.Clear;



  Output.GetUnassignedViewNames(stringList);

  UnassignedViewsListBox.Items.Assign(stringList);

  if (stringList.Count = 0) then

  begin

    LABtn.Enabled := false;

    RABtn.Enabled := false;

  end;

  stringList.Clear;





  if (GroupComboBox.ItemIndex = -1) then

    ViewsFromGroupListBox.Items.Clear

  else

  begin

    group:= TGroup(GroupComboBox.Items.Objects[GroupComboBox.ItemIndex]);

    Output.GetViewNamesFromGroup(group, stringList);

    ViewsFromGroupListBox.Items.Assign(stringList);

    stringList.Clear;

  end;



  if ( ((GroupComboBox.Items.Count <> 0) and (ViewsFromGroupListBox.Items.Count <> 0)) or

       (UnassignedViewsListBox.Items.Count <> 0) ) then

  begin

    LABtn.Enabled := true;

    RABtn.Enabled := true;

  end;





  if (Output.InputComplete) then

    ActivateRun

  else

    DeactivateRun;



  stringList.Free;

end;



procedure TMainForm.CreateGrpBtnClick(Sender: TObject);

var GroupEditForm: TEditorGroupForm;

    group: TGroup;

begin

  GroupEditForm := TEditorGroupForm.Create(nil);

  try



    if (GroupEditForm.ShowModal = mrOk) then

    begin

      //add the group to our internal state



      group := GroupEditForm.GetGroup;

      Output.AddGroup(group);



      //update the groupListBox

      RefreshGroupTab;

    end;

  finally

    GroupEditForm.Release;

  end;

end;



procedure TMainForm.DelGrpBtnClick(Sender: TObject);

var group: TGroup;

begin

  if (GroupsListBox.ItemIndex = -1) then Exit;



  group := TGroup(GroupsListBox.Items.Objects[GroupsListBox.ItemIndex]);

  Output.DeleteGroup(group);



  //update the groupListBox

  GroupComboBox.ItemIndex := GroupComboBox.Items.Count-2;

  RefreshGroupTab;

end;



procedure TMainForm.EditGrpBtnClick(Sender: TObject);

var ind: Integer;

    tmpGrp : TGroup;

    GroupEditForm :TEditorGroupForm;

begin

  ind := GroupsListBox.ItemIndex;

  if (ind = -1) then Exit; //no group selected

  tmpGrp := TGroup(GroupsListBox.Items.Objects[ind]);



  GroupEditForm := TEditorGroupForm.Create(nil);

  GroupEditForm.SetGroup(tmpGrp);



  if (GroupEditForm.ShowModal = mrOk) then

  begin

    tmpGrp.Name := GroupEditForm.GrpnameEd.Text;

    tmpGrp.showOnLine := StrToInt(GroupEditForm.LineNoEd.Text);

    tmpGrp.showInColumn := StrToInt(GroupEditForm.ColNoEd.Text);

    tmpGrp.ViewsAsPopup := GroupEditForm.PopupCheckBox.Checked;

    

    //update the groupListBox

    RefreshGroupTab;

  end;



  GroupEditForm.Release;

end;



procedure TMainForm.GroupsListBoxDblClick(Sender: TObject);

begin

  EditGrpBtnClick(Sender);

end;



procedure TMainForm.AddRegBtnClick(Sender: TObject);

var stringList, tables_stringList: TStringList;

    i,j, lineNo, colNo: Integer;

    group : TGroup;

    noPosFound : Boolean;

    region : SW_Region;

    table: SW_Table;

    view : TView;

begin

  //get all regions from the EER-Model

  stringList := TStringList.Create;

  Model.GetAllRegions(stringList);



  lineNo := 1;

  colNo := 1;

  for i:= 0 to stringList.Count-1 do

  begin



    noPosFound := true;

    while (noPosFound) do

    begin

      if (Output.GroupPositionFree(lineNo, ColNo) ) then

      begin

        group := TGroup.Create(stringList[i],lineNo, colNo,false);

        Output.AddGroup(group);



        //Should the views be added too?

        region := SW_Region(stringList.Objects[i]);

        tables_stringList:= TStringList.Create;

        model.GetAllTablesInRegion(region, tables_stringList);



        if ( MessageDlg(Group_TablesOverview+' '+stringList[i]+' :'+#10+

                        tables_stringList.Text +#10 + Group_ViewsBeCreated,

                        mtConfirmation,[mbYes,mbNo],0) = mrYes) THEN

        begin

          //create views

          for j:=0 to tables_stringList.Count-1 do

          begin

            table := SW_Table(tables_stringList.Objects[j]);

            view := CreateViewLikeTable(table);

            Output.AddView(view);

            Output.AssignViewToGroup(group ,view);

            table.Free;

          end;

        end;



        tables_stringList.Free;

        noPosFound := false;

      end

      else

        lineNo:= lineNo+1;

    end;



  end;



  //update the groupListBox

  RefreshGroupTab;



  stringList.Free;

end;





procedure TMainForm.GroupComboBoxChange(Sender: TObject);

begin

  RefreshGroupTab;

end;



procedure TMainForm.LABtnClick(Sender: TObject);

⌨️ 快捷键说明

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