-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUpdateContactForm.java
331 lines (295 loc) · 11.1 KB
/
UpdateContactForm.java
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class UpdateContactForm extends JFrame{
private JLabel titleLabel;
private JButton updateButton;
private JButton cancelButton;
private JButton backToHomeButton;
private JButton searchButton;
private JLabel idLabel;
private JLabel nameLabel;
private JLabel phoneNumberLabel;
private JLabel companyNameLabel;
private JLabel salaryLabel;
private JLabel birthDayLabel;
private JLabel genIdLabel;
private JTextField updateNameText;
private JTextField updateTpText;
private JTextField updateCompanyText;
private JTextField updateSalaryText;
private JTextField updateBirthDayText;
private JTextField searchText;
public UpdateContactForm(){
setSize(725,735);
setTitle("Update Contact Form ");
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
setLocationRelativeTo(null);
setLayout(new BorderLayout());
setResizable(false);
JPanel titlePanel=new JPanel();
titlePanel.setPreferredSize(new Dimension(725, 100));
titlePanel.setBackground(new Color(95, 119, 222));
titlePanel.setLayout(new BorderLayout());
titleLabel=new JLabel("UPDATE CONTACT");
titleLabel.setFont(new Font("",1,35));
titleLabel.setHorizontalAlignment(JLabel.CENTER);
titlePanel.add(titleLabel);
add(titlePanel, BorderLayout.NORTH);
JPanel detailPanel=new JPanel(new GridLayout(9,1));
detailPanel.setPreferredSize(new Dimension(725,635));
detailPanel.setLayout(null);
searchText=new JTextField(15);
searchText.setFont(new Font("",0,25));
searchText.setBounds(37,18,380,38);
/*searchText.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent evt){
String search=searchText.getText();
int index=ContactController.searchContact(search);
if(index!=-1){
genIdLabel.setText(ContactController.getContact(index).getID());
updateNameText.setText(ContactController.getContact(index).getName());
updateTpText.setText(ContactController.getContact(index).getphoneNumber());
updateCompanyText.setText(ContactController.getContact(index).getcompanyName());
updateSalaryText.setText(Double.toString(ContactController.getContact(index).getSalary()));
updateBirthDayText.setText(ContactController.getContact(index).getbirthDay());
}else{
JOptionPane.showMessageDialog(null,"No Contact found for "+"\""+search+"\".....");
searchText.setText("");
return;
}
}
});*/
detailPanel.add(searchText);
searchButton=new JButton("Search");
searchButton.setFont(new Font("",1,25));
searchButton.setBounds(450,18,150,38);
searchButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent evt){
ContactList contactList=DBConnection.getInstance().getContactList();
String nameOrPhone=searchText.getText();
int index=ContactController.searchContacts(nameOrPhone);
if(searchText.getText().equals("")){
JOptionPane.showMessageDialog(null,"Text field is Empty... Search Contact again");
searchText.requestFocus();
}else if(index!=-1){
genIdLabel.setText(contactList.get(index).getId());
updateNameText.setText(contactList.get(index).getName());
updateTpText.setText(contactList.get(index).getPhoneNumber());
updateCompanyText.setText(contactList.get(index).getCompanyName());
updateSalaryText.setText(""+contactList.get(index).getSalary());
updateBirthDayText.setText(contactList.get(index).getBirthday());
}else{
JOptionPane.showMessageDialog(null,"No contact found for "+nameOrPhone);
searchText.setText("");
searchText.requestFocus();
}
}
});
detailPanel.add(searchButton);
idLabel=new JLabel("Contact ID ");
idLabel.setFont(new Font("",1,25));
idLabel.setBounds(37,70,250,55);
detailPanel.add(idLabel);
nameLabel=new JLabel("Name");
nameLabel.setFont(new Font("",1,25));
nameLabel.setBounds(37,120,250,55);
detailPanel.add(nameLabel);
phoneNumberLabel=new JLabel("Phone Number");
phoneNumberLabel.setFont(new Font("",1,25));
phoneNumberLabel.setBounds(37,180,250,55);
detailPanel.add(phoneNumberLabel);
companyNameLabel=new JLabel("Company Name");
companyNameLabel.setFont(new Font("",1,25));
companyNameLabel.setBounds(37,250,250,55);
detailPanel.add(companyNameLabel);
salaryLabel=new JLabel("Salary");
salaryLabel.setFont(new Font("",1,25));
salaryLabel.setBounds(37,315,250,55);
detailPanel.add(salaryLabel);
birthDayLabel=new JLabel("B'Day(YYYY-MM-DD)");
birthDayLabel.setFont(new Font("",1,25));
birthDayLabel.setBounds(37,380,250,55);
detailPanel.add(birthDayLabel);
genIdLabel=new JLabel("");
genIdLabel.setFont(new Font("",1,26));
genIdLabel.setBounds(347,75,250,55);
detailPanel.add(genIdLabel);
updateNameText=new JTextField(15);
updateNameText.setFont(new Font("",0,25));
updateNameText.setBounds(350,135,260,36);
detailPanel.add(updateNameText);
updateTpText=new JTextField(20);
updateTpText.setFont(new Font("",0,25));
updateTpText.setBounds(350,195,260,36);
/*updateTpText.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent evt){
boolean tele=ContactController.readingphonenumber(updateTpText.getText());
if(!tele){
int a=JOptionPane.showConfirmDialog(null,"Invalid Number...Do You want add again ?", "Error",JOptionPane.YES_NO_OPTION, JOptionPane.ERROR_MESSAGE);
if(a==JOptionPane.YES_OPTION){
updateTpText.setText("");
updateTpText.requestFocus();
return;
}else {
dispose();
ContactController.reduceCount();
genIdLabel.setText(ContactController.genarateId());
updateNameText.setText("");
updateTpText.setText("");
updateCompanyText.setText("");
updateSalaryText.setText("");
updateBirthDayText.setText("");
return;
}
}
return;
}
});*/
detailPanel.add(updateTpText);
updateCompanyText=new JTextField(10);
updateCompanyText.setFont(new Font("",0,25));
updateCompanyText.setBounds(350,260,260,36);
detailPanel.add(updateCompanyText);
updateSalaryText=new JTextField(10);
updateSalaryText.setFont(new Font("",0,25));
updateSalaryText.setBounds(350,325,260,36);
/*updateSalaryText.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent evt){
boolean sala=ContactController.checkSalary(Double.parseDouble(updateSalaryText.getText()));
if(sala){
int a=JOptionPane.showConfirmDialog(null,"Invalid Salary...Do You want add again ?", "Error",JOptionPane.YES_NO_OPTION, JOptionPane.ERROR_MESSAGE);
if(a==JOptionPane.YES_OPTION){
updateSalaryText.setText("");
updateSalaryText.requestFocus();
return;
}else {
dispose();
ContactController.reduceCount();
genIdLabel.setText(ContactController.genarateId());
updateNameText.setText("");
updateTpText.setText("");
updateCompanyText.setText("");
updateSalaryText.setText("");
updateBirthDayText.setText("");
return;
}
}
return;
}
});*/
detailPanel.add(updateSalaryText);
updateBirthDayText=new JTextField(10);
updateBirthDayText.setFont(new Font("",0,25));
updateBirthDayText.setBounds(350,390,260,36);
/*updateBirthDayText.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent evt){
boolean dob=ContactController.birthDayValidate(updateBirthDayText.getText());
if(!dob){
int a=JOptionPane.showConfirmDialog(null,"Invalid Birthday...Do You want add again ?", "Error",JOptionPane.YES_NO_OPTION, JOptionPane.ERROR_MESSAGE);
if(a==JOptionPane.YES_OPTION){
updateBirthDayText.setText("");
updateBirthDayText.requestFocus();
return;
}else {
dispose();
ContactController.reduceCount();
genIdLabel.setText(ContactController.genarateId());
updateNameText.setText("");
updateTpText.setText("");
updateCompanyText.setText("");
updateSalaryText.setText("");
updateBirthDayText.setText("");
return;
}
}
return;
}
});*/
detailPanel.add(updateBirthDayText);
updateButton=new JButton("Update");
updateButton.setFont(new Font("",1,24));
updateButton.setBounds(350,450,180,36);
updateButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent evt){
try{
String id=genIdLabel.getText();
String name=updateNameText.getText();
String phoneNumber=updateTpText.getText();
String companyName=updateCompanyText.getText();
double salary=Double.parseDouble(updateSalaryText.getText());
String birthday=updateBirthDayText.getText();
String nameOrPhone=searchText.getText();
int index=ContactController.searchContacts(nameOrPhone);
boolean isUpdateContacts=ContactController.updateContacts(id,name,phoneNumber,companyName,salary,birthday,index);
if(isUpdateContacts){
JOptionPane.showMessageDialog(null,"Update Success");
int option=JOptionPane.showConfirmDialog(null,"Do you want to update another contact ? ","Confirm",JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
if(option==JOptionPane.YES_OPTION){
searchText.setText("");
searchText.requestFocus();
genIdLabel.setText("");
updateNameText.setText("");
updateTpText.setText("");
updateCompanyText.setText("");
updateSalaryText.setText("");
updateBirthDayText.setText("");
}else if(option==JOptionPane.NO_OPTION){
searchText.setText("");
genIdLabel.setText("");
updateNameText.setText("");
updateTpText.setText("");
updateCompanyText.setText("");
updateSalaryText.setText("");
updateBirthDayText.setText("");
dispose();
}
}else{
JOptionPane.showMessageDialog(null,"Update Fail");
}
}catch(NumberFormatException ex){
JOptionPane.showMessageDialog(null,"Text Field is empty...");
searchText.requestFocus();
}
}
});
detailPanel.add(updateButton);
cancelButton=new JButton("Cancel");
cancelButton.setFont(new Font("",1,24));
cancelButton.setBounds(550,450,130,36);
cancelButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent evt){
searchText.setText("");
genIdLabel.setText("");
updateNameText.setText("");
updateTpText.setText("");
updateCompanyText.setText("");
updateSalaryText.setText("");
updateBirthDayText.setText("");
return;
}
});
detailPanel.add(cancelButton);
backToHomeButton=new JButton("Back To HomePage");
backToHomeButton.setFont(new Font("",1,24));
backToHomeButton.setBounds(350,500,331,36);
backToHomeButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent evt){
searchText.setText("");
dispose();
genIdLabel.setText("");
updateNameText.setText("");
updateTpText.setText("");
updateCompanyText.setText("");
updateSalaryText.setText("");
updateBirthDayText.setText("");
return;
}
});
detailPanel.add(backToHomeButton);
add(detailPanel);
}
public static void main(String args[]){
new UpdateContactForm().setVisible(true);
}
}