Advertisement
Guest User

Untitled

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