Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using Npgsql;
- using System.Text;
- using System.Threading.Tasks;
- namespace Projekt2
- {
- class Program
- {
- static void Main(string[] args)
- {
- GlownaFunkcja CzasPracy = new GlownaFunkcja();
- CzasPracy.Funkcja();
- Console.ReadKey();
- }
- }
- class GlownaFunkcja : Menu
- {
- public void Funkcja()
- {
- Rysuj();
- Poruszanie();
- }
- }
- class Menu : WorkTime
- {
- protected static ConsoleKeyInfo Przycisk;
- protected int x = 10;
- protected int y = 1;
- public void Rysuj()
- {
- Console.WriteLine("----------------------------------");
- Console.WriteLine("| 1. Wejscie |");
- Console.WriteLine("| 2. Wyjscie |");
- Console.WriteLine("| 3. Zlicz pensje |");
- Console.WriteLine("----------------------------------");
- }
- public void Poruszanie()
- {
- do
- {
- Console.SetCursorPosition(x, y);
- Przycisk = Console.ReadKey(true);
- if (Przycisk.Key == ConsoleKey.DownArrow && y < 3)
- {
- y += 1;
- }
- if (Przycisk.Key == ConsoleKey.UpArrow && y > 1)
- {
- y -= 1;
- }
- if (Przycisk.Key == ConsoleKey.Enter)
- {
- if (y == 1)
- {
- Console.Clear();
- Wejscie();
- Console.Clear();
- Rysuj();
- }
- if (y == 2)
- {
- Console.Clear();
- Wyjscie();
- Console.Clear();
- Rysuj();
- }
- if (y == 3)
- {
- Console.Clear();
- Salary Pensja = new Salary();
- Pensja.Wynagrodzenie();
- Console.Clear();
- Rysuj();
- }
- }
- } while (Przycisk.Key != ConsoleKey.Escape);
- }
- }
- class WorkTime : sql
- {
- private int idWorker;
- DateTime[] wejscie = new DateTime[20];
- protected int[] pracuje = new int[20];
- DateTime[] wyjscie = new DateTime[20];
- public void Praca()
- {
- Wejscie();
- Console.ReadKey(); Console.Clear();
- Wyjscie();
- }
- public void Wejscie()
- {
- Console.Write("Podaj ID pracownika: ");
- int.TryParse(Console.ReadLine(),out idWorker);
- SprawdzenieCzyJest(idWorker);
- if (sprawdzenie == "F")
- {
- Console.WriteLine("Pracownika o tym ID nie ma w bazie!");
- }
- else if ( pracuje[idWorker] == 1 ) //Sprawdzenie czy już się odbił
- {
- Console.WriteLine("Już się zarejestrowałeś tego dnia");
- }
- else
- {
- wejscie[idWorker] = DateTime.Now;
- pracuje[idWorker] = 1;
- //String.Format("{0:HH.mm.ss}", dt);
- Console.WriteLine("Rejestracja pomyślna. Czas rejestracji: " + wejscie[idWorker]);
- }
- Console.ReadKey();
- }
- public void Wyjscie()
- {
- Console.Write("Podaj ID pracownika: ");
- int.TryParse(Console.ReadLine(), out idWorker);
- SprawdzenieCzyJest(idWorker);
- if (sprawdzenie == "F")
- {
- Console.WriteLine("Pracownika o tym ID nie ma w bazie!");
- }
- else if (pracuje[idWorker] == 0) //Sprawdzenie czy już się odbił
- {
- Console.WriteLine("Nie Zarejestrowałeś się tego dnia");
- }
- else
- {
- wyjscie[idWorker] = DateTime.Now;
- pracuje[idWorker] = 0;
- Console.WriteLine("Wyrejestowanie pomyślne. Czas wyrejestrowania: " + wyjscie[idWorker]);
- TimeSpan result = wyjscie[idWorker] - wejscie[idWorker];
- Console.WriteLine("Byłeś w pracy: " + result);
- double godziny = result.TotalSeconds;
- ZapisDoBazy(idWorker, godziny);
- }
- Console.ReadKey();
- }
- }
- class Salary : WorkTime
- {
- private double sklEmeryt;
- private double sklRent;
- private double sklChor;
- private double sklZdrow;
- private double pensjaBruttoPomniejszona;
- private double wynagordzeniePomniejszone;
- private double podstawaPodatekDochodowy;
- private double skladkaZdrowotna775;
- private double podatekDochodowy;
- private double pensjaNetto;
- private bool miejsce;
- private bool wiek;
- private double godziny;
- private int id;
- private int stawka;
- private string komunikat;
- public void Wynagrodzenie()
- {
- Obliczenia(Dane());
- }
- private double Dane()
- {
- Console.Write("Podaj id pracownika: ");
- while (true)
- {
- komunikat = Console.ReadLine();
- if (int.TryParse(komunikat, out id))
- break;
- else
- Console.Write("Podaj liczbę! ");
- }
- SprawdzenieCzyJest(id);
- if (sprawdzenie == "T")
- {
- Console.Write("Podaj stawkę pracownika na godzinę brutto: ");
- while (true)
- {
- komunikat = Console.ReadLine();
- if (int.TryParse(komunikat, out stawka))
- break;
- else
- Console.Write("Podaj liczbę! ");
- }
- Console.Clear();
- WczytanieGodzin(id);
- godziny = GodzinyZliczone;
- return stawka * godziny;
- }
- else
- Console.WriteLine("Pracownika o tym ID nie ma w bazie!");
- Console.WriteLine("Naciśniej dowolny przycisk aby wrócić do menu.");
- Console.ReadKey();
- return 0;
- }
- private void Obliczenia(double pensja)
- {
- if (pensja != 0)
- {
- Console.WriteLine("Enter = tak, Dowolny klawisz = nie");
- //OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO
- Console.Write("Praca w miejscu zamieszkania: ");
- if (Console.ReadKey().Key == ConsoleKey.Enter)
- {
- Console.SetCursorPosition(30, 1);
- Console.WriteLine("TAK");
- miejsce = true;
- }
- else { Console.SetCursorPosition(30, 1); Console.WriteLine("NIE"); miejsce = false; }
- Console.Write("Ukończony 26 rok życia: ");
- if (Console.ReadKey().Key == ConsoleKey.Enter)
- {
- Console.SetCursorPosition(25, 2);
- Console.WriteLine("TAK");
- wiek = true;
- }
- else { Console.SetCursorPosition(25, 2); Console.WriteLine("NIE"); wiek = false; }
- //OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO
- sklEmeryt = Math.Round(pensja * 0.0976, 2);
- sklRent = Math.Round(pensja * 0.015, 2);
- sklChor = Math.Round(pensja * 0.0245, 2);
- pensjaBruttoPomniejszona = Math.Round(pensja - (sklEmeryt + sklRent + sklChor), 2); //składki socjalne
- sklZdrow = Math.Round(pensjaBruttoPomniejszona * 0.09, 2); // ubezpieczenie zdrowotne
- if (miejsce == true) { wynagordzeniePomniejszone = Math.Round(pensjaBruttoPomniejszona - 250); }
- else wynagordzeniePomniejszone = Math.Round(pensjaBruttoPomniejszona - 300);
- if (wynagordzeniePomniejszone * 12 < 85528) { podstawaPodatekDochodowy = Math.Round(wynagordzeniePomniejszone * 0.17, 2); } //PRÓG PODATKOWY
- else podstawaPodatekDochodowy = Math.Round(wynagordzeniePomniejszone * 0.17, 2);
- podstawaPodatekDochodowy -= 43.76;
- skladkaZdrowotna775 = Math.Round(pensjaBruttoPomniejszona * 0.0775, 2);
- podatekDochodowy = Math.Round(podstawaPodatekDochodowy - skladkaZdrowotna775);
- if (wiek == true) { pensjaNetto = (pensjaBruttoPomniejszona - sklZdrow - podatekDochodowy); }
- else pensjaNetto = (pensjaBruttoPomniejszona - sklZdrow);
- Console.WriteLine("\n==========================================================");
- Console.WriteLine($"Koszt pracodawcy: {Math.Round(pensja + (pensja * 0.0976) + (pensja * 0.065) + (pensja * 0.0167) + (pensja * 0.0245) + (pensja * 0.001), 2)}");
- Console.WriteLine("Pensja brutto: " + pensja);
- Console.WriteLine("Składka na ubezpieczenie emerytalne: " + sklEmeryt);
- Console.WriteLine("Składka na ubezpieczenie rentowe: " + sklRent);
- Console.WriteLine("Składka na ubezpieczenie chorobowe: " + sklChor);
- Console.WriteLine("Składka na ubezpieczenie zdrowotne: " + sklZdrow);
- if (wiek == true) { Console.WriteLine("Podatek dochodowy: " + podatekDochodowy); }
- else Console.WriteLine("Podatek dochodowy: 0");
- Console.WriteLine("Pensja netto (na rękę): " + pensjaNetto);
- Console.WriteLine("==========================================================\n");
- Console.WriteLine("Naciśniej dowolny przycisk aby wrócić do menu.");
- Console.ReadKey();
- }
- }
- }
- class sql
- {
- protected double GodzinyZliczone = 0;
- protected string sprawdzenie = "";
- protected void ZapisDoBazy(int id, double godziny)
- {
- using (var baza = new NpgsqlConnection("Server=localhost; Username=postgres;Database=postgres;Port=5432;SSLMode=Prefer"))
- {
- baza.Open();
- using (var command = new NpgsqlCommand("select * from pracownicy where id_pracownika = @n", baza))
- {
- command.Parameters.AddWithValue("n", id);
- var reader = command.ExecuteReader();
- while (reader.Read())
- {
- GodzinyZliczone = reader.GetDouble(3);
- }
- }
- baza.Close();
- baza.Open();
- using (var command = new NpgsqlCommand("UPDATE pracownicy SET ilosc_godzin_przepracowanych = @q WHERE id_pracownika = @n", baza))
- {
- command.Parameters.AddWithValue("n", id);
- command.Parameters.AddWithValue("q", godziny+GodzinyZliczone);
- int nRows = command.ExecuteNonQuery();
- }
- }
- }
- protected void WczytanieGodzin(int id)
- {
- using (var baza = new NpgsqlConnection("Server=localhost; Username=postgres;Database=postgres;Port=5432;SSLMode=Prefer"))
- {
- baza.Open();
- using (var command = new NpgsqlCommand("select * from pracownicy where id_pracownika = @n", baza))
- {
- command.Parameters.AddWithValue("n", id);
- var reader = command.ExecuteReader();
- while (reader.Read())
- {
- GodzinyZliczone = reader.GetDouble(3);
- }
- }
- }
- }
- protected void SprawdzenieCzyJest(int id)
- {
- using (var baza = new NpgsqlConnection("Server=localhost; Username=postgres;Database=postgres;Port=5432;SSLMode=Prefer"))
- {
- baza.Open();
- using (var command = new NpgsqlCommand("SELECT id_pracownika FROM pracownicy", baza))
- {
- var reader = command.ExecuteReader();
- while (reader.Read())
- {
- if (reader.GetInt32(0) == id)
- {
- sprawdzenie = "T";
- break;
- }
- else
- {
- sprawdzenie = "F";
- }
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement