-
Notifications
You must be signed in to change notification settings - Fork 0
/
UserInterface.cs
145 lines (125 loc) · 5.73 KB
/
UserInterface.cs
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
using System;
using System.Windows.Forms;
using System.Collections.Generic;
using System.Linq;
namespace Self_Checkout_Simulator
{
public partial class UserInterface : Form
{
// Attributes
SelfCheckout selfCheckout;
BarcodeScanner barcodeScanner;
BaggingAreaScale baggingAreaScale;
LooseItemScale looseItemScale;
ScannedProducts scannedProducts;
// Constructor
public UserInterface()
{
InitializeComponent();
// NOTE: This is where we set up all the objects,
// and create the various relationships between them.
baggingAreaScale = new BaggingAreaScale();
scannedProducts = new ScannedProducts();
barcodeScanner = new BarcodeScanner();
looseItemScale = new LooseItemScale();
selfCheckout = new SelfCheckout(baggingAreaScale, scannedProducts, looseItemScale);
barcodeScanner.LinkToSelfCheckout(selfCheckout);
baggingAreaScale.LinkToSelfCheckout(selfCheckout);
looseItemScale.LinkToSelfCheckout(selfCheckout);
//button enabled/disabled
btnUserWeighsLooseProduct.Enabled = false;
btnUserPutsProductInBaggingAreaCorrect.Enabled = false;
btnUserPutsProductInBaggingAreaIncorrect.Enabled = false;
btnUserChooseToPay.Enabled = false;
btnAdminOverridesWeight.Enabled = false;
UpdateDisplay();
}
// Operations
private void UserScansProduct(object sender, EventArgs e)
{
barcodeScanner.BarcodeDetected();
btnUserScansBarcodeProduct.Enabled = false;
btnUserSelectsLooseProduct.Enabled = false;
btnUserPutsProductInBaggingAreaCorrect.Enabled = true;
btnUserPutsProductInBaggingAreaIncorrect.Enabled = true;
UpdateDisplay();
}
private void UserPutsProductInBaggingAreaCorrect(object sender, EventArgs e)
{
baggingAreaScale.WeightChangeDetected(selfCheckout.GetCurrentProduct().GetWeight());
btnUserPutsProductInBaggingAreaCorrect.Enabled = false;
btnUserPutsProductInBaggingAreaIncorrect.Enabled = false;
btnUserScansBarcodeProduct.Enabled = true;
btnUserSelectsLooseProduct.Enabled = true;
btnUserChooseToPay.Enabled = true;
UpdateDisplay();
}
private void UserPutsProductInBaggingAreaIncorrect(object sender, EventArgs e)
{
// NOTE: We are pretending to put down an item with the wrong weight.
// To simulate this we'll use a random number, here's one for you to use.
int weight = new Random().Next(20, 100);
btnUserPutsProductInBaggingAreaCorrect.Enabled = false;
btnUserPutsProductInBaggingAreaIncorrect.Enabled = false;
btnUserScansBarcodeProduct.Enabled = false;
btnUserSelectsLooseProduct.Enabled = false;
btnUserChooseToPay.Enabled = false;
btnAdminOverridesWeight.Enabled = true;
selfCheckout.BaggingAreaWeightChanged(weight);
UpdateDisplay();
}
private void UserSelectsALooseProduct(object sender, EventArgs e)
{
btnUserPutsProductInBaggingAreaCorrect.Enabled = false;
btnUserPutsProductInBaggingAreaIncorrect.Enabled = false;
btnUserScansBarcodeProduct.Enabled = false;
btnUserSelectsLooseProduct.Enabled = false;
btnUserWeighsLooseProduct.Enabled = true;
btnUserChooseToPay.Enabled = false;
btnAdminOverridesWeight.Enabled = false;
selfCheckout.LooseProductSelected();
UpdateDisplay();
}
private void UserWeighsALooseProduct(object sender, EventArgs e)
{
// NOTE: We are pretending to weigh a banana or whatever here.
// To simulate this we'll use a random number, here's one for you to use.
int weight = new Random().Next(20, 100);
looseItemScale.WeightChangeDetected(weight);
UpdateDisplay();
}
private void AdminOverridesWeight(object sender, EventArgs e)
{
// TODO
btnUserPutsProductInBaggingAreaCorrect.Enabled = false;
btnUserPutsProductInBaggingAreaIncorrect.Enabled = false;
btnAdminOverridesWeight.Enabled = false;
btnUserScansBarcodeProduct.Enabled = true;
btnUserSelectsLooseProduct.Enabled = true;
btnUserChooseToPay.Enabled = true;
UpdateDisplay();
}
private void UserChoosesToPay(object sender, EventArgs e)
{
selfCheckout.UserPaid();
UpdateDisplay();
}
void UpdateDisplay()
{
lbBasket.Items.Clear();
foreach(Product p in scannedProducts.GetProducts())
{
lbBasket.Items.Add(p.GetName());
}
lblScreen.Text = selfCheckout.GetPromptForUser();
lblTotalPrice.Text = Convert.ToString(scannedProducts.CalculatePrice());
lblBaggingAreaCurrentWeight.Text = Convert.ToString(baggingAreaScale.GetCurrentWeight());
lblBaggingAreaExpectedWeight.Text = Convert.ToString(baggingAreaScale.GetExpectedWeight());
// button updates do later
// TODO: use all the information we have to update the UI:
// - set whether buttons are enabled
// - set label texts
// - refresh the scanned products list box
}
}
}