unitfrm3d.pas
来自「关联规则算法的实现和表示Delphi源码」· PAS 代码 · 共 367 行
PAS
367 行
unit UnitFrm3D;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, TeeProcs, TeEngine, Chart, StdCtrls, ExtCtrls, Series, ComCtrls,UnitDM,UnitFrm3DView;
type
TFrm3D = class(TForm)
Panel1: TPanel;
GroupBox1: TGroupBox;
TreeView1: TTreeView;
TreeView2: TTreeView;
TreeView3: TTreeView;
ComboBox1: TComboBox;
ComboBox2: TComboBox;
ComboBox3: TComboBox;
Button1: TButton;
RadioButton1: TRadioButton;
RadioButton2: TRadioButton;
RadioButton3: TRadioButton;
procedure FormShow(Sender: TObject);
procedure TreeView1Click(Sender: TObject);
procedure TreeView1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure TreeView3MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure TreeView2MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure TreeView2Click(Sender: TObject);
procedure TreeView3Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
m_PointX,m_Pointy:integer;
public
{ Public declarations }
procedure FillDimTime();
procedure FillDimCustomer();
procedure FillDimProduct();
end;
var
Frm3D: TFrm3D;
implementation
{$R *.dfm}
procedure TFrm3D.FillDimTime();
var
root:TTreeNode;
m_strYear:String;
strMDX:string;
col:integer;
begin
with TreeView1.Items do
begin
root:=Add(nil,'Year');
strMDX:='select {[DimTime].[Year].members} on columns from sales';
DM.Cellset1.Open(strMDX,DM.catalog1.Get_ActiveConnection());
for col:=1 to DM.Cellset1.Axes[0].Positions.Count do
begin
m_strYear:=DM.Cellset1.Axes[0].Positions[col-1].Members[0].Caption;
AddChild(root,m_strYear);
end;
DM.Cellset1.Close;
end;
end;
procedure TFrm3D.FillDimCustomer();
var
root:TTreeNode;
m_strCountry:String;
strMDX:string;
col:integer;
begin
with TreeView2.Items do
begin
root:=Add(nil,'Country');
strMDX:='select {[DimCustomer].[Country].members} on columns from sales';
DM.Cellset1.Open(strMDX,DM.catalog1.Get_ActiveConnection());
for col:=1 to DM.Cellset1.Axes[0].Positions.Count do
begin
m_strCountry:=DM.Cellset1.Axes[0].Positions[col-1].Members[0].Caption;
AddChild(root,m_strCountry);
end;
DM.Cellset1.Close;
end;
end;
procedure TFrm3D.FillDimProduct();
var
root:TTreeNode;
m_strCategory:String;
strMDX:string;
col:integer;
begin
with TreeView3.Items do
begin
root:=Add(nil,'Category');
strMDX:='select {[DimProduct].[Category].members} on columns from sales';
DM.Cellset1.Open(strMDX,DM.catalog1.Get_ActiveConnection());
for col:=1 to DM.Cellset1.Axes[0].Positions.Count do
begin
m_strCategory:=DM.Cellset1.Axes[0].Positions[col-1].Members[0].Caption;
AddChild(root,m_strCategory);
end;
DM.Cellset1.Close;
end;
end;
procedure TFrm3D.FormShow(Sender: TObject);
begin
if (TreeView1.Items.Count=0)then
FillDimTime();
if (TreeView3.Items.Count=0) then
FillDimProduct();
if (Treeview2.Items.Count=0) then
FillDimCustomer();
end;
procedure TFrm3D.TreeView1Click(Sender: TObject); //based on TreeView1MouseDown();
var
theNode:TTreeNode;
strMDX:string;
col:integer;
m_strMonth:string;
begin
theNode:=TreeView1.GetNodeAt(m_PointX,m_PointY);
if (theNode<>nil) then
begin
ComboBox1.Text :='['+theNode.Text+']';
if (theNode.Level=1)and (not theNode.HasChildren) then
begin
strMDX:='select {[DimTime].[';
strMDX:=strMDX+theNode.Text;
strMDX:=strMDX+'].children} on columns from sales';
DM.Cellset1.Open(strMDX,DM.catalog1.Get_ActiveConnection());
for col:=1 to DM.Cellset1.Axes[0].Positions.Count do
begin
m_strMonth:=DM.Cellset1.Axes[0].Positions[col-1].Members[0].Caption;
TreeView1.Items.AddChild(theNode,m_strMonth);
end;
DM.Cellset1.Close;
end;
end;
end;
procedure TFrm3D.TreeView1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
m_PointX:=x;
m_PointY:=y;
end;
procedure TFrm3D.TreeView3MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
m_pointX:=x;
m_PointY:=y;
end;
procedure TFrm3D.TreeView2MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
m_pointX:=x;
m_PointY:=y;
end;
procedure TFrm3D.TreeView2Click(Sender: TObject);
var
theNode:TTreeNode;
strMDX:string;
col:integer;
m_strChild:string;
begin
theNode:=TreeView2.GetNodeAt(m_PointX,m_PointY);
if (theNode<>nil) then
begin
ComboBox2.Text :='['+theNode.Text+']';
if (theNode.Level>0) and(theNode.Level<3) and (not theNode.HasChildren) then
begin
strMDX:='select {[DimCustomer].[';
strMDX:=strMDX+theNode.Text;
strMDX:=strMDX+'].children} on columns from sales';
DM.Cellset1.Open(strMDX,DM.catalog1.Get_ActiveConnection());
for col:=1 to DM.Cellset1.Axes[0].Positions.Count do
begin
m_strChild:=DM.Cellset1.Axes[0].Positions[col-1].Members[0].Caption;
TreeView2.Items.AddChild(theNode,m_strChild);
end;
DM.Cellset1.Close;
end;
end;
end;
procedure TFrm3D.TreeView3Click(Sender: TObject);
var
theNode:TTreeNode;
strMDX:string;
col:integer;
m_strChild:string;
begin
theNode:=TreeView3.GetNodeAt(m_PointX,m_PointY);
if (theNode<>nil) then
begin
ComboBox3.Text :=theNode.Text;
if (theNode.Level=1)then
ComboBox3.Text :='[Category].['+theNode.Text+']' ;
if (theNode.Level =2)then
Combobox3.Text :='[Product].['+theNode.Text+']' ;
if (theNode.Level=1) and (not theNode.HasChildren) then
begin
strMDX:='select {[DimProduct].[';
strMDX:=strMDX+theNode.Text;
strMDX:=strMDX+'].children} on columns from sales';
DM.Cellset1.Open(strMDX,DM.catalog1.Get_ActiveConnection());
for col:=1 to DM.Cellset1.Axes[0].Positions.Count do
begin
m_strChild:=DM.Cellset1.Axes[0].Positions[col-1].Members[0].Caption;
TreeView3.Items.AddChild(theNode,m_strChild);
end;
DM.Cellset1.Close;
end;
end;
end;
procedure TFrm3D.Button1Click(Sender: TObject);
var
strDimTime,strDimCustomer,strDimProduct,strMDX:string;
begin
//strMDX:='select {[Measures].[totalPrice]} on columns, {[DimTime].[year].members} on rows from sales';
strDimTime:='[DimTime].';
strDimTime:=strDimTime+ComboBox1.Text;
strDimProduct:='[DimProduct].';
strDimProduct:=strDimProduct+Combobox3.Text;
strDimCustomer:='[DimCustomer].';
strDimCustomer:=strDimCustomer+combobox2.Text;
if (RadioButton1.Checked) then
begin
strMDX:='select {[measures].[totalPrice]} on columns,';
strMDX:=strMDX+'{';
strMDX:=strMDX+strDimTime;
strMDX:=strMDX+'.children } on rows from sales where (';
strMDX:=strMDX+strDimCustomer;
strMDX:=strMDX+',';
strMDX:=strMDX+strDimProduct;
strMDX:=strMDX+')';
end
else if (RadioButton2.Checked)then
begin
strMDX:='select {[measures].[totalPrice]} on columns,';
strMDX:=strMDX+'{';
strMDX:=strMDX+strDimCustomer;
strMDX:=strMDX+'.children } on rows from sales where (';
strMDX:=strMDX+strDimProduct;
strMDX:=strMDX+',';
strMDX:=strMDX+strDimTime;
strMDX:=strMDX+')';
end
else if (RadioButton3.Checked) then
begin
strMDX:='select {[measures].[totalPrice]} on columns,';
strMDX:=strMDX+'{';
strMDX:=strMDX+strDimProduct;
strMDX:=strMDX+'.children } on rows from sales where (';
strMDX:=strMDX+strDimCustomer;
strMDX:=strMDX+',';
strMDX:=strMDX+strDimTime;
strMDX:=strMDX+')';
end
else
begin
ShowMessage('未选择X轴!');
exit;
end ;
Frm3DView.strMDX:=strMDX;
Frm3DView.Show;
end;
end.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?