Advertisement
Guest User

Untitled

a guest
Apr 17th, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.11 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 MySql.Data.MySqlClient;
  7.  
  8. namespace Wage_Calculator_Application
  9. {
  10. class Program
  11. {
  12.  
  13. static double rate = 0;
  14. static double difference = 0;
  15. static double gross = 0;
  16. static double normalwage = 0;
  17. static double overtime = 0;
  18. static double overtimetwo = 0;
  19. static double tax = 0;
  20. static double NIN = 0;
  21. static double net = 0;
  22. static string job = "";
  23.  
  24. static private MySqlConnection connection;
  25. static private string server;
  26. static private string database;
  27. static private string uid;
  28. static private string password;
  29.  
  30.  
  31. static void Main(string[] args)
  32. {
  33. Boolean login = true;
  34. string username = "admin"; // Setting a Username
  35. string password = "secure123"; // Setting a password
  36. Initialise();
  37.  
  38. while (login == true)
  39. {
  40.  
  41. Console.WriteLine("Please login:");
  42. Console.WriteLine("Username:"); // Asking for the user name
  43. string username2 = Console.ReadLine();
  44.  
  45. if (username2 == username) // if what they wrote matches what is stored in "username"
  46. {
  47. Console.Clear();
  48. Console.WriteLine("Successful! Please enter the Password"); // if it was correct, it proceeds to this.
  49. string password2 = Console.ReadLine();
  50.  
  51. if (password2 == password) // checks if the password
  52. {
  53.  
  54. Inputs(); // switches to the Input method, deciding what to do with wage slips
  55. break; // ends the loop
  56.  
  57. }
  58. else
  59. {
  60.  
  61. Console.WriteLine("Wrong Password!"); // just displays wrong password
  62.  
  63. }
  64.  
  65. }
  66. else
  67. {
  68.  
  69. Console.WriteLine("Invalid Username, please try again"); // displays if the username wasnt fount
  70.  
  71. }
  72.  
  73. }
  74.  
  75. }
  76. static void Initialise() // connects to the database
  77. {
  78.  
  79. server = "localhost"; // sql host
  80. database = "wagecalculator"; // database
  81. uid = "root"; // sql name
  82. password = ""; // sql password
  83. string connectionString;
  84. connectionString = "SERVER=" + server + ";" + "DATABASE=" + database + ";" + "UID=" + uid + ";" + "PASSWORD=" + password + ";"; // connection to the Database
  85. connection = new MySqlConnection(connectionString);
  86.  
  87. }
  88. static void Inputs()
  89. {
  90. Boolean options = true; // creates a boolean called options, (booleans can only be true or false)
  91.  
  92. while (options == true)
  93. {
  94. Console.Clear();
  95. Console.WriteLine("Welcome back, admin");
  96. Console.WriteLine("Please select an option from the list below");
  97. Console.WriteLine("---------------------------"); // list options that the user can do once logged in
  98. Console.WriteLine("A) Create a Wage Slip");
  99. Console.WriteLine("B) Help");
  100. Console.WriteLine("C) Exit");
  101. string choice = Console.ReadLine();
  102. choice = choice.ToUpper();
  103.  
  104. if (choice == "A")
  105. {
  106.  
  107. createWageSlip(); // switches to the createWageSlip method
  108.  
  109. }
  110. if (choice == "B")
  111. {
  112.  
  113. WageSlipHelp(); // switches to the WageSlipHelp method
  114.  
  115. }
  116. if (choice == "C")
  117. {
  118.  
  119. Console.WriteLine("Closing application..."); // if exiting, it will close the aplication.
  120. Console.WriteLine("Goodbye!");
  121. options = false;
  122.  
  123. }
  124. else
  125. {
  126.  
  127. Console.WriteLine("Please pick an option.."); // if A,B,C wasnt picked, then this shows.
  128. Console.ReadLine();
  129.  
  130. }
  131.  
  132. }
  133.  
  134. }
  135.  
  136. static void createWageSlip()
  137. {
  138.  
  139.  
  140. Console.Clear();
  141. Console.WriteLine("Please write the First Name of the person");
  142. string first_name = Console.ReadLine(); // writing the person first name and stores it in first_name
  143. Console.WriteLine("Please write the Last Name of the person");
  144. string last_name = Console.ReadLine(); // writing the person last name and stores it in last_name
  145. Console.WriteLine("Thank you, please enter their NI");
  146. string NI = Console.ReadLine(); // writing the persons NI and stores it in NI
  147. Console.WriteLine("How many hours have they worked in the past week?");
  148. int hoursweekly = int.Parse(Console.ReadLine()); // writing the hours worked of that person and stores it in hoursweekly
  149. Console.Clear(); // Clears the console
  150. Console.WriteLine("What is their Job?"); // Lists what job they do
  151. Console.WriteLine("Please choose one.");
  152. Console.WriteLine("A) Programmer");
  153. Console.WriteLine("B) Administrator/Clerk");
  154. Console.WriteLine("C) Project Leader/Manager");
  155. Console.WriteLine("D) Manual");
  156. string userchoice = Console.ReadLine();
  157. userchoice = userchoice.ToUpper(); // gets what they picked and puts it to uppercase
  158.  
  159. if (userchoice == "A") // if choose A then do this
  160. {
  161.  
  162. rate = 12.03; // set rate as 12.03
  163. job = "Programmer"; // set job as Programmer
  164.  
  165.  
  166. }
  167. else if (userchoice == "B") // if choose B then do this
  168. {
  169.  
  170. rate = 8.07; // set rate as 8.07
  171. job = "Administrator / Clerk"; // set job as Administrator / Clerk
  172.  
  173.  
  174. }
  175. else if (userchoice == "C") // if choose C then do this
  176. {
  177.  
  178. rate = 22.54; // set rate as 22.54
  179. job = "Project Leader / Manager"; // set job as Project Leader / Manager
  180.  
  181. }
  182. else if (userchoice == "D") // if choose D then do this
  183. {
  184.  
  185. Console.WriteLine("Please enter your rate"); // telling them to enter their own rate
  186. rate = double.Parse(Console.ReadLine());
  187. job = "Manual Entry";
  188.  
  189. }
  190. else // else just display this
  191. {
  192.  
  193. Console.WriteLine("Sorry, please try again");
  194.  
  195. }
  196.  
  197. if (hoursweekly > 40) // if hoursweekly is over 40
  198. {
  199.  
  200. if (hoursweekly > 50) // if hoursweekly is over 50
  201. {
  202.  
  203. difference = hoursweekly - 50;
  204. normalwage = 40 * rate;
  205. overtime = 10 * (rate * 1.5);
  206. overtimetwo = difference * (rate * 2);
  207. gross = normalwage + overtime + overtimetwo;
  208.  
  209. }
  210. else
  211. {
  212.  
  213. difference = hoursweekly - 40;
  214. normalwage = 40 * rate;
  215. overtime = difference * (rate * 1.5);
  216. gross = normalwage + overtime;
  217.  
  218. }
  219.  
  220. }
  221. else
  222. {
  223.  
  224. gross = hoursweekly * rate; // else it will times hoursweekly and rate together to equal the gross.
  225.  
  226. }
  227. double oovertime = (overtime + overtimetwo); // adds whatever is stored into overtime and overtimetwo together.
  228.  
  229. tax = gross * 0.25; // gets the gross and times it by 0.25 for the tax
  230. 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
  231. net = gross - tax - NIN; // then take away gross, tax and NIN from eachother for their NET
  232.  
  233. Console.Clear();
  234. Console.WriteLine("► Wage Calculator ◄");
  235. Console.WriteLine("Name » " + first_name + " " + last_name);
  236. Console.WriteLine("National Insurance » " + NI);
  237. Console.WriteLine("Hours Worked » " + hoursweekly);
  238. Console.WriteLine("Job » " + job);
  239. Console.WriteLine("Payment » £" + net); // This just lists everything out
  240.  
  241. 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"
  242. connection.Open(); // this then connects to the SQL Server
  243. MySqlCommand cmd = new MySqlCommand(query, connection); // then this runs the command which is stored into "query"
  244. cmd.ExecuteNonQuery();
  245. connection.Close(); // then closes the connection to the SQL Server
  246. Console.WriteLine("\nRecord Added - Press enter"); // displays this once done
  247.  
  248. Console.ReadLine();
  249.  
  250. }
  251. static void WageSlipHelp()
  252. {
  253.  
  254. Console.Clear();
  255. Console.WriteLine("» Wage Calculator Help «");
  256. 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.");
  257.  
  258. Console.ReadLine(); // this just displays help, on what to do in the program
  259.  
  260. }
  261. }
  262. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement