Guest User

Untitled

a guest
Jan 7th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.77 KB | None | 0 0
  1. private void setTeacherTable1(){
  2. //Sets Teacher Table to preselected class
  3.  
  4. TeacherScreen ts = new TeacherScreen();
  5.  
  6. try {
  7. String ncc1 = classroomCon1.getText();
  8. String sql = "select * from "+ncc1+"";
  9.  
  10. pst = conn.prepareStatement(sql);
  11. rs = pst.executeQuery();
  12. ts.teacherTable1.setModel(DbUtils.resultSetToTableModel(rs));
  13.  
  14. rs.close();
  15. pst.close();
  16. }
  17. catch (Exception e){
  18. JOptionPane.showMessageDialog(null, e);
  19. }
  20.  
  21. }
  22.  
  23. private void login(){
  24.  
  25. loginDatabase();
  26.  
  27. if (usernameCon1.getText().matches(Usr1.getText()) && passwordCon1.getText().matches(Pass1.getText()) && positionCon1.getText().equals("Administrator")){
  28.  
  29. Admin();
  30. usernameCon1.setText("");
  31. passwordCon1.setText("");
  32. positionCon1.setText("");
  33. Usr1.setText("");
  34. Pass1.setText("");
  35. systemExit();
  36.  
  37. }
  38.  
  39. else if (usernameCon1.getText().matches(Usr1.getText()) && passwordCon1.getText().matches(Pass1.getText()) && positionCon1.getText().equals("Manager")){
  40.  
  41. manager();
  42. usernameCon1.setText("");
  43. passwordCon1.setText("");
  44. positionCon1.setText("");
  45. Usr1.setText("");
  46. Pass1.setText("");
  47. systemExit();
  48.  
  49. }
  50.  
  51. else if (usernameCon1.getText().matches(Usr1.getText()) && passwordCon1.getText().matches(Pass1.getText()) && positionCon1.getText().equals("Teacher")){
  52.  
  53. teacher();
  54. usernameCon1.setText("");
  55. passwordCon1.setText("");
  56. positionCon1.setText("");
  57. Usr1.setText("");
  58. Pass1.setText("");
  59. setTeacherTable1();
  60. closeLogin();
  61.  
  62. }
  63.  
  64. else {
  65.  
  66. JOptionPane.showMessageDialog(null, "Invalid Login", "Invalid Login", JOptionPane.ERROR_MESSAGE);
  67. Usr1.requestFocus();
  68.  
  69. }
  70.  
  71. }
  72.  
  73. private void loginDatabase(){
  74. //Checks to see if Login is Administrator and then sends him to his respective location
  75.  
  76. String userName1 = Usr1.getText();
  77. String passWord1 = Pass1.getText();
  78.  
  79. try{
  80. String query1 = "select * from LoginManager where Username='"+userName1+"' and Password='"+passWord1+"'";
  81. PreparedStatement pst1 = conn.prepareStatement(query1);
  82. ResultSet rs1 = pst1.executeQuery();
  83.  
  84. if (rs1.next()){
  85.  
  86. String add1 = rs1.getString("Username");
  87. usernameCon1.setText(add1);
  88.  
  89. String add2 = rs1.getString("Password");
  90. passwordCon1.setText(add2);
  91.  
  92. String add3 = rs1.getString("Position");
  93. positionCon1.setText(add3);
  94.  
  95. String add4 = rs1.getString("Classroom");
  96. classroomCon1.setText(add4);
  97.  
  98. }
  99.  
  100. pst1.close();
  101. rs1.close();
  102.  
  103. }catch(Exception e){
  104. JOptionPane.showMessageDialog(null, e);
  105. }
  106.  
  107. }
Add Comment
Please, Sign In to add comment