Advertisement
Guest User

Untitled

a guest
Jan 17th, 2020
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.97 KB | None | 0 0
  1. package hy360;
  2.  
  3. import java.sql.*;
  4.  
  5. import javax.swing.JFrame;
  6. import javax.swing.JOptionPane;
  7.  
  8. public class Main {
  9. static int pas_id = 1010;
  10. static int cas_id = 2010;
  11. static int pts_id = 3010;
  12. static int cts_id = 4010;
  13. public static final String[] staff = {"Μόνιμος Διοικητικός Υπάλληλος", "Συμβασιούχος Διοικητικός Υπάλληλος", "Μόνιμο Μέλος Διδακτικού Προσωπικού", "Συμβασιούχο Μέλος Διαδακτικού Προσωπικού"};
  14.  
  15. public static void add_staff() throws ClassNotFoundException, SQLException {
  16.  
  17. String FirstName = JOptionPane.showInputDialog("Όνομα: ");
  18. String LastName = JOptionPane.showInputDialog("Επίθετο: ");
  19. String MaritalStatus = JOptionPane.showInputDialog("Συνολικά μέλη οικογένειας (π.χ.άγαμος 1 μελος):");
  20. String PersonelCategory;
  21. String Department = JOptionPane.showInputDialog("Τμήμα: ");
  22. String FirstWorkDay = JOptionPane.showInputDialog("Ημερομηνία πρόσληψης (ΗΗ/ΜΜ/ΧΧΧΧ): ") ;
  23. String Address = JOptionPane.showInputDialog("Διεύθυνση: ");
  24. String PhoneNumber = JOptionPane.showInputDialog("Αριθμός Τηλεφώνου: ");
  25. String BankAccount = JOptionPane.showInputDialog("Αριθμός Λογαριασμού: ") ;
  26. String BankName = JOptionPane.showInputDialog("Όνομα τράπεζας: ");
  27. String Script1;
  28. String Script2;
  29. JFrame frame = new JFrame();
  30. String s = (String) JOptionPane.showInputDialog(frame, "Σε ποιά μισθολογική κατηγορία ανήκει ο υπάλληλος;", "Επιλογή μισθολογικής κατηγορίας.",JOptionPane.QUESTION_MESSAGE, null, staff, staff[0]);
  31. Class.forName("com.mysql.cj.jdbc.Driver");
  32. String mysqlConnUrl = "jdbc:mysql://localhost:3306/employees";
  33. String mysqlUserName = "root";
  34. String mysqlPassword = "";
  35. Connection conn = DriverManager.getConnection(mysqlConnUrl, mysqlUserName , mysqlPassword);
  36. Statement st = conn.createStatement();
  37.  
  38. if(s.equals("Μόνιμος Διοικητικός Υπάλληλος")) {
  39. PersonelCategory = "P.A.S."; // = Permanent Administrative Staff
  40. Script1 = "insert into employees values(" + "'" + pas_id + "', " + "'" + FirstName + "', " + "'" + LastName + "', " + "'" + Integer.parseInt(MaritalStatus) + "', " + "'" + PersonelCategory + "', " + "'" + Department + "', "
  41. + "'" + FirstWorkDay + "', " + "'" + Address + "', " + "'" + PhoneNumber + "', " + "'" + BankAccount + "', " + "'" + BankName + "')";
  42. System.out.println(Script1);
  43. st.executeUpdate(Script1);
  44. conn.close();
  45. mysqlConnUrl = "jdbc:mysql://localhost:3306/payroll_categories";
  46. conn = DriverManager.getConnection(mysqlConnUrl, mysqlUserName , mysqlPassword);
  47. st = conn.createStatement();
  48. Script2 = "insert into permanent_administrative_staff values(" + "'" + pas_id + "'," + "'" + 2000 + "')";
  49. System.out.println(Script2);
  50. st.executeUpdate(Script2);
  51. conn.close();
  52. pas_id++;
  53. }
  54. else if(s.equals("Συμβασιούχος Διοικητικός Υπάλληλος")) {
  55. PersonelCategory = "C.A.S."; // = Contracted Administrative Staff
  56. String ContractExpiry = JOptionPane.showInputDialog("Ημερομηνία λήξης σύμβασης (ΗΗ/ΜΜ/ΧΧΧΧ):");
  57. Script1 = "insert into employees values(" + "'" + pas_id + "', " + "'" + FirstName + "', " + "'" + LastName + "', " + "'" + Integer.parseInt(MaritalStatus) + "', " + "'" + PersonelCategory + "', " + "'" + Department + "', "
  58. + "'" + FirstWorkDay + "', " + "'" + Address + "', " + "'" + PhoneNumber + "', " + "'" + BankAccount + "', " + "'" + BankName + "')";
  59. System.out.println(Script1);
  60. st.executeUpdate(Script1);
  61. conn.close();
  62. mysqlConnUrl = "jdbc:mysql://localhost:3306/payroll_categories";
  63. conn = DriverManager.getConnection(mysqlConnUrl, mysqlUserName , mysqlPassword);
  64. st = conn.createStatement();
  65. Script2 = "insert into contracted_administrative_staff values(" + "'" + cas_id + "', " + "'" + FirstWorkDay + "', " + "'" + ContractExpiry + "'," +"'" + 2000 +"')";
  66. System.out.println(Script2);
  67. st.executeUpdate(Script2);
  68. conn.close();
  69. cas_id++;
  70. }
  71. else if(s.equals("Μόνιμο Μέλος Διδακτικού Προσωπικού")) {
  72. PersonelCategory = "P.T.S."; // = Permanent Teaching Staff
  73. Script1 = "insert into employees values(" + "'" + pts_id + "', " + "'" + FirstName + "', " + "'" + LastName + "', " + "'" + Integer.parseInt(MaritalStatus) + "', " + "'" + PersonelCategory + "', " + "'" + Department + "', "
  74. + "'" + FirstWorkDay + "', " + "'" + Address + "', " + "'" + PhoneNumber + "', " + "'" + BankAccount + "', " + "'" + BankName + "')";
  75. System.out.println(Script1);
  76. st.executeUpdate(Script1);
  77. conn.close();
  78. mysqlConnUrl = "jdbc:mysql://localhost:3306/payroll_categories";
  79. conn = DriverManager.getConnection(mysqlConnUrl, mysqlUserName , mysqlPassword);
  80. st = conn.createStatement();
  81. Script2 = "insert into permanent_teaching_staff values(" + "'" + pts_id + "'," + "'" + 3000 + "')";
  82. System.out.println(Script2);
  83. st.executeUpdate(Script2);
  84. conn.close();
  85. pts_id++;
  86. }
  87. else if(s.equals("Συμβασιούχο Μέλος Διαδακτικού Προσωπικού")) {
  88. PersonelCategory = "C.T.S."; // Contracted Teaching Staff
  89. String ContractExpiry = JOptionPane.showInputDialog("Ημερομηνία λήξης σύμβασης (ΗΗ/ΜΜ/ΧΧΧΧ):");
  90. Script1 = "insert into employees values(" + "'" + cts_id + "', " + "'" + FirstName + "', " + "'" + LastName + "', " + "'" + Integer.parseInt(MaritalStatus) + "', " + "'" + PersonelCategory + "', " + "'" + Department + "', "
  91. + "'" + FirstWorkDay + "', " + "'" + Address + "', " + "'" + PhoneNumber + "', " + "'" + BankAccount + "', " + "'" + BankName + "')";
  92. System.out.println(Script1);
  93. st.executeUpdate(Script1);
  94. conn.close();
  95. mysqlConnUrl = "jdbc:mysql://localhost:3306/payroll_categories";
  96. conn = DriverManager.getConnection(mysqlConnUrl, mysqlUserName , mysqlPassword);
  97. st = conn.createStatement();
  98. Script2 = "insert into contracted_teaching_staff values(" + "'" + cts_id + "', " + "'" + FirstWorkDay + "', " + "'" + ContractExpiry + "'," + "'" + 3000 +"')";
  99. System.out.println(Script2);
  100. st.executeUpdate(Script2);
  101. conn.close();
  102. cts_id++;
  103. }
  104.  
  105. }
  106.  
  107. public static void contract_renewal() {
  108. int id;
  109. String FName = JOptionPane.showInputDialog("Όνομα: ");
  110. String LName = JOptionPane.showInputDialog("Επίθετο: ");
  111. String FirstDay = JOptionPane.showInputDialog("Πρώτη ημέρα σύμβασης (ΗΗ/ΜΜ/ΧΧΧΧ): ");
  112. String LastDay = JOptionPane.showInputDialog("Τελευταία μέρα σύμβασης (ΗΗ/ΜΜ/ΧΧΧΧ): ");
  113.  
  114.  
  115. }
  116. public static void main(String[] lal) throws ClassNotFoundException, SQLException {
  117. add_staff();
  118. add_staff();
  119. add_staff();
  120. add_staff();
  121. }
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement