-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
350 lines (259 loc) · 11.5 KB
/
Copy pathProgram.cs
File metadata and controls
350 lines (259 loc) · 11.5 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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Speech.Synthesis;
namespace InventorySystem
{
class Program
{
// File path of inventory
public static string filepath = "..\\Inventory.txt";
// Filepath of customer's cart
public static string filepath_c = "..\\Cart.txt";
public static string add_to_cart;
public static string name, contact;
public static int total = 0;
public static string dline = "=====================================================================================";
public static string sline = "-------------------------------------------------------------------------------------";
public static SpeechSynthesizer s = new SpeechSynthesizer();
static void Main()
{
Console.BackgroundColor = ConsoleColor.White;
Console.Clear();
Console.ForegroundColor = ConsoleColor.Black;
FileStream fs_c = new FileStream(filepath_c, FileMode.Create, FileAccess.Write);
fs_c.Close();
// Configure the audio output.
s.SetOutputToDefaultAudioDevice();
Console.ForegroundColor = ConsoleColor.DarkGray;
string heading = "Shopping Cart & Inventory System";
Console.WriteLine(dline);
Console.WriteLine("\t\t\t"+ heading);
Console.WriteLine(sline);
s.Speak("Shopping Cart & Inventory System");
Console.WriteLine("Select your category: ");
Console.WriteLine("\n\t[1]Retailer");
Console.WriteLine("\t[2]Customer\n");
Console.WriteLine(dline);
//s.Speak("Select your category: ");
Console.Write("\nChoice: ");
string opt = Console.ReadLine();
if (opt == "1")
{
Retailer();
}
else if (opt == "2")
{
Customer();
}
else
{
Console.WriteLine("\nInvalid Option Entered!");
s.Speak("Invalid Option Entered");
}
}
//Retailer
static void Retailer()
{
s.SetOutputToDefaultAudioDevice();
Console.ForegroundColor = ConsoleColor.Blue;
Console.Clear();
Console.WriteLine(dline);
Console.WriteLine("\t\t\tWelcome to the Inventory System!");
Console.WriteLine(sline);
s.Speak("Welcome to the Inventory System! ");
Console.Write("\n\t[1] View items in Inventory");
Console.Write("\n\t[2] Add items to Inventory\n\n");
Console.Write(dline);
Console.Write("\n\nChoice: ");
string opt = Console.ReadLine();
Console.Clear();
switch (opt)
{
case "1":
ViewItems();
Console.WriteLine("\nPress \"Enter\" to return to main menu. ");
s.Speak("Press Enter to return to main menu");
Console.ReadKey();
Main();
break;
case "2":
AddItems();
break;
default:
Console.WriteLine("Invalid Option!");
s.Speak("Invalid Option");
break;
}
}
//Retailer - To add items to inventory
static void AddItems()
{
Console.Write("\nEnter the item do you want to add: ");
s.Speak("Enter the item do you want to add ");
string item = Console.ReadLine();
Console.Write("Enter price of one unit of entered item: ");
s.Speak("Enter price of one unit of entered item:");
int price = Convert.ToInt32(Console.ReadLine());
FileStream fs = new FileStream(filepath, FileMode.Append, FileAccess.Write);
StreamWriter write = new StreamWriter(fs);
write.Write(string.Format("{0},", item.ToUpper()));
write.WriteLine(string.Format("{0}", price));
write.Close();
fs.Close();
Console.WriteLine("\nSaved!\n");
s.Speak("Saved");
Console.Write("\nDo you want to add more items?(Y/N): ");
s.Speak("Do you want to add more items?");
char more = Convert.ToChar(Console.ReadLine());
if (more == 'y' || more == 'Y')
{
AddItems();
}
else
{
Console.WriteLine("\nOkay!");
Console.ReadKey();
Main();
s.Speak("Okay");
}
}
//Retailer - To view Items available in Inventory
static void ViewItems()
{
Console.ForegroundColor = ConsoleColor.DarkYellow;
FileStream fs = new FileStream(filepath, FileMode.Open, FileAccess.Read);
StreamReader read = new StreamReader(fs);
Console.WriteLine("========================================");
Console.WriteLine("{0,16}{1,16}", "ITEM", "PRICE");
Console.WriteLine("----------------------------------------");
string str = read.ReadLine();
read.ReadLine();
while (!read.EndOfStream)
{
string line = read.ReadLine();
string[] values = line.Split(',');
Console.Write(string.Format("{0, 16}", values[0]));
Console.WriteLine(string.Format("{0, 16}", values[1]));
}
read.Close();
fs.Close();
Console.WriteLine("========================================");
}
//Customer
static void Customer()
{
Console.ForegroundColor = ConsoleColor.DarkYellow;
Console.Clear();
Console.WriteLine("========================================");
Console.WriteLine("\t\tDetails");
Console.WriteLine("----------------------------------------");
Console.Write("\nEnter your name: ");
s.Speak("Please enter your name");
name = Console.ReadLine();
Console.Write("Enter your contact number: ");
s.Speak("Please enter your contact number");
contact = Console.ReadLine();
Console.WriteLine();
Console.WriteLine("========================================");
Console.WriteLine("\nFollowing is the list of items along \nwith per unit price: \n");
s.Speak("Following is the list of available items:");
ViewItems();
Console.WriteLine();
Console.WriteLine("Enter the name of items you want to add to cart: \n(Enter \"0\" to get receipt)\n");
s.Speak("Enter the name of items you want to add to cart");
while (add_to_cart != "0")
{
add_to_cart = Console.ReadLine();
AddToCart();
}
Console.Clear();
Console.BackgroundColor = ConsoleColor.DarkGray;
Receipt();
Console.ReadKey();
Main();
}
//Customer - to add Items in Customer's Cart
static void AddToCart()
{
FileStream fs = new FileStream(filepath, FileMode.Open, FileAccess.Read);
StreamReader read = new StreamReader(fs);
bool found = false;
string str = read.ReadLine();
while (!read.EndOfStream)
{
string[] values = str.Split(',');
if (add_to_cart.ToUpper() == values[0])
{
FileStream fs_c = new FileStream(filepath_c, FileMode.Append, FileAccess.Write);
StreamWriter write_c = new StreamWriter(fs_c);
write_c.Write(string.Format("{0},", values[0]));
write_c.WriteLine(string.Format("{0}", values[1]));
total += int.Parse(values[1]);
write_c.Close();
found = true;
break;
}
str = read.ReadLine();
}
if (found == false && add_to_cart.ToUpper() != "0")
{
Buzzer();
Console.WriteLine("Sorry, item is not available!");
s.Speak("Sorry, item is not available");
}
read.Close();
fs.Close();
}
//Customer - Generate customer's receipt
static void Receipt()
{
Console.Clear();
Console.ForegroundColor = ConsoleColor.White;
string seperators = "-----------------------------------------------------------";
string heading = "RECEIPT";
Console.WriteLine("===========================================================");
Console.WriteLine("\t\t\t" + heading);
Console.WriteLine(seperators);
Random random = new Random();
int randomBetween100And500 = random.Next(1000, 5000);
string sp = "Muhammad Hamza";
Console.Write("Customer Name: " + name);
Console.WriteLine(string.Format("{0, 34}", ("Contact Number: " + contact)));
Console.Write("Sales Person: " + sp);
Console.WriteLine(string.Format("{0, 30}", ("Receipt Number: " + randomBetween100And500)));
Console.WriteLine(seperators);
Console.WriteLine("{0,16}{1,28}", "ITEM", "PRICE");
Console.WriteLine();
FileStream fs_c = new FileStream(filepath_c, FileMode.Open, FileAccess.Read);
StreamReader read_c = new StreamReader(fs_c);
string str = read_c.ReadLine();
while (str != null)
{
string[] values = str.Split(',');
Console.Write(string.Format("{0, 16}", values[0]));
Console.WriteLine(string.Format("{0, 28}", values[1]));
str = read_c.ReadLine();
}
Console.WriteLine();
Console.WriteLine("===========================================================");
Console.WriteLine("{0,16}{1,28}", "TOTAL: ", total);
string tot = Convert.ToString(total);
Console.WriteLine("===========================================================");
s.Speak("Your Total is" + total);
Console.ReadLine();
read_c.Close();
fs_c.Close();
}
//Customer - Beep if unavialable Item is put in the Cart by Customer
static void Buzzer()
{
var soundPlayer = new System.Media.SoundPlayer();
soundPlayer.SoundLocation = "..\\buzzer.wav";
soundPlayer.PlaySync();
}
}
}