Advertisement
Guest User

Untitled

a guest
Apr 4th, 2019
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.58 KB | None | 0 0
  1. package application.controllers;
  2.  
  3. import java.net.URL;
  4. import java.sql.Connection;
  5. import java.sql.DriverManager;
  6. import java.sql.ResultSet;
  7. import java.sql.SQLException;
  8. import java.sql.Statement;
  9. import java.time.LocalDate;
  10. import java.util.ResourceBundle;
  11. import application.SoldItems;
  12. import javafx.collections.FXCollections;
  13. import javafx.collections.ObservableList;
  14. import javafx.fxml.FXML;
  15. import javafx.fxml.Initializable;
  16. import javafx.scene.control.DatePicker;
  17. import javafx.scene.control.Label;
  18. import javafx.scene.control.TableColumn;
  19. import javafx.scene.control.TableView;
  20. import javafx.scene.control.cell.PropertyValueFactory;
  21.  
  22. public class DailySalesController implements Initializable {
  23.  
  24. // بتحط محل علامة الاستفهام هاي الاوبجكت تايب وتحت الاوبجكت تايب وشو بدك يعرض وتنساش تيبل دوت سيت داتا
  25. @FXML
  26. private TableView<SoldItems> table;
  27.  
  28. @FXML
  29. private TableColumn<SoldItems, String> itemColumn;
  30.  
  31. @FXML
  32. private TableColumn<SoldItems, Integer> quantityColumn;
  33.  
  34. @FXML
  35. private TableColumn<SoldItems, Double> TotalSellPriceColumn;
  36.  
  37. @FXML
  38. private TableColumn<SoldItems, Double> profitColumn;
  39.  
  40. @FXML
  41. private DatePicker date;
  42.  
  43. @FXML
  44. private Label totalSellPrice;
  45.  
  46. @FXML
  47. private Label totalProfit;
  48.  
  49. ResultSet rs;
  50. ObservableList<SoldItems> data;
  51. @Override
  52. public void initialize(URL location, ResourceBundle resources) {
  53. // TODO Auto-generated method stub
  54. date.setValue(LocalDate.now());
  55. data = FXCollections.observableArrayList();
  56.  
  57. try {
  58.  
  59. //هون
  60.  
  61.  
  62. date.valueProperty().addListener((observable, oldDate, newDate)->{
  63. showInTable(newDate);
  64.  
  65. /* your code here */
  66.  
  67. });
  68.  
  69.  
  70.  
  71. } catch (Exception e) {
  72. // TODO Auto-generated catch block
  73. e.printStackTrace();
  74. }
  75.  
  76.  
  77.  
  78.  
  79.  
  80. showInTable(LocalDate.now());
  81.  
  82. }
  83.  
  84. public void showInTable(LocalDate date) {
  85. try {
  86. DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
  87. Connection connection=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","imad","11");
  88. Statement statement=connection.createStatement();
  89. String q="select * from sold";
  90. rs=statement.executeQuery(q);
  91. data.clear();
  92. double totalprofit=0;
  93. double sellprice=0;
  94. System.out.println();
  95. while(rs.next()) {
  96.  
  97. //System.out.println("Hi1");
  98. if(date.equals(rs.getDate("selling_date").toLocalDate())) {
  99. //System.out.println("Hi");
  100. data.add(new SoldItems(rs.getString("ITEM_NAME"),rs.getInt("quantity"),rs.getDouble("SELL_PRICE"),rs.getDate("Selling_date").toLocalDate(),rs.getDouble("buy_price")));
  101.  
  102.  
  103. System.out.println(rs.getString("ITEM_NAME")+" "+rs.getInt("quantity")+" "+rs.getDouble("SELL_PRICE")+" "+rs.getDate("Selling_date").toLocalDate()+" "+rs.getDouble("buy_price"));
  104. }
  105.  
  106. }
  107. table.setItems(data);
  108. itemColumn.setCellValueFactory( new PropertyValueFactory<>("name") );
  109. quantityColumn.setCellValueFactory( new PropertyValueFactory<>("quant") );
  110. TotalSellPriceColumn.setCellValueFactory( new PropertyValueFactory<>("totalsellPrice") );
  111. profitColumn.setCellValueFactory( new PropertyValueFactory<>("profit") );
  112.  
  113.  
  114. for(int i=0;i<data.size();i++) {
  115. totalprofit+=data.get(i).getProfit();
  116. sellprice+=data.get(i).getTotalSellPrice();
  117. }
  118. totalSellPrice.setText(sellprice+"");
  119. totalProfit.setText(totalprofit+"");
  120. }
  121.  
  122.  
  123. catch (SQLException e) {
  124. // TODO Auto-generated catch block
  125. }
  126.  
  127.  
  128.  
  129.  
  130. }
  131.  
  132.  
  133.  
  134. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement