unitfrmmain.~pas

来自「关联规则算法的实现和表示Delphi源码」· ~PAS 代码 · 共 433 行

~PAS
433
字号
unit UnitFrmMain;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, ComCtrls, TeeProcs, TeEngine, Chart, Series, Menus,
  ToolWin, Buttons,ADOMD_TLB,ActiveX, StdCtrls,UnitDM, ImgList, ActnList;

type
  TFrmMain = class(TForm)
    ListView1: TListView;
    StatusBar1: TStatusBar;
    MainMenu1: TMainMenu;
    File1: TMenuItem;
    ETL: TMenuItem;
    OLap1: TMenuItem;
    TreeView1: TTreeView;
    DataMining1: TMenuItem;
    Association1: TMenuItem;
    ToolBar1: TToolBar;
    ToolButton1: TToolButton;
    ToolButton2: TToolButton;
    ToolButton3: TToolButton;
    ToolButton4: TToolButton;
    ToolButton5: TToolButton;
    ToolBar2: TToolBar;
    ImageList1: TImageList;
    Chart1: TChart;
    Series3: TBarSeries;
    Series4: TBarSeries;
    Series1: TLineSeries;
    Series2: TLineSeries;
    ActionList1: TActionList;
    ActionAssociation: TAction;
    ActionETL: TAction;
    ActionOLAP: TAction;
    procedure TreeView1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure TreeView1DblClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure ActionAssociationExecute(Sender: TObject);


  private
    { Private declarations }
  public
    { Public declarations }
    ActiveNode:TTreeNode;


     //Of DimTime
    procedure DimTimeYear();
    procedure DimTimeMonth();

    //of DimCustomer
    Procedure DimCustomerCountry();
    procedure DimCustoemrCity();
    Procedure DimCustomerCustomer();

    //of DimProduct
    procedure DimProductCategory();
    procedure DimProductProduct();

    procedure OpenMDXIntoLine(strMDX:string);
    procedure OpenMDXIntoBar(strMDX:string);
  end;

var
  FrmMain: TFrmMain;


  strMDX:String;

implementation

uses UnitFrmYearAndCountry, UnitFrmYearAndProduct,UnitFrmCustomerAndProduct,
  UnitFrmCustomerAndCategory, UnitFrm3D, UnitFrmAssociation;

{$R *.dfm}

procedure TFrmMain.TreeView1MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
       ActiveNode:=TreeView1.GetNodeAt(x,y);
end;





procedure TFrmMain.DimTimeYear();
begin

  strMdx:='select ';
  strMdx:=strMdx+'{[Measures].[quantity],[Measures].[totalPrice]} on columns, ';
  strMdx:=strMdx+' {[DimTime].[Year].Members} on rows from Sales';
  OpenMDXIntoBar(strMdx);



end;

procedure TFrmMain.DimTimeMonth();
begin
  strMdx:='select ';
  strMdx:=strMdx+'{[Measures].[quantity],[Measures].[totalPrice]} on columns, ';
  strMdx:=strMdx+' {[DimTime].[Month].Members} on rows from Sales';
    OpenMDXIntoLine(strMdx);
end;

    //of DimCustomer
Procedure TFrmMain.DimCustomerCountry();
begin

  strMdx:='select ';
  strMdx:=strMdx+'{[Measures].[quantity],[Measures].[totalPrice]} on columns, ';
  strMdx:=strMdx+' {[DimCustomer].[Country].Members} on rows from Sales';
  OpenMDXIntoBar(strMdx);

end;
procedure TFrmMain.DimCustoemrCity();
begin

  strMdx:='select ';
  strMdx:=strMdx+'{[Measures].[quantity],[Measures].[totalPrice]} on columns, ';
  strMdx:=strMdx+' {[DimCustomer].[City].Members} on rows from Sales';
  OpenMDXIntoLine(strMdx);
end;
Procedure TFrmMain.DimCustomerCustomer();
begin
  strMdx:='select ';
  strMdx:=strMdx+'{[Measures].[quantity],[Measures].[totalPrice]} on columns, ';
  strMdx:=strMdx+' {[DimCustomer].[Customer].Members} on rows from Sales';

  OpenMDXIntoLine(strMdx);
