SHOW:
|
|
- or go back to the newest paste.
1 | package application; | |
2 | ||
3 | import java.sql.Connection; | |
4 | import java.sql.DriverManager; | |
5 | import java.sql.PreparedStatement; | |
6 | import java.sql.ResultSet; | |
7 | - | import java.util.ArrayList; |
7 | + | |
8 | ||
9 | - | import com.mysql.jdbc.PreparedStatement; |
9 | + | import com.mysql.cj.jdbc.integration.jboss.ExtendedMysqlExceptionSorter; |
10 | ||
11 | import javafx.event.ActionEvent; | |
12 | import javafx.event.EventHandler; | |
13 | import javafx.geometry.Insets; | |
14 | import javafx.geometry.Pos; | |
15 | import javafx.scene.Scene; | |
16 | import javafx.scene.control.Alert; | |
17 | import javafx.scene.control.Alert.AlertType; | |
18 | import javafx.scene.control.Button; | |
19 | import javafx.scene.control.ButtonType; | |
20 | - | public class Cart extends Stage { |
20 | + | import javafx.scene.control.ChoiceBox; |
21 | - | public Cart(Stage prev , String userName) { |
21 | + | import javafx.scene.control.PasswordField; |
22 | - | Stage current = this; |
22 | + | import javafx.scene.control.TextField; |
23 | - | java.util.List<Button> list = new ArrayList<Button>(); |
23 | + | |
24 | - | GridPane gridPane = new GridPane(); |
24 | + | |
25 | - | int counter =0; |
25 | + | |
26 | - | try { |
26 | + | |
27 | - | ResultSet rs; |
27 | + | public class SignUp extends Stage{ |
28 | - | Connection con = DriverManager.getConnection( "jdbc:mysql://localhost:3306/Online_Book_Store?useSSL=false", "root", "ahmed666" ); |
28 | + | |
29 | - | PreparedStatement p = (PreparedStatement) con.prepareStatement("select * from CART where USER_NAME='"+userName+"'"); |
29 | + | public SignUp(Stage stage,Scene scene) { |
30 | - | rs = p.executeQuery(); |
30 | + | setAttribute(stage,scene); |
31 | - | while(rs.next()) { |
31 | + | |
32 | - | list.add(new Button("Purchase")); |
32 | + | |
33 | - | list.get(counter).setStyle("-fx-background-color: darkslateblue; -fx-text-fill: white;"); |
33 | + | |
34 | - | Text ISBN = new Text(Integer.toString(rs.getInt("ISBN"))); |
34 | + | void setAttribute(Stage stage,Scene scene) { |
35 | - | Text copies = new Text(Integer.toString(rs.getInt("COPIES"))); |
35 | + | Text userName = new Text("user Name "); |
36 | - | ISBN.setStyle("-fx-font: normal italic 15px 'serif' "); |
36 | + | Text pass = new Text("password "); |
37 | - | copies.setStyle("-fx-font: normal italic 15px 'serif' "); |
37 | + | Text creditCard = new Text("credit number "); |
38 | - | gridPane.add(ISBN,0,counter+1); |
38 | + | Text FName = new Text("first name "); |
39 | - | gridPane.add(copies,1,counter+1); |
39 | + | Text Lname = new Text("last name "); |
40 | - | gridPane.add(list.get(counter),(400/30) ,counter+1); |
40 | + | Text phone = new Text("phone number "); |
41 | - | |
41 | + | Text shippingAddress = new Text("shipping address "); |
42 | - | |
42 | + | Text EMail = new Text("E-mai"); |
43 | - | // Purchasing handling |
43 | + | TextField userNameField = new TextField(); |
44 | - | Button b; |
44 | + | PasswordField passField = new PasswordField(); |
45 | - | b = list.get(counter); |
45 | + | TextField creditField = new TextField(); |
46 | - | |
46 | + | TextField firstNameField = new TextField(); |
47 | - | list.get(counter).setOnAction(new EventHandler<ActionEvent>() { |
47 | + | TextField lastNameField = new TextField(); |
48 | - | @Override |
48 | + | TextField phoneField = new TextField(); |
49 | - | public void handle(ActionEvent event) { |
49 | + | TextField shippingField = new TextField(); |
50 | - | // connect to db |
50 | + | TextField EMailField = new TextField(); |
51 | - | try { |
51 | + | |
52 | - | String c = copies.getText(); |
52 | + | Text signUpChoice = new Text("sign up as :"); |
53 | - | String i = ISBN.getText(); |
53 | + | ChoiceBox signUpChoiceBox = new ChoiceBox(); |
54 | - | Connection con = DriverManager.getConnection( "jdbc:mysql://localhost:3306/Online_Book_Store?useSSL=false", "root", "ahmed666" ); |
54 | + | signUpChoiceBox.getItems().addAll( "User","Manager"); |
55 | - | PreparedStatement p = (PreparedStatement) con.prepareStatement("update BOOK_STORE set BOOK_COPIES = BOOK_COPIES - "+c+ |
55 | + | signUpChoiceBox.getSelectionModel().selectFirst(); |
56 | - | " where ISBN = "+i); |
56 | + | |
57 | - | p.executeUpdate(); |
57 | + | |
58 | - | p = (PreparedStatement) con.prepareStatement("delete from CART where ISBN = "+i+" and USER_NAME = '"+userName+"'"); |
58 | + | Button signUpButton = new Button("sign up"); |
59 | - | p.executeUpdate(); |
59 | + | Button back = new Button("back"); |
60 | - | b.setDisable(true); |
60 | + | GridPane gridPane2 = new GridPane(); |
61 | - | |
61 | + | |
62 | - | } |
62 | + | gridPane2.setMinSize(600, 400); |
63 | - | catch (SQLException e) { |
63 | + | gridPane2.setPadding(new Insets(10, 10, 10, 10)); |
64 | - | // TODO Auto-generated catch block |
64 | + | |
65 | - | e.printStackTrace(); |
65 | + | // Setting the vertical and horizontal gaps between the columns |
66 | - | } |
66 | + | gridPane2.setVgap(30); |
67 | - | |
67 | + | gridPane2.setHgap(30); |
68 | - | |
68 | + | |
69 | - | |
69 | + | // Setting the Grid alignment |
70 | - | } |
70 | + | gridPane2.setAlignment(Pos.CENTER); |
71 | - | }); |
71 | + | |
72 | - | |
72 | + | // Arranging all the nodes in the grid |
73 | - | counter++; |
73 | + | |
74 | gridPane2.add(userName, 0, 0); | |
75 | - | |
75 | + | gridPane2.add(userNameField, 1, 0); |
76 | - | } |
76 | + | gridPane2.add(pass, 0, 1); |
77 | - | catch (SQLException e) { |
77 | + | gridPane2.add(passField, 1, 1); |
78 | - | // TODO Auto-generated catch block |
78 | + | gridPane2.add(FName, 0, 2); |
79 | - | e.printStackTrace(); |
79 | + | gridPane2.add(firstNameField, 1, 2); |
80 | - | } |
80 | + | gridPane2.add(Lname, 0, 3); |
81 | gridPane2.add(lastNameField, 1, 3); | |
82 | gridPane2.add(phone, 0, 4); | |
83 | - | //back button |
83 | + | gridPane2.add(phoneField, 1, 4); |
84 | - | Button back = new Button("Back"); |
84 | + | gridPane2.add(EMail, 0, 5); |
85 | - | back.setStyle("-fx-background-color: darkslateblue; -fx-text-fill: white;"); |
85 | + | gridPane2.add(EMailField, 1, 5); |
86 | - | gridPane.add(back, 0, 400/30); |
86 | + | gridPane2.add(shippingAddress, 0, 6); |
87 | - | back.setOnAction(new EventHandler<ActionEvent>() { |
87 | + | gridPane2.add(shippingField, 1, 6); |
88 | - | @Override |
88 | + | gridPane2.add(creditCard, 0, 7); |
89 | - | public void handle(ActionEvent event) { |
89 | + | gridPane2.add(creditField, 1, 7); |
90 | - | current.close(); |
90 | + | gridPane2.add(signUpChoice, 0, 8); |
91 | - | prev.show(); |
91 | + | gridPane2.add(signUpChoiceBox, 1, 8); |
92 | - | } |
92 | + | gridPane2.add(signUpButton, 0, 9); |
93 | - | }); |
93 | + | gridPane2.add(back, 1, 9); |
94 | - | |
94 | + | |
95 | - | //Setting size for the pane |
95 | + | // Styling nodes |
96 | - | gridPane.setMinSize(600, 400); |
96 | + | signUpButton.setStyle("-fx-background-color: darkslateblue; -fx-text-fill: white;"); |
97 | - | |
97 | + | back.setStyle("-fx-background-color: darkslateblue; -fx-text-fill: white;"); |
98 | - | //Setting the padding |
98 | + | |
99 | - | gridPane.setPadding(new Insets(10, 10, 10, 10)); |
99 | + | userName.setStyle("-fx-font: normal bold 20px 'serif' "); |
100 | - | |
100 | + | pass.setStyle("-fx-font: normal bold 20px 'serif' "); |
101 | - | //Setting the vertical and horizontal gaps between the columns |
101 | + | FName.setStyle("-fx-font: normal bold 20px 'serif' "); |
102 | - | gridPane.setVgap(30); |
102 | + | Lname.setStyle("-fx-font: normal bold 20px 'serif' "); |
103 | - | gridPane.setHgap(30); |
103 | + | phone.setStyle("-fx-font: normal bold 20px 'serif' "); |
104 | EMail.setStyle("-fx-font: normal bold 20px 'serif' "); | |
105 | - | if(counter == 0 ) { |
105 | + | shippingAddress.setStyle("-fx-font: normal bold 20px 'serif' "); |
106 | - | Text noRes = new Text("Cart is Empty"); |
106 | + | creditCard.setStyle("-fx-font: normal bold 20px 'serif' "); |
107 | - | gridPane.add(noRes,600/120 , 400/60 ); |
107 | + | signUpChoice.setStyle("-fx-font: normal bold 20px 'serif' "); |
108 | - | noRes.setStyle("-fx-font: normal bold 20px 'serif' "); |
108 | + | |
109 | - | } |
109 | + | // Creating a scene object |
110 | - | else { |
110 | + | Scene scene2 = new Scene(gridPane2); |
111 | - | Text ISBN = new Text("ISBN"); |
111 | + | |
112 | - | Text copies = new Text("COPIES"); |
112 | + | // Setting title to the Stage |
113 | - | Button purchaseAll = new Button("Purchase All"); |
113 | + | stage.setTitle("Sign Up "); |
114 | - | |
114 | + | |
115 | - | // Add Nodes to GridPane |
115 | + | // Adding scene to the stage |
116 | - | gridPane.add(ISBN,0,0); |
116 | + | stage.setScene(scene2); |
117 | - | gridPane.add(copies,1,0); |
117 | + | |
118 | - | gridPane.add(purchaseAll, 4 , 400/30); |
118 | + | // Displaying the contents of the stage |
119 | - | |
119 | + | stage.show(); |
120 | - | // set styling |
120 | + | |
121 | - | ISBN.setStyle("-fx-font: normal bold 15px 'serif' "); |
121 | + | |
122 | - | copies.setStyle("-fx-font: normal bold 15px 'serif' "); |
122 | + | |
123 | - | purchaseAll.setStyle("-fx-background-color: darkslateblue; -fx-text-fill: white;"); |
123 | + | |
124 | - | |
124 | + | back.setOnAction(new EventHandler<ActionEvent>() { |
125 | - | |
125 | + | @Override |
126 | - | |
126 | + | public void handle(ActionEvent event) { |
127 | - | purchaseAll.setOnAction(new EventHandler<ActionEvent>() { |
127 | + | stage.setTitle("Log in "); |
128 | - | @Override |
128 | + | |
129 | - | public void handle(ActionEvent event) { |
129 | + | // Adding scene to the stage |
130 | - | try { |
130 | + | stage.setScene(scene); |
131 | - | Connection con = DriverManager.getConnection( "jdbc:mysql://localhost:3306/Online_Book_Store?useSSL=false", "root", "ahmed666" ); |
131 | + | |
132 | - | PreparedStatement p = (PreparedStatement) con.prepareStatement("update BOOK_STORE set BOOK_COPIES = BOOK_COPIES - ( select COPIES" |
132 | + | // Displaying the contents of the stage |
133 | - | + " from CART where BOOK_STORE.ISBN = ISBN and USER_NAME ='"+userName+"') where ISBN IN ( select ISBN from CART );"); |
133 | + | stage.show(); |
134 | - | System.out.println("update BOOK_STORE set BOOK_COPIES = BOOK_COPIES - ( select COPIES" |
134 | + | |
135 | - | + " from CART where BOOK_STORE.ISBN = ISBN and USER_NAME ='"+userName+"') where ISBN IN ( select ISBN from CART ); "); |
135 | + | |
136 | - | p.executeUpdate(); |
136 | + | |
137 | - | p = (PreparedStatement) con.prepareStatement("delete from CART where USER_NAME = '"+userName+"'"); |
137 | + | }); |
138 | - | p.executeUpdate(); |
138 | + | |
139 | - | purchaseAll.setDisable(true); |
139 | + | signUpButton.setOnAction(new EventHandler<ActionEvent>() { |
140 | - | for(int i =0 ; i< list.size() ;i++) { |
140 | + | @Override |
141 | - | list.get(i).setDisable(true); |
141 | + | public void handle(ActionEvent event) { |
142 | - | } |
142 | + | String userName = userNameField.getText(); |
143 | - | |
143 | + | String pass = passField.getText(); |
144 | - | } |
144 | + | String firstName =firstNameField.getText(); |
145 | - | catch (SQLException e) { |
145 | + | String lastName = lastNameField.getText(); |
146 | - | // TODO Auto-generated catch block |
146 | + | String phone= phoneField.getText(); |
147 | - | e.printStackTrace(); |
147 | + | String Email =EMailField.getText(); |
148 | - | } |
148 | + | String shipping =shippingField.getText(); |
149 | - | } |
149 | + | String numberOfCredit = creditField.getText(); |
150 | - | }); |
150 | + | String type = (String) signUpChoiceBox.getValue(); |
151 | ||
152 | - | |
152 | + | System.out.println(userName); |
153 | - | } |
153 | + | System.out.println(pass); |
154 | - | Scene scene = new Scene(gridPane); |
154 | + | System.out.println(firstName); |
155 | - | setScene(scene); |
155 | + | System.out.println(lastName); |
156 | System.out.println(phone); | |
157 | System.out.println(Email); | |
158 | System.out.println(shipping); | |
159 | System.out.println(numberOfCredit); | |
160 | System.out.println(type); | |
161 | ||
162 | ||
163 | ||
164 | ||
165 | ||
166 | try { | |
167 | Class.forName("com.mysql.jdbc.Driver") ; | |
168 | } catch (ClassNotFoundException e1) { | |
169 | // TODO Auto-generated catch block | |
170 | e1.printStackTrace(); | |
171 | } | |
172 | ||
173 | Connection conn = null; | |
174 | try { | |
175 | conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/Online_Book_Store?useSSL=false", "root", "admin"); | |
176 | } catch (SQLException e) { | |
177 | // TODO Auto-generated catch block | |
178 | e.printStackTrace(); | |
179 | } | |
180 | try { | |
181 | String query; | |
182 | String selectQuery; | |
183 | ||
184 | if(type.equals("Manager")) { | |
185 | query = "insert into MANAGERS values (?,?,?,?,?,?,?,?)" ; | |
186 | selectQuery="select * from MANAGERS where USER_NAME = ?"; | |
187 | }else { | |
188 | query = "insert into USERS values (?,?,?,?,?,?,?,?)" ; | |
189 | selectQuery="select * from USERS where USER_NAME = ?"; | |
190 | } | |
191 | PreparedStatement selectStmt = conn.prepareStatement(selectQuery); | |
192 | selectStmt.setString(1, userName); | |
193 | ResultSet res=selectStmt.executeQuery(); | |
194 | ||
195 | ||
196 | ||
197 | ||
198 | PreparedStatement stmt = conn.prepareStatement(query); | |
199 | stmt.setString(1, userName); | |
200 | stmt.setString(2, pass); | |
201 | stmt.setString(3, firstName); | |
202 | stmt.setString(4, lastName); | |
203 | stmt.setString(5, phone); | |
204 | stmt.setString(6, Email); | |
205 | stmt.setString(7, shipping); | |
206 | stmt.setString(8, numberOfCredit); | |
207 | if(pass.isEmpty()) { | |
208 | Alert alert = new Alert(AlertType.WARNING, "please enter password" , ButtonType.OK); | |
209 | alert.showAndWait(); | |
210 | }else if (res.next()) { | |
211 | Alert alert = new Alert(AlertType.WARNING, "dublicate user name " , ButtonType.OK); | |
212 | alert.showAndWait(); | |
213 | } | |
214 | else { | |
215 | stmt.executeUpdate(); | |
216 | ||
217 | } | |
218 | } catch (SQLException e) { | |
219 | // TODO Auto-generated catch block | |
220 | e.printStackTrace(); | |
221 | } | |
222 | ||
223 | try { | |
224 | conn.close(); | |
225 | } catch (SQLException e) { | |
226 | // TODO Auto-generated catch block | |
227 | e.printStackTrace(); | |
228 | } | |
229 | ||
230 | ||
231 | } | |
232 | ||
233 | }); | |
234 | ||
235 | ||
236 | ||
237 | } | |
238 | ||
239 | ||
240 | ||
241 | } |