-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHomePage_Patients.java
More file actions
354 lines (283 loc) · 10.1 KB
/
Copy pathHomePage_Patients.java
File metadata and controls
354 lines (283 loc) · 10.1 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
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
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
package DoctorsAP;
import java.awt.EventQueue;
import javax.swing.border.TitledBorder;
import net.proteanit.sql.DbUtils;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.sql.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.*;
import java.awt.Color;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.Font;
import java.awt.Image;
public class HomePage_Patients {
protected static final JOptionPane JSPINNER_ID = null;
JFrame frame;
private JTable table;
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
HomePage_Patients window = new HomePage_Patients ();
window.frame.setVisible(true);
window.frame.setResizable(false);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
Connection connection = null;
private JScrollPane scrollPane;
private JButton btnSave;
private JTextField txt_P_ID;
private JTextField txt_P_Name;
private JTextField txt_P_Number;
private JTextField txt_A_Address;
private JPanel panel;
private JTextField txt_search;
private JButton button;
private JTabbedPane tabbedPane;
private JPanel panel_appointment;
private JPanel panel_profile;
private JTextField txt_D_Name;
private JTextField txt_D_ID;
JLabel labelforProfile;
/**
* Create the application.
*/
public void refreshTable(){
try {
String query= "select * from p_registration";
PreparedStatement pst = connection.prepareStatement(query);
ResultSet rs = pst.executeQuery();
table.setModel(DbUtils.resultSetToTableModel(rs));
} catch (Exception e) {
e.printStackTrace();
}
}
// Function To Resize The Image To Fit Into JLabel
public ImageIcon ResizeImage(String ImagePath, byte[] pic)
{
ImageIcon MyImage = null;
if(ImagePath != null)
{
MyImage = new ImageIcon(ImagePath);
}else
{
MyImage = new ImageIcon(pic);
}
Image img = MyImage.getImage();
Image newImg = img.getScaledInstance(labelforProfile.getWidth(), labelforProfile.getHeight(), Image.SCALE_SMOOTH);
ImageIcon image = new ImageIcon(newImg);
return image;
}
HomePage_Patients () {
connection = SQLconnection.dbConnector();
frame = new JFrame();
frame.setBounds(100, 100, 1100, 560);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.getContentPane().setLayout(null);
tabbedPane = new JTabbedPane(JTabbedPane.TOP);
tabbedPane.setBounds(10, 11, 1073, 485);
frame.getContentPane().add(tabbedPane);
panel_appointment = new JPanel();
tabbedPane.addTab("Appointment", null, panel_appointment, null);
panel_appointment.setLayout(null);
panel = new JPanel();
panel.setBounds(10, 60, 248, 289);
panel_appointment.add(panel);
panel.setBorder(new TitledBorder(null, "Patient's Information", TitledBorder.LEADING, TitledBorder.TOP, null, null));
panel.setLayout(null);
JLabel lblPhoneNo = new JLabel();
lblPhoneNo.setBounds(10, 217, 94, 25);
panel.add(lblPhoneNo);
lblPhoneNo.setText("Phone No :");
lblPhoneNo.setHorizontalAlignment(SwingConstants.RIGHT);
lblPhoneNo.setForeground(Color.BLACK);
JLabel lblP_Name = new JLabel();
lblP_Name.setBounds(10, 64, 94, 25);
panel.add(lblP_Name);
lblP_Name.setText("Patient's Name :");
lblP_Name.setHorizontalAlignment(SwingConstants.RIGHT);
lblP_Name.setForeground(Color.BLACK);
JLabel lblP_ID = new JLabel();
lblP_ID.setBounds(10, 28, 94, 25);
panel.add(lblP_ID);
lblP_ID.setText("Patient's ID :");
lblP_ID.setHorizontalAlignment(SwingConstants.RIGHT);
lblP_ID.setForeground(Color.BLACK);
txt_P_ID = new JTextField();
txt_P_ID.setBounds(114, 28, 113, 25);
panel.add(txt_P_ID);
txt_P_ID.setToolTipText("Please type ur current log in ID");
txt_P_ID.setText("");
txt_P_Name = new JTextField();
txt_P_Name.setBounds(114, 64, 113, 25);
panel.add(txt_P_Name);
txt_P_Name.setToolTipText("Please input your full name");
txt_P_Name.setText("");
txt_P_Number = new JTextField();
txt_P_Number.setBounds(114, 217, 113, 25);
panel.add(txt_P_Number);
txt_P_Number.setToolTipText("Please input your mobile number");
txt_P_Number.setText("");
txt_A_Address = new JTextField();
txt_A_Address.setBounds(114, 253, 113, 25);
panel.add(txt_A_Address);
txt_A_Address.setToolTipText("Please input your full adress");
txt_A_Address.setText("");
JLabel lblAdress = new JLabel();
lblAdress.setBounds(20, 253, 80, 25);
panel.add(lblAdress);
lblAdress.setText("Address :");
lblAdress.setHorizontalAlignment(SwingConstants.RIGHT);
lblAdress.setForeground(Color.BLACK);
txt_D_Name = new JTextField();
txt_D_Name.setToolTipText("Please input your full name");
txt_D_Name.setText("");
txt_D_Name.setBounds(114, 100, 113, 25);
panel.add(txt_D_Name);
JLabel lblDoctorsName = new JLabel();
lblDoctorsName.setText("Doctor's Name :");
lblDoctorsName.setHorizontalAlignment(SwingConstants.RIGHT);
lblDoctorsName.setForeground(Color.BLACK);
lblDoctorsName.setBounds(10, 100, 94, 25);
panel.add(lblDoctorsName);
txt_D_ID = new JTextField();
txt_D_ID.setToolTipText("Please input your full name");
txt_D_ID.setText("");
txt_D_ID.setBounds(114, 136, 113, 25);
panel.add(txt_D_ID);
JLabel lblDoctorsId = new JLabel();
lblDoctorsId.setText("Doctor's ID :");
lblDoctorsId.setHorizontalAlignment(SwingConstants.RIGHT);
lblDoctorsId.setForeground(Color.BLACK);
lblDoctorsId.setBounds(10, 136, 94, 25);
panel.add(lblDoctorsId);
button = new JButton("<<");
button.setBounds(10, 11, 130, 25);
panel_appointment.add(button);
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
//HomePageCustomer window = new HomePageCustomer();
//window.frame.setVisible(true);
//window.frame.setResizable(false);
frame.dispose();
}
});
JPanel panel_1 = new JPanel();
panel_1.setBounds(0, 0, 1072, 439);
panel_appointment.add(panel_1);
panel_1.setBackground(new Color(255, 255, 255));
panel_1.setLayout(null);
JButton btnclear = new JButton("Clear");
btnclear.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
txt_P_ID.setText(null);
txt_P_Name.setText(null);
txt_P_Number.setText(null);
txt_A_Address.setText(null);
}
});
JLabel label_photo = new JLabel("");
label_photo.setBounds(711, 67, 281, 281);
panel_1.add(label_photo);
label_photo.setOpaque(true);
label_photo.setBackground(Color.GRAY);
panel_1.add(label_photo);
btnclear.setBounds(185, 365, 70, 38);
panel_1.add(btnclear);
btnSave = new JButton("Confirm Appointment");
btnSave.setBounds(10, 365, 165, 38);
panel_1.add(btnSave);
scrollPane = new JScrollPane();
scrollPane.setBounds(266, 65, 435, 283);
panel_1.add(scrollPane);
table = new JTable();
table.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent arg0) {
try {
int row = table.getSelectedRow();
String NAME_D=(table.getModel().getValueAt(row, 0)).toString();
String query= "select * from p_registration where NAME_P='"+NAME_D+"' ";
PreparedStatement pst = connection.prepareStatement(query);
ResultSet rs = pst.executeQuery();
while (rs.next())
{
txt_D_Name.setText(rs.getString("NAME_P"));
txt_D_ID.setText(rs.getString("ID_P"));
//label_photo.setIcon(new ImageIcon(rs.getBytes("PHOTO_P")));
label_photo.setIcon(ResizeImage(null, rs.getBytes("PHOTO_P")));
}
} catch (Exception e) {
e.printStackTrace();
}
}
});
scrollPane.setViewportView(table);
JLabel lblSearch = new JLabel();
lblSearch.setBounds(489, 29, 70, 25);
panel_1.add(lblSearch);
lblSearch.setText("Search");
lblSearch.setHorizontalAlignment(SwingConstants.RIGHT);
lblSearch.setForeground(Color.BLACK);
txt_search = new JTextField();
txt_search.setToolTipText("Search by model name");
txt_search.setBounds(571, 17, 130, 34);
panel_1.add(txt_search);
txt_search.addKeyListener(new KeyAdapter() {
@Override
public void keyReleased(KeyEvent arg0) {
try {
String query= "select * from service where NAME_D=? ";
PreparedStatement pst = connection.prepareStatement(query);
pst.setString(1, txt_search.getText());
ResultSet rs = pst.executeQuery();
table.setModel(DbUtils.resultSetToTableModel(rs));
//while (rs.next())
//{
// pst.close();
//}
} catch (Exception e) {
e.printStackTrace();
}
}
});
txt_search.setColumns(10);
panel_profile = new JPanel();
tabbedPane.addTab("Profile", null, panel_profile, null);
panel_profile.setLayout(null);
labelforProfile = new JLabel("");
labelforProfile.setOpaque(true);
labelforProfile.setBackground(Color.GRAY);
labelforProfile.setBounds(10, 11, 333, 281);
panel_profile.add(labelforProfile);
btnSave.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
try {
String query= "insert into test_drive(Customer_ID,Car_No,Customer_Name,Phone_No,Address) values(?,?,?,?,?)";
PreparedStatement pst = connection.prepareStatement(query);
pst.setString(1, txt_P_ID.getText());
//pst.setString(2, txt_carNo.getText());
pst.setString(3, txt_P_Name.getText());
pst.setString(4, txt_P_Number.getText());
pst.setString(5, txt_A_Address.getText());
pst.execute();
JOptionPane.showMessageDialog(null, "data saved");
pst.close();
} catch (Exception e) {
e.printStackTrace();
}
refreshTable();
}
});
refreshTable();
}
}