-
Notifications
You must be signed in to change notification settings - Fork 0
/
DoctorInfomodify.java
332 lines (249 loc) · 6.53 KB
/
DoctorInfomodify.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
332
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import javax.swing.*;
class DoctorInfomodify extends JFrame implements ActionListener
{
static Connection cn=null;
Statement st=null;
ResultSet rs=null;
JLabel lmain,ldi,lname,ladd,ltel,lspecial,ldid,ldspec,lwork,lworkfrom,lworkto;
JTextField tfname,tftel,tfdid,tfworkf,tfworkt;
TextArea taadd,taspecial;
JButton bsub,bclr,bmod,bback;
int x,y;
String str;
clsSettings settings = new clsSettings();
DoctorInfomodify()
{
super("Doctor Information");
setSize(1024,768);
setVisible(true);
setLayout(null);
lmain=new JLabel("Doctor Information");
lmain.setBounds(440,35,107,15);
add(lmain);
ldi=new JLabel("Doctor Information");
ldi.setBounds(40,70,120,15);
add(ldi);
lname=new JLabel("Name :");
lname.setBounds(104,97,70,25);
add(lname);
tfname=new JTextField(30);
tfname.setBounds(270,97,250,20);
add(tfname);
ladd=new JLabel("Address :");
ladd.setBounds(104,138,70,15);
add(ladd);
taadd=new TextArea();
taadd.setBounds(270,138,250,100);
add(taadd);
ltel=new JLabel("Contact :");
ltel.setBounds(575,138,50,25);
add(ltel);
ldid=new JLabel("Doctor ID:");
ldid.setBounds(570,97,70,25);
add(ldid);
tfdid=new JTextField(30);
tfdid.setBounds(643,97,50,20);
add(tfdid);
tftel=new JTextField(30);
tftel.setBounds(640,138,200,20);
add(tftel);
settings.Numvalidator(tftel);
ldspec=new JLabel("Specialization :");
ldspec.setBounds(104,310,100,25);
add(ldspec);
taspecial=new TextArea();
taspecial.setBounds(270,310,250,100);
add(taspecial);
lwork=new JLabel("Working hours :");
lwork.setBounds(570,310,100,15);
add(lwork);
lworkfrom=new JLabel("From :");
lworkfrom.setBounds(670,305,37,25);
add(lworkfrom);
tfworkf=new JTextField(30);
tfworkf.setBounds(710,310,30,20);
add(tfworkf);
settings.Numvalidator(tfworkf);
lworkto=new JLabel("to :");
lworkto.setBounds(747,305,20,25);
add(lworkto);
tfworkt=new JTextField(30);
tfworkt.setBounds(775,310,30,20);
add(tfworkt);
settings.Numvalidator(tfworkt);
bsub=new JButton("SEARCH",new ImageIcon("images/search.png"));
bsub.setBounds(250,643,110,30);
add(bsub);
bclr=new JButton("CLEAR",new ImageIcon("images/LOGGOFF.PNG"));
bclr.setBounds(390,643,100,30);
add(bclr);
bmod=new JButton("MODIFY",new ImageIcon("images/modify.png"));
bmod.setBounds(530,643,100,30);
add(bmod);
bback=new JButton("BACK",new ImageIcon("images/restore.png"));
bback.setBounds(700,643,100,30);
add(bback);
try{
Class.forName("org.postgresql.Driver");
cn=DriverManager.getConnection("jdbc:postgresql://localhost:5432/hospital", "akhil", "123");
}
catch(Exception e)
{
System.out.println(e);
}
bclr.addActionListener(new clear());
bsub.addActionListener(new submit());
bmod.addActionListener(new modify());
bback.addActionListener(new back());
}
public void actionPerformed(ActionEvent ae)
{}
class clear implements ActionListener
{
public void actionPerformed(ActionEvent ae)
{
tfname.setText("");
tftel.setText("");
tfdid.setText("");
tfworkf.setText("");
tfworkt.setText("");
taadd.setText("");
taspecial.setText("");
}
}
public static void main(String[] args)
{
new DoctorInfomodify();
System.out.println("Doctors Info Mod");
}
class back implements ActionListener
{
public void actionPerformed(ActionEvent ae)
{
new docStart();
setVisible(false);
}
}
class submit implements ActionListener
{
public void actionPerformed(ActionEvent ae)
{
try{
Integer num=Integer.parseInt(tfdid.getText());
String name;
String addr;
String contact;
String spec;
String workf;
String workt;
Statement st=cn.createStatement();
ResultSet rs=st.executeQuery("SELECT * FROM DOC WHERE did="+num);
if(rs.next())
{
num=rs.getInt("did");
name=rs.getString("name");
addr=rs.getString("address");
contact=rs.getString("contact");
spec=rs.getString("specialization");
workf=rs.getString("workfrom");
workt=rs.getString("workto");
tfname.setText(name);
taadd.setText(addr);
tftel.setText(contact);
taspecial.setText(spec);
tfworkf.setText(workf);
tfworkt.setText(workt);
}
else {
JOptionPane.showMessageDialog(null, "id no. not Found");}
}
catch(SQLException sq)
{
System.out.println(sq);
}
}
}
class modify implements ActionListener
{
public void actionPerformed(ActionEvent ae)
{
try{
Integer num1=Integer.parseInt(tfdid.getText());
if(num1.equals(null))
{
System.out.println("num");
throw new BlankException();
}
String name1=tfname.getText();
int a;
a=name1.charAt(0);
if(name1.equals("") || a==32)
{
throw new BlankException();
}
else
{
for(int i=0; i<name1.length(); i++)
{
boolean check = Character.isLetter(name1.charAt(i));
a=name1.charAt(i);
System.out.print(" "+a);
if(!((a>=65 && a<=90) || (a>=97 && a<=122) || (a==32) ||(a==46)))
{
throw new NameEx();
}
}
}
String addr1=taadd.getText();
if(addr1.equals(null))
{
System.out.println("addr");
throw new BlankException();
}
String contact1=tftel.getText();
String spec1=taspecial.getText();
String workf1=tfworkf.getText();
String workt1=tfworkt.getText();
//Statement st1=cn.createStatement();
String str="UPDATE DOC SET name=?,address=?,contact=?,specialization=?,workfrom=?,workto=? WHERE did=?";
Statement st1= cn.createStatement();
PreparedStatement psmt=cn.prepareStatement(str);
psmt.setString(1,name1);
psmt.setString(2,addr1);
psmt.setString(3,contact1);
psmt.setString(4,spec1);
psmt.setString(5,workf1);
psmt.setString(6,workt1);
psmt.setInt(7,num1);
psmt.executeUpdate();
new SuccessDialog2();
}catch(SQLException sq)
{
String message = "Enter Valid Doctor ID and Contact.";
JOptionPane.showMessageDialog(new JFrame(), message, "ERROR!",
JOptionPane.ERROR_MESSAGE);
System.out.println(sq);
}
catch(BlankException be)
{
new ErrorDialog2();
}
catch(NumberFormatException nfe)
{
new ErrorDialog();
}
catch(NameEx ne)
{
new ErrorDialog1();
}
catch(Exception e)
{
System.out.println(e);
new EDt();
}
}
}
}