Advertisement
Guest User

home

a guest
Jan 31st, 2019
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.36 KB | None | 0 0
  1. package application;
  2.  
  3. import javafx.scene.Scene;
  4.  
  5. import javafx.stage.Stage;
  6. import javafx.scene.text.Font;
  7. import javafx.scene.text.Text;
  8. import javafx.scene.control.Alert;
  9. import javafx.scene.control.Button;
  10. import javafx.scene.control.ButtonType;
  11. import javafx.scene.control.ChoiceBox;
  12. import javafx.scene.control.TextField;
  13. import javafx.scene.image.Image;
  14. import javafx.scene.image.ImageView;
  15. import javafx.scene.control.Alert.AlertType;
  16. import javafx.scene.Group;
  17. import javafx.scene.Node;
  18. import javafx.scene.layout.GridPane;
  19.  
  20. import java.io.FileInputStream;
  21. import java.io.FileNotFoundException;
  22. import java.sql.Connection;
  23. import java.sql.DriverManager;
  24. import java.sql.PreparedStatement;
  25. import java.sql.ResultSet;
  26. import java.sql.SQLException;
  27. import java.time.LocalDate;
  28. import java.time.LocalDateTime;
  29. import java.time.format.DateTimeFormatter;
  30.  
  31. import javafx.event.ActionEvent;
  32. import javafx.event.EventHandler;
  33. import javafx.geometry.Insets;
  34. import javafx.geometry.Pos;
  35.  
  36.  
  37. public class HomePage extends Stage{
  38.     public HomePage() {
  39.         Stage current = this;
  40.         Connection con;
  41.        
  42.        
  43.        
  44.         Button addPatient = new Button("Add Patient");
  45.         addPatient.setMinSize(100, 50);
  46.         Button search = new Button("Search");
  47.         search.setMinSize(100, 50);
  48.         Button missing = new Button("Missing Reports");
  49.         missing.setMinSize(100, 50);
  50.         Button upComing = new Button("Up Coming Sessions");
  51.         upComing.setMinSize(100, 50);
  52.         Button provider = new Button("Provider");
  53.         provider.setMinSize(100, 50);
  54.        
  55.        
  56.        
  57.         //Styling nodes  
  58.         addPatient.setStyle("-fx-background-color: pink; -fx-text-fill: black;");
  59.         search.setStyle("-fx-background-color: pink; -fx-text-fill: black;");
  60.         missing.setStyle("-fx-background-color: pink; -fx-text-fill: black;");
  61.         upComing.setStyle("-fx-background-color: pink; -fx-text-fill: black;");
  62.         provider.setStyle("-fx-background-color: pink; -fx-text-fill: black;");
  63.        
  64.    
  65.        
  66.        
  67.         //Creating a Grid Pane
  68.         GridPane gridPane = new GridPane();    
  69.          
  70.         //Setting size for the pane  
  71.         gridPane.setMinSize(800, 600);
  72.            
  73.         //Setting the padding  
  74.         gridPane.setPadding(new Insets(10, 10, 10, 10));
  75.          
  76.         //Setting the vertical and horizontal gaps between the columns
  77.         gridPane.setVgap(30);
  78.         gridPane.setHgap(30);      
  79.          
  80.         //Setting the Grid alignment
  81.        // gridPane.setAlignment(Pos.CENTER);
  82.            
  83.         //Arranging all the nodes in the grid
  84.         gridPane.add(search,1,1);      
  85.         gridPane.add(upComing, 2, 1);
  86.         gridPane.add(addPatient, 3,1 );
  87.         gridPane.add(missing,5 ,1 );
  88.         gridPane.add(provider,4 ,1 );
  89.         gridPane.setStyle("-fx-background-image: url(\"33682672_1485248468245623_4434124833390854144_n.jpg\"); -fx-background-color:white;");
  90.        
  91.        
  92.      
  93.        
  94.        
  95.        
  96.        
  97.         upComing.setOnAction(new EventHandler<ActionEvent>() {
  98.             @Override
  99.             public void handle(ActionEvent event) {
  100.                 LocalDate date = LocalDate.now();
  101.                 Sessions sessions = new Sessions(current, date);
  102.                 sessions.show();
  103.                 current.close();
  104.                
  105.             }
  106.         });
  107.        
  108.         addPatient.setOnAction(new EventHandler<ActionEvent>() {
  109.             @Override
  110.             public void handle(ActionEvent event) {
  111.                 Connection conn = null;
  112.                 try {
  113.                     conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/company?useSSL=false","root", "ahmed666");
  114.                     String select="select * from help";                
  115.                     PreparedStatement selectStmt = conn.prepareStatement(select);
  116.                     ResultSet res=selectStmt.executeQuery();
  117.                     String ID = null;
  118.                     while(res.next()) {
  119.                         ID=res.getString("ID");
  120.                     }
  121.                     if(ID!=null) {
  122.                     String delete="delete from help where ID = ?";                 
  123.                     PreparedStatement deleteStmt = conn.prepareStatement(delete);
  124.                     deleteStmt.setString(1, ID);
  125.                     deleteStmt.executeUpdate();
  126.                     }
  127.  
  128.                 } catch (SQLException e) {
  129.                     // TODO Auto-generated catch block
  130.                     e.printStackTrace();
  131.                 }
  132.  
  133.                
  134.                 Add add = new Add(current);
  135.                 add.show();
  136.                 current.close();
  137.                
  138.             }
  139.         });
  140.        
  141.         search.setOnAction(new EventHandler<ActionEvent>() {
  142.             @Override
  143.             public void handle(ActionEvent event) {
  144.                 Search searchPage = new Search(current,null,null);
  145.                 searchPage.show();
  146.                 current.close();
  147.                
  148.             }
  149.         });
  150.        
  151.         missing.setOnAction(new EventHandler<ActionEvent>() {
  152.             @Override
  153.             public void handle(ActionEvent event) {
  154.                 MissingReports missingPage = new MissingReports(current);
  155.                 missingPage.show();
  156.                 current.close();
  157.                
  158.             }
  159.         });
  160.        
  161.         provider.setOnAction(new EventHandler<ActionEvent>() {
  162.             @Override
  163.             public void handle(ActionEvent event) {
  164.                 Provider provider = new Provider(current);
  165.                 provider.show();
  166.                 current.close();
  167.                
  168.             }
  169.         });
  170.        
  171.        
  172.        
  173.        
  174.        
  175.        
  176.        
  177.         Scene scene = new Scene(gridPane);
  178.        
  179.         //scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
  180.         setScene(scene);
  181.         setTitle(" رؤية");
  182.     }
  183.  
  184. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement