unitfrmcustomerandcategory.pas

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

PAS
199
字号
unit UnitFrmCustomerAndCategory;

interface

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

type
  TFrmCustomerAndCategory = class(TForm)
    Panel1: TPanel;
    Chart1: TChart;
    GroupBox1: TGroupBox;
    RadioGroup1: TRadioGroup;
    Label1: TLabel;
    ComboBox1: TComboBox;
    RadioButton1: TRadioButton;
    ListBox1: TListBox;
    Label2: TLabel;
    Series1: TBarSeries;
    procedure FormShow(Sender: TObject);
    procedure ComboBox1Change(Sender: TObject);
    procedure ListBox1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure ListBox1DblClick(Sender: TObject);
    procedure Chart1DblClick(Sender: TObject);
  private
    { Private declarations }
    strMDX:string;


    listItem:Integer;
  public
    { Public declarations }
    procedure FillCustomerComboBox();

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

var
  FrmCustomerAndCategory: TFrmCustomerAndCategory;

implementation

{$R *.dfm}


procedure TFrmCustomerAndCategory.FillCustomerComboBox();
var
 col:integer;
 columnLabel:string;
begin

    strMDX:='select {[DimCustomer].[Customer].members} on columns from sales';


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


  ComboBox1.Items.Clear;



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

      begin

      columnLabel:=DM.Cellset1.Axes[0].Positions[col-1].Members[0].Caption;
      ComboBox1.Items.Add(columnLabel);


      end;


    DM.Cellset1.Close();


end;

procedure TFrmCustomerAndCategory.FormShow(Sender: TObject);
begin
  FillCustomerComboBox();
  Combobox1.Text :=combobox1.Items[0];
  MakeStrMDX();
  OpenMDXintoBar(strMDX);
end;

procedure TFrmCustomerAndCategory.MakeStrMDX();
begin

    strMDX:='select {[Measures].totalPrice} on columns,';
    strMDX:=strMDX+' {[DimProduct].[category].members} on rows';
    strMDX:=strMDX+' from sales ';
    strMDX:=strMDX+' where [DimCustomer].[';
    strMDX:=strMDX+Combobox1.Text;
    strMDX:=strMDX+']';
end;

procedure TFrmCustomerAndCategory.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;
  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);
            ListBox1.Items.Add(rowLabel);
          end
        else
          begin
            value:=DM.Cellset1.Item[PSafeArray(TVarData(v).VArray)].Value;
            Chart1.Series[0].Add(value,rowLabel);
            ListBox1.Items.Add(rowLabel);
          end;

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


   end;

   end;

    DM.Cellset1.Close();



end;
procedure TFrmCustomerAndCategory.ComboBox1Change(Sender: TObject);
begin
  MakeStrMDX();
  OpenMDXintoBar(strMDX);
end;

procedure TFrmCustomerAndCategory.ListBox1MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
m_point:TPoint;
begin
    m_point.X :=x;
    m_point.Y :=y;
    ListItem:=Listbox1.ItemAtPos(m_point,true);
end;

procedure TFrmCustomerAndCategory.ListBox1DblClick(Sender: TObject);
begin
  if (RadioButton1.Checked)then
  begin
     FrmCustomerAndProduct.ComboBox1.Text := Combobox1.Text ;
     FrmCustomerAndProduct.ComboBox2.Text :=Listbox1.Items[listItem];
     FrmCustomerAndProduct.MakeStrMDX();
     FrmCustomerAndProduct.OpenMDX();
     FrmCustomerAndProduct.Show;

  end;
end;



procedure TFrmCustomerAndCategory.Chart1DblClick(Sender: TObject);
var
  tmp:integer;
  thelabel:String ;
begin
  tmp:=Series1.GetCursorValueIndex;
  theLabel:=series1.XValueToText(tmp);
  if (tmp<>-1) then
   begin
       ListItem:=tmp;
        ListBox1.Selected[tmp]:=true;
       ListBox1DblClick(Sender);  //this function are running or not ,depending on radioButton1 and radiobutton selected or not
   end;
end;
end.

⌨️ 快捷键说明

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