Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package carcarefx;
- import java.io.IOException;
- import java.net.URL;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- import java.util.ResourceBundle;
- import javafx.beans.property.Property;
- import javafx.collections.FXCollections;
- import javafx.collections.ObservableList;
- import javafx.event.ActionEvent;
- import javafx.fxml.FXML;
- import javafx.fxml.FXMLLoader;
- import javafx.fxml.Initializable;
- import javafx.scene.Parent;
- import javafx.scene.Scene;
- import javafx.scene.control.Button;
- import javafx.scene.control.Label;
- import javafx.scene.control.TableColumn;
- import javafx.scene.control.TablePosition;
- import javafx.scene.control.TableView;
- import javafx.scene.control.TextField;
- import javafx.scene.control.cell.PropertyValueFactory;
- import javafx.scene.layout.AnchorPane;
- import javafx.stage.Stage;
- import javax.swing.JOptionPane;
- public class FXMLDocumentController implements Initializable {
- public Connection getConnection() {
- Connection con = null;
- try {
- Class.forName("org.sqlite.JDBC");
- con = DriverManager.getConnection("jdbc:sqlite:FAWZY.db");
- }
- catch(SQLException ex){
- JOptionPane.showMessageDialog(null, ex);
- } catch (ClassNotFoundException ex) {
- JOptionPane.showMessageDialog(null, ex);
- }
- return con;
- }
- //customertab//customertab//customertab//customertab//customertab//customertab//customertab//
- //customertab//customertab//customertab//customertab//customertab//customertab//customertab//
- @FXML private TableView<customer> customertable ;
- @FXML private TableColumn owner_col;
- @FXML private TableColumn boardno_col;
- @FXML private TableColumn motorno_col;
- @FXML private Button btn_addcustomer;
- @FXML private Button btn_modifycustomer;
- @FXML private Button btn_removecustomer;
- @FXML private Button btn_serviceforclient;
- @FXML private Button btn_reportclient;
- public static String caseofcustomer;
- public static String boardno;
- @FXML private TextField txtcustomer;
- @FXML private void addcustomer() throws IOException {
- Stage stage = (Stage) btn_addcustomer.getScene().getWindow();
- stage.close();
- Stage stage1=new Stage();
- stage1.setScene(new Scene(FXMLLoader.load(getClass().getResource("customer.fxml"))));
- stage1.show();
- caseofcustomer="new";
- }
- @FXML private void modifycustomer() throws IOException {
- if(customertable.getSelectionModel().getSelectedIndex()>=0){
- caseofcustomer="modify";
- TablePosition pos = customertable.getSelectionModel().getSelectedCells().get(0);
- int row = customertable.getSelectionModel().getSelectedIndex();
- // System.out.println(row);
- //TableColumn col = pos.getTableColumn();
- TableColumn col = customertable.getVisibleLeafColumn(1);
- // this gives the value in the selected cell:
- boardno = (String) customertable.getVisibleLeafColumn(1).getCellObservableValue(customertable.getSelectionModel().getSelectedIndex()).getValue();
- // System.out.println(col+boardno);
- Stage stage = (Stage) btn_addcustomer.getScene().getWindow();
- stage.close();
- Stage stage1=new Stage();
- stage1.setScene(new Scene(FXMLLoader.load(getClass().getResource("customer.fxml"))));
- stage1.show();
- }
- else{
- JOptionPane.showMessageDialog(null, "برجاء اختيارالعميل ");
- }
- }
- @FXML public void removecustomer(){
- // TODO add your handling code here:
- int r=dealertable.getSelectionModel().getSelectedIndex();
- if(r<0){
- JOptionPane.showMessageDialog(null, "برجاء اختيار العميل");
- }else{
- boolean x = false;
- try {
- String bord=(String) dealertable.getVisibleLeafColumn(1).getCellObservableValue(dealertable.getSelectionModel().getSelectedIndex()).getValue();;
- System.out.println(bord);
- String UpdateQuery = null;
- PreparedStatement PS = null;
- Connection Con = getConnection();
- UpdateQuery = "DELETE FROM customer WHERE boardno= '"+bord+"'";
- x=true;
- PS = Con.prepareStatement(UpdateQuery);
- PS.execute();
- // JOptionPane.showMessageDialog(null, "Product cleared");
- } catch (SQLException ex) {
- JOptionPane.showMessageDialog(null, ex);
- }
- if(x){
- dealertable.getItems().remove(dealertable.getSelectionModel().getSelectedItem());
- }
- }
- }
- //dealertab//dealertab//dealertab//dealertab//dealertab//dealertab//dealertab//dealertab//
- //dealertab//dealertab//dealertab//dealertab//dealertab//dealertab//dealertab//dealertab//
- @FXML TableView dealertable;
- @FXML TableColumn serialofdealer_col;
- @FXML TableColumn nameofdealer_col;
- @FXML TableColumn phoneofdealer_col;
- @FXML Button btn_adddealer;
- @FXML Button btn_modifydealer;
- @FXML Button btn_removedealer;
- public static String caseofdealer;
- public static String serialofdealer;
- @FXML public void adddealer() throws IOException{
- Stage stage = (Stage) btn_adddealer.getScene().getWindow();
- stage.close();
- Stage stage1=new Stage();
- stage1.setScene(new Scene(FXMLLoader.load(getClass().getResource("dealer.fxml"))));
- stage1.show();
- caseofdealer="new";
- }
- @Override
- public void initialize(URL url, ResourceBundle rb) {
- owner_col.setCellValueFactory(new PropertyValueFactory<>("owner"));
- boardno_col.setCellValueFactory(new PropertyValueFactory<>("boardno"));
- motorno_col.setCellValueFactory(new PropertyValueFactory<>("motorno"));
- customertable.setItems(getcustomers());
- serialofdealer_col.setCellValueFactory(new PropertyValueFactory<dealer,Integer>("ID"));
- nameofdealer_col.setCellValueFactory(new PropertyValueFactory<dealer,String>("name"));
- phoneofdealer_col.setCellValueFactory(new PropertyValueFactory<dealer,String>("phone"));
- dealertable.setItems(getdealers());
- }
- public Connection getconnection(){
- Connection con=null;
- try{
- Class.forName("org.sqlite.JDBC");
- con=DriverManager.getConnection("jdbc:sqlite:FAWZY.db");
- }catch(Exception ex){
- JOptionPane.showMessageDialog(null, ex);
- }
- ;
- return con;
- }
- public ObservableList<customer> customers=FXCollections.observableArrayList();
- private ObservableList<customer> getcustomers(){
- getconnection();
- try{
- String query="select owner,boardno,motorno from car";
- Connection con= getconnection();
- Statement st;
- ResultSet rs;
- st=con.createStatement();
- rs=st.executeQuery(query);
- while(rs.next()){
- customers.add(new customer(rs.getString("owner"),rs.getString("boardno"),rs.getString("motorno")));
- customertable.setItems(customers);
- }
- }catch(Exception ex){
- JOptionPane.showMessageDialog(null, ex);
- }
- return customers;
- }
- public ObservableList<dealer> dealers=FXCollections.observableArrayList();
- private ObservableList<dealer> getdealers(){
- getconnection();
- try{
- String query="SELECT ID,name,phone FROM dealears";
- Connection con= getconnection();
- Statement st;
- ResultSet rs;
- st=con.createStatement();
- rs=st.executeQuery(query);
- while(rs.next()){
- dealers.add(new dealer(rs.getInt(1),rs.getString(2),rs.getString(3)));
- dealertable.setItems(dealers);
- }
- }catch(Exception ex){
- JOptionPane.showMessageDialog(null, ex);
- }
- return dealers;
- }
- }
- package carcarefx;
- import javafx.beans.property.IntegerProperty;
- import javafx.beans.property.StringProperty;
- public class dealer {
- private final int Serial;
- private final String Name;
- private final String Phone;
- public dealer(int serial, String name, String phone) {
- this.Serial = serial;
- this.Name = name;
- this.Phone = phone;
- }
- public int getSerial() {
- return Serial;
- }
- public String getName() {
- return Name;
- }
- public String getPhone() {
- return Phone;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement