Advertisement
Guest User

Untitled

a guest
Oct 24th, 2016
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 23.04 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.IO;
  7. using Newtonsoft.Json;
  8. using Newtonsoft.Json.Linq;
  9. using Console = Colorful.Console;
  10. using System.Drawing;
  11.  
  12. namespace KCKProjekt
  13. {
  14. public class User
  15. {
  16. public string imie { get; set; }
  17. public string nazwisko { get; set; }
  18. public string haslo { get; set; }
  19. public string login { get; set; }
  20. public string dataUr { get; set; }
  21. public string rok { get; set; }
  22. public string miesiac { get; set; }
  23. public string dzien { get; set; }
  24. public string waga { get; set; }
  25. public string wzrost { get; set; }
  26. public string aktywnosc { get; set; }
  27. public string plec { get; set; }
  28. public int wiek { get; set; }
  29. public float BMI { get; set; }
  30. public float PPM { get; set; }
  31. public float CPM { get; set; }
  32. public float newCPM { get; set; }
  33. public string kg { get; set; }
  34. File file = new File();
  35. public int dziennie { get; set; }
  36. public int zuzyte { get; set; }
  37. List<User> profileList = new List<User>();
  38.  
  39. public User()
  40. {
  41.  
  42. }
  43.  
  44. public void uzupelnijListe()
  45. {
  46. profileList = file.listaProfili();
  47. }
  48.  
  49. public void zapiszListe()
  50. {
  51. file.zapisywaniePliku(profileList);
  52. }
  53.  
  54. public void zarejestrujProfil()
  55. {
  56. User us = new User();
  57.  
  58. Console.CursorVisible = false;
  59. Console.SetCursorPosition(0, 0);
  60. Console.WriteLine("______________________", Color.DarkCyan);
  61.  
  62. Console.SetCursorPosition(0, 2);
  63. Console.WriteLine("LOGOWANIE UŻYTKOWNIKA");
  64.  
  65. Console.SetCursorPosition(0, 3);
  66. Console.WriteLine("______________________", Color.DarkCyan);
  67.  
  68. Console.SetCursorPosition(0, 6);
  69.  
  70. try
  71. {
  72. Console.Write("Imie: ");
  73. us.imie = Console.ReadLine();
  74. if (us.imie.Length <= 0)
  75. {
  76. do
  77. {
  78. Console.WriteLine("Pole wymagane");
  79. Console.Write("Imie: ");
  80. us.imie = Console.ReadLine();
  81. } while (us.imie.Length <= 0);
  82. }
  83.  
  84. Console.Write("Nazwisko: ");
  85. us.nazwisko = Console.ReadLine();
  86. if (us.nazwisko.Length <= 0)
  87. {
  88. do
  89. {
  90. Console.WriteLine("Pole wymagane");
  91. Console.Write("Nazwisko: ");
  92. us.nazwisko = Console.ReadLine();
  93. } while (us.nazwisko.Length <= 0);
  94. }
  95. Console.WriteLine("Data urodzenia: ");
  96. Console.Write("Rok: ");
  97. us.rok = Console.ReadLine();
  98. if (us.rok.Length <= 0 || int.Parse(us.rok) >= 2016 || int.Parse(us.rok) < 1899)
  99. {
  100.  
  101. do
  102. {
  103. Console.WriteLine("Wprowadź odpowiedni rok");
  104. Console.Write("Rok: ");
  105. us.rok = Console.ReadLine();
  106. } while (us.rok.Length <= 0 || int.Parse(us.rok) >= 2016 || int.Parse(us.rok) < 1899);
  107. }
  108.  
  109. Console.Write("Miesiąc: ");
  110. us.miesiac = Console.ReadLine();
  111. if (us.miesiac.Length <= 0 || int.Parse(us.miesiac) > 12 || int.Parse(us.miesiac) < 1)
  112. {
  113. do
  114. {
  115. Console.WriteLine("Wprowadź odpowiedni miesiąc");
  116. Console.Write("Miesiąc: ");
  117. us.miesiac = Console.ReadLine();
  118. } while (us.miesiac.Length <= 0 || int.Parse(us.miesiac) > 12 || int.Parse(us.miesiac) < 1);
  119.  
  120. }
  121. Console.Write("Dzień: ");
  122. us.dzien = Console.ReadLine();
  123. if (us.dzien.Length <= 0 || (int.Parse(us.dzien) > 32 || int.Parse(us.dzien) < 1))
  124. {
  125. do
  126. {
  127. Console.WriteLine("Wprowadź odpowiedni dzień");
  128. Console.Write("Dzień: ");
  129. us.dzien = Console.ReadLine();
  130. } while (us.dzien.Length <= 0 || (int.Parse(us.dzien) > 32 || int.Parse(us.dzien) < 1));
  131. }
  132.  
  133. us.dataUr = us.rok + "-" + us.miesiac + "-" + us.dzien;
  134.  
  135. us.wiek = DateTime.Now.Year - int.Parse(us.rok);
  136. Console.WriteLine("Wiek: " + us.wiek);
  137.  
  138. Console.WriteLine("Płeć: ");
  139. Console.WriteLine("1- kobieta\n2- mężczyzna");
  140. us.plec = Console.ReadLine();
  141. if (us.plec.Length <= 0 || int.Parse(us.plec) <= 0)
  142. {
  143. do
  144. {
  145. Console.WriteLine("Pole wymagane. Wybierz płeć");
  146. Console.WriteLine("Płeć:");
  147. Console.WriteLine("1- kobieta\n2- mężczyzna");
  148. us.plec = Console.ReadLine();
  149. } while (us.plec.Length <= 0 || int.Parse(us.plec) <= 0);
  150. }
  151. Console.Write("Hasło: ");
  152. us.haslo = "";
  153. ConsoleKeyInfo keyInfo;
  154. do
  155. {
  156. keyInfo = Console.ReadKey(true);
  157. // Skip if Backspace or Enter is Pressed
  158. if (keyInfo.Key != ConsoleKey.Backspace && keyInfo.Key != ConsoleKey.Enter)
  159. {
  160. us.haslo += keyInfo.KeyChar;
  161. Console.Write("*");
  162. }
  163. else
  164. {
  165. if (keyInfo.Key == ConsoleKey.Backspace && us.haslo.Length > 0)
  166. {
  167. // Remove last charcter if Backspace is Pressed
  168. us.haslo = us.haslo.Substring(0, (us.haslo.Length - 1));
  169. Console.Write("\b \b");
  170. }
  171. }
  172. }
  173. // Stops Getting Password Once Enter is Pressed
  174. while (keyInfo.Key != ConsoleKey.Enter);
  175.  
  176. if (us.haslo.Length <= 0)
  177. {
  178. do
  179. {
  180. Console.WriteLine("\nHaslo nieprawidlowe.");
  181. Console.Write("Hasło: ");
  182. do
  183. {
  184. keyInfo = Console.ReadKey(true);
  185. if (keyInfo.Key != ConsoleKey.Backspace && keyInfo.Key != ConsoleKey.Enter)
  186. {
  187. us.haslo += keyInfo.KeyChar;
  188. Console.Write("*");
  189. }
  190. else
  191. {
  192. if (keyInfo.Key == ConsoleKey.Backspace && us.haslo.Length > 0)
  193. {
  194. us.haslo = us.haslo.Substring(0, (us.haslo.Length - 1));
  195. Console.Write("\b \b");
  196. }
  197. }
  198. }
  199. while (keyInfo.Key != ConsoleKey.Enter);
  200. } while (us.haslo.Length <= 0);
  201. }
  202. Console.Write("\nLogin:");
  203. us.login = Console.ReadLine();
  204. if (us.login.Length <= 0)
  205. {
  206. do
  207. {
  208. Console.WriteLine("Pole wymagane");
  209. Console.Write("Login: ");
  210. us.login = Console.ReadLine();
  211. } while (us.login.Length <= 0);
  212. }
  213.  
  214. StreamReader loadFileUser = new StreamReader("Profile.txt");
  215.  
  216. string line;
  217. while ((line = loadFileUser.ReadLine()) != null)
  218. {
  219. User load1 = JsonConvert.DeserializeObject<User>(line);
  220. //Console.WriteLine("\ndodalem na liste i wczytalem z pliku");
  221. if (load1.login == us.login)
  222. {
  223. do
  224. {
  225. Console.WriteLine("Podany login już istnieje!");
  226. Console.Write("Login: ");
  227. us.login = Console.ReadLine();
  228. } while (load1.login == us.login);
  229. loadFileUser.Close();
  230. break;
  231. }
  232. }
  233.  
  234. Console.Write("Waga (kg):");
  235. us.waga = Console.ReadLine();
  236. if (us.waga.Length <= 0 || float.Parse(us.waga) <= 0)
  237. {
  238. do
  239. {
  240. Console.WriteLine("Pole wymagane. Wprowadź właściwą wagę.");
  241. Console.Write("Waga (kg): ");
  242. us.waga = Console.ReadLine();
  243. } while (us.waga.Length <= 0 || float.Parse(us.waga) <= 0);
  244. }
  245.  
  246. Console.Write("Wzrost (cm):");
  247. us.wzrost = Console.ReadLine();
  248. if (us.wzrost.Length <= 0 || float.Parse(us.wzrost) <= 0)
  249. {
  250. do
  251. {
  252. Console.WriteLine("Pole wymagane. Wprowadź właściwy wzrost.");
  253. Console.Write("Wzrost (cm): ");
  254. us.wzrost = Console.ReadLine();
  255. } while (us.wzrost.Length <= 0 || float.Parse(us.wzrost) <= 0);
  256. }
  257.  
  258. Console.WriteLine("Aktywność fizyczna:");
  259. Console.WriteLine("1- znikoma\n2- bardzo mala\n3- umiarkowana\n4- duża\n5- bardzo duża");
  260. us.aktywnosc = Console.ReadLine();
  261. if (us.aktywnosc.Length <= 0 || int.Parse(us.aktywnosc) <= 0)
  262. {
  263. do
  264. {
  265. Console.WriteLine("Pole wymagane. Wybierz aktywność");
  266. Console.WriteLine("Aktywność fizyczna: ");
  267. Console.WriteLine("1- znikoma\n2- bardzo mala\n3- umiarkowana\n4- duża\n5- bardzo duża");
  268. us.aktywnosc = Console.ReadLine();
  269. } while (us.aktywnosc.Length <= 0 || int.Parse(us.aktywnosc) <= 0);
  270. }
  271. Console.WriteLine("Chce schudnąć(-)/przytyć tygodniowo (kg): ");
  272. us.kg = Console.ReadLine();
  273. if (us.kg.Length <= 0)
  274. {
  275. do
  276. {
  277. Console.WriteLine("Pole wymagane. ");
  278. Console.Write("Chce schudnąć(-)/przytyć tygodniowo(kg): ");
  279. us.kg = Console.ReadLine();
  280.  
  281. } while (us.kg.Length <= 0);
  282. }
  283.  
  284. Kalkulator kal = new Kalkulator();
  285. kal.mojeBMI(us);
  286. kal.zapotrzebowanieKCAL(us);
  287. profileList.Add(us);
  288. //File load = new File();
  289. //file.zapisywaniePlikuProfile(profileList);
  290. zapiszListe();
  291. }
  292. catch (FormatException)
  293. {
  294. Console.WriteLine("Wprowadziles zle dane");
  295. }
  296.  
  297. }
  298.  
  299. public void zalogujProfil()
  300. {
  301. string log;
  302. string pass;
  303. try
  304. {
  305. User us = new User();
  306.  
  307. Console.CursorVisible = false;
  308. Console.SetCursorPosition(0, 0);
  309. Console.WriteLine("______________________", Color.DarkCyan);
  310.  
  311. Console.SetCursorPosition(0, 2);
  312. Console.WriteLine("LOGOWANIE UŻYTKOWNIKA");
  313.  
  314. Console.SetCursorPosition(0, 3);
  315. Console.WriteLine("______________________", Color.DarkCyan);
  316.  
  317. Console.SetCursorPosition(0, 6);
  318. Console.Write("Login: ");
  319. // us.login = Console.ReadLine();
  320. log = Console.ReadLine();
  321. if (log.Length <= 0)
  322. {
  323. do
  324. {
  325. Console.WriteLine("Login nieprawidlowy");
  326. Console.Write("Login: ");
  327. log = Console.ReadLine();
  328. } while (log.Length <= 0);
  329.  
  330.  
  331. }
  332. Console.Write("Hasło: ");
  333. pass = "";
  334. ConsoleKeyInfo keyInfo;
  335. do
  336. {
  337. keyInfo = Console.ReadKey(true);
  338. // Skip if Backspace or Enter is Pressed
  339. if (keyInfo.Key != ConsoleKey.Backspace && keyInfo.Key != ConsoleKey.Enter)
  340. {
  341. pass += keyInfo.KeyChar;
  342. Console.Write("*");
  343. }
  344. else
  345. {
  346. if (keyInfo.Key == ConsoleKey.Backspace && pass.Length > 0)
  347. {
  348. // Remove last charcter if Backspace is Pressed
  349. pass = pass.Substring(0, (pass.Length - 1));
  350. Console.Write("\b \b");
  351. }
  352. }
  353. }
  354. // Stops Getting Password Once Enter is Pressed
  355. while (keyInfo.Key != ConsoleKey.Enter);
  356.  
  357. if (pass.Length <= 0)
  358. {
  359. do
  360. {
  361. Console.WriteLine("\nHaslo nieprawidlowe.");
  362. Console.Write("Hasło: ");
  363. do
  364. {
  365. keyInfo = Console.ReadKey(true);
  366. if (keyInfo.Key != ConsoleKey.Backspace && keyInfo.Key != ConsoleKey.Enter)
  367. {
  368. pass += keyInfo.KeyChar;
  369. Console.Write("*");
  370. }
  371. else
  372. {
  373. if (keyInfo.Key == ConsoleKey.Backspace && pass.Length > 0)
  374. {
  375. pass = pass.Substring(0, (pass.Length - 1));
  376. Console.Write("\b \b");
  377. }
  378. }
  379. }
  380. while (keyInfo.Key != ConsoleKey.Enter);
  381. } while (pass.Length <= 0);
  382. }
  383.  
  384. // File load = new File();
  385. Console.SetCursorPosition(0, 16);
  386. // us = load.wczytywaniePlikuProfile(log, pass);
  387.  
  388. foreach (User use in profileList)
  389. {
  390. if (use.login == log && use.haslo == pass)
  391. {
  392. this.imie = use.imie;
  393. this.nazwisko = use.nazwisko;
  394. this.waga = use.waga;
  395. this.wzrost = use.wzrost;
  396. this.dataUr = use.dataUr;
  397. this.wiek = use.wiek;
  398. this.aktywnosc = use.aktywnosc;
  399. this.login = use.login;
  400. this.plec = use.plec;
  401. this.haslo = use.haslo;
  402. this.BMI = use.BMI;
  403. this.kg = use.kg;
  404. this.CPM = use.CPM;
  405. this.newCPM = use.newCPM;
  406. }
  407. }
  408.  
  409. }
  410. catch (FormatException)
  411. {
  412. Console.WriteLine("Wprowadziles zle dane");
  413. }
  414.  
  415. }
  416.  
  417. public void wyswietlPasek()
  418. {
  419. int progress = 600;
  420. int total = 1200;
  421. //draw empty progress bar
  422. Console.CursorLeft = 0;
  423. Console.Write("["); //start
  424. Console.CursorLeft = 32;
  425. Console.Write("]"); //end
  426. Console.CursorLeft = 1;
  427. float onechunk = 30.0f / total;
  428.  
  429. //draw filled part
  430. int position = 1;
  431. for (int i = 0; i < onechunk * progress; i++)
  432. {
  433. Console.BackgroundColor = Color.Green;
  434. Console.CursorLeft = position++;
  435. Console.Write(" ");
  436. }
  437.  
  438. //draw unfilled part
  439. for (int i = position; i <= 31; i++)
  440. {
  441. Console.BackgroundColor = Color.Red;
  442. Console.CursorLeft = position++;
  443. Console.Write(" ");
  444. }
  445.  
  446. //draw totals
  447. Console.CursorLeft = 35;
  448. Console.BackgroundColor = Color.Black;
  449. Console.Write(progress.ToString() + " of " + total.ToString() + " "); //blanks at the end remove any excess
  450.  
  451. }
  452.  
  453. public void wyswietlProfil()
  454. {
  455. Console.CursorVisible = false;
  456. Console.SetCursorPosition(0, 15);
  457. Console.WriteLine("______________________", Color.DarkCyan);
  458. Console.SetCursorPosition(0, 23);
  459. Console.WriteLine("______________________", Color.DarkCyan);
  460.  
  461. Console.SetCursorPosition(0, 17);
  462. Console.WriteLine("Imie: " + imie);
  463. Console.WriteLine("Nazwisko: " + nazwisko);
  464. Console.WriteLine("Data urodzenia: " + dataUr);
  465. Console.WriteLine("Waga: " + waga);
  466. Console.WriteLine("Wzrost: " + wzrost);
  467. Console.WriteLine("Aktywność: " + aktywnosc);
  468. }
  469.  
  470. public void edytujProfil()
  471. {
  472. Console.SetCursorPosition(13, 15);
  473. Console.WriteLine("_______________________________", Color.DarkCyan);
  474. Console.SetCursorPosition(13, 23);
  475. Console.WriteLine("_______________________________", Color.DarkCyan);
  476.  
  477.  
  478. foreach (User use in profileList)
  479. {
  480. if (use.login == login && use.haslo == haslo)
  481. {
  482. Console.SetCursorPosition(20, 17);
  483. Console.Write("Edytuj imie: ");
  484. this.imie = Console.ReadLine();
  485. use.imie = imie;
  486.  
  487. Console.SetCursorPosition(20, 18);
  488. Console.Write("Edytuj nazwisko: ");
  489. this.nazwisko = Console.ReadLine();
  490. use.nazwisko = nazwisko;
  491.  
  492. Console.SetCursorPosition(20, 19);
  493. Console.Write("Edytuj datę urodzenia: ");
  494. this.dataUr = Console.ReadLine();
  495. use.dataUr = dataUr;
  496.  
  497. Console.SetCursorPosition(20, 20);
  498. Console.Write("Edytuj waga: ");
  499. this.waga = Console.ReadLine();
  500. use.waga = waga;
  501.  
  502. Console.SetCursorPosition(20, 21);
  503. Console.Write("Edytuj wzrost: ");
  504. this.wzrost = Console.ReadLine();
  505. use.wzrost = wzrost;
  506.  
  507. Console.SetCursorPosition(20, 22);
  508. Console.Write("Edytuj aktywność: ");
  509. this.aktywnosc = Console.ReadLine();
  510. use.aktywnosc = aktywnosc;
  511. }
  512. }
  513.  
  514. zapiszListe();
  515. Console.SetCursorPosition(20, 25);
  516. Console.WriteLine("Zaktualizowałeś dane");
  517. Console.SetCursorPosition(20, 26);
  518. Console.WriteLine("Wciśnij dowolny klawisz aby zakończyć...");
  519. Console.ReadKey();
  520. }
  521.  
  522. public void edytujWage()
  523. {
  524. string wag = this.waga;
  525. foreach (User use in profileList)
  526. {
  527. if (use.login == login && use.haslo == haslo)
  528. {
  529. Console.CursorVisible = false;
  530. Console.SetCursorPosition(25, 3);
  531. Console.WriteLine("_______________________________", Color.DarkCyan);
  532. Console.SetCursorPosition(25, 7);
  533. Console.WriteLine("_______________________________", Color.DarkCyan);
  534.  
  535. Console.SetCursorPosition(25, 5);
  536. Console.WriteLine("Wpisz nową wagę: kg");
  537. Console.SetCursorPosition(42, 5);
  538. this.waga = Console.ReadLine();
  539. use.waga = waga;
  540. }
  541. }
  542.  
  543. zapiszListe();
  544. Console.SetCursorPosition(25, 6);
  545. Console.WriteLine("Zaktualizowałeś wagę z " + wag + " na " + this.waga);
  546. Console.SetCursorPosition(25, 9);
  547. Console.WriteLine("Wciśnij dowolny klawisz aby zakończyć...");
  548. Console.ReadKey();
  549. }
  550.  
  551. public void wyswietlLoginHaslo()
  552. {
  553. Console.CursorVisible = false;
  554. Console.SetCursorPosition(0, 15);
  555. Console.WriteLine("_________________", Color.DarkCyan);
  556. Console.SetCursorPosition(0, 19);
  557. Console.WriteLine("_________________", Color.DarkCyan);
  558.  
  559. Console.SetCursorPosition(0, 17);
  560. Console.WriteLine("Login: " + login);
  561. Console.WriteLine("Hasło: " + haslo);
  562. }
  563.  
  564. public void edytujLoginHaslo()
  565. {
  566. foreach (User use in profileList)
  567. {
  568. if (use.login == login && use.haslo == haslo)
  569. {
  570. Console.SetCursorPosition(13, 15);
  571. Console.WriteLine("________________________", Color.DarkCyan);
  572. Console.SetCursorPosition(13, 19);
  573. Console.WriteLine("________________________", Color.DarkCyan);
  574.  
  575. Console.SetCursorPosition(17, 17);
  576. Console.Write("Edytuj login: ");
  577. this.login = Console.ReadLine();
  578. use.login = login;
  579. Console.SetCursorPosition(17, 18);
  580. Console.Write("Edytuj haslo: ");
  581. this.haslo = Console.ReadLine();
  582. use.haslo = haslo;
  583. }
  584. }
  585.  
  586. zapiszListe();
  587. Console.SetCursorPosition(17, 21);
  588. Console.WriteLine("Zaktualizowałeś dane");
  589. Console.SetCursorPosition(17, 22);
  590. Console.WriteLine("Wciśnij dowolny klawisz aby zakończyć...");
  591. Console.ReadKey();
  592. }
  593. }
  594. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement