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

本文介绍了一个基于Table类封装的销售报表类SaleReport的实现。SaleReport简化了销售数据的管理和统计,提供了添加、删除记录及统计销售额等功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

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

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

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

21InBlock.gif        public string Name
22ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
23InBlock.gif            get
24ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
25InBlock.gif                return this.Name;
26ExpandedSubBlockEnd.gif            }

27ExpandedSubBlockEnd.gif        }

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

35InBlock.gif        public void AddRecord(string staff, string commodity, double cash)
36ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
37InBlock.gif            Row row = this.NewRow();
38InBlock.gif            row["序号"= this.Rows.Count + 1;
39InBlock.gif            row["姓名"= staff;
40InBlock.gif            row["商品名称"= commodity;
41InBlock.gif            row["日期"= DateTime.Now;
42InBlock.gif            row["数量"= cash;
43InBlock.gif
44InBlock.gif            this.Rows.Add(row);
45ExpandedSubBlockEnd.gif        }

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

51InBlock.gif        public void RemoveAt(int index)
52ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
53InBlock.gif            this.Rows.RemoveAt(index);
54ExpandedSubBlockEnd.gif        }

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

60InBlock.gif        public double GetTotal()
61ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
62InBlock.gif            double cash = 0;
63InBlock.gif            foreach (Row row in this.Rows)
64ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
65InBlock.gif                cash += (double)row["数量"];
66ExpandedSubBlockEnd.gif            }

67InBlock.gif            return cash;
68ExpandedSubBlockEnd.gif        }

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

75InBlock.gif        public double GetTotal(string staff)
76ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
77InBlock.gif            double cash = 0;
78InBlock.gif            foreach (Row row in this.Rows)
79ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
80InBlock.gif                if ((string)row["姓名"== staff)
81ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
82InBlock.gif                    cash += (double)row["数量"];
83ExpandedSubBlockEnd.gif                }

84ExpandedSubBlockEnd.gif            }

85InBlock.gif            return cash;
86ExpandedSubBlockEnd.gif        }

87InBlock.gif
88ExpandedBlockEnd.gif    }


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

转载于:https://www.cnblogs.com/shyleoking/archive/2007/02/13/649839.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值