-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
410 lines (406 loc) · 16.3 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
406
407
408
409
410
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Reflection;
using CABS.Models;
namespace CABS
{
class Program
{
static UAccaount ua = new UAccaount();
static void Main()
{
x1:
CheckApp();
Welcoming();
if (ua != null)
{
if (ua.Role == "Client")
{
ClientPart();
}
else if (ua.Role == "Admin")
{
AdminPart();
}
}
else
{
goto x1;
}
}
static void CheckApp()
{
SqlConnection cn = new SqlConnection(@"Data Source = localhost;Initial Catalog = CADB; Integrated Security=True;");
cn.Open();
string cm = $"select * from U_Graph";
SqlCommand cd = new SqlCommand(cm, cn);
SqlDataReader r = cd.ExecuteReader();
string cmd = "";
while (r.Read())
{
if (r.GetValue("Months").ToString() == "0")
{
UAppS(int.Parse(r.GetValue("U_AppId").ToString()));
}
}
r.Close();
}
static void UAppS(int? id)
{
SqlConnection cn = new SqlConnection(@"Data Source = localhost;Initial Catalog = CADB; Integrated Security=True;");
cn.Open();
string cmd = $"update U_App set Done = 'True' where id = {id}";
SqlCommand cd = new SqlCommand(cmd, cn);
cd.ExecuteNonQuery();
}
private static void AdminPart()
{
while (true)
{
x1:
Console.WriteLine($"Welcome to Admin panel\n1-for see all clients\n2-for see all clients and their apps\n3-for exit");
int chs = 0;
try
{
chs = int.Parse(Console.ReadLine());
}
catch (Exception ex)
{
Console.WriteLine("You have to write number!!!");
goto x1;
}
switch (chs)
{
case 1:
{
var li = ua.SelectAll();
Console.WriteLine("id\tFullName\tFamily Status\tAge\tNationality\tGender\tIdentity Card's numbers");
foreach (var x in li)
{
Console.WriteLine($"{x.id}\t{x.FullName}\t{x.FStatus}\t{x.Age}\t{x.CityZone}\t{x.Gender}\t{x.ICNum}");
Console.WriteLine("=======================================================================================");
}
}
break;
case 2:
{
var li = ua.SelectAll();
UApp up = new UApp();
Console.WriteLine("id\tFullName\tFamily Status\tAge\tNationality\tGender\tIdentity Card's numbers");
foreach (var x in li)
{
Console.WriteLine($"{x.id}\t\t{x.FullName}\t\t{x.FStatus}\t\t{x.Age}\t\t{x.CityZone}\t\t{x.Gender}\t\t{x.ICNum}");
Console.WriteLine("=======================================================================================");
Console.WriteLine("\tid\tCreditSum\tCreditGoal\tCreditDeadLine\tPayment\tPayed");
Console.WriteLine("=======================================================================================");
foreach (var z in up.SelectAll())
{
Console.WriteLine($"\t{z.id}\t\t{z.CreditSum}\t\t{z.CreditGoal}\t\t{z.CreditDeadLine}\t\t{z.Pay}\t\t{z.Done}");
Console.WriteLine("=======================================================================================");
}
}
}
break;
}
if (chs == 3)
{
break;
}
}
}
private static bool CountP(UApp uap)
{
int points = 0;
points += ua.Gender.ToLower() == "m" ? 1 : 2;
points += ua.FStatus.ToLower() == "married" ? 2 : ua.FStatus == "not" ? 1 : ua.FStatus == "break up" ? 1 : 2;
points += ua.Age <= 25 ? 0 : ua.Age <= 35 ? 1 : ua.Age <= 62 ? 2 : 1;
points += ua.CityZone.ToLower() == "tajikistan" ? 1 : 0;
if (uap.Pay * 0.8 > uap.CreditSum) { points += 4; }
if (uap.Pay * 0.8 <= uap.CreditSum && uap.Pay * 1.5 > uap.CreditSum) { points += 3; }
if (uap.Pay * 1.5 <= uap.CreditSum && uap.Pay * 2.5 >= uap.CreditSum) { points += 2; }
if (uap.Pay * 2.5 < uap.CreditSum) { points += 1; }
points += uap.CreditGoal.ToLower() == "for phone" ? 0 : uap.CreditGoal.ToLower() == "equipment" ? 1 : uap.CreditGoal.ToLower() == "repairs" ? 1 : 0;
points += uap.CreditDeadLine < 12 ? 1 : 1;
var li = uap.SingleAllById(ua.id);
int s = 0;
foreach (var x in li)
{
if (x.Status == true && x.Done == true)
{
s++;
}
}
points += s > 3 ? 2 : s >= 1 && s <= 2 ? -1 : 0;
return points >= 12;
}
private static void ClientPart()
{
while (true)
{
x2:
Console.Write($"Welcome {ua.FullName}\n1 for add an application\n2 for show your history of applications\n3-for show your aceped apps with graphic\n4 for Exit\n");
int chs = 0;
try
{
chs = int.Parse(Console.ReadLine());
}
catch
{
Console.WriteLine("Write a number!");
goto x2;
}
if (chs == 1)
{
UApp uapp = new UApp();
c1:
Console.Write("Credit sum:");
try
{
uapp.CreditSum = (double.Parse(Console.ReadLine()));
}
catch
{
Console.WriteLine("Write a number");
goto c1;
}
Console.Write("Credit goal:");
uapp.CreditGoal = Console.ReadLine();
Console.Write("How many month do you need?");
uapp.CreditDeadLine = double.Parse(Console.ReadLine());
c2:
Console.Write("You payment:");
try
{
uapp.Pay = double.Parse(Console.ReadLine());
}
catch
{
Console.WriteLine("Write a number");
goto c2;
}
bool st = CountP(uapp);
uapp.Status = st;
uapp.UId = ua.id;
uapp.Add(uapp);
if (uapp.Status)
{
double pmonth = uapp.CreditSum / uapp.CreditDeadLine;
SqlConnection cn = new SqlConnection(@"Data Source = localhost;Initial Catalog = CADB; Integrated Security=True;");
cn.Open();
string cm = $"select * from U_App where UId = { ua.id } and CreditGoal = '{uapp.CreditGoal}' and CreditDeadLine = {uapp.CreditDeadLine}";
SqlCommand cd = new SqlCommand(cm, cn);
SqlDataReader r = cd.ExecuteReader();
UApp ml = new UApp();
while (r.Read())
{
ml = new UApp()
{
id = int.Parse(r.GetValue("id").ToString()),
UId = int.Parse(r.GetValue("UId").ToString()),
CreditSum = double.Parse(r.GetValue("CreditSum").ToString()),
CreditGoal = r.GetValue("CreditGoal").ToString(),
CreditDeadLine = double.Parse(r.GetValue("CreditDeadLine").ToString()),
Status = bool.Parse(r.GetValue("Status").ToString()),
Pay = double.Parse(r.GetValue("Pay").ToString())
};
}
cn.Close();
UGraph ug = new UGraph()
{
PMonth = pmonth,
Months = uapp.CreditDeadLine,
U_AppId = ml.id
};
ug.Add(ug);
}
string acceped = uapp.Status ? "aceped" : "refused";
Console.ForegroundColor = uapp.Status ? ConsoleColor.Green : ConsoleColor.Red;
Console.WriteLine($"You credit status {acceped}");
Console.ForegroundColor = ConsoleColor.Black;
}
else if (chs == 2)
{
UApp uapp = new UApp();
var li = uapp.SingleAllById(ua.id);
Console.WriteLine($"ID\tCreditSum\tCreditDeadline\tCreditStatus");
foreach (var x in li)
{
System.Console.WriteLine("====================================");
string acpd = x.Status ? "aceped" : "canceled";
Console.WriteLine($"{x.id}\t\t{x.CreditSum}\t\t{x.CreditDeadLine}\t\t{acpd}");
System.Console.WriteLine("====================================");
}
}
else if (chs == 3)
{
UApp uapp = new UApp();
var li = uapp.SingleAllById(ua.id);
Console.WriteLine($"ID\tCreditSum\tCreditDeadline\tCreditStatus\tPayed");
foreach (var x in li)
{
System.Console.WriteLine("====================================");
Console.WriteLine($"{x.id}\t\t{x.CreditSum}\t\t{x.CreditDeadLine}\t{x.Status}\t\t{x.Done}");
System.Console.WriteLine("====================================");
UGraph ug = new UGraph();
ug = ug.SingleById(x.id);
Console.WriteLine("\tId\tPer Month\tMonths");
Console.WriteLine($"\t{ug.id}\t{ug.PMonth}\t\t{ug.Months}");
System.Console.WriteLine("====================================");
}
Console.WriteLine("Do you have money for paying this month?Y/N");
char ches = char.Parse(Console.ReadKey().KeyChar.ToString().ToLower());
Console.WriteLine();
if (ches == 'y')
{
d1:
Console.WriteLine("Enter ID of app from sight graph");
int id = 0;
try
{
id = int.Parse(Console.ReadLine());
}
catch
{
Console.WriteLine("Please choose number");
goto d1;
}
SqlConnection cn = new SqlConnection(@"Data Source = localhost;Initial Catalog = CADB; Integrated Security=True;");
cn.Open();
string cm = $"select * from U_Graph where id={id}";
SqlCommand cd = new SqlCommand(cm, cn);
SqlDataReader r = cd.ExecuteReader();
string cmd = "";
while (r.Read())
{
cmd = $"update U_Graph set Months = {int.Parse(r.GetValue("Months").ToString()) - 1} where id = {id}";
}
r.Close();
cd.CommandText = cmd;
cd.ExecuteNonQuery();
cn.Close();
}
}
else
{
break;
}
}
}
static void Welcoming()
{
Console.Write("1-for SignUp\n2-for SignIn\n3-for Exit\n");
int chs = 0;
try
{
chs = int.Parse(Console.ReadLine());
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
Welcoming();
}
switch (chs)
{
case 1:
{
SingUp();
}
break;
case 2:
{
SingIn();
}
break;
}
}
private static void SingUp()
{
UAccaount ut = new UAccaount();
Console.Write("Login(your numbers):");
int lg = int.Parse(Console.ReadLine());
string pass1 = Pass("Password");
string pass2 = Pass("Repeat password");
if (pass1 != pass2)
{
Console.WriteLine("Passwords are not identity!");
SingIn();
}
else
{
ut.Login = lg;
ut.Password = pass1;
Console.Clear();
Console.Write("FullName:");
ut.FullName = Console.ReadLine();
Console.Write("Gender(M/F):");
ut.Gender = Console.ReadLine();
Console.Write("Family status(married or not):");
ut.FStatus = Console.ReadLine();
Console.Write("Age:");
ut.Age = int.Parse(Console.ReadLine());
Console.Write("Do you wont to be Admin?Y/N");
string chs = Console.ReadLine();
ut.RoleId = chs == "Y" ? 1 : 2;
Console.Write("CityZone:");
ut.CityZone = Console.ReadLine().ToLower();
Console.Write("Identity Card Number:");
ut.ICNum = Console.ReadLine();
ua.Add(ut);
ut.Role = ut.RoleId == 1 ? "Admin" : "Client";
ua = ut;
}
}
static string Pass(string txt)
{
// \b-backspace
// \r-enter
string pass = "";
while (true)
{
Console.Clear();
Console.Write(txt);
foreach (var x in pass)
{
Console.Write("*");
}
char pc = Console.ReadKey().KeyChar;
if (pc == '\b')
{
EndLess(ref pass);
}
else if (pc == '\r')
{
break;
}
else
{
pass += pc.ToString();
}
}
return pass;
}
static void EndLess(ref string x)
{
char[] z = x.ToCharArray();
x = "";
for (int i = 0; i < z.Length - 1; i++)
{
x += z[i];
}
}
private static void SingIn()
{
Console.Write("Login:");
int log = int.Parse(Console.ReadLine());
string pass = Pass("Pass");
ua = ua.SignIn(log, pass);
if (ua.id == 0 || ua == null)
{
Console.WriteLine("Login or Password was not correct!");
SingIn();
}
}
}
}