Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2017
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 20.94 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package project_netbeans;
  7.  
  8. import java.sql.ResultSet;
  9. import java.sql.SQLException;
  10. import java.util.ArrayList;
  11. import javafx.collections.FXCollections;
  12. import javafx.collections.ObservableList;
  13. import javafx.geometry.Insets;
  14. import javafx.geometry.Pos;
  15. import javafx.scene.Node;
  16. import javafx.scene.Scene;
  17. import javafx.scene.control.Button;
  18. import javafx.scene.control.ComboBox;
  19. import javafx.scene.control.Label;
  20. import javafx.scene.control.TextField;
  21. import javafx.scene.image.Image;
  22. import javafx.scene.image.ImageView;
  23. import javafx.scene.layout.BorderPane;
  24. import javafx.scene.layout.GridPane;
  25. import javafx.scene.layout.HBox;
  26. import javafx.scene.layout.StackPane;
  27. import javafx.scene.layout.VBox;
  28. import javafx.scene.text.Font;
  29. import javafx.stage.Modality;
  30. import javafx.stage.Stage;
  31.  
  32.  
  33. public class PaymentForm {
  34.  
  35. static String paymentMethod;
  36. static long loyaltyNumber;
  37. static Database database = new Database();
  38. static Customer cust;
  39. static Order order;
  40. static PreOrder preOrder;
  41. public static void Payment(){
  42.  
  43. Stage primaryStage = new Stage();
  44. primaryStage.setTitle("Payment");
  45.  
  46. BorderPane pane = new BorderPane();
  47. pane.setStyle("-fx-padding: 10; -fx-background-color: #28ABE3" );
  48.  
  49. //here we are creating a new image which will be our create new logo
  50. Image image = new Image("Image/Payment.png");
  51. StackPane LogoBackGround = new StackPane(); //create a new stack pane to hold this image and allow us
  52. //to center it within the border top pane
  53. LogoBackGround.setPrefSize(75,75);//setting the size we want
  54.  
  55. ImageView Logo = new ImageView(image); //creating a new image view that will be used
  56. Logo.setFitHeight(75); //fitting the image to the image view
  57. Logo.setFitWidth(75);
  58.  
  59. LogoBackGround.setPadding(new Insets(30,0,0,0));
  60. LogoBackGround.getChildren().add(Logo); //adding the logo to the stack pane
  61.  
  62. pane.setTop(LogoBackGround); //adding the stack pane to the top region of the borderpane
  63. pane.setCenter(CenterLayout());
  64.  
  65. Scene scene = new Scene(pane, 500, 600);
  66. primaryStage.setResizable(false);
  67. primaryStage.setScene(scene);
  68. primaryStage.initModality(Modality.APPLICATION_MODAL);
  69.  
  70. primaryStage.show();
  71. }
  72.  
  73.  
  74. private static StackPane CenterLayout(){
  75. StackPane CenterPane = new StackPane();
  76.  
  77. VBox CenterLayout = new VBox();
  78. CenterLayout.setSpacing(10);
  79. CenterLayout.setPadding(new Insets(10,10,10,10));
  80.  
  81. StackPane CustLoyaltyBackGround = new StackPane();
  82. CustLoyaltyBackGround.setStyle("-fx-background-color: White; -fx-border-color: Black;");
  83.  
  84. VBox CustLoyaltyLayout = new VBox();//creating a new VBox for the overall structure
  85. CustLoyaltyLayout.setSpacing(10);
  86. CustLoyaltyLayout.setPadding(new Insets(10,10,10,10));
  87. HBox LoyaltyNum = new HBox(); //creating a new hBox as i want a lable and text box in line with each other
  88. Label lblLoyaltyNum = new Label("Loyalty Number: ");//adding the label
  89. lblLoyaltyNum.setFont(new Font("Arial",20));//seeting the font for the lable
  90. TextField txtLoyaltyNum = new TextField();//creating a new textbox for the user to enter the value
  91. txtLoyaltyNum.setPrefWidth(150);//setting the height and width of the text box
  92. txtLoyaltyNum.setPrefHeight(15);
  93. txtLoyaltyNum.textProperty().addListener((observable, oldValue, newValue) -> {
  94.  
  95.  
  96. loyaltyNumber = Long.valueOf(txtLoyaltyNum.getText()); //setting the action to assign the value of the text box
  97. //after every change to the textfield text property
  98.  
  99. });
  100.  
  101. LoyaltyNum.getChildren().addAll(lblLoyaltyNum, txtLoyaltyNum);//adding the label adn the textbox to the HBox
  102. CustLoyaltyLayout.getChildren().add(LoyaltyNum);//adding the HBox to the VBox
  103. CustLoyaltyBackGround.getChildren().add(CustLoyaltyLayout); //adding the VBox to the background
  104.  
  105. Button btnRegisterNewCustomer = new Button("Register new customer"); //creating a new Button to register a new customer
  106. btnRegisterNewCustomer.setPrefHeight(15);//setting the size of the button
  107. btnRegisterNewCustomer.setPrefWidth(200);
  108. btnRegisterNewCustomer.setOnAction(e -> {
  109. ((Node)e.getSource()).getScene().getWindow().hide();
  110. RegisterNewLoyaltyCustomer.display();
  111. ((Stage)((Node)e.getSource()).getScene().getWindow()).show();
  112. });
  113.  
  114. CustLoyaltyLayout.getChildren().add(btnRegisterNewCustomer); //adding them to the VBox
  115.  
  116. Label lblPointsEarned = new Label("Loyalty points earned from this transaction: "); //creating a new Label to display text
  117. lblPointsEarned.setFont(new Font("Arial",20)); //setting the font
  118. CustLoyaltyLayout.getChildren().add(lblPointsEarned); //adding the label to the VBox
  119.  
  120.  
  121. Label lblActualPointsEarned = new Label("_____"); //creating a new label to display the points they will earn
  122. lblActualPointsEarned.setFont(new Font("Arial",20)); //setting the font of the label
  123.  
  124. CustLoyaltyLayout.getChildren().add(lblActualPointsEarned); //adding it to the vbox
  125.  
  126. StackPane SP_PaymentBackGround = new StackPane(); //new stack pane for the Payment details background
  127. SP_PaymentBackGround.setStyle("-fx-background-color: White; -fx-border-color: Black;"); ////settting the style of the stackpane
  128.  
  129. VBox VX_PaymentLayout = new VBox(); //creating a new VBox for the overall layout of the payment details
  130. VX_PaymentLayout.setPadding(new Insets(10,10,10,10)); //spacing out the elements
  131. VX_PaymentLayout.setSpacing(10);
  132.  
  133. HBox HB_PaymentOptions = new HBox(); //creating a HBox as i want the buttons to be inline
  134. HB_PaymentOptions.setSpacing(20); //spacing out the buttons
  135. HB_PaymentOptions.setAlignment(Pos.CENTER);
  136.  
  137. Button btnCash = new Button("Cash");//creating the buttons for cash, credit and loyalty points
  138. btnCash.setPrefSize(110, 125);
  139. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  140. //moved all button actions to the bottom of the method
  141.  
  142. Button btnCredit = new Button("Credit");
  143. btnCredit.setPrefSize(110,125);
  144.  
  145.  
  146. Button btnLoyalty = new Button("Loyalty Points");
  147. btnLoyalty.setPrefSize(110,125);
  148.  
  149.  
  150. HB_PaymentOptions.getChildren().addAll(btnCash,btnCredit,btnLoyalty); //adding the buttons to the HBOx
  151.  
  152. VX_PaymentLayout.getChildren().add(HB_PaymentOptions); //adding the HBox to the VBox
  153.  
  154. SP_PaymentBackGround.getChildren().add(VX_PaymentLayout); //adding the VBox to the stackpane
  155.  
  156. GridPane GP_PaymentDetails = new GridPane();
  157. GP_PaymentDetails.setPadding(new Insets(10,10,10,10));
  158.  
  159. //stackpane for card details
  160.  
  161. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  162. StackPane SP_CardDetails = new StackPane();
  163. SP_CardDetails.setVisible(false); //setting these to hidden by defualt because depenind on which option they hit it will show relevant pane
  164. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172. //vbox for the details \
  173. VBox VB_CardDetails = new VBox();
  174. VB_CardDetails.setSpacing(10);
  175. HBox HB_CardDetails = new HBox();
  176. HB_CardDetails.setSpacing(10);
  177.  
  178. Label lblCardType = new Label("Card type: ");
  179. lblCardType.setFont(new Font("Arial",20));
  180.  
  181. ObservableList<String> options = FXCollections.observableArrayList( //creating an array list to hold the values of the combo box
  182. "Visa",
  183. "MasterCard",
  184. "American Express"
  185. );
  186. final ComboBox cboCardType = new ComboBox(options); //then creating the combo box
  187. cboCardType.setPrefWidth(200);
  188.  
  189. HBox HB_CardNum = new HBox(); //creating a hbox for the card number so the label and textbox will be next to each other
  190. HB_CardNum.setSpacing(10); //setting the spacing
  191. Label lblCardNum = new Label("Card number: "); //creating the label
  192. lblCardNum.setFont(new Font("Arial",20));//setting the font
  193.  
  194. TextField txtCardNum = new TextField(); //creating the textbox for the card number
  195. txtCardNum.setPrefWidth(200); //setting the size
  196.  
  197. //adding the elements first to the HBox so they will be aligned
  198. HB_CardDetails.getChildren().addAll(lblCardType, cboCardType);
  199. HB_CardNum.getChildren().addAll(lblCardNum,txtCardNum); //adding the label and textbox to the hbox for the card number
  200. VB_CardDetails.getChildren().addAll(HB_CardDetails,HB_CardNum); //then adding them to the VBox as there will be other elements added
  201. SP_CardDetails.getChildren().add(VB_CardDetails); //adding the vbOX to the stackpane
  202.  
  203.  
  204.  
  205.  
  206. StackPane SP_Loyalty = new StackPane();
  207.  
  208. //vbox for the details \
  209. VBox VB_LoyaltyDetails = new VBox();
  210. VB_LoyaltyDetails.setSpacing(10);
  211. HBox HB_LoyaltyDetails = new HBox();
  212. HB_LoyaltyDetails.setSpacing(10);
  213.  
  214. Label lblLoyaltyPointsAvailable = new Label("Loyalty points available: ");
  215. lblLoyaltyPointsAvailable.setFont(new Font("Arial",20));
  216.  
  217. TextField txtPointsAvailable = new TextField();
  218. txtPointsAvailable.setPrefWidth(100);
  219.  
  220.  
  221. HBox HB_LoyaltyRequired = new HBox(); //creating a hbox for the card number so the label and textbox will be next to each other
  222. HB_LoyaltyRequired.setSpacing(10); //setting the spacing
  223. Label lblLoyaltyRequired = new Label("Loyalty points required: "); //creating the label
  224. lblLoyaltyRequired.setFont(new Font("Arial",20));//setting the font
  225.  
  226. TextField txtLoyaltyPointsRequired = new TextField(); //creating the textbox for the card number
  227. txtLoyaltyPointsRequired.setPrefWidth(100); //setting the size
  228.  
  229. //adding the elements first to the HBox so they will be aligned
  230. HB_LoyaltyDetails.getChildren().addAll(lblLoyaltyPointsAvailable, txtPointsAvailable);
  231. HB_LoyaltyRequired.getChildren().addAll(lblLoyaltyRequired,txtLoyaltyPointsRequired); //adding the label and textbox to the hbox for the card number
  232. VB_LoyaltyDetails.getChildren().addAll(HB_LoyaltyDetails,HB_LoyaltyRequired); //then adding them to the VBox as there will be other elements added
  233. SP_Loyalty.getChildren().add(VB_LoyaltyDetails); //adding the vbOX to the stackpane
  234.  
  235. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  236.  
  237.  
  238. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  239. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  240. //If they click the cash button we dont need anything else to display
  241. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  242. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  243. btnCash.setOnAction(e -> {
  244. paymentMethod = "Cash"; //valued needed for order construtor and will be recorded in database
  245. SP_CardDetails.setVisible(false);
  246. SP_Loyalty.setVisible(false);
  247. txtCardNum.clear();
  248. txtPointsAvailable.clear();
  249. txtLoyaltyPointsRequired.clear();
  250. });
  251.  
  252.  
  253. ////////////////////////////////////////////////////////////////////////////
  254. ///////////////////////////////////////////////////////////////////////////
  255. //if they click the credit card button it will display the stacl pane for the card details
  256. ////////////////////////////////////////////////////////////////////////////
  257. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  258. btnCredit.setOnAction(e -> {
  259. paymentMethod = "Card";
  260. SP_CardDetails.setVisible(true);
  261. SP_Loyalty.setVisible(false);
  262. txtCardNum.clear();
  263. txtPointsAvailable.clear();
  264. txtLoyaltyPointsRequired.clear();
  265.  
  266. });
  267. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  268.  
  269.  
  270. ////////////////////////////////////////////////////////////////////////////
  271. ///////////////////////////////////////////////////////////////////////////
  272. //if they click the credit card button it will display the stacl pane for the card details
  273. ////////////////////////////////////////////////////////////////////////////
  274. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  275.  
  276.  
  277. btnLoyalty.setOnAction(e ->{
  278. paymentMethod = "Loyalty";
  279. SP_CardDetails.setVisible(false);
  280. SP_Loyalty.setVisible(true);
  281. txtCardNum.clear();
  282. txtPointsAvailable.clear();
  283. txtLoyaltyPointsRequired.clear();
  284. });
  285.  
  286.  
  287.  
  288. SP_Loyalty.setVisible(false);
  289.  
  290. GP_PaymentDetails.add(SP_CardDetails, 0, 0);
  291. GP_PaymentDetails.add(SP_Loyalty, 0, 0);
  292.  
  293. HBox HB_AmountDue = new HBox();
  294. HB_AmountDue.setSpacing(10);
  295.  
  296. Label lblAmountDue = new Label("Amount due: ");
  297. lblAmountDue.setFont(new Font("Arial",20));
  298.  
  299. TextField txtAmountDue = new TextField();
  300. txtAmountDue.setText("€ " + String.valueOf(OrderingScreen.iTotal));
  301. txtAmountDue.setPrefSize(200,30);
  302. HB_AmountDue.getChildren().addAll(lblAmountDue,txtAmountDue);
  303.  
  304.  
  305.  
  306. HBox HB_ConfirmCancel = new HBox();
  307. HB_ConfirmCancel.setSpacing(10);
  308.  
  309.  
  310.  
  311.  
  312.  
  313.  
  314.  
  315.  
  316.  
  317.  
  318.  
  319.  
  320.  
  321.  
  322.  
  323.  
  324.  
  325.  
  326.  
  327.  
  328. Button btnConfirm = new Button("Confirm payment");
  329. btnConfirm.setFont(new Font("Arial",20));
  330. btnConfirm.setPrefSize(200, 40);
  331. btnConfirm.setOnAction(e -> {//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  332. ((Node)e.getSource()).getScene().getWindow().hide();//this allows us to hide the current window
  333. //so the new window can be displayed on its own
  334.  
  335. generateOrder(loyaltyNumber);
  336. SandwichShopSystem.refresh.fire();
  337.  
  338. });///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  339.  
  340.  
  341.  
  342.  
  343.  
  344.  
  345.  
  346.  
  347.  
  348.  
  349. Button btnCancel = new Button("Cancel");
  350. btnCancel.setFont(new Font("Arial",20));
  351. btnCancel.setPrefSize(150,25);
  352. btnCancel.setOnAction(e -> {//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  353. ((Node)e.getSource()).getScene().getWindow().hide();//this allows us to hide the current window
  354. //so the new window can be displayed on its own
  355.  
  356. });/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  357.  
  358.  
  359.  
  360.  
  361.  
  362. HB_ConfirmCancel.getChildren().addAll(btnConfirm,btnCancel);
  363.  
  364.  
  365. CenterLayout.getChildren().addAll(CustLoyaltyBackGround,SP_PaymentBackGround,GP_PaymentDetails,HB_AmountDue,HB_ConfirmCancel);
  366.  
  367. CenterPane.getChildren().add(CenterLayout);
  368.  
  369. return CenterPane;
  370.  
  371. }
  372.  
  373. public static void generateOrder(long iLoyalty)
  374. {
  375. if (String.valueOf(iLoyalty).trim() == "")
  376. {
  377. loyaltyNumber = 0;
  378. }
  379. else
  380. {
  381. loyaltyNumber = Long.valueOf(iLoyalty);
  382. }
  383.  
  384. ResultSet customers = database.getTable("LOYALTYCUSTOMER");
  385.  
  386. if (String.valueOf(loyaltyNumber).trim() != "") //Check to see if the loyalty field is empty
  387. {
  388. try
  389. {
  390. while(customers.next()) //cycle through the values
  391. {
  392. if (customers.getLong("LOYALTYID") == loyaltyNumber) //Check to see if the customer loyalty number exists
  393. {
  394. cust = new Customer(customers.getString("NAME"), customers.getString("EMAIL"), customers.getLong("LOYALTYID"), customers.getInt("LOYALTYBALANCE"));
  395. //if the loyalty number is matched load that customer into a customer object - required to write to database
  396. }
  397. }
  398.  
  399.  
  400. }
  401. catch (SQLException ex)
  402. {
  403. ex.printStackTrace();
  404. }
  405. }
  406. else
  407. {
  408. cust = new Customer();
  409. }
  410.  
  411.  
  412. if (NewOrderPopUp.preOrder == false)
  413. {
  414. order = new Order(paymentMethod, cust.getLoyaltyNumber()); //Create the order Object
  415. }
  416. else
  417. {
  418. preOrder = new PreOrder(paymentMethod, cust.getLoyaltyNumber(), NewOrderPopUp.preName, NewOrderPopUp.preCollection, NewOrderPopUp.preNumber);
  419. }
  420.  
  421. //Add the quantities of each product selected in the ordering screen
  422.  
  423. ArrayList<OrderDetail> details = new ArrayList(); //Create an array for the orderDetails
  424.  
  425. if (NewOrderPopUp.preOrder == false)
  426. {
  427. for(int x = 1; x <= OrderingScreen.quantities.size();x++)
  428. {
  429.  
  430. if (OrderingScreen.quantities.get(x - 1) != 0)//if the quantity selected is not equal to zero add to the array of order details
  431. {
  432. details.add(new OrderDetail(order.getOrderNumber(),x ,OrderingScreen.quantities.get(x-1)));
  433.  
  434. }
  435. }
  436.  
  437.  
  438. order.calculateTotal(details);
  439.  
  440. database.write(order,cust);
  441. database.write(details);
  442.  
  443.  
  444.  
  445. }
  446. else
  447. {
  448. for(int x = 1; x <= OrderingScreen.quantities.size();x++)
  449. {
  450.  
  451. if (OrderingScreen.quantities.get(x-1) != 0)//if the quantity selected is not equal to zero add to the array of order details
  452. {
  453. details.add(new OrderDetail(preOrder.getOrderNumber(),x ,OrderingScreen.quantities.get(x-1)));
  454.  
  455. }
  456. }
  457.  
  458.  
  459. preOrder.calculateTotal(details);
  460.  
  461. database.write(preOrder,cust);
  462. database.write(details);
  463.  
  464.  
  465. System.out.println("PreOrder Sucess");
  466. }
  467.  
  468.  
  469. }
  470.  
  471.  
  472. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement