Table是怎样炼成的:SaleReport Table的继承者
2007-02-13 23:40
253 查看
有了Table,我们对其继承,实现更符合业务要求的类
1
/**//// <summary>
2
/// 描述一个销售报表
3
/// </summary>
4
public class SaleReport : Table
5
{
6
7
public SaleReport(string reportName)
8
: base(reportName, new ColumnCollection())
9
{
10
11
this.Columns.Add("序号", typeof(int), 0);
12
this.Columns.Add("姓名", typeof(string), null);
13
this.Columns.Add("商品名称", typeof(string), null);
14
this.Columns.Add("日期", typeof(DateTime), null);
15
this.Columns.Add("数量", typeof(double), null);
16
}
17
18
/**//// <summary>
19
/// 报表的名称
20
/// </summary>
21
public string Name
22
{
23
get
24
{
25
return this.Name;
26
}
27
}
28
29
/**//// <summary>
30
/// 加入数据
31
/// </summary>
32
/// <param name="staff"></param>
33
/// <param name="commodity"></param>
34
/// <param name="cash"></param>
35
public void AddRecord(string staff, string commodity, double cash)
36
{
37
Row row = this.NewRow();
38
row["序号"] = this.Rows.Count + 1;
39
row["姓名"] = staff;
40
row["商品名称"] = commodity;
41
row["日期"] = DateTime.Now;
42
row["数量"] = cash;
43
44
this.Rows.Add(row);
45
}
46
47
/**//// <summary>
48
/// 移除数据
49
/// </summary>
50
/// <param name="index"></param>
51
public void RemoveAt(int index)
52
{
53
this.Rows.RemoveAt(index);
54
}
55
56
/**//// <summary>
57
/// 返回销售报表的销售金额
58
/// </summary>
59
/// <returns></returns>
60
public double GetTotal()
61
{
62
double cash = 0;
63
foreach (Row row in this.Rows)
64
{
65
cash += (double)row["数量"];
66
}
67
return cash;
68
}
69
70
/**//// <summary>
71
/// 返回销售报表的销售金额
72
/// </summary>
73
/// <param name="staff">销售员</param>
74
/// <returns></returns>
75
public double GetTotal(string staff)
76
{
77
double cash = 0;
78
foreach (Row row in this.Rows)
79
{
80
if ((string)row["姓名"] == staff)
81
{
82
cash += (double)row["数量"];
83
}
84
}
85
return cash;
86
}
87
88
}
SaleReport对外封装了对Table的处理细节,使用SaleReport的用户不会感觉到在使用Table类
1
SaleReport report = new SaleReport("销售台帐");
2
report.AddRecord("Alex", "Phone", 2600);
3
report.AddRecord("Alex", "PC", 4560);
4
report.AddRecord("Alex", "Table", 234);
5
report.AddRecord("Sidney", "Phone", 2100);
6
report.AddRecord("Sidney", "TV", 4500);
7
report.AddRecord("Tom", "oven", 300);
8
report.AddRecord("Leo", "oven", 240);
9
10
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
1
/**//// <summary>
2
/// 描述一个销售报表
3
/// </summary>
4
public class SaleReport : Table
5
{
6
7
public SaleReport(string reportName)
8
: base(reportName, new ColumnCollection())
9
{
10
11
this.Columns.Add("序号", typeof(int), 0);
12
this.Columns.Add("姓名", typeof(string), null);
13
this.Columns.Add("商品名称", typeof(string), null);
14
this.Columns.Add("日期", typeof(DateTime), null);
15
this.Columns.Add("数量", typeof(double), null);
16
}
17
18
/**//// <summary>
19
/// 报表的名称
20
/// </summary>
21
public string Name
22
{
23
get
24
{
25
return this.Name;
26
}
27
}
28
29
/**//// <summary>
30
/// 加入数据
31
/// </summary>
32
/// <param name="staff"></param>
33
/// <param name="commodity"></param>
34
/// <param name="cash"></param>
35
public void AddRecord(string staff, string commodity, double cash)
36
{
37
Row row = this.NewRow();
38
row["序号"] = this.Rows.Count + 1;
39
row["姓名"] = staff;
40
row["商品名称"] = commodity;
41
row["日期"] = DateTime.Now;
42
row["数量"] = cash;
43
44
this.Rows.Add(row);
45
}
46
47
/**//// <summary>
48
/// 移除数据
49
/// </summary>
50
/// <param name="index"></param>
51
public void RemoveAt(int index)
52
{
53
this.Rows.RemoveAt(index);
54
}
55
56
/**//// <summary>
57
/// 返回销售报表的销售金额
58
/// </summary>
59
/// <returns></returns>
60
public double GetTotal()
61
{
62
double cash = 0;
63
foreach (Row row in this.Rows)
64
{
65
cash += (double)row["数量"];
66
}
67
return cash;
68
}
69
70
/**//// <summary>
71
/// 返回销售报表的销售金额
72
/// </summary>
73
/// <param name="staff">销售员</param>
74
/// <returns></returns>
75
public double GetTotal(string staff)
76
{
77
double cash = 0;
78
foreach (Row row in this.Rows)
79
{
80
if ((string)row["姓名"] == staff)
81
{
82
cash += (double)row["数量"];
83
}
84
}
85
return cash;
86
}
87
88
}
SaleReport对外封装了对Table的处理细节,使用SaleReport的用户不会感觉到在使用Table类
1
SaleReport report = new SaleReport("销售台帐");
2
report.AddRecord("Alex", "Phone", 2600);
3
report.AddRecord("Alex", "PC", 4560);
4
report.AddRecord("Alex", "Table", 234);
5
report.AddRecord("Sidney", "Phone", 2100);
6
report.AddRecord("Sidney", "TV", 4500);
7
report.AddRecord("Tom", "oven", 300);
8
report.AddRecord("Leo", "oven", 240);
9
10
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
相关文章推荐
- Table是怎样炼成的:SaleReport Table的继承者
- Table是怎样炼成的:SaleReport Table的继承者
- Table是怎样炼成的:Table
- Table是怎样炼成的:Column、ColumnCollection
- Table是怎样炼成的:Row、RowCollection
- Table是怎样炼成的:Row、RowCollection
- Table是怎样炼成的:HtmlTable
- Table是怎样炼成的:Column、ColumnCollection
- Table是怎样炼成的:HtmlTable
- Table是怎样炼成的:Table
- Table是怎样炼成的:HtmlTable
- 优秀的JavaScript模块是怎样炼成的
- 福布斯富豪榜上的软件工程师――李彦宏创业:百度是怎样炼成的
- 钢铁是怎样炼成的
- 商业分析能力是怎样炼成的?
- 【学生必备求职指南】好简历是怎样炼成的?毕业生简历实例点评版 转载
- A query report table or views does not exist.
- 伟大的程序员是怎样炼成的?
- 伟大的程序员是怎样炼成的?
- 干货 | AI 工程师必读,从实践的角度解析一名合格的AI工程师是怎样炼成的