unitfrmcustomerandproduct.pas

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

PAS
115
字号
unit UnitFrmCustomerAndProduct;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, TeEngine, Series, TeeProcs, Chart, ExtCtrls,ADOMD_TLB,ActiveX,UnitDM;

type
  TFrmCustomerAndProduct = class(TForm)
    Panel1: TPanel;
    Chart1: TChart;
    GroupBox1: TGroupBox;
    Label1: TLabel;
    Label2: TLabel;
    ComboBox1: TComboBox;
    ComboBox2: TComboBox;
    Series1: TPieSeries;
    ListBox1: TListBox;
    Label3: TLabel;
  private
    { Private declarations }
    strMDX:string;

  public
    { Public declarations }
    procedure MakeStrMDX();
    procedure OpenMDX();


  end;

var
  FrmCustomerAndProduct: TFrmCustomerAndProduct;

implementation

{$R *.dfm}

procedure TFrmCustomerAndProduct.MakeStrMDX();
begin
    strMDX:='select {[measures].totalPrice} on columns,';
    strMDX:=strMDX+' {[DimProduct].[';
    strMDX:=strMDX+Combobox2.Text ;
    strMDX:=strMDX+'].children} on rows from sales ';
    strMDX:=strMDX+'where [DimCustomer].[';
    strMDX:=strMDX+Combobox1.Text ;
    strMDX:=strMDX+ ']';

end;
procedure TFrmCustomerAndProduct.OpenMDX();
var
 col,row:integer;
 columnLabel,rowLabel:String;
 value:real;
 v:OleVariant;

 m_strListItem:String;
begin



  DM.Cellset1.Open(strMdx,DM.Catalog1.Get_ActiveConnection());
 // do some cleaning job
  Chart1.Series[0].Clear;
   Listbox1.Items.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
            begin
            Chart1.Series[0].Add(0,rowLabel);

             m_strListItem:=rowLabel+'   :';
            m_strListItem:=m_strListItem+'0';
            ListBox1.Items.Add(m_strListItem);

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

            m_strListItem:=rowLabel+'   :';
            m_strListItem:=m_strListItem+FloatTostr(value);
            ListBox1.Items.Add(m_strListItem);

          end;

        Chart1.Series[0].Title:=COlumnLabel;


   end;

   end;

    DM.Cellset1.Close();


end;
end.

⌨️ 快捷键说明

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