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

📄 main.pas

📁 DBDesigner 4 is a database design system that integrates database design, modelling, creation and ma
💻 PAS
📖 第 1 页 / 共 2 页
字号:
  ReportAsText:=TStringList.Create;
  try
    theSaveDialog:=TSaveDialog.Create(nil);
    try
  {$IFDEF MSWINDOWS}
      //On Windows use native Win32 Open Dlg
      theSaveDialog.UseNativeDialog:=True;
      theSaveDialog.OnShow:=DMMain.OnOpenSaveDlgShow;
  {$ENDIF}

      theSaveDialog.Title:='Save File As ...';
      theSaveDialog.Width:=600;
      theSaveDialog.Height:=450;
      theSaveDialog.DefaultExt:='html';

      RecentSaveFileAsDir:=DMMain.LoadValueFromSettingsIniFile('RecentDirectories', 'RecentSaveFileAsDir', '');
      {if(RecentSaveFileAsDir='')or(Not(DirectoryExists(RecentSaveFileAsDir)))then
        RecentSaveFileAsDir:=ExtractFilePath(Application.ExeName)+
          'Models'+PathDelim;}

      theSaveDialog.InitialDir:=RecentSaveFileAsDir;
      theSaveDialog.FileName:=lastFileName;
      theSaveDialog.Filter:='HTML files (*.html)|*.html';

      //Build HTML File
      ReportAsText.Text:=BuildHTMLFile(LayoutComboBox.Items[LayoutComboBox.ItemIndex]);

      if(ReportAsText.Text<>'')then
      begin
        if(theSaveDialog.Execute)then
        begin
          ReportAsText.SaveToFile(theSaveDialog.FileName);

          lastFileName:=ExtractFileName(theSaveDialog.FileName);
          RecentSaveFileAsDir:=ExtractFilePath(theSaveDialog.FileName);
          DMMain.SaveValueInSettingsIniFile('RecentDirectories', 'RecentSaveFileAsDir', RecentSaveFileAsDir);

          DMMain.BrowsePage(theSaveDialog.FileName);
        end;
      end;
    finally
      theSaveDialog.Free;
    end;
  finally
    ReportAsText.Free;
  end;
end;

procedure TMainForm.GetLayouts;
var result: integer;
  SearchRec: TSearchRec;
begin
{$IFDEF MSWINDOWS}
  Result := FindFirst(ExtractFilePath(Application.ExeName)+PathDelim+
    'Data'+PathDelim+'Plugins'+PathDelim+'HTMLReport'+PathDelim+'*.*',
    faDirectory, SearchRec);
{$ELSE}
  Result := FindFirst(ExtractFilePath(Application.ExeName)+PathDelim+
    'Data'+PathDelim+'Plugins'+PathDelim+'HTMLReport'+PathDelim+'*',
    faDirectory, SearchRec);
{$ENDIF}

  if(Result<>0)then
    Exit;

  LayoutComboBox.Items.Clear;

  try
    while Result = 0 do
    begin
      if(Copy(SearchRec.Name, 1, 1)<>'.')and
        (SearchRec.Name<>'CVS')then
        LayoutComboBox.Items.Add(SearchRec.Name);

      Result := FindNext(SearchRec);
    end;
  finally
    FindClose(SearchRec);
  end;

  if(LayoutComboBox.Items.IndexOf('Standard')<>-1)then
    LayoutComboBox.ItemIndex:=LayoutComboBox.Items.IndexOf('Standard')
  else
    LayoutComboBox.ItemIndex:=0;
end;

procedure TMainForm.StorePluginDataInModel;
var thePluginData: TEERPluginData;
begin
  //Store changes to model

  //Get PluginData from Model
  thePluginData:=EERModel.GetPluginDataByID('HTMLReport', -1);
  if(thePluginData=nil)then
    thePluginData:=EERModel.AddPluginData('HTMLReport', -1);
  //If a value has changed, store model
  if(thePluginData.Params.Values['SelectedTables']<>SelectedTables)then
  begin
    thePluginData.Params.Values['SelectedTables']:=SelectedTables;

    //Delete file and create new, so the new file has a different timestamp
    //DeleteFile(ModelFileName);

    EERModel.SaveToFile(ModelFileName);
  end;
end;

function TMainForm.BuildHTMLFile(layout: string): string;
var theFilePath: string;
  aReportFile: TStringList;
  theReport, s: string;
  i, j: integer;
  theRegion: TEERRegion;
  theTable: TEERTable;
  theTables: TList;
