Advertisement
Guest User

Untitled

a guest
Apr 7th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.92 KB | None | 0 0
  1. package abdfx2;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.ResultSet;
  6. import java.sql.ResultSetMetaData;
  7. import java.sql.SQLException;
  8. import java.sql.Statement;
  9. import java.util.regex.Pattern;
  10.  
  11. import javafx.application.Application;
  12. import javafx.geometry.Pos;
  13. import javafx.scene.Scene;
  14. import javafx.scene.control.Button;
  15. import javafx.scene.control.Label;
  16. import javafx.scene.control.ScrollPane;
  17. import javafx.scene.control.TextField;
  18. import javafx.scene.layout.GridPane;
  19. import javafx.scene.layout.HBox;
  20. import javafx.scene.layout.VBox;
  21. import javafx.stage.Stage;
  22.  
  23. public class Przychodnia extends Application {
  24.  
  25. Connection con;
  26. int kolumny;
  27. public void start(Stage stage) throws Exception {
  28.  
  29. Label wynik= new Label("Polaczono z bd");
  30. Label err1= new Label("Blad polaczenia z bd");
  31. Label err2= new Label("Blad sterownika");
  32. String lekarz= "select nazwisko, specjalizacja, nr_pokoju from lekarz";
  33. Label pacjent= new Label("select p.nazwisko");
  34. TextField tf= new TextField();
  35. // Label spisLekarzy;
  36.  
  37.  
  38. GridPane okno= new GridPane();
  39. ScrollPane Sp = new ScrollPane();
  40. Sp.setPrefSize(400, 400);
  41. VBox lewy=new VBox();
  42. //lewy.setMinWidth(200);
  43. lewy.setAlignment(Pos.TOP_LEFT);
  44. lewy.setMinWidth(200);
  45. okno.add(lewy, 0, 0, 1, 3);
  46. HBox prawy= new HBox();
  47. prawy.setMinWidth(200);
  48. prawy.setAlignment(Pos.TOP_LEFT);
  49. Sp.setContent(prawy);
  50. okno.add(prawy,0, 4, 1, 4);
  51. Button polaczenie= new Button("Polacz z baza");
  52. polaczenie.setMinSize(200, 30);
  53. Button lekarze= new Button("Sprawdz lekarzy");
  54. lekarze.setMinSize(200, 30);
  55. Button wizyty= new Button("Znajdz");
  56. Button szukajka= new Button("Szukaj wizyte");
  57. szukajka.setMinSize(200, 30);
  58. wizyty.setMinSize(200, 30);
  59. try {
  60. Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
  61. con = DriverManager.getConnection("jdbc:sqlserver://"+
  62. "153.19.7.13:1401;databaseName=mchudzinski;"+
  63. "user=mchudzinski;password=253748;");
  64. Statement zap= con.createStatement();
  65. String res = "";
  66. ResultSet wynik_zapytania = zap.executeQuery(lekarz);
  67. ResultSetMetaData ile_kol= wynik_zapytania.getMetaData();
  68. kolumny= ile_kol.getColumnCount();
  69.  
  70. zap.close();
  71. con.close();
  72. }
  73. catch(SQLException error_polaczenie){}
  74. catch(ClassNotFoundException error_sterownik) {}
  75. VBox[] vBoxes=new VBox[kolumny];
  76. for (int i=0;i<vBoxes.length;i++) {
  77. vBoxes[i]= new VBox();
  78. vBoxes[i].setPrefSize(200, 200);
  79. }
  80.  
  81. lewy.getChildren().addAll(polaczenie, lekarze, szukajka);
  82. szukajka.setOnAction(e->{
  83. prawy.getChildren().clear();
  84. okno.getChildren().remove(Sp);
  85. okno.add(Sp, 1, 0, 1, 1);
  86. prawy.getChildren().addAll(tf,wizyty);
  87.  
  88. });
  89. wizyty.setOnAction(e -> {
  90. prawy.getChildren().clear();
  91. okno.getChildren().remove(Sp);
  92. okno.add(Sp, 1, 0, 1, 1);
  93. try {
  94. Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
  95. con = DriverManager.getConnection("jdbc:sqlserver://"+
  96. "153.19.7.13:1401;databaseName=mchudzinski;"+
  97. "user=mchudzinski;password=253748;");
  98. Statement zap= con.createStatement();
  99. String nazw="SELECT pacjent.nazwisko, wizyta.data_wizyty, lekarz.nazwisko, lekarz.specjalizacja, lekarz.nr_pokoju FROM wizyta LEFT JOIN pacjent on wizyta.id_pacjent = pacjent.id_pacjent LEFT JOIN lekarz on wizyta.id_lekarz = lekarz.id_lekarz where pacjent.nazwisko='"+tf.getText()+"'";
  100. ResultSet wynik_zapytania = zap.executeQuery(nazw);
  101. int i=1;
  102. String spr="";
  103. while(wynik_zapytania.next()) {
  104. spr=spr+wynik_zapytania.getString(1)+" "+wynik_zapytania.getString(2)+" "+wynik_zapytania.getString(3)
  105. +" "+wynik_zapytania.getString(4)+" "+wynik_zapytania.getString(5)+"\n";
  106.  
  107. i++;
  108. }
  109. Label lab= new Label(spr);
  110. prawy.getChildren().addAll(lab);
  111. zap.close();
  112. con.close();
  113.  
  114. }
  115. catch(SQLException error_polaczenie){
  116. System.out.println("pol");
  117. }
  118. catch(ClassNotFoundException error_sterownik) {}
  119.  
  120. });
  121. polaczenie.setOnAction(e-> {
  122. prawy.getChildren().clear();
  123. okno.getChildren().remove(Sp);
  124. okno.add(Sp, 1, 0, 1, 1);
  125.  
  126. try{
  127. Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
  128. con = DriverManager.getConnection("jdbc:sqlserver://"+
  129. "153.19.7.13:1401;databaseName=mchudzinski;"+
  130. "user=mchudzinski;password=253748;");
  131. prawy.getChildren().add(wynik);
  132. }
  133. catch(SQLException error_polaczenie) {
  134. prawy.getChildren().add(err1);
  135. }
  136. catch(ClassNotFoundException error_sterownik) {
  137. prawy.getChildren().add(err2);
  138.  
  139. }
  140.  
  141. });
  142. lekarze.setOnAction(e->{
  143. prawy.getChildren().clear();
  144. okno.getChildren().remove(Sp);
  145. prawy.getChildren().addAll(vBoxes);
  146. okno.add(Sp, 1, 0, 1, 1);
  147. for(int i=0;i<vBoxes.length;i++) {
  148. vBoxes[i].getChildren().clear();
  149. }
  150. try {
  151. Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
  152. con = DriverManager.getConnection("jdbc:sqlserver://"+
  153. "153.19.7.13:1401;databaseName=mchudzinski;"+
  154. "user=mchudzinski;password=253748;");
  155. Statement zap= con.createStatement();
  156.  
  157. ResultSet wynik_zapytania = zap.executeQuery(lekarz);
  158. while(wynik_zapytania.next())
  159. {
  160. int i=1, j;
  161. for(j=0;j<vBoxes.length;j++) {
  162. Label col=new Label(wynik_zapytania.getString(i));
  163. vBoxes[j].getChildren().add(col);
  164. i++;
  165. }
  166. }
  167.  
  168.  
  169. zap.close();
  170. con.close();
  171. }
  172. catch(SQLException error_polaczenie){}
  173. catch(ClassNotFoundException error_sterownik) {}
  174. });
  175.  
  176. Scene scena= new Scene(okno, 800, 600);
  177. stage.setScene(scena);
  178. stage.show();
  179.  
  180. }
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192. public static void main(String[] args) {
  193. // TODO Auto-generated method stub
  194. Application.launch(args);
  195. }
  196.  
  197. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement