通用图形分析,枚举SQL服务器及数据库
分类:多线程

unit uMain;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, dxCntner, dxEditor, dxExEdtr, dxEdLib, StdCtrls,
ComCtrls,ComObj, Buttons;
type
TfrmMain = class(TForm)
Panel1: TPanel;
Bevel1: TBevel;
Bevel2: TBevel;
Bevel4: TBevel;
Label1: TLabel;
HostName: TdxPickEdit;
Label2: TLabel;
DataBaseName: TdxPickEdit;
GroupBox1: TGroupBox;
Label3: TLabel;
dxEdit1: TdxEdit;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
Label4: TLabel;
Label5: TLabel;
UserID: TdxEdit;
UserPass: TdxEdit;
Label6: TLabel;
PassLogin: TRadioButton;
NtLogin: TRadioButton;
procedure HostNameDropDown(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
procedure DataBaseNameDropDown(Sender: TObject);
procedure NtLoginClick(Sender: TObject);
procedure PassLoginClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
frmMain: TfrmMain;
implementation
{$R *.dfm}
procedure TfrmMain.HostNameDropDown(Sender: TObject);
var
SQLServer:Variant;
ServerList:Variant;
i,nServers:integer;
begin
if HostName.Items.Count<1 then
begin
HostName.Items.Clear;
SQLServer:=CreateOleObject('SQLDMO.Application');
ServerList:=SQLServer.ListAvailableSQLServers;
nServers:=ServerList.Count;
for i:=0 to nservers-1 do
HostName.Items.Add(ServerList.Item(i));
SQLServer:=NULL;
serverList:=NULL;

{*******************************************************}
{                                                       }
{       图形分析                                        }
{                                                       }
{       版权所有 (C) 2008 咏南工作室(陈新光)            }
{                                                       }
{*******************************************************}

object FormChart: TFormChart
  Left = 106
  Top = 175
  Width = 758
  Height = 485
  Caption = '图形分析'
  Color = clBtnFace
  Font.Charset = ANSI_CHARSET
  Font.Color = clWindowText
  Font.Height = -12
  Font.Name = '宋体'
  Font.Style = []
  OldCreateOrder = False
  Position = poDesktopCenter
  OnClose = FormClose
  OnCreate = FormCreate
  OnShow = FormShow
  PixelsPerInch = 96
  TextHeight = 12
  object Panel1: TPanel
    Left = 0
    Top = 0
    Width = 750
    Height = 65
    Align = alTop
    BevelOuter = bvNone
    TabOrder = 0
    object Label1: TLabel
      Left = 368
      Top = 13
      Width = 138
      Height = 12
      Caption = '标识字段(XLabelsSource)'
    end
    object Label2: TLabel
      Left = 368
      Top = 38
      Width = 126
      Height = 12
      Caption = '统计字段(ValueSource)'
    end
    object RadioGroup1: TRadioGroup
      Left = 8
      Top = 2
      Width = 265
      Height = 50
      Caption = '图形格式'
      Columns = 4
      Items.Strings = (
        '柱状图'
        '饼形图'
        '领域图'
        '曲线图')
      TabOrder = 0
      OnClick = RadioGroup1Click
    end
    object CheckBox1: TCheckBox
      Left = 289
      Top = 25
      Width = 62
      Height = 17
      BiDiMode = bdLeftToRight
      Caption = '3D风格'
      ParentBiDiMode = False
      TabOrder = 1
      OnClick = CheckBox1Click
    end
    object BitBtn1: TBitBtn
      Left = 663
      Top = 6
      Width = 82
      Height = 25
      Caption = '生成图形(&B)'
      TabOrder = 2
      OnClick = BitBtn1Click
    end
    object ComboBox1: TComboBox
      Left = 512
      Top = 8
      Width = 145
      Height = 20
      ImeName = '极品五笔输入法'
      ItemHeight = 12
      TabOrder = 3
    end
    object ComboBox2: TComboBox
      Left = 512
      Top = 32
      Width = 145
      Height = 20
      ImeName = '极品五笔输入法'
      ItemHeight = 12
      TabOrder = 4
    end
    object BitBtn2: TBitBtn
      Left = 663
      Top = 34
      Width = 34
      Height = 25
      Caption = '打印'
      TabOrder = 5
      OnClick = BitBtn2Click
    end
    object BitBtn3: TBitBtn
      Left = 709
      Top = 34
      Width = 34
      Height = 25
      Caption = '导出'
      TabOrder = 6
      OnClick = BitBtn3Click
    end
  end
  object DBChart1: TDBChart
    Left = 0
    Top = 65
    Width = 750
    Height = 393
    BackWall.Brush.Color = clWhite
    BackWall.Brush.Style = bsClear
    Title.Text.Strings = (
      'TDBChart')
    View3D = False
    Align = alClient
    TabOrder = 1
  end
end

在项目的工程文件中勾选主题,设置缺省主题为Windows

end;
end;
procedure TfrmMain.BitBtn2Click(Sender: TObject);
begin
Close;
end;
procedure TfrmMain.DataBaseNameDropDown(Sender: TObject);
var
SQLServer:Variant;
Server:Variant;
db:Variant;
i,j:integer;
begin
SQLServer:=CreateOleObject('SQLDMO.Application');
Server:=CreateOleObject('SQLDMO.SQLServer');
if NtLogin.Checked then
begin
Server.LoginSecure:=True;
//设置为WINDOWS登录模式
Server.Connect(HostName.Text);
Server.IntegratedSecurity.SecurityMode:=1;
Server.DisConnect;
Server.Stop;
while Server.Status<>3 do
begin
end;
Server.Start(True,HostName.Text);
end
else
begin
Server.LoginSecure:=True;
//设置为混合登录模式
Server.Connect(HostName.Text);
Server.IntegratedSecurity.SecurityMode:=2;
Server.DisConnect;
Server.Stop;
while Server.Status<>3 do
begin
end;
Server.Start(True,HostName.Text);
end;
db:=Server.DataBases;
i:=db.Count;
DataBaseName.Items.Clear;
for j:=1 to i do
DataBaseName.Items.Add(db.item(j).name);
Server:=NULL;
SQLServer:=NULL;
db:=NULL;
end;
procedure TfrmMain.NtLoginClick(Sender: TObject);
begin
if Ntlogin.Checked=True then
begin
UserID.Enabled:=False;
UserPass.Enabled:=False;
end;
end;
procedure TfrmMain.PassLoginClick(Sender: TObject);
begin
if PassLogin.Checked=True then
begin
UserID.Enabled:=True;
UserPass.Enabled:=True;
end;
end;
end.
程序中使用的控件为Developer Express Inc的扩展控件。经过测试可通过两种登录方式

unit uChart;

 

图片 1

interface

//单元设计: 陈新光(CXG)
//设计时间: 2009-10-8 16:57:35
//单元功用: 图形分析窗体

 

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, TeeProcs, TeEngine, Chart, DBChart, StdCtrls,db,Series,
  Buttons;

 

部分代码如下:

type
  TColParams = record
    FieldName: string;
    Title: string;
  end;
  TFormChart = class(TForm)
    Panel1: TPanel;
    DBChart1: TDBChart;
    RadioGroup1: TRadioGroup;
    CheckBox1: TCheckBox;
    Label1: TLabel;
    Label2: TLabel;
    BitBtn1: TBitBtn;
    ComboBox1: TComboBox;
    ComboBox2: TComboBox;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure CheckBox1Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure RadioGroup1Click(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    FFirstRun:Boolean;
    ColArray,ColArray2: array of TColParams;
    FDataSet:TDataSet;
    FTitle:string;
    Bar:TBarSeries;              //柱形
    Pie:TPieSeries;              //饼形
    Area:TAreaSeries;            //领域图
    FastLine:TFastLineSeries;    //曲线图
    procedure CreateSeries;
    procedure CreateChart;
    procedure FillField;
    function GetLableFieldName:string;
    function GetValueFieldName:string;
    { Private declarations }
  public
    { Public declarations }
  end;

unit uChart;

uses
  Vcl.Themes;
    
procedure TfrmMain.Button1Click(Sender: TObject);
begin
  TStyleManager.SetStyle(ComboBox1.Text);
end;
    
procedure TfrmMain.FormCreate(Sender: TObject);
Var
 StyleName  : string;
begin
  ComboBox1.Items.Clear;
  for StyleName in TStyleManager.StyleNames do
    ComboBox1.Items.Add(StyleName);
end;

var
  FormChart: TFormChart;

interface

运行效果如下:

const
  FLable='请录入标识字段';
  FValue='请录入统计字段';

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, TeeProcs, TeEngine, Chart, DBChart, StdCtrls, db, Series,
  Buttons;

图片 2

//==============================================================================
// ATitle: TDBChart.title
//==============================================================================

type
  TColParams = record
    FieldName: string;
    Title: string;
  end;
  TFormChart = class(TForm)
    Panel1: TPanel;
    DBChart1: TDBChart;
    RadioGroup1: TRadioGroup;
    CheckBox1: TCheckBox;
    Label1: TLabel;
    Label2: TLabel;
    BitBtn1: TBitBtn;
    ComboBox1: TComboBox;
    ComboBox2: TComboBox;
    BitBtn2: TBitBtn;
    BitBtn3: TBitBtn;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure CheckBox1Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure RadioGroup1Click(Sender: TObject);
    procedure BitBtn2Click(Sender: TObject);
    procedure BitBtn3Click(Sender: TObject);
  private
    FFirstRun: Boolean;
    ColArray, ColArray2: array of TColParams;
    Fdataset: TDataSet;
    FTitle: string;
    Bar: TBarSeries; //柱形
    Pie: TPieSeries; //饼形
    Area: TAreaSeries; //领域图
    FastLine: TFastLineSeries; //曲线图
    procedure CreateSeries;
    procedure CreateChart;
    procedure FillField;
    function GetLableFieldName: string;
    function GetValueFieldName: string;
    { Private declarations }
  public
    { Public declarations }
  end;

procedure ShowChart(ADataSet:TDataSet;ATitle:string='');

var
  FormChart: TFormChart;

implementation

const
  FLable = '请录入标识字段';
  FValue = '请录入统计字段';

{$R *.dfm}

//==============================================================================
// ATitle: TDBChart.title
//==============================================================================

procedure ShowChart(ADataSet:TDataSet;ATitle:string='');
begin
  FormChart:=TFormChart.Create(nil);
  try
    FormChart.FDataSet:=ADataSet;
    FormChart.FTitle:=ATitle;
    FormChart.RadioGroup1.ItemIndex:=0;
    FormChart.DBChart1.Title.Text.Clear;
    FormChart.DBChart1.Title.Text.Add(FormChart.FTitle);
    FormChart.ShowModal;
  finally
    FormChart.Free;
  end;
end;

procedure Execute(dataset: TDataSet; ATitle: string = '');

procedure TFormChart.BitBtn1Click(Sender: TObject);
begin
//  DBChart1.FreeAllSeries();
  FFirstRun:=False;
  CreateChart;
end;

implementation

procedure TFormChart.CheckBox1Click(Sender: TObject);
begin
  DBChart1.View3D:=CheckBox1.Checked;
end;

uses
  uFunction;

procedure TFormChart.CreateChart;
begin
  if FFirstRun then exit;

{$R *.dfm}

  if Trim(ComboBox1.Text)='' then
  begin
    ShowMessage(FLable);
    Exit;
  end;
  if Trim(ComboBox2.Text)='' then
  begin
    ShowMessage(FValue);
    Exit;
  end;

procedure Execute(dataset: TDataSet; ATitle: string = '');
begin
  FormChart := TFormChart.Create(nil);
  try
    FormChart.Fdataset := dataset;
    FormChart.FTitle := ATitle;
    FormChart.RadioGroup1.ItemIndex := 0;
    FormChart.DBChart1.Title.Text.Clear;
    FormChart.DBChart1.Title.Text.Add(FormChart.FTitle);
    FormChart.ShowModal;
  finally
    FreeAndNil(FormChart);
  end;
end;

  DBChart1.SeriesList.Clear;

procedure TFormChart.BitBtn1Click(Sender: TObject);
begin
  FFirstRun := False;
  CreateChart;
end;

  DBChart1.View3D:=CheckBox1.Checked;
 
  case RadioGroup1.ItemIndex of
    0:
    begin
      with Bar do
      begin
        ParentChart := DBChart1;
        marks.Style:= smsvalue;
        DataSource := FDataSet;
        XLabelsSource :=GetLableFieldName;
        YValues.ValueSource :=GetValueFieldName;
      end;
    end;
    1:
    begin
      with Pie do
      begin
        ParentChart := DBChart1;
        marks.Style:= smsvalue;
        DataSource := FDataSet;
        XLabelsSource :=GetLableFieldName;
        YValues.ValueSource :=GetValueFieldName;
      end;
    end;
    2:
    begin
      with Area do
      begin
        ParentChart := DBChart1;
        marks.Style:= smsvalue;
        DataSource := FDataSet;
        XLabelsSource :=GetLableFieldName;
        YValues.ValueSource :=GetValueFieldName;
      end;
    end;
    3:
    begin
      with FastLine do
      begin
        ParentChart := DBChart1;
        marks.Style:= smsvalue;
        DataSource := FDataSet;
        XLabelsSource :=GetLableFieldName;
        YValues.ValueSource :=GetValueFieldName;
      end;
    end;
  end;
  FFirstRun:=False;
end;

procedure TFormChart.BitBtn2Click(Sender: TObject);
begin
  DBChart1.Print;
end;

procedure TFormChart.CreateSeries;
begin
  Bar:=TBarSeries.Create(Self);
  Pie:=TPieSeries.Create(Self);
  Area:=TAreaSeries.Create(Self);
  FastLine:=TFastLineSeries.Create(Self);
end;

procedure TFormChart.BitBtn3Click(Sender: TObject);
var
  sav: TSaveDialog;
begin
  sav := TSaveDialog.Create(nil);
  try
    sav.Filter := '位图(BMP)|*.BMP';
    sav.FileName := '文件1';
    sav.FilterIndex := 1;
    if sav.Execute then
      DBChart1.SaveToBitmapFile(sav.FileName + '.BMP');
  finally
    sav.Free;
  end;
end;

procedure TFormChart.FillField;
var
  i:Integer;
begin
  ComboBox1.Items.Clear;
  ComboBox2.Items.Clear;

procedure TFormChart.CheckBox1Click(Sender: TObject);
begin
  DBChart1.View3D := CheckBox1.Checked;
end;

  SetLength(ColArray,FDataSet.FieldCount);
  SetLength(ColArray2,FDataSet.FieldCount);
 
  for i:=0 to FDataSet.FieldCount-1 do
  begin
    if not (FDataSet.Fields[i] is TNumericField)
      or (FDataSet.Fields[i] is TIntegerField) then
    begin
      ColArray[i].FieldName:=FDataSet.Fields[i].FieldName;
      ColArray[i].Title:=FDataSet.Fields[i].DisplayLabel;
      ComboBox1.Items.Add(ColArray[i].Title);
      if ComboBox1.Items.Count>0 then
        ComboBox1.ItemIndex:=0;
    end else
    begin
      ColArray2[i].FieldName:=FDataSet.Fields[i].FieldName;
      ColArray2[i].Title:=FDataSet.Fields[i].DisplayLabel;
      ComboBox2.Items.Add(ColArray2[i].Title);
      if ComboBox2.Items.Count>0 then
        ComboBox2.ItemIndex:=0;
    end; 
  end;
end;

procedure TFormChart.CreateChart;
begin
  if FFirstRun then exit;

procedure TFormChart.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Action:=caFree;
end;

  if Trim(ComboBox1.Text) = '' then
  begin
    ShowMessage(FLable);
    Exit;
  end;
  if Trim(ComboBox2.Text) = '' then
  begin
    ShowMessage(FValue);
    Exit;
  end;

procedure TFormChart.FormCreate(Sender: TObject);
begin
  FFirstRun:=True;
  CreateSeries;
end;

  DBChart1.SeriesList.Clear;

procedure TFormChart.FormDestroy(Sender: TObject);
begin
  FreeAndNil(Bar);
  FreeAndNil(Pie);
  FreeAndNil(Area);
  FreeAndNil(FastLine);
  FormChart:=nil;
end;

  DBChart1.View3D := CheckBox1.Checked;

procedure TFormChart.FormShow(Sender: TObject);
begin
  FillField;
end;

  case RadioGroup1.ItemIndex of
    0:
      begin
        with Bar do
        begin
          ParentChart := DBChart1;
          marks.Style := smsvalue;
          DataSource := fDataSet;
          XLabelsSource := GetLableFieldName;
          YValues.ValueSource := GetValueFieldName;
        end;
      end;
    1:
      begin
        with Pie do
        begin
          ParentChart := DBChart1;
          marks.Style := smsvalue;
          DataSource := FDataSet;
          XLabelsSource := GetLableFieldName;
          YValues.ValueSource := GetValueFieldName;
        end;
      end;
    2:
      begin
        with Area do
        begin
          ParentChart := DBChart1;
          marks.Style := smsvalue;
          DataSource := FDataSet;
          XLabelsSource := GetLableFieldName;
          YValues.ValueSource := GetValueFieldName;
        end;
      end;
    3:
      begin
        with FastLine do
        begin
          ParentChart := DBChart1;
          marks.Style := smsvalue;
          DataSource := FDataSet;
          XLabelsSource := GetLableFieldName;
          YValues.ValueSource := GetValueFieldName;
        end;
      end;
  end;
  FFirstRun := False;
end;

function TFormChart.GetLableFieldName: string;
var
  i:Integer;
begin
  for i := Low(ColArray) to High(ColArray) do
  begin
    if ColArray[i].Title=ComboBox1.Text then
      Result:=ColArray[i].FieldName;
  end;   
end;

procedure TFormChart.CreateSeries;
begin
  Bar := TBarSeries.Create(Self);
  Pie := TPieSeries.Create(Self);
  Area := TAreaSeries.Create(Self);
  FastLine := TFastLineSeries.Create(Self);
end;

function TFormChart.GetValueFieldName: string;
var
  i:Integer;
begin
  for i := Low(ColArray2) to High(ColArray2) do
  begin
    if ColArray2[i].Title=ComboBox2.Text then
      Result:=ColArray2[i].FieldName;
  end;   
end;

procedure TFormChart.FillField;
var
  i: Integer;
begin
  ComboBox1.Items.Clear;
  ComboBox2.Items.Clear;

procedure TFormChart.RadioGroup1Click(Sender: TObject);
begin
//  DBChart1.FreeAllSeries();
  CreateChart;
end;

  SetLength(ColArray, Fdataset.FieldCount);
  SetLength(ColArray2, Fdataset.FieldCount);

end.

  for i := 0 to Fdataset.FieldCount - 1 do
  begin
    if not (Fdataset.Fields[i] is TNumericField)
      or (Fdataset.Fields[i] is TIntegerField) then
    begin
      ColArray[i].FieldName := Fdataset.Fields[i].FieldName;
      ColArray[i].Title := Fdataset.Fields[i].DisplayLabel;
      ComboBox1.Items.Add(ColArray[i].Title);
      if ComboBox1.Items.Count > 0 then
        ComboBox1.ItemIndex := 0;
    end else
    begin
      ColArray2[i].FieldName := Fdataset.Fields[i].FieldName;
      ColArray2[i].Title := Fdataset.Fields[i].DisplayLabel;
      ComboBox2.Items.Add(ColArray2[i].Title);
      if ComboBox2.Items.Count > 0 then
        ComboBox2.ItemIndex := 0;
    end;
  end;
end;

procedure TFormChart.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  FreeAndNil(Bar);
  FreeAndNil(Pie);
  FreeAndNil(Area);
  FreeAndNil(FastLine);
  Action := caFree;
  FormChart := nil;
end;

procedure TFormChart.FormCreate(Sender: TObject);
begin
  FFirstRun := True;
  CreateSeries;
end;

procedure TFormChart.FormShow(Sender: TObject);
begin
  CheckBox1.Checked := True;
  FillField;
end;

function TFormChart.GetLableFieldName: string;
var
  i: Integer;
begin
  for i := Low(ColArray) to High(ColArray) do
  begin
    if ColArray[i].Title = ComboBox1.Text then
      Result := ColArray[i].FieldName;
  end;
end;

function TFormChart.GetValueFieldName: string;
var
  i: Integer;
begin
  for i := Low(ColArray2) to High(ColArray2) do
  begin
    if ColArray2[i].Title = ComboBox2.Text then
      Result := ColArray2[i].FieldName;
  end;
end;

procedure TFormChart.RadioGroup1Click(Sender: TObject);
begin
  CreateChart;
end;

end.

本文由10bet手机官网发布于多线程,转载请注明出处:通用图形分析,枚举SQL服务器及数据库

上一篇:没有了 下一篇:监控系统文件操作,语句中使用字符串
猜你喜欢
热门排行
精彩图文