begin
  BuildHTMLFile:='';

  theFilePath:=ExtractFilePath(Application.ExeName)+PathDelim+
    'Data'+PathDelim+'Plugins'+PathDelim+'HTMLReport'+PathDelim+layout+PathDelim;

  if(Not(FileExists(theFilePath+'ReportHeader.txt')))then
    Exit;

  aReportFile:=TStringList.Create;
  theTables:=TList.Create;
  try
    aReportFile.LoadFromFile(theFilePath+'ReportHeader.txt');
    theReport:=DMMain.ReplaceText(aReportFile.Text,
      '<?=$Modelname?>', 'Database Model '+ExtractFileName(EERModel.ModelFilename));

    aReportFile.LoadFromFile(theFilePath+'Report.css');

    theReport:=DMMain.ReplaceText(theReport,
      '<? include ''Report.css''; ?>', aReportFile.Text);

    if(ListRegionsCheckBox.Checked)then
    begin
      for i:=0 to RegionsComboBox.Items.Count-1 do
      begin
        theRegion:=EERModel.GetEERObjectByName(EERRegion, RegionsComboBox.Items[i]);

        if(theRegion<>nil)then
        begin
          //Load Region Template
          aReportFile.LoadFromFile(theFilePath+'ReportRegions.txt');
          theReport:=theReport+
            DMMain.ReplaceText(aReportFile.Text, '<?=$Regionname?>',
              theRegion.ObjName);

          //Build HTMLTableList
          theTables.Clear;
          theRegion.GetEERObjsInRegion([EERTable], theTables);
          if(SortOrderPosRBtn.Checked)then
            EERModel.SortEERObjectListByOrderPos(theTables)
          else
            EERModel.SortEERObjectListByObjName(theTables);

          s:='';
          for j:=0 to theTables.Count-1 do
            s:=s+BuildHTMLTable(TEERTable(theTables[j]), layout);

          //Insert HTMLTableList into Report File
          theReport:=DMMain.ReplaceText(theReport,
            '<? include ''ReportTables.txt''; ?>', s);
        end;
      end;
    end
    else
    begin
      for i:=0 to TablesCheckListBox.Items.Count-1 do
      begin
        theTable:=EERModel.GetEERObjectByName(EERTable, TablesCheckListBox.Items[i]);
        if(theTable<>nil)then
          theReport:=theReport+BuildHTMLTable(theTable, layout);
      end;
    end;

    aReportFile.LoadFromFile(theFilePath+'ReportFooter.txt');
    theReport:=theReport+aReportFile.Text;

    BuildHTMLFile:=theReport;
  finally
    aReportFile.Free;
    theTables.Free;
  end;
end;

function TMainForm.BuildHTMLTable(theTable: TEERTable; layout: string): string;
var theFilePath: string;
  aReportFile: TStringList;
  s, s1, cols, indices, index, IndexKind: string;
  i, j: integer;
  theCol: TEERColumn;
  theDatatype: TEERDatatype;