end;

    //of DimProduct
procedure TFrmMain.DimProductCategory();
begin
  strMdx:='select ';
  strMdx:=strMdx+'{[Measures].[quantity],[Measures].[totalPrice]} on columns, ';
  strMdx:=strMdx+' {[DimProduct].[Category].Members} on rows from Sales';

  OpenMDXIntoBar(strMdx);
end;
procedure TFrmMain.DimProductProduct();
begin
  strMdx:='select ';
  strMdx:=strMdx+'{[Measures].[quantity],[Measures].[totalPrice]} on columns, ';
  strMdx:=strMdx+' {[DimProduct].[Product].Members} on rows from Sales';
  OpenMDXIntoLine(strMdx);
end;



procedure TFrmMain.OpenMDXIntoLine(strMDX:string);
var
 col,row:integer;
 columnLabel,rowLabel:String;
 value:real;
 v:OleVariant;
begin



  DM.Cellset1.Open(strMdx,DM.Catalog1.Get_ActiveConnection());

  Chart1.Series[0].Clear;
  Chart1.Series[1].Clear;
  Chart1.Series[2].Clear;
  Chart1.Series[3].Clear;

  for col:=1 to DM.Cellset1.Axes[0].Positions.Count do
  begin
   for row:=1 to DM.Cellset1.Axes[1].Positions.Count do
   begin

        columnLabel:=DM.Cellset1.Axes[0].Positions[col-1].Members[0].Caption;
        rowLabel:=DM.Cellset1.Axes[1].Positions[row-1].Members[0].Caption;

        v:=VarArrayCreate([0,1],VarVariant);
        v[0]:=col-1;
        v[1]:=row-1;

        if (DM.Cellset1.Item[PSafeArray(TVarData(v).VArray)].Value=NULL)then
            Chart1.Series[col-1].Add(0,rowLabel)
        else
          begin
            value:=DM.Cellset1.Item[PSafeArray(TVarData(v).VArray)].Value;
            Chart1.Series[col-1].Add(value,rowLabel);
          end;

        Chart1.Series[col-1].Title:=COlumnLabel;


   end;

   end;

    DM.Cellset1.Close();

end;


procedure TFrmMain.OpenMDXIntoBar(strMDX:string);
var
 col,row:integer;
 columnLabel,rowLabel:String;
 value:real;
 v:OleVariant;
begin



  DM.Cellset1.Open(strMdx,DM.Catalog1.Get_ActiveConnection());

  Chart1.Series[0].Clear;
  Chart1.Series[1].Clear;
  Chart1.Series[2].Clear;
  Chart1.Series[3].Clear;
  


  for col:=1 to DM.Cellset1.Axes[0].Positions.Count do
  begin
   for row:=1 to DM.Cellset1.Axes[1].Positions.Count do
   begin

        columnLabel:=DM.Cellset1.Axes[0].Positions[col-1].Members[0].Caption;
        rowLabel:=DM.Cellset1.Axes[1].Positions[row-1].Members[0].Caption;

        v:=VarArrayCreate([0,1],VarVariant);
        v[0]:=col-1;
        v[1]:=row-1;

        if (DM.Cellset1.Item[PSafeArray(TVarData(v).VArray)].Value=NULL)then
            Chart1.Series[col+1].Add(0,rowLabel)
        else
          begin
            value:=DM.Cellset1.Item[PSafeArray(TVarData(v).VArray)].Value;
            Chart1.Series[col+1].Add(value,rowLabel);
          end;

        Chart1.Series[col+1].Title:=COlumnLabel;


   end;

   end;

    DM.Cellset1.Close();



end;
procedure TFrmMain.TreeView1DblClick(Sender: TObject);
var
  ListItem1:TListItem;
  i:integer;
