-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathReport.cs
More file actions
190 lines (181 loc) · 5.7 KB
/
Report.cs
File metadata and controls
190 lines (181 loc) · 5.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
using System;
using System.Collections.Generic;
using System.Text;
// container for the BuilderDesignPattern
namespace BuilderDesignPattern
{
public class Report
{
private double count = 0.0;
private double price = 20;
private double totalprice = 0.0;
public double Itemcode = 2345;
public double Date;
public string Name;
//Function to Add the item count
public void addItemCount(double x)
{
count = count + x;
}
//Function to Get the Item count
public double getItemCount()
{
return count;
}
//Function to calculate the price of items
public void ItemPrice(double noofitems)
{
totalprice = price * noofitems;
}
//Function to return total price of Item
public double getItemPrice()
{
return totalprice;
}
//Function to find out Item Code
public double getItemCode()
{
return Itemcode;
}
//Function to find out Expiry Date of Item
public double getExpiryDate()
{
return Date;
}
//Function to get the Item Name
public string getItemName()
{
return Name;
}
public string ReportType { get; set; }
public string ReportNoItems { get; set; }
public string ReportContent { get; set; }
public string ReportItemCode { get; set; }
public string ReportDate { get; set; }
public string ReportName { get; set; }
//function to display report
public void DisplayReport()
{
Console.WriteLine("Report Type :" + ReportType);
Console.WriteLine("NoofItems :" + ReportNoItems);
Console.WriteLine("Content :" + ReportContent);
Console.WriteLine("Item Code :" + ReportItemCode);
Console.WriteLine("Expiry Date :" + ReportDate);
Console.WriteLine("Expiry Name :" + ReportName);
}
}
//Abstract class interface for report
public abstract class ReportBuilder
{
protected Report reportObject;
public abstract void SetReportType();
public abstract void SetReportNoItems();
public abstract void SetReportContent();
public abstract void SetReportItemCode();
public abstract void SetReportDate();
public abstract void SetReportName();
public void CreateNewReport()
{
reportObject = new Report();
}
public Report GetReport()
{
return reportObject;
}
}
//Two different reports : Expiry report
public class Expiry : ReportBuilder
{
public override void SetReportContent()
{
reportObject.ReportContent = "Expiry Report";
}
public override void SetReportNoItems()
{
reportObject.ReportNoItems = "10";
}
public override void SetReportType()
{
reportObject.ReportType = "Expiry Report";
}
public override void SetReportItemCode()
{
reportObject.ReportItemCode = "3324";
}
public override void SetReportDate()
{
reportObject.ReportDate = "05/20/2020";
}
public override void SetReportName()
{
reportObject.ReportName = "Banana";
}
}
//Class for TotalDonated Report
public class TotalDonated : ReportBuilder
{
public override void SetReportContent()
{
reportObject.ReportContent = "PDF Content Section";
}
public override void SetReportNoItems()
{
reportObject.ReportNoItems = "10" ;
}
public override void SetReportType()
{
reportObject.ReportType = "Total Donated Food Report";
}
public override void SetReportItemCode()
{
reportObject.ReportItemCode = "3324";
}
public override void SetReportDate()
{
reportObject.ReportDate = "05/20/2020";
}
public override void SetReportName()
{
reportObject.ReportName = "Banana";
}
}
public class ReportDirector
{
public Report MakeReport(ReportBuilder reportBuilder)
{
reportBuilder.CreateNewReport();
reportBuilder.SetReportType();
reportBuilder.SetReportNoItems();
reportBuilder.SetReportContent();
reportBuilder.SetReportItemCode();
reportBuilder.SetReportDate();
reportBuilder.SetReportName();
return reportBuilder.GetReport();
}
}
class Program
{
static void Main(string[] args)
{
// Client Code
Report report;
ReportDirector reportDirector = new ReportDirector();
// Construct and display Reports
Console.WriteLine("-----------------------------------");
Console.WriteLine("-----Details of Total Donated Report-----");
Console.WriteLine("");
TotalDonated totaldonated = new TotalDonated();
report = reportDirector.MakeReport(totaldonated);
report.DisplayReport();
Console.WriteLine("");
Console.WriteLine("-------------------");
Console.WriteLine("-----------------------------------");
Console.WriteLine("-----Details of Expiry Report-----");
Console.WriteLine("");
Expiry expiry = new Expiry();
report = reportDirector.MakeReport(expiry);
report.DisplayReport();*/
Console.ReadKey();
}
}
}