Table是怎样炼成的:SaleReport Table的继承者

有了Table,我们对其继承,实现更符合业务要求的类

1ExpandedBlockStart.gifContractedBlock.gif/**////<summary>
2InBlock.gif///描述一个销售报表
3ExpandedBlockEnd.gif///</summary>

4None.gifpublicclassSaleReport:Table
5ExpandedBlockStart.gifContractedBlock.gifdot.gif{
6InBlock.gif
7InBlock.gifpublicSaleReport(stringreportName)
8InBlock.gif:base(reportName,newColumnCollection())
9ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
10InBlock.gif
11InBlock.gifthis.Columns.Add("序号",typeof(int),0);
12InBlock.gifthis.Columns.Add("姓名",typeof(string),null);
13InBlock.gifthis.Columns.Add("商品名称",typeof(string),null);
14InBlock.gifthis.Columns.Add("日期",typeof(DateTime),null);
15InBlock.gifthis.Columns.Add("数量",typeof(double),null);
16ExpandedSubBlockEnd.gif}

17InBlock.gif
18ExpandedSubBlockStart.gifContractedSubBlock.gif/**////<summary>
19InBlock.gif///报表的名称
20ExpandedSubBlockEnd.gif///</summary>

21InBlock.gifpublicstringName
22ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
23InBlock.gifget
24ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
25InBlock.gifreturnthis.Name;
26ExpandedSubBlockEnd.gif}

27ExpandedSubBlockEnd.gif}

28InBlock.gif
29ExpandedSubBlockStart.gifContractedSubBlock.gif/**////<summary>
30InBlock.gif///加入数据
31InBlock.gif///</summary>
32InBlock.gif///<paramname="staff"></param>
33InBlock.gif///<paramname="commodity"></param>
34ExpandedSubBlockEnd.gif///<paramname="cash"></param>

35InBlock.gifpublicvoidAddRecord(stringstaff,stringcommodity,doublecash)
36ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
37InBlock.gifRowrow=this.NewRow();
38InBlock.gifrow["序号"]=this.Rows.Count+1;
39InBlock.gifrow["姓名"]=staff;
40InBlock.gifrow["商品名称"]=commodity;
41InBlock.gifrow["日期"]=DateTime.Now;
42InBlock.gifrow["数量"]=cash;
43InBlock.gif
44InBlock.gifthis.Rows.Add(row);
45ExpandedSubBlockEnd.gif}

46InBlock.gif
47ExpandedSubBlockStart.gifContractedSubBlock.gif/**////<summary>
48InBlock.gif///移除数据
49InBlock.gif///</summary>
50ExpandedSubBlockEnd.gif///<paramname="index"></param>

51InBlock.gifpublicvoidRemoveAt(intindex)
52ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
53InBlock.gifthis.Rows.RemoveAt(index);
54ExpandedSubBlockEnd.gif}

55InBlock.gif
56ExpandedSubBlockStart.gifContractedSubBlock.gif/**////<summary>
57InBlock.gif///返回销售报表的销售金额
58InBlock.gif///</summary>
59ExpandedSubBlockEnd.gif///<returns></returns>

60InBlock.gifpublicdoubleGetTotal()
61ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
62InBlock.gifdoublecash=0;
63InBlock.gifforeach(Rowrowinthis.Rows)
64ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
65InBlock.gifcash+=(double)row["数量"];
66ExpandedSubBlockEnd.gif}

67InBlock.gifreturncash;
68ExpandedSubBlockEnd.gif}

69InBlock.gif
70ExpandedSubBlockStart.gifContractedSubBlock.gif/**////<summary>
71InBlock.gif///返回销售报表的销售金额
72InBlock.gif///</summary>
73InBlock.gif///<paramname="staff">销售员</param>
74ExpandedSubBlockEnd.gif///<returns></returns>

75InBlock.gifpublicdoubleGetTotal(stringstaff)
76ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
77InBlock.gifdoublecash=0;
78InBlock.gifforeach(Rowrowinthis.Rows)
79ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
80InBlock.gifif((string)row["姓名"]==staff)
81ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
82InBlock.gifcash+=(double)row["数量"];
83ExpandedSubBlockEnd.gif}

84ExpandedSubBlockEnd.gif}

85InBlock.gifreturncash;
86ExpandedSubBlockEnd.gif}

87InBlock.gif
88ExpandedBlockEnd.gif}


SaleReport对外封装了对Table的处理细节,使用SaleReport的用户不会感觉到在使用Table类
1None.gifSaleReportreport=newSaleReport("销售台帐");
2None.gifreport.AddRecord("Alex","Phone",2600);
3None.gifreport.AddRecord("Alex","PC",4560);
4None.gifreport.AddRecord("Alex","Table",234);
5None.gifreport.AddRecord("Sidney","Phone",2100);
6None.gifreport.AddRecord("Sidney","TV",4500);
7None.gifreport.AddRecord("Tom","oven",300);
8None.gifreport.AddRecord("Leo","oven",240);
9None.gif
10None.gifreport.Print();


运行的结果是
序号 姓名 商品名称 日期 数量

1 Alex Phone 2007-2-13 23:19:27 2600
2 Alex PC 2007-2-13 23:19:27 4560
3 Alex Table 2007-2-13 23:19:27 234
4 Sidney Phone 2007-2-13 23:19:27 2100
5 Sidney TV 2007-2-13 23:19:27 4500
6 Tom oven 2007-2-13 23:19:27 300
7 Leo oven 2007-2-13 23:19:27 240

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值