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; } } }