您的位置:首页 > 其它

OLE DB for DM实践 —— 用数据挖掘实现交叉销售

2007-07-25 21:11 489 查看
我们在访问一些销售网站时,常常会碰上这种情况:浏览某商品信息的同时,网页上会打出促销广告,购买此商品加另一商品可以享受折扣,就像下面图片中的那样。

3<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
4
5<html xmlns="http://www.w3.org/1999/xhtml" >
6<head runat="server">
7 <title>无标题页</title>
8</head>
9<body>
10 <form id="form1" runat="server">
11 <div>
12 <asp:Label ID="Label1" runat="server" Height="1px" Text="选择您想要的商品"
13 Width="200px" style="z-index: 108; left: 10px; position: absolute; top: 15px"></asp:Label>
14 <asp:Label ID="Label2" runat="server" Height="1px" Style="left: 270px;
15 position: absolute; top: 15px; z-index: 101;" Text="您已选购的商品" Width="270px"></asp:Label><br />
16 <br />
17 <asp:ListBox ID="ListBox1" runat="server" DataSourceID="AdventureWorksDW"
18 DataTextField="Model" DataValueField="Model" Height="353px" Width="200px" style="z-index: 102; left: 10px; position: absolute; top: 53px"></asp:ListBox> 
19 <asp:ListBox ID="ListBox2" runat="server" Height="353px" Style="z-index: 103; left: 270px;
20 position: absolute; top: 53px" Width="270px" AutoPostBack="True"></asp:ListBox>
21 <asp:Button ID="Button1" runat="server" Font-Bold="True" Font-Size="16pt" Style="left: 218px;
22 position: absolute; top: 160px; z-index: 104;" Text=">" Width="41px" Height="41px" />
23 <asp:Button ID="Button2" runat="server" Font-Bold="True" Font-Size="16pt" Style="left: 218px;
24 position: absolute; top: 221px; z-index: 105;" Text="<" Width="41px" Height="41px" />
25 <asp:SqlDataSource ID="AdventureWorksDW" runat="server" ConnectionString="Data Source=127.0.0.1;Initial Catalog=AdventureWorksDW;Integrated Security=True"
26 ProviderName="System.Data.SqlClient"
27 SelectCommand="SELECT DISTINCT Model FROM vAssocSeqLineItems"></asp:SqlDataSource>
28
29 </div>
30    
31 <asp:Panel ID="Panel1" runat="server" BorderStyle="None" BorderWidth="1px" Enabled="False"
32 Height="182px" Style="z-index: 106; left: 10px; position: absolute; top: 420px"
33 Width="380px">
34 <asp:Label ID="Label3" runat="server" Height="62px" Style="z-index: 100; left: 6px;
35 position: absolute; top: 3px" Text="您可以捆绑购买下面的一种商品,捆绑购买将享受9折优惠" Width="370px"></asp:Label>
36 <asp:RadioButtonList ID="RadioButtonList1" runat="server" Height="71px" RepeatLayout="Flow"
37 Style="z-index: 101; left: 6px; position: absolute; top: 72px" Width="370px">
38 </asp:RadioButtonList>
39 <asp:Button ID="Button3" runat="server" Style="z-index: 103; left: 6px; position: absolute;
40 top: 151px" Text="确定" Width="370px" />
41 </asp:Panel>
42 <asp:Label ID="Label4" runat="server" Height="50px" Style="z-index: 107; left: 10px;
43 position: absolute; top: 610px" Width="380px" Font-Size="12pt"></asp:Label>
44 </form>
45</body>
46</html>
47

向项目中添加Microsoft.AnalysisServices.AdomdClient引用,然后写后台代码:

1Imports Microsoft.AnalysisServices.AdomdClient
2
170'商品可以打包销售,包中有多个商品
171<Serializable()> _
172Class PackageClass Package
173 Public ReadOnly Property name()Property name() As String '包的名称,格式是:“商品型号名 + 商品型号名,折扣”
174 Get
175 Dim v As String = ""
176 For i As Integer = 1 To Me.models.Count
177 If i = 1 Then
178 v += models(i)
179 Else
180 v += " + " + models(i)
181 End If
182 Next
183 If Me.discount <> 10 Then
184 v += " , " + Me.discount.ToString + "折"
185 End If
186 Return v
187 End Get
188 End Property
189 Public discount As Integer '折扣
190 Public removed As Boolean '包从已选商品列表中删除标识
191 Public models As Collection '商品型号集合
192 Public Sub New()Sub New(ByVal firstModel As String)
193 Me.models = New Collection
194 Me.models.Add(firstModel)
195 Me.discount = 10
196 Me.removed = False
197 End Sub
198End Class

总结:从代码中可以看出Adomd与Ado在查询方面的使用方法区别不大,关键是对于OLE DB for DM中嵌套表及DMX的理解。我这里仅仅是简单的实践而已,实际环境中的就不可能这么简单,商务网站一般不会是在客户选择了一件商品后就打折促销,而是等客户选购完他需要的商品后,再将其他商品打折推销给客户;另外对复杂的挖掘模型查询是非常费时的,代码中还需要考虑线程异步的问题。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