begin

  if (ActiveNode.Text ='年') then
    begin

      DimTimeYear();

      ListView1.Items.Clear;
      ListItem1:=ListView1.Items.Add();
      ListItem1.Caption:='......';
      for i:=1 to 5 do
      ListItem1.SubItems.Add('All');
      ListItem1.SubItems.Add('Blue');
      ListItem1.SubItems.Add('Red');

    end

  else if (ActiveNode.Text ='月')then
       begin

      DimTimeMonth();

      ListView1.Items.Clear;
      ListItem1:=ListView1.Items.Add();
      ListItem1.Caption:='......';
      for i:=1 to 5 do
      ListItem1.SubItems.Add('All');
      ListItem1.SubItems.Add('Blue');
      ListItem1.SubItems.Add('Red');

      end
  else if (ActiveNode.Text ='国家')then

      begin

      DimCustomerCountry();

      ListView1.Items.Clear;
      ListItem1:=ListView1.Items.Add();
      ListItem1.Caption:='All';
      ListItem1.SubItems.Add('......');
      for i:=1 to 4 do
      ListItem1.SubItems.Add('All');
      ListItem1.SubItems.Add('Blue');
      ListItem1.SubItems.Add('Red');

      end

  else if (ActiveNode.Text='城市') then

      begin

      DimCustoemrCity();

      ListView1.Items.Clear;
      ListItem1:=ListView1.Items.Add();
      ListItem1.Caption:='All';
      ListItem1.SubItems.Add('All');
      ListItem1.SubItems.Add('......');
      for i:=1 to 3 do
      ListItem1.SubItems.Add('All');
      ListItem1.SubItems.Add('Blue');
      ListItem1.SubItems.Add('Red');

      end
  else if (ActiveNode.Text ='客户')and (ActiveNode.Parent.Index=1)then

      begin

      DimCustomerCustomer();

      ListView1.Items.Clear;
      ListItem1:=ListView1.Items.Add();
      ListItem1.Caption:='All';
      for i:=1 to 2 do
      ListItem1.SubItems.Add('All');

      ListItem1.SubItems.Add('......');
      for i:=1 to 2 do
      ListItem1.SubItems.Add('All');
      ListItem1.SubItems.Add('Blue');
      ListItem1.SubItems.Add('Red');

      end

  else if (ActiveNode.Text='种类')then

      begin

      DimProductCategory();
      ListView1.Items.Clear;
      ListItem1:=ListView1.Items.Add();
      ListItem1.Caption:='All';
      for i:=1 to 3 do
      ListItem1.SubItems.Add('All');

      ListItem1.SubItems.Add('......');

      ListItem1.SubItems.Add('All');
      ListItem1.SubItems.Add('Blue');
      ListItem1.SubItems.Add('Red');

      end

  else if (ActiveNode.text='商品')and(ActiveNode.Parent.Index=2) then

      begin

      DimProductProduct();
      
      ListView1.Items.Clear;
      ListItem1:=ListView1.Items.Add();
      ListItem1.Caption:='All';
      for i:=1 to 4 do
      ListItem1.SubItems.Add('All');

      ListItem1.SubItems.Add('......');


      ListItem1.SubItems.Add('Blue');
      ListItem1.SubItems.Add('Red');

      end

  else if (ActiveNode.Text='时间+客户')  then
      begin
          //FrmYearAndCountry.Left :=ListView1.Left ;
          //FrmYearAndCountry.Top :=ListView1.Top;
          //FrmYearAndCountry.Width :=Chart1.Width;
          //FrmYearAndCountry.Height:=Chart1.Height+ListView1.Height;
          FrmYearAndCountry.Show;

       end
  else if (ActiveNode.Text ='时间+商品')then
      begin
          FrmYearAndProduct.show;
      end
  else if (ActiveNode.Text='客户+商品')then
       begin
           FrmCustomerAndCategory.show;
       end
  else if (ActiveNode.Text='时间+客户+商品') then
        begin

            Frm3D.Show;
        end;


end;

procedure TFrmMain.FormShow(Sender: TObject);
var
  i:integer;
begin
    for i:=1 to 20 do
      begin
  //Series4.Add(1000*random(10),'');
  Series1.Add(1000*random(10),'');
  Series2.Add(1000*random(10),'');
  //Series3.Add(1000*random(10),'');
  end;
end;



procedure TFrmMain.ActionAssociationExecute(Sender: TObject);
begin
 FrmAssociation.Show;
end;

end.

⌨️ 快捷键说明

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