begin
  BuildHTMLTable:='';

  theFilePath:=ExtractFilePath(Application.ExeName)+PathDelim+
    'Data'+PathDelim+'Plugins'+PathDelim+'HTMLReport'+PathDelim+layout+PathDelim;

  //Only if the table is in the SelectedTables string
  if(Pos(theTable.ObjName+';', SelectedTables)>0)then
  begin
    aReportFile:=TStringList.Create;
    try
      aReportFile.LoadFromFile(theFilePath+'ReportTables.txt');
      s:=DMMain.ReplaceText(aReportFile.Text,
        '<?=$Tablename?>', theTable.ObjName);
      s:=DMMain.ReplaceText(s,
        '<?=$TableComments?>', '<br>'+DMMain.ReplaceText(theTable.Comments, #13#10, '<br>'));

      //Insert HTML Column List
      aReportFile.LoadFromFile(theFilePath+'ReportTableColumns.txt');
      cols:='';
      for i:=0 to theTable.Columns.Count-1 do
      begin
        theCol:=TEERColumn(theTable.Columns[i]);
        theDatatype:=EERModel.GetDataType(theCol.idDatatype);

        cols:=cols+aReportFile.Text;

        if(theCol.PrimaryKey)then
        begin
          //---------------------------
          //Colname
          cols:=DMMain.ReplaceText(cols,
            '<?=ColumnName?>', '<b>'+theCol.ColName+'</b>');

          //---------------------------
          //Dataype
          cols:=DMMain.ReplaceText(cols,
            '<?=DataType?>', '<b>'+trim(theDatatype.TypeName+
              theCol.DatatypeParams)+'</b>');
        end
        else
        begin
          //---------------------------
          //Colname
          cols:=DMMain.ReplaceText(cols,
            '<?=ColumnName?>', theCol.ColName);

          //---------------------------
          //Dataype
          cols:=DMMain.ReplaceText(cols,
            '<?=DataType?>', trim(theDatatype.TypeName+
              theCol.DatatypeParams));
        end;

        //---------------------------
        //Primary Key
        if(theCol.PrimaryKey)then
          s1:='PK'
        else
          s1:='&nbsp;';
        cols:=DMMain.ReplaceText(cols,
          '<?=PrimaryKey?>', s1);

        //---------------------------
        //NotNull
        if(theCol.NotNull)then
          s1:='NN'
        else
          s1:='&nbsp;';
        cols:=DMMain.ReplaceText(cols,
          '<?=NotNull?>', s1);

        //---------------------------
        //Flags
        s1:='';
        for j:=0 to theDatatype.OptionCount do
          if(theCol.OptionSelected[j])then
            s1:=s1+theDatatype.Options[j]+' ';

        if(trim(s1)='')then
          s1:='&nbsp;';
        cols:=DMMain.ReplaceText(cols,
          '<?=Flags?>', s1);

        //---------------------------
        //DefaultValue
        if(theCol.DefaultValue<>'')then
          s1:=theCol.DefaultValue
        else
          s1:='&nbsp;';
        cols:=DMMain.ReplaceText(cols,
          '<?=DefaultValue?>', s1);

        //---------------------------
        //Comment
        if(theCol.Comments<>'')then
          s1:=theCol.Comments
        else
          s1:='&nbsp;';
        cols:=DMMain.ReplaceText(cols,
          '<?=Comment?>', s1);

        //---------------------------
        //AutoInc
        if(theCol.AutoInc)then
          s1:='AI'
        else
          s1:='&nbsp;';
        cols:=DMMain.ReplaceText(cols,
          '<?=AutoInc?>', s1);
      end;
      s:=DMMain.ReplaceText(s,
        '<? include ''ReportTableColumns.txt''; ?>', cols);

      //Insert HTML Index List
      if(Not(ListIndicesCheckBox.Checked))or
        (theTable.Indices.Count=0)then
        indices:=''
      else
      begin
        aReportFile.LoadFromFile(theFilePath+'ReportTableIndices.txt');
        indices:=aReportFile.Text;

        aReportFile.LoadFromFile(theFilePath+'ReportTableIndexValues.txt');
        s1:=aReportFile.Text;

        index:='';
        for i:=0 to theTable.Indices.Count-1 do
        begin
          case TEERIndex(theTable.Indices[i]).IndexKind of
            ik_PRIMARY:
              IndexKind:='PRIMARY';
            ik_INDEX:
              IndexKind:='Index';
            ik_UNIQUE_INDEX:
              IndexKind:='Unique Index';
            ik_FULLTEXT_INDEX:
              IndexKind:='Fulltext Index';
          else
            IndexKind:='';
          end;

          index:=index+s1;
          index:=DMMain.ReplaceText(index,
            '<?=IndexName?>', TEERIndex(theTable.Indices[i]).IndexName);

          index:=DMMain.ReplaceText(index,
            '<?=IndexType?>', IndexKind);

          cols:='';
          for j:=0 to TEERIndex(theTable.Indices[i]).Columns.Count-1 do
            cols:=cols+TEERColumn(theTable.GetColumnById(
              StrToInt(TEERIndex(theTable.Indices[i]).Columns[j])
                )).ColName+'<br>';

          index:=DMMain.ReplaceText(index,
            '<?=Columns?>', cols);
        end;

        indices:=DMMain.ReplaceText(indices,
          '<? include ''ReportTableIndexValues.txt''; ?>', index);
      end;
      s:=DMMain.ReplaceText(s,
        '<? include ''ReportTableIndices.txt''; ?>', indices);


      BuildHTMLTable:=s;
    finally
      aReportFile.Free;
    end;
  end;
end;



procedure TMainForm.SortOrderPosRBtnClick(Sender: TObject);
begin
  RegionsComboBoxCloseUp(self);
end;

end.

⌨️ 快捷键说明

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