Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using MySql.Data.MySqlClient;
- namespace Wage_Calculator_Application
- {
- class Program
- {
- static double rate = 0;
- static double difference = 0;
- static double gross = 0;
- static double normalwage = 0;
- static double overtime = 0;
- static double overtimetwo = 0;
- static double tax = 0;
- static double NIN = 0;
- static double net = 0;
- static string job = "";
- static private MySqlConnection connection;
- static private string server;
- static private string database;
- static private string uid;
- static private string password;
- static void Main(string[] args)
- {
- Boolean login = true;
- string username = "admin"; // Setting a Username
- string password = "secure123"; // Setting a password
- Initialise();
- while (login == true)
- {
- Console.WriteLine("Please login:");
- Console.WriteLine("Username:"); // Asking for the user name
- string username2 = Console.ReadLine();
- if (username2 == username) // if what they wrote matches what is stored in "username"
- {
- Console.Clear();
- Console.WriteLine("Successful! Please enter the Password"); // if it was correct, it proceeds to this.
- string password2 = Console.ReadLine();
- if (password2 == password) // checks if the password
- {
- Inputs(); // switches to the Input method, deciding what to do with wage slips
- break; // ends the loop
- }
- else
- {
- Console.WriteLine("Wrong Password!"); // just displays wrong password
- }
- }
- else
- {
- Console.WriteLine("Invalid Username, please try again"); // displays if the username wasnt fount
- }
- }
- }
- static void Initialise() // connects to the database
- {
- server = "localhost"; // sql host
- database = "wagecalculator"; // database
- uid = "root"; // sql name
- password = ""; // sql password
- string connectionString;
- connectionString = "SERVER=" + server + ";" + "DATABASE=" + database + ";" + "UID=" + uid + ";" + "PASSWORD=" + password + ";"; // connection to the Database
- connection = new MySqlConnection(connectionString);
- }
- static void Inputs()
- {
- Boolean options = true; // creates a boolean called options, (booleans can only be true or false)
- while (options == true)
- {
- Console.Clear();
- Console.WriteLine("Welcome back, admin");
- Console.WriteLine("Please select an option from the list below");
- Console.WriteLine("---------------------------"); // list options that the user can do once logged in
- Console.WriteLine("A) Create a Wage Slip");
- Console.WriteLine("B) Help");
- Console.WriteLine("C) Exit");
- string choice = Console.ReadLine();
- choice = choice.ToUpper();
- if (choice == "A")
- {
- createWageSlip(); // switches to the createWageSlip method
- }
- if (choice == "B")
- {
- WageSlipHelp(); // switches to the WageSlipHelp method
- }
- if (choice == "C")
- {
- Console.WriteLine("Closing application..."); // if exiting, it will close the aplication.
- Console.WriteLine("Goodbye!");
- options = false;
- }
- else
- {
- Console.WriteLine("Please pick an option.."); // if A,B,C wasnt picked, then this shows.
- Console.ReadLine();
- }
- }
- }
- static void createWageSlip()
- {
- Console.Clear();
- Console.WriteLine("Please write the First Name of the person");
- string first_name = Console.ReadLine(); // writing the person first name and stores it in first_name
- Console.WriteLine("Please write the Last Name of the person");
- string last_name = Console.ReadLine(); // writing the person last name and stores it in last_name
- Console.WriteLine("Thank you, please enter their NI");
- string NI = Console.ReadLine(); // writing the persons NI and stores it in NI
- Console.WriteLine("How many hours have they worked in the past week?");
- int hoursweekly = int.Parse(Console.ReadLine()); // writing the hours worked of that person and stores it in hoursweekly
- Console.Clear(); // Clears the console
- Console.WriteLine("What is their Job?"); // Lists what job they do
- Console.WriteLine("Please choose one.");
- Console.WriteLine("A) Programmer");
- Console.WriteLine("B) Administrator/Clerk");
- Console.WriteLine("C) Project Leader/Manager");
- Console.WriteLine("D) Manual");
- string userchoice = Console.ReadLine();
- userchoice = userchoice.ToUpper(); // gets what they picked and puts it to uppercase
- if (userchoice == "A") // if choose A then do this
- {
- rate = 12.03; // set rate as 12.03
- job = "Programmer"; // set job as Programmer
- }
- else if (userchoice == "B") // if choose B then do this
- {
- rate = 8.07; // set rate as 8.07
- job = "Administrator / Clerk"; // set job as Administrator / Clerk
- }
- else if (userchoice == "C") // if choose C then do this
- {
- rate = 22.54; // set rate as 22.54
- job = "Project Leader / Manager"; // set job as Project Leader / Manager
- }
- else if (userchoice == "D") // if choose D then do this
- {
- Console.WriteLine("Please enter your rate"); // telling them to enter their own rate
- rate = double.Parse(Console.ReadLine());
- job = "Manual Entry";
- }
- else // else just display this
- {
- Console.WriteLine("Sorry, please try again");
- }
- if (hoursweekly > 40) // if hoursweekly is over 40
- {
- if (hoursweekly > 50) // if hoursweekly is over 50
- {
- difference = hoursweekly - 50;
- normalwage = 40 * rate;
- overtime = 10 * (rate * 1.5);
- overtimetwo = difference * (rate * 2);
- gross = normalwage + overtime + overtimetwo;
- }
- else
- {
- difference = hoursweekly - 40;
- normalwage = 40 * rate;
- overtime = difference * (rate * 1.5);
- gross = normalwage + overtime;
- }
- }
- else
- {
- gross = hoursweekly * rate; // else it will times hoursweekly and rate together to equal the gross.
- }
- double oovertime = (overtime + overtimetwo); // adds whatever is stored into overtime and overtimetwo together.
- tax = gross * 0.25; // gets the gross and times it by 0.25 for the tax
- NIN = (gross - tax) * 0.11; // then take the tax off their gross, and times it by 0.11 and it will store it in the NIN
- net = gross - tax - NIN; // then take away gross, tax and NIN from eachother for their NET
- Console.Clear();
- Console.WriteLine("► Wage Calculator ◄");
- Console.WriteLine("Name » " + first_name + " " + last_name);
- Console.WriteLine("National Insurance » " + NI);
- Console.WriteLine("Hours Worked » " + hoursweekly);
- Console.WriteLine("Job » " + job);
- Console.WriteLine("Payment » £" + net); // This just lists everything out
- string query = "INSERT INTO workers VALUES(NULL, '" + first_name + "','" + last_name + "','" + NI + "','" + hoursweekly + "','" + job + "','" + net + "')"; // this gets the SQL code and puts it into the string "query"
- connection.Open(); // this then connects to the SQL Server
- MySqlCommand cmd = new MySqlCommand(query, connection); // then this runs the command which is stored into "query"
- cmd.ExecuteNonQuery();
- connection.Close(); // then closes the connection to the SQL Server
- Console.WriteLine("\nRecord Added - Press enter"); // displays this once done
- Console.ReadLine();
- }
- static void WageSlipHelp()
- {
- Console.Clear();
- Console.WriteLine("» Wage Calculator Help «");
- Console.WriteLine("\nCreating a Wage Slip » Once you're on the page for Creating a Wage Slip, you'll be asked the persons name. Enter their First name, press enter and then enter their last name, then hit Enter again. Once you've done this, it will then ask for their National Insurance Number, enter in carefully. Do not mess this up. After done, double check it. Once you're sure, it will then ask how many hours they've worked in that week. Enter the number of hours, and then it will ask for their job which will calculate their rate per hour, then it will calculate it and display it on screen.");
- Console.ReadLine(); // this just displays help, on what to do in the program
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement