-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreditCardWindowController.java
More file actions
159 lines (123 loc) · 3.76 KB
/
CreditCardWindowController.java
File metadata and controls
159 lines (123 loc) · 3.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
package healthcareLook;
import java.net.URL;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Calendar;
import java.util.Date;
import java.util.ResourceBundle;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.control.TextField;
import javafx.scene.control.Tooltip;
import javafx.scene.image.ImageView;
public class CreditCardWindowController implements Initializable{
@FXML
TextField cardNumber;
@FXML
TextField cardName;
@FXML
TextField cvvcode;
@FXML
ComboBox month;
@FXML
ComboBox year;
@FXML
ComboBox cardType;
@FXML
Button cardSubmit;
@FXML
ImageView creditError;
Tooltip tip;
boolean isdone = true;
Date today = Calendar.getInstance().getTime();
int monthtest;
int yeartest;
boolean ispaid = true;
@Override
public void initialize(URL location, ResourceBundle resources) {
String[] format = today.toString().split(" ");
switch(format[1]){
case "Aug": monthtest = 8;
break;
case "Sep": monthtest = 9;
break;
case "Oct": monthtest = 10;
break;
case "Nov": monthtest = 11;
break;
case "Dec": monthtest = 12;
break;
case "Jan": monthtest = 1;
break;
case "Feb": monthtest = 2;
break;
case "Mar": monthtest = 3;
break;
case "Apr": monthtest = 4;
break;
case "May": monthtest = 5;
break;
case "Jun": monthtest = 6;
break;
case "Jul": monthtest = 7;
break;
}
yeartest = Integer.parseInt(format[5]);
for(int yearcount = 2000; yearcount< 2107; yearcount++){
year.getItems().add(Integer.toString(yearcount));
}
month.getItems().addAll("01","02","03","04","05","06","07","08","09","10","11","12");
cardType.getItems().addAll("Visa", "Discover", "MasterCard", "American Express");
cardType.getSelectionModel().selectFirst();
month.getSelectionModel().selectFirst();
year.getSelectionModel().selectLast();
cardSubmit.setOnAction(c->{
isdone= true;
//This checks if all the data has been entered. and stops if the data has not all been entered correctly
if(cardName.getText().trim().equals("")){
isdone = false;
tip.install(creditError, new Tooltip("Please fill in all Fields with the appropriate data."));
creditError.setVisible(true);
}
else{
creditError.setVisible(false);
}
if(cardNumber.getText().trim().equals("")){
isdone = false;
tip.install(creditError, new Tooltip("Please fill in all Fields with the appropriate data."));
creditError.setVisible(true);
}
else{
creditError.setVisible(false);
}
if(cvvcode.getText().trim().equals("")){
isdone = false;
tip.install(creditError, new Tooltip("Please fill in all Fields with the appropriate data."));
creditError.setVisible(true);
}
else{
creditError.setVisible(false);
}
//This checks if the card is expired. this compares to the current month and year.
if(Integer.parseInt(month.getSelectionModel().getSelectedItem().toString()) < monthtest && Integer.parseInt(year.getSelectionModel().getSelectedItem().toString()) < yeartest){
isdone = false;
tip.install(creditError, new Tooltip("The card is expired. Please select another card."));
creditError.setVisible(true);
//Card is expired
}
else{
creditError.setVisible(false);
}
if(isdone){
//If everything is good to go then the window will return a true and the window closes.
CreditCardWindow.SetPaid(ispaid);
CreditCardWindow.stageClose();
}
});
}
}