Advertisement
Guest User

Untitled

a guest
Jul 19th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.39 KB | None | 0 0
  1.  
  2. package carcarefx;
  3.  
  4.  
  5. import java.io.IOException;
  6. import java.net.URL;
  7. import java.sql.Connection;
  8. import java.sql.DriverManager;
  9. import java.sql.PreparedStatement;
  10. import java.sql.ResultSet;
  11. import java.sql.SQLException;
  12. import java.sql.Statement;
  13. import java.util.ResourceBundle;
  14. import javafx.beans.property.Property;
  15. import javafx.collections.FXCollections;
  16. import javafx.collections.ObservableList;
  17. import javafx.event.ActionEvent;
  18. import javafx.fxml.FXML;
  19. import javafx.fxml.FXMLLoader;
  20. import javafx.fxml.Initializable;
  21. import javafx.scene.Parent;
  22. import javafx.scene.Scene;
  23. import javafx.scene.control.Button;
  24. import javafx.scene.control.Label;
  25. import javafx.scene.control.TableColumn;
  26. import javafx.scene.control.TablePosition;
  27. import javafx.scene.control.TableView;
  28. import javafx.scene.control.TextField;
  29. import javafx.scene.control.cell.PropertyValueFactory;
  30. import javafx.scene.layout.AnchorPane;
  31. import javafx.stage.Stage;
  32. import javax.swing.JOptionPane;
  33.  
  34. public class FXMLDocumentController implements Initializable {
  35. public Connection getConnection() {
  36. Connection con = null;
  37.  
  38. try {
  39. Class.forName("org.sqlite.JDBC");
  40. con = DriverManager.getConnection("jdbc:sqlite:FAWZY.db");
  41. }
  42. catch(SQLException ex){
  43. JOptionPane.showMessageDialog(null, ex);
  44. } catch (ClassNotFoundException ex) {
  45. JOptionPane.showMessageDialog(null, ex);
  46. }
  47.  
  48.  
  49. return con;
  50. }
  51. //customertab//customertab//customertab//customertab//customertab//customertab//customertab//
  52. //customertab//customertab//customertab//customertab//customertab//customertab//customertab//
  53. @FXML private TableView<customer> customertable ;
  54. @FXML private TableColumn owner_col;
  55. @FXML private TableColumn boardno_col;
  56. @FXML private TableColumn motorno_col;
  57. @FXML private Button btn_addcustomer;
  58. @FXML private Button btn_modifycustomer;
  59. @FXML private Button btn_removecustomer;
  60. @FXML private Button btn_serviceforclient;
  61. @FXML private Button btn_reportclient;
  62. public static String caseofcustomer;
  63. public static String boardno;
  64. @FXML private TextField txtcustomer;
  65.  
  66. @FXML private void addcustomer() throws IOException {
  67. Stage stage = (Stage) btn_addcustomer.getScene().getWindow();
  68. stage.close();
  69. Stage stage1=new Stage();
  70. stage1.setScene(new Scene(FXMLLoader.load(getClass().getResource("customer.fxml"))));
  71. stage1.show();
  72. caseofcustomer="new";
  73. }
  74. @FXML private void modifycustomer() throws IOException {
  75. if(customertable.getSelectionModel().getSelectedIndex()>=0){
  76. caseofcustomer="modify";
  77. TablePosition pos = customertable.getSelectionModel().getSelectedCells().get(0);
  78. int row = customertable.getSelectionModel().getSelectedIndex();
  79. // System.out.println(row);
  80. //TableColumn col = pos.getTableColumn();
  81. TableColumn col = customertable.getVisibleLeafColumn(1);
  82.  
  83. // this gives the value in the selected cell:
  84. boardno = (String) customertable.getVisibleLeafColumn(1).getCellObservableValue(customertable.getSelectionModel().getSelectedIndex()).getValue();
  85. // System.out.println(col+boardno);
  86. Stage stage = (Stage) btn_addcustomer.getScene().getWindow();
  87. stage.close();
  88. Stage stage1=new Stage();
  89. stage1.setScene(new Scene(FXMLLoader.load(getClass().getResource("customer.fxml"))));
  90. stage1.show();
  91. }
  92. else{
  93. JOptionPane.showMessageDialog(null, "برجاء اختيارالعميل ");
  94.  
  95. }
  96. }
  97. @FXML public void removecustomer(){
  98. // TODO add your handling code here:
  99. int r=dealertable.getSelectionModel().getSelectedIndex();
  100. if(r<0){
  101. JOptionPane.showMessageDialog(null, "برجاء اختيار العميل");
  102. }else{
  103. boolean x = false;
  104. try {
  105. String bord=(String) dealertable.getVisibleLeafColumn(1).getCellObservableValue(dealertable.getSelectionModel().getSelectedIndex()).getValue();;
  106. System.out.println(bord);
  107. String UpdateQuery = null;
  108. PreparedStatement PS = null;
  109. Connection Con = getConnection();
  110. UpdateQuery = "DELETE FROM customer WHERE boardno= '"+bord+"'";
  111. x=true;
  112. PS = Con.prepareStatement(UpdateQuery);
  113.  
  114. PS.execute();
  115. // JOptionPane.showMessageDialog(null, "Product cleared");
  116.  
  117. } catch (SQLException ex) {
  118. JOptionPane.showMessageDialog(null, ex);
  119. }
  120. if(x){
  121. dealertable.getItems().remove(dealertable.getSelectionModel().getSelectedItem());
  122. }
  123. }
  124. }
  125.  
  126. //dealertab//dealertab//dealertab//dealertab//dealertab//dealertab//dealertab//dealertab//
  127. //dealertab//dealertab//dealertab//dealertab//dealertab//dealertab//dealertab//dealertab//
  128. @FXML TableView dealertable;
  129. @FXML TableColumn serialofdealer_col;
  130. @FXML TableColumn nameofdealer_col;
  131. @FXML TableColumn phoneofdealer_col;
  132. @FXML Button btn_adddealer;
  133. @FXML Button btn_modifydealer;
  134. @FXML Button btn_removedealer;
  135. public static String caseofdealer;
  136. public static String serialofdealer;
  137.  
  138. @FXML public void adddealer() throws IOException{
  139. Stage stage = (Stage) btn_adddealer.getScene().getWindow();
  140. stage.close();
  141. Stage stage1=new Stage();
  142. stage1.setScene(new Scene(FXMLLoader.load(getClass().getResource("dealer.fxml"))));
  143. stage1.show();
  144. caseofdealer="new";
  145. }
  146.  
  147.  
  148.  
  149.  
  150.  
  151.  
  152.  
  153.  
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169. @Override
  170. public void initialize(URL url, ResourceBundle rb) {
  171. owner_col.setCellValueFactory(new PropertyValueFactory<>("owner"));
  172. boardno_col.setCellValueFactory(new PropertyValueFactory<>("boardno"));
  173. motorno_col.setCellValueFactory(new PropertyValueFactory<>("motorno"));
  174. customertable.setItems(getcustomers());
  175. serialofdealer_col.setCellValueFactory(new PropertyValueFactory<dealer,Integer>("ID"));
  176. nameofdealer_col.setCellValueFactory(new PropertyValueFactory<dealer,String>("name"));
  177. phoneofdealer_col.setCellValueFactory(new PropertyValueFactory<dealer,String>("phone"));
  178. dealertable.setItems(getdealers());
  179. }
  180. public Connection getconnection(){
  181. Connection con=null;
  182. try{
  183. Class.forName("org.sqlite.JDBC");
  184. con=DriverManager.getConnection("jdbc:sqlite:FAWZY.db");
  185. }catch(Exception ex){
  186. JOptionPane.showMessageDialog(null, ex);
  187. }
  188. ;
  189. return con;
  190. }
  191. public ObservableList<customer> customers=FXCollections.observableArrayList();
  192. private ObservableList<customer> getcustomers(){
  193. getconnection();
  194. try{
  195. String query="select owner,boardno,motorno from car";
  196. Connection con= getconnection();
  197. Statement st;
  198. ResultSet rs;
  199. st=con.createStatement();
  200. rs=st.executeQuery(query);
  201. while(rs.next()){
  202. customers.add(new customer(rs.getString("owner"),rs.getString("boardno"),rs.getString("motorno")));
  203. customertable.setItems(customers);
  204. }
  205. }catch(Exception ex){
  206. JOptionPane.showMessageDialog(null, ex);
  207. }
  208. return customers;
  209. }
  210. public ObservableList<dealer> dealers=FXCollections.observableArrayList();
  211. private ObservableList<dealer> getdealers(){
  212. getconnection();
  213. try{
  214. String query="SELECT ID,name,phone FROM dealears";
  215. Connection con= getconnection();
  216. Statement st;
  217. ResultSet rs;
  218. st=con.createStatement();
  219. rs=st.executeQuery(query);
  220. while(rs.next()){
  221. dealers.add(new dealer(rs.getInt(1),rs.getString(2),rs.getString(3)));
  222. dealertable.setItems(dealers);
  223. }
  224. }catch(Exception ex){
  225. JOptionPane.showMessageDialog(null, ex);
  226. }
  227. return dealers;
  228. }
  229. }
  230.  
  231.  
  232.  
  233.  
  234.  
  235.  
  236. package carcarefx;
  237.  
  238. import javafx.beans.property.IntegerProperty;
  239. import javafx.beans.property.StringProperty;
  240.  
  241. public class dealer {
  242. private final int Serial;
  243. private final String Name;
  244. private final String Phone;
  245.  
  246. public dealer(int serial, String name, String phone) {
  247. this.Serial = serial;
  248. this.Name = name;
  249. this.Phone = phone;
  250. }
  251.  
  252. public int getSerial() {
  253. return Serial;
  254. }
  255.  
  256. public String getName() {
  257. return Name;
  258. }
  259.  
  260. public String getPhone() {
  261. return Phone;
  262. }
  263.  
  264.  
  265. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement