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

📄 dbconnselect.pas

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

//----------------------------------------------------------------------------------------------------------------------
//
// 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 DBConnLogin.pas
// --------------------
// Version 1.1, 21.03.2003, Mike
// Description
//   Contains the TDBConnSelectForm form which is used to manage database connections
//
// Changes:
//   Version 1.1, 21.03.2003, Mike
//     Prevent DBConns with the same name after drag'n'drop a
//     database onto the DBConn List
//   Version 1.0, 13.03.2003, Mike
//     initial version
//
//----------------------------------------------------------------------------------------------------------------------

interface

uses
  Qt, SysUtils, Types, Classes, QGraphics, QControls, QForms, QDialogs,
  QStdCtrls, QImgList, QComCtrls, DBDM, QGrids, QButtons, SqlExpr,
  QExtCtrls, IniFiles, QMenus, QTypes, StrUtils, Contnrs;

type
  TDBConnSelectForm = class(TForm)
    ConnectionPnl: TPanel;
    DBConnImgList: TImageList;
    TopPnl: TPanel;
    Label4: TLabel;
    LeftPnl: TPanel;
    HSplitter: TSplitter;
    Panel3: TPanel;
    Panel4: TPanel;
    CancelBtn: TSpeedButton;
    Label2: TLabel;
    UsernameEd: TEdit;
    Label3: TLabel;
    PasswdEd: TEdit;
    ConnectBtn: TBitBtn;
    Label6: TLabel;
    ConnectionsListView: TListView;
    Panel2: TPanel;
    DBConnLbl: TLabel;
    DBConnPopupMenu: TPopupMenu;
    DeleteConnectionMI: TMenuItem;
    HostsPopupMenu: TPopupMenu;
    RenameHostMI: TMenuItem;
    DeleteHostMI: TMenuItem;
    ChangeHostsIPMI: TMenuItem;
    DBConnEd: TEdit;
    Panel5: TPanel;
    Panel6: TPanel;
    DBConnTV: TTreeView;
    NewConnBtn: TSpeedButton;
    N1: TMenuItem;
    DropDatabaseMI: TMenuItem;
    AddConnection1: TMenuItem;
    N2: TMenuItem;
    DelConSBtn: TSpeedButton;
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);

    procedure GetNetworkHosts;
    procedure StoreNetworkHosts;

    procedure SetData(theDBConns: TObjectList; theSelDBConn: TDBConn);
    procedure ConnectBtnClick(Sender: TObject);
    procedure CancelBtnClick(Sender: TObject);
    procedure ConnectionsListViewSelectItem(Sender: TObject;
      Item: TListItem; Selected: Boolean);
    procedure FormShow(Sender: TObject);
    procedure ConnectionsListViewEdited(Sender: TObject; Item: TListItem;
      var S: WideString);
    procedure DelConnBtnClick(Sender: TObject);
    procedure ConnectionsListViewMouseDown(Sender: TObject;
      Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    procedure ConnectionsListViewDblClick(Sender: TObject);
    procedure DBConnTVExpanding(Sender: TObject; Node: TTreeNode;
      var AllowExpansion: Boolean);
    procedure DBConnTVItemClick(Sender: TObject; Button: TMouseButton;
      Node: TTreeNode; const Pt: TPoint);
    procedure RenameHostMIClick(Sender: TObject);
    procedure RenameHostMIShow(Sender: TObject);
    procedure ChangeHostsIPMIClick(Sender: TObject);
    procedure DeleteHostMIClick(Sender: TObject);
    procedure DBConnTVMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure DBConnTVCustomDrawItem(Sender: TCustomViewControl;
      Item: TCustomViewItem; Canvas: TCanvas; const Rect: TRect;
      State: TCustomDrawState; Stage: TCustomDrawStage;
      var DefaultDraw: Boolean);
    procedure RefreshDBConnList;
    procedure ConnectionsListViewDragOver(Sender, Source: TObject; X,
      Y: Integer; State: TDragState; var Accept: Boolean);
    procedure ConnectionsListViewDragDrop(Sender, Source: TObject; X,
      Y: Integer);
    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    procedure HSplitterMoved(Sender: TObject);
    procedure ConnectionsListViewClick(Sender: TObject);
    procedure NewConnBtnClick(Sender: TObject);
    procedure DropDatabaseMIShow(Sender: TObject);
    procedure DropDatabaseMIClick(Sender: TObject);
    procedure OnTypeSelectLBoxDblClick(Sender: TObject);
    procedure ResetDefaultParams(theDBConn: TDBConn);
    procedure AddConnection1Click(Sender: TObject);
    procedure FormKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure DelConSBtnClick(Sender: TObject);
  private
    { Private-Deklarationen }
    mx, my: integer;
    Localhost,
    MySqlNode, OracleNode, ODBCNode, SQLiteNode, MSSQLNode: TTreeNode;
    ModalResultIsOK: Boolean;
  public
    { Public-Deklarationen }
    SelDBConn: TDBConn;
    DBConns: TObjectList;
    DBHosts: TObjectList;
    NetworkHosts: TTreeNode;
  end;

var
  DBConnSelectForm: TDBConnSelectForm;

implementation

uses DBConnLogin, DBConnEditor, MainDM;

{$R *.xfm}

procedure TDBConnSelectForm.FormCreate(Sender: TObject);
begin
  DMMain.InitForm(self, True);
  
  ModalResultIsOK:=False;

  DBHosts:=TObjectList.Create;

  Left:=Application.MainForm.Left+(Application.MainForm.Width-746) div 2;
end;

procedure TDBConnSelectForm.FormDestroy(Sender: TObject);
begin
  StoreNetworkHosts;

  DBHosts.Free;
end;

procedure TDBConnSelectForm.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  //
end;

procedure TDBConnSelectForm.GetNetworkHosts;
var i: integer;
  theTreeNode, theChildTreeNode: TTreeNode;
  theIni: TMemIniFile;
  hostcount: integer;
  theDBHost: TDBHost;
begin
  DBConnTV.Items.Clear;

  theTreeNode:=DBConnTV.Items.Add(nil, DMMain.GetTranslatedMessage('All Connections', 107));
  theTreeNode.ImageIndex:=0;
  theTreeNode.SelectedIndex:=1;

  //The MySQL Folder
  theTreeNode:=DBConnTV.Items.Add(theTreeNode, 'MySQL');
  theTreeNode.ImageIndex:=0;
  theTreeNode.SelectedIndex:=1;
  MySQLNode:=theTreeNode;

  //Make the MySQL Subs
  theDBHost:=TDBHost.Create;
  theDBHost.Caption:='Localhost';
  theDBHost.HostName:='127.0.0.1';
  theDBHost.User_Name:='root';
  DBHosts.Add(theDBHost);

  theTreeNode:=DBConnTV.Items.AddChild(theTreeNode, 'Localhost');
  theTreeNode.ImageIndex:=2;
  theTreeNode.SelectedIndex:=2;
  theTreeNode.SubItems.Add('HOST');
  theTreeNode.SubItems.Add('127.0.0.1');
  theTreeNode.SubItems.Add('root');
  theTreeNode.SubItems.Add('');
  Localhost:=theTreeNode;

  theChildTreeNode:=DBConnTV.Items.AddChild(theTreeNode,'...');
  theChildTreeNode.ImageIndex:=7;
  theChildTreeNode.SelectedIndex:=7;

  theTreeNode:=DBConnTV.Items.Add(theTreeNode, 'Network Hosts');
  theTreeNode.ImageIndex:=3;
  theTreeNode.SelectedIndex:=3;

  NetworkHosts:=theTreeNode;

  //Load Hosts from IniFile
  //Read IniFile
  try
    theIni:=TMemIniFile.Create(DMMain.SettingsPath+'DBConn_Hosts.ini');
    try
      Localhost.SubItems[2]:=
        theIni.ReadString('Hosts', 'LocalHost_User_Name', 'root');

      hostcount:=StrToInt(theIni.ReadString('Hosts', 'HostCount', '0'));

      for i:=1 to hostcount do
      begin
        theDBHost:=TDBHost.Create;
        theDBHost.Caption:=theIni.ReadString('Host'+IntToStr(i), 'HostName', 'Network Host');
        theDBHost.HostName:=theIni.ReadString('Host'+IntToStr(i), 'IP', '127.0.0.1');
        theDBHost.User_Name:=theIni.ReadString('Host'+IntToStr(i), 'User_Name', 'root');
        DBHosts.Add(theDBHost);

        theChildTreeNode:=DBConnTV.Items.AddChild(theTreeNode, theDBHost.Caption);
        theChildTreeNode.Data:=theDBHost;
        theChildTreeNode.ImageIndex:=4;
        theChildTreeNode.SelectedIndex:=4;
        theChildTreeNode.SubItems.Add('HOST');
        theChildTreeNode.SubItems.Add(theDBHost.HostName);
        theChildTreeNode.SubItems.Add(theDBHost.User_Name);
        theChildTreeNode.SubItems.Add('');

        theChildTreeNode:=DBConnTV.Items.AddChild(theChildTreeNode, '...');
        theChildTreeNode.ImageIndex:=7;
        theChildTreeNode.SelectedIndex:=7;
      end;

    finally
      theIni.Free;
    end;
  except
  end;

  theChildTreeNode:=DBConnTV.Items.AddChild(theTreeNode, '...');
  theChildTreeNode.ImageIndex:=4;
  theChildTreeNode.SelectedIndex:=4;

  theTreeNode.Expanded:=True;

  MySQLNode.Expanded:=True;

  //--------------------------------------------------------
  //The SQLite Folder
  theTreeNode:=DBConnTV.Items.Add(MySQLNode, 'SQLite');
  theTreeNode.ImageIndex:=0;
  theTreeNode.SelectedIndex:=1;
  SQLiteNode:=theTreeNode;

  //Make the SQLite Subs
  theChildTreeNode:=DBConnTV.Items.AddChild(theTreeNode, 'NewSQLiteConn');
  theChildTreeNode.ImageIndex:=7;
  theChildTreeNode.SelectedIndex:=7;
  theChildTreeNode.SubItems.Add('DB');
  theChildTreeNode.SubItems.Add('SQLite');

  //--------------------------------------------------------
  //The Oracle Folder
  theTreeNode:=DBConnTV.Items.Add(MySQLNode, 'Oracle');
  theTreeNode.ImageIndex:=0;
  theTreeNode.SelectedIndex:=1;
  OracleNode:=theTreeNode;

  //Make the Oracle Subs
  theChildTreeNode:=DBConnTV.Items.AddChild(theTreeNode, 'NewOracleConn');
  theChildTreeNode.ImageIndex:=7;
  theChildTreeNode.SelectedIndex:=7;
  theChildTreeNode.SubItems.Add('DB');
  theChildTreeNode.SubItems.Add('Oracle');

{$IFDEF MSWINDOWS}
  //--------------------------------------------------------
  //The MSSQL Folder
  theTreeNode:=DBConnTV.Items.Add(MySQLNode, 'MSSQL');
  theTreeNode.ImageIndex:=0;
  theTreeNode.SelectedIndex:=1;
  MSSQLNode:=theTreeNode;

  //Make the MSSQL Subs
  theChildTreeNode:=DBConnTV.Items.AddChild(theTreeNode, 'NewMSSQLConn');
  theChildTreeNode.ImageIndex:=7;
  theChildTreeNode.SelectedIndex:=7;
  theChildTreeNode.SubItems.Add('DB');
  theChildTreeNode.SubItems.Add('MSSQL');
{$ENDIF}

  //--------------------------------------------------------
  //The ODBC Folder
  theTreeNode:=DBConnTV.Items.Add(MySQLNode, 'ODBC');
  theTreeNode.ImageIndex:=0;
  theTreeNode.SelectedIndex:=1;
  ODBCNode:=theTreeNode;

  //Make the ODBC Subs
  theChildTreeNode:=DBConnTV.Items.AddChild(theTreeNode, 'NewODBCConn');
  theChildTreeNode.ImageIndex:=7;
  theChildTreeNode.SelectedIndex:=7;
  theChildTreeNode.SubItems.Add('DB');
  theChildTreeNode.SubItems.Add('ODBC');
end;

procedure TDBConnSelectForm.StoreNetworkHosts;
var i: integer;
  theIni: TMemIniFile;
begin
  //Load Hosts from IniFile
  //Read IniFile
  theIni:=TMemIniFile.Create(DMMain.SettingsPath+'DBConn_Hosts.ini');
  try
    theIni.WriteString('Hosts', 'LocalHost_User_Name', Localhost.SubItems[2]);

    theIni.WriteString('Hosts', 'HostCount', IntToStr(NetworkHosts.Count-1));

    for i:=1 to NetworkHosts.Count-1 do
    begin
      theIni.WriteString('Host'+IntToStr(i), 'HostName', NetworkHosts.Item[i-1].Text);
      theIni.WriteString('Host'+IntToStr(i), 'IP', NetworkHosts.Item[i-1].SubItems[1]);
      theIni.WriteString('Host'+IntToStr(i), 'User_Name', NetworkHosts.Item[i-1].SubItems[2]);
    end;

    theIni.UpdateFile;
  finally
    theIni.Free;
  end;
end;

procedure TDBConnSelectForm.SetData(theDBConns: TObjectList; theSelDBConn: TDBConn);
var i: integer;
begin
  DBConns:=theDBConns;

  GetNetworkHosts;

⌨️ 快捷键说明

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