-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
405 lines (360 loc) · 19.8 KB
/
Program.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
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
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
using System;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.InteropServices;
namespace ConsoleApp4
{
public class Program
{
public static List<Customer> customer = new List<Customer>();
static void Main(string[] args)
{
Customer c = new Customer();
Insurance i = new Insurance();
Random rand = new Random();
i.Create_Table_Customer();
i.Create_Table_Policy();
label1:
try
{
Console.WriteLine("1.Customer Registeration\n2.Select Policy Type\n3.View Customer Details\n4.View All Customer Details\n5.Exit\n");
long Switch_Input = Convert.ToInt16(Console.ReadLine());
Console.WriteLine("\n");
switch (Switch_Input)
{
// Customer Registeration
case 1:
{
int Input1 = rand.Next(1111111, 9999999);
// Loop to validate the customer name
label3:
Console.Write("Enter the Customer_Name [Max 50 Characters] : ");
string Input2 = Console.ReadLine();
if (Input2.Length > 50 || Input2.Length < 2)
{
Console.WriteLine("Invalid Input");
goto label3;
}
// Loop to validate the email
label4:
Console.Write("Enter your Email_Id : ");
string Input3 = Console.ReadLine();
if (Input3.Length < 6)
{
Console.WriteLine("Invalid Input");
goto label4;
}
// Loop to validate the password
label5:
Console.Write("Enter the Password [Max 30 Characters] : ");
string Input4 = Console.ReadLine();
if (Input4.Length > 30 || Input4.Length < 4)
{
Console.WriteLine("Invalid Input");
goto label5;
}
// Loop to validate the address
label6:
Console.Write("Enter the Address [Max 100 Characters] : ");
string Input5 = Console.ReadLine();
if (Input5.Length > 100 || Input5.Length < 5)
{
Console.WriteLine("Invalid Input");
goto label6;
}
// Loop to validate the contact number
label7:
Console.Write("Enter the Contact_Number : ");
long Input6 = Convert.ToInt64(Console.ReadLine());
if (Input6.ToString().Length != 10)
{
Console.WriteLine("Invalid Input");
goto label7;
}
// Loop to validate the nominee name
label8:
Console.Write("Enter the Nominee Name [Max 50 Characters] : ");
string Input7 = Console.ReadLine();
if (Input7.Length > 50 || Input7.Length < 2)
{
Console.WriteLine("Invalid Input");
goto label8;
}
// Loop to validate the relationship with nominee
label9:
Console.Write("Enter the Relationship with the Nominee [Max 50 Characters] : ");
string Input8 = Console.ReadLine();
if (Input8.Length > 50 || Input8.Length < 2)
{
Console.WriteLine("Invalid Input");
goto label9;
}
// Creating a customer object with the inputs
Customer Customer_Obj = new Customer(Input1, Input2, Input3, Input4, Input5, Input6, Input7, Input8);
// Adding the customer to the database and checking the result
int n = i.AddCustomer(Input1.ToString(), Input2, Input3, Input4, Input5, Input6.ToString(), Input7, Input8 );
// To check the customer is already present or not
if (n!=0)
{
Console.WriteLine("\n" + n + " Customer Registration is successful\n" + "Your Customer Id : " + Input1 + "\n");
}
else
{
Console.WriteLine("\nCustomer is already Registered with same address , contact or email.\n");
}
break;
}
// Select Policy Type
case 2:
{
label14:
Console.Write("Enter the seven digit Customer_id : ");
string Cust_Id1 = Console.ReadLine();
if (Cust_Id1.Length != 7) { Console.WriteLine("Invalid Input"); goto label14; }
string id = i.fetchCustomerid(Cust_Id1);
if (Cust_Id1!=id)
{
Console.WriteLine("Customer is not registered...\n");
goto label1;
}
string S_Assured;
string Prem_ium;
string T_erm;
string Pol_type;
string title;
label10:
Console.WriteLine("\nSelect the policy type Given below - \n1.General insurance\n2.Health insurance\n3.Motor insurance\n");
int P_in = Convert.ToInt32(Console.ReadLine());
switch (P_in)
{
// General Insurance
case 1:
{
label11:
Console.WriteLine("Select any one General insurance policy from below options - ");
Console.WriteLine("1. Title - janand SumAssured - 300000 Premium - 1567 Term - 2 Years\n" +
"2. Title - BimaGold SumAssured - 700000 Premium - 3347 Term - 3 Years\n" +
"3. Title - ChildCareer SumAssured - 1200000 Premium - 5466 Term - 5 Years\n");
int T_in = Convert.ToInt32(Console.ReadLine());
if (T_in != 1 && T_in != 2 && T_in != 3)
{
Console.WriteLine("Please Select from the below Choice ");
goto label11;
}
if (T_in == 1)
{
title = "Janand";
S_Assured = "300000";
Prem_ium = "1567";
T_erm = "2";
Pol_type = "General";
}
else if (T_in == 2)
{
S_Assured = "700000";
Prem_ium = "3347";
T_erm = "3";
Pol_type = "General";
title = "BimaGold";
}
else
{
S_Assured = "1200000";
Prem_ium = "5466";
T_erm = "5";
Pol_type = "General";
title = "ChildCarrer";
}
c.Assign_Value(Cust_Id1, S_Assured, Pol_type, Prem_ium, T_erm, title);
break;
}
// Health Insurance
case 2:
{
label12:
Console.WriteLine("Select any one Health insurance policy from below options - ");
Console.WriteLine("1. Title - janand SumAssured - 300000 Premium - 1567 Term - 2 Years\n" +
"2. Title - BimaGold SumAssured - 700000 Premium - 3347 Term - 3 Years\n" +
"3. Title - ChildCareer SumAssured - 1200000 Premium - 5466 Term - 5 Years\n");
int T_in = Convert.ToInt32(Console.ReadLine());
if (T_in != 1 && T_in != 2 && T_in != 3)
{
Console.WriteLine("Please Select from the below Choice ");
goto label12;
}
if (T_in == 1)
{
title = "Janand";
S_Assured = "300000";
Prem_ium = "1567";
T_erm = "2";
Pol_type = "Health";
}
else if (T_in == 2)
{
S_Assured = "700000";
Prem_ium = "3347";
T_erm = "3";
Pol_type = "Health";
title = "BimaGold";
}
else
{
S_Assured = "1200000";
Prem_ium = "5466";
T_erm = "5";
Pol_type = "Health";
title = "ChildCarrer";
}
c.Assign_Value(Cust_Id1, S_Assured, Pol_type, Prem_ium, T_erm, title);
break;
}
// Motor Insurance
case 3:
{
label13:
Console.WriteLine("Select any one Motor insurance policy from below options - ");
Console.WriteLine("1. Title - janand SumAssured - 300000 Premium - 1567 Term - 2 Years\n" +
"2. Title - BimaGold SumAssured - 700000 Premium - 3347 Term - 3 Years\n" +
"3. Title - ChildCareer SumAssured - 1200000 Premium - 5466 Term - 5 Years\n");
int T_in = Convert.ToInt32(Console.ReadLine());
if (T_in != 1 && T_in != 2 && T_in != 3)
{
Console.WriteLine("Please Select from the below Choice");
goto label13;
}
if (T_in == 1)
{
title = "Janand";
S_Assured = "300000";
Prem_ium = "1567";
T_erm = "2";
Pol_type = "Motor";
}
else if (T_in == 2)
{
S_Assured = "700000";
Prem_ium = "3347";
T_erm = "3";
Pol_type = "Motor";
title = "BimaGold";
}
else
{
S_Assured = "1200000";
Prem_ium = "5466";
T_erm = "5";
Pol_type = "Motor";
title = "ChildCarrer";
}
c.Assign_Value(Cust_Id1, S_Assured, Pol_type, Prem_ium, T_erm, title);
break;
}
default:
Console.WriteLine("Please Select from the below Choice "); goto label10;
}
break;
}
case 3:
// case 3 is for fetching customer information by customer ID
{
// label15 is used for implementing a loop for getting input from the user
label15:
Console.Write("Enter the seven digit Customer_id : ");
string Cust_Id = Console.ReadLine();
Console.WriteLine();
// Checking if the length of the entered customer ID is 7
if (Cust_Id.Length != 7)
{
Console.WriteLine("Invalid Input");
// If the length is not 7, the program goes back to label15 to ask for input again
goto label15;
}
// Calling the method `fetchCustomerid` on an object of type `i` with the entered customer ID
string id = i.fetchCustomerid(Cust_Id);
// Checking if the entered customer ID matches the returned customer ID
if (Cust_Id != id)
{
Console.WriteLine("Customer is not registered...\n");
// If the customer ID is not registered, the program goes back to label1 to display the menu again
goto label1;
}
else
{
// If the customer ID is registered, calling the `showAll` method on an object of type `c` with the entered customer ID
c.showAll(Cust_Id);
}
// Exiting the case statement
break;
}
case 4:
// case 4 is for showing information of all customers
{
// Calling the `showAll` method on an object of type `c` without any parameters
c.showAll();
// Exiting the case statement
break;
}
case 5:
// case 5 is for exiting the program
{
Console.WriteLine("Welcome Back!");
Console.ReadKey();
// Terminating the program by returning from the main method
return;
}
default:
// For all other inputs, the program displays an error message to the user
Console.WriteLine("Please Select from the below Choice ");
// Exiting the case statement
break;
}
goto label1;
}
// The program has three catch blocks to handle exceptions
// The first catch block catches the FormatException that occurs when the user enters a value that is not a number
catch (FormatException)
{
Console.WriteLine("Entered value is not a number.");
}
// The second catch block catches the CustomerNotFound exception and displays the error message
catch (CustomerNotFound e)
{
Console.WriteLine(e.Message);
}
// The third catch block catches the CustomerAlreadyPresent exception and displays the error message
catch (CustomerAlreadyPresent e)
{
Console.WriteLine(e.Message);
}
// After the catch blocks, the program goes back to label1 to display the menu again
Console.WriteLine();
goto label1;
}
}
// Definition of the exception class "CustomerAlreadyPresent"
// that inherits from the base class "Exception".
class CustomerAlreadyPresent : Exception
{
// Constructor that takes a string message as an argument
// and passes it to the base class constructor.
public CustomerAlreadyPresent(string msg) : base(msg)
{
// Empty constructor body
}
}
// Definition of the exception class "CustomerNotFound"
// that inherits from the base class "Exception".
class CustomerNotFound : Exception
{
// Constructor that takes a string message as an argument
// and passes it to the base class constructor.
public CustomerNotFound(string msg) : base(msg)
{
// Empty constructor body
}
}
}