Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2020
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.12 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using Npgsql;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8.  
  9. namespace Projekt2
  10. {
  11. class Program
  12. {
  13. static void Main(string[] args)
  14. {
  15. GlownaFunkcja CzasPracy = new GlownaFunkcja();
  16.  
  17. CzasPracy.Funkcja();
  18.  
  19. Console.ReadKey();
  20.  
  21. }
  22. }
  23.  
  24.  
  25.  
  26. class GlownaFunkcja : Menu
  27. {
  28. public void Funkcja()
  29. {
  30. Rysuj();
  31. Poruszanie();
  32. }
  33.  
  34. }
  35.  
  36.  
  37. class Menu : WorkTime
  38. {
  39. protected static ConsoleKeyInfo Przycisk;
  40. protected int x = 10;
  41. protected int y = 1;
  42.  
  43.  
  44. public void Rysuj()
  45. {
  46.  
  47. Console.WriteLine("----------------------------------");
  48. Console.WriteLine("| 1. Wejscie |");
  49. Console.WriteLine("| 2. Wyjscie |");
  50. Console.WriteLine("| 3. Zlicz pensje |");
  51. Console.WriteLine("----------------------------------");
  52.  
  53. }
  54.  
  55. public void Poruszanie()
  56. {
  57.  
  58. do
  59. {
  60. Console.SetCursorPosition(x, y);
  61.  
  62. Przycisk = Console.ReadKey(true);
  63.  
  64. if (Przycisk.Key == ConsoleKey.DownArrow && y < 3)
  65. {
  66. y += 1;
  67. }
  68. if (Przycisk.Key == ConsoleKey.UpArrow && y > 1)
  69. {
  70. y -= 1;
  71. }
  72. if (Przycisk.Key == ConsoleKey.Enter)
  73. {
  74. if (y == 1)
  75. {
  76. Console.Clear();
  77. Wejscie();
  78. Console.Clear();
  79. Rysuj();
  80. }
  81. if (y == 2)
  82. {
  83. Console.Clear();
  84. Wyjscie();
  85. Console.Clear();
  86. Rysuj();
  87. }
  88. if (y == 3)
  89. {
  90. Console.Clear();
  91. Salary Pensja = new Salary();
  92. Pensja.Wynagrodzenie();
  93. Console.Clear();
  94. Rysuj();
  95. }
  96. }
  97. } while (Przycisk.Key != ConsoleKey.Escape);
  98. }
  99.  
  100. }
  101. class WorkTime : sql
  102. {
  103.  
  104. private int idWorker;
  105. DateTime[] wejscie = new DateTime[20];
  106. protected int[] pracuje = new int[20];
  107. DateTime[] wyjscie = new DateTime[20];
  108.  
  109. public void Praca()
  110. {
  111. Wejscie();
  112. Console.ReadKey(); Console.Clear();
  113. Wyjscie();
  114. }
  115. public void Wejscie()
  116. {
  117.  
  118.  
  119. Console.Write("Podaj ID pracownika: ");
  120. int.TryParse(Console.ReadLine(),out idWorker);
  121. SprawdzenieCzyJest(idWorker);
  122. if (sprawdzenie == "F")
  123. {
  124. Console.WriteLine("Pracownika o tym ID nie ma w bazie!");
  125. }
  126. else if ( pracuje[idWorker] == 1 ) //Sprawdzenie czy już się odbił
  127. {
  128. Console.WriteLine("Już się zarejestrowałeś tego dnia");
  129. }
  130. else
  131. {
  132. wejscie[idWorker] = DateTime.Now;
  133. pracuje[idWorker] = 1;
  134. //String.Format("{0:HH.mm.ss}", dt);
  135. Console.WriteLine("Rejestracja pomyślna. Czas rejestracji: " + wejscie[idWorker]);
  136. }
  137. Console.ReadKey();
  138. }
  139. public void Wyjscie()
  140. {
  141. Console.Write("Podaj ID pracownika: ");
  142. int.TryParse(Console.ReadLine(), out idWorker);
  143. SprawdzenieCzyJest(idWorker);
  144. if (sprawdzenie == "F")
  145. {
  146. Console.WriteLine("Pracownika o tym ID nie ma w bazie!");
  147. }
  148. else if (pracuje[idWorker] == 0) //Sprawdzenie czy już się odbił
  149. {
  150. Console.WriteLine("Nie Zarejestrowałeś się tego dnia");
  151. }
  152. else
  153. {
  154. wyjscie[idWorker] = DateTime.Now;
  155. pracuje[idWorker] = 0;
  156. Console.WriteLine("Wyrejestowanie pomyślne. Czas wyrejestrowania: " + wyjscie[idWorker]);
  157.  
  158. TimeSpan result = wyjscie[idWorker] - wejscie[idWorker];
  159. Console.WriteLine("Byłeś w pracy: " + result);
  160. double godziny = result.TotalSeconds;
  161.  
  162. ZapisDoBazy(idWorker, godziny);
  163. }
  164. Console.ReadKey();
  165. }
  166. }
  167.  
  168. class Salary : WorkTime
  169. {
  170. private double sklEmeryt;
  171. private double sklRent;
  172. private double sklChor;
  173. private double sklZdrow;
  174. private double pensjaBruttoPomniejszona;
  175. private double wynagordzeniePomniejszone;
  176. private double podstawaPodatekDochodowy;
  177. private double skladkaZdrowotna775;
  178. private double podatekDochodowy;
  179. private double pensjaNetto;
  180. private bool miejsce;
  181. private bool wiek;
  182. private double godziny;
  183. private int id;
  184. private int stawka;
  185. private string komunikat;
  186. public void Wynagrodzenie()
  187. {
  188. Obliczenia(Dane());
  189. }
  190. private double Dane()
  191. {
  192. Console.Write("Podaj id pracownika: ");
  193. while (true)
  194. {
  195. komunikat = Console.ReadLine();
  196. if (int.TryParse(komunikat, out id))
  197. break;
  198. else
  199. Console.Write("Podaj liczbę! ");
  200. }
  201. SprawdzenieCzyJest(id);
  202. if (sprawdzenie == "T")
  203. {
  204.  
  205.  
  206.  
  207. Console.Write("Podaj stawkę pracownika na godzinę brutto: ");
  208. while (true)
  209. {
  210. komunikat = Console.ReadLine();
  211. if (int.TryParse(komunikat, out stawka))
  212. break;
  213. else
  214. Console.Write("Podaj liczbę! ");
  215. }
  216. Console.Clear();
  217.  
  218. WczytanieGodzin(id);
  219. godziny = GodzinyZliczone;
  220.  
  221. return stawka * godziny;
  222. }
  223. else
  224. Console.WriteLine("Pracownika o tym ID nie ma w bazie!");
  225. Console.WriteLine("Naciśniej dowolny przycisk aby wrócić do menu.");
  226. Console.ReadKey();
  227. return 0;
  228.  
  229. }
  230. private void Obliczenia(double pensja)
  231. {
  232. if (pensja != 0)
  233. {
  234. Console.WriteLine("Enter = tak, Dowolny klawisz = nie");
  235. //OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO
  236. Console.Write("Praca w miejscu zamieszkania: ");
  237. if (Console.ReadKey().Key == ConsoleKey.Enter)
  238. {
  239. Console.SetCursorPosition(30, 1);
  240. Console.WriteLine("TAK");
  241. miejsce = true;
  242. }
  243. else { Console.SetCursorPosition(30, 1); Console.WriteLine("NIE"); miejsce = false; }
  244.  
  245. Console.Write("Ukończony 26 rok życia: ");
  246. if (Console.ReadKey().Key == ConsoleKey.Enter)
  247. {
  248. Console.SetCursorPosition(25, 2);
  249. Console.WriteLine("TAK");
  250. wiek = true;
  251. }
  252. else { Console.SetCursorPosition(25, 2); Console.WriteLine("NIE"); wiek = false; }
  253. //OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO
  254.  
  255. sklEmeryt = Math.Round(pensja * 0.0976, 2);
  256. sklRent = Math.Round(pensja * 0.015, 2);
  257. sklChor = Math.Round(pensja * 0.0245, 2);
  258.  
  259. pensjaBruttoPomniejszona = Math.Round(pensja - (sklEmeryt + sklRent + sklChor), 2); //składki socjalne
  260. sklZdrow = Math.Round(pensjaBruttoPomniejszona * 0.09, 2); // ubezpieczenie zdrowotne
  261.  
  262. if (miejsce == true) { wynagordzeniePomniejszone = Math.Round(pensjaBruttoPomniejszona - 250); }
  263. else wynagordzeniePomniejszone = Math.Round(pensjaBruttoPomniejszona - 300);
  264.  
  265. if (wynagordzeniePomniejszone * 12 < 85528) { podstawaPodatekDochodowy = Math.Round(wynagordzeniePomniejszone * 0.17, 2); } //PRÓG PODATKOWY
  266. else podstawaPodatekDochodowy = Math.Round(wynagordzeniePomniejszone * 0.17, 2);
  267.  
  268. podstawaPodatekDochodowy -= 43.76;
  269.  
  270. skladkaZdrowotna775 = Math.Round(pensjaBruttoPomniejszona * 0.0775, 2);
  271.  
  272. podatekDochodowy = Math.Round(podstawaPodatekDochodowy - skladkaZdrowotna775);
  273.  
  274. if (wiek == true) { pensjaNetto = (pensjaBruttoPomniejszona - sklZdrow - podatekDochodowy); }
  275. else pensjaNetto = (pensjaBruttoPomniejszona - sklZdrow);
  276.  
  277. Console.WriteLine("\n==========================================================");
  278. Console.WriteLine($"Koszt pracodawcy: {Math.Round(pensja + (pensja * 0.0976) + (pensja * 0.065) + (pensja * 0.0167) + (pensja * 0.0245) + (pensja * 0.001), 2)}");
  279. Console.WriteLine("Pensja brutto: " + pensja);
  280. Console.WriteLine("Składka na ubezpieczenie emerytalne: " + sklEmeryt);
  281. Console.WriteLine("Składka na ubezpieczenie rentowe: " + sklRent);
  282. Console.WriteLine("Składka na ubezpieczenie chorobowe: " + sklChor);
  283. Console.WriteLine("Składka na ubezpieczenie zdrowotne: " + sklZdrow);
  284. if (wiek == true) { Console.WriteLine("Podatek dochodowy: " + podatekDochodowy); }
  285. else Console.WriteLine("Podatek dochodowy: 0");
  286. Console.WriteLine("Pensja netto (na rękę): " + pensjaNetto);
  287. Console.WriteLine("==========================================================\n");
  288. Console.WriteLine("Naciśniej dowolny przycisk aby wrócić do menu.");
  289. Console.ReadKey();
  290. }
  291. }
  292. }
  293.  
  294. class sql
  295. {
  296. protected double GodzinyZliczone = 0;
  297. protected string sprawdzenie = "";
  298.  
  299. protected void ZapisDoBazy(int id, double godziny)
  300. {
  301. using (var baza = new NpgsqlConnection("Server=localhost; Username=postgres;Database=postgres;Port=5432;SSLMode=Prefer"))
  302. {
  303.  
  304. baza.Open();
  305.  
  306. using (var command = new NpgsqlCommand("select * from pracownicy where id_pracownika = @n", baza))
  307. {
  308.  
  309. command.Parameters.AddWithValue("n", id);
  310. var reader = command.ExecuteReader();
  311.  
  312.  
  313. while (reader.Read())
  314. {
  315. GodzinyZliczone = reader.GetDouble(3);
  316. }
  317.  
  318. }
  319. baza.Close();
  320. baza.Open();
  321.  
  322. using (var command = new NpgsqlCommand("UPDATE pracownicy SET ilosc_godzin_przepracowanych = @q WHERE id_pracownika = @n", baza))
  323. {
  324. command.Parameters.AddWithValue("n", id);
  325. command.Parameters.AddWithValue("q", godziny+GodzinyZliczone);
  326.  
  327. int nRows = command.ExecuteNonQuery();
  328. }
  329.  
  330.  
  331. }
  332.  
  333. }
  334. protected void WczytanieGodzin(int id)
  335. {
  336. using (var baza = new NpgsqlConnection("Server=localhost; Username=postgres;Database=postgres;Port=5432;SSLMode=Prefer"))
  337. {
  338.  
  339. baza.Open();
  340.  
  341. using (var command = new NpgsqlCommand("select * from pracownicy where id_pracownika = @n", baza))
  342. {
  343. command.Parameters.AddWithValue("n", id);
  344.  
  345. var reader = command.ExecuteReader();
  346.  
  347.  
  348. while (reader.Read())
  349. {
  350. GodzinyZliczone = reader.GetDouble(3);
  351. }
  352. }
  353. }
  354. }
  355. protected void SprawdzenieCzyJest(int id)
  356. {
  357. using (var baza = new NpgsqlConnection("Server=localhost; Username=postgres;Database=postgres;Port=5432;SSLMode=Prefer"))
  358. {
  359.  
  360. baza.Open();
  361.  
  362. using (var command = new NpgsqlCommand("SELECT id_pracownika FROM pracownicy", baza))
  363. {
  364.  
  365. var reader = command.ExecuteReader();
  366. while (reader.Read())
  367. {
  368. if (reader.GetInt32(0) == id)
  369. {
  370. sprawdzenie = "T";
  371. break;
  372. }
  373. else
  374. {
  375. sprawdzenie = "F";
  376. }
  377.  
  378.  
  379. }
  380. }
  381. }
  382.  
  383. }
  384. }
  385. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement