-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathFrmAddEditPatient.java
More file actions
195 lines (171 loc) · 6.2 KB
/
FrmAddEditPatient.java
File metadata and controls
195 lines (171 loc) · 6.2 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
package hms;
import javax.swing.*;
import java.sql.*;
import java.awt.*;
import java.awt.event.*;
class FrmAddEditPatient extends JInternalFrame
{
/**
*
*/
private static final long serialVersionUID = 1L;
JLabel lblId,lblName,lblContact,lblAddress,lblMailId,lblAge,lblGender,lblF_Name;
JTextField txtId,txtName,txtContact,txtMailId,txtAge,txtF_Name;
JTextArea txtarAddress;
JRadioButton rbGen_Male,rbGen_Female;
ButtonGroup bg;
JPanel p1;
JButton btnSave,btnDiscard;
DConnection dc;
ResultSet rst;
int pat_id=0;
FrmAddEditPatient(boolean flag,String query,FrmPatient fp)
{
super("Add/Edit Patient",true,true,true,true);
setResizable(false);
dc=new DConnection();
p1=new JPanel();
setLayout(new GridLayout(9,2));
lblId = new JLabel("Patient Id");
lblId.setForeground(new Color(64,0,0));
lblId.setFont(new Font(Font.SERIF,Font.ITALIC+Font.BOLD,18));
lblName = new JLabel("Patient Name");
lblName.setForeground(new Color(64,0,0));
lblName.setFont(new Font(Font.SERIF,Font.ITALIC+Font.BOLD,18));
lblContact = new JLabel("Contact");
lblContact.setForeground(new Color(64,0,0));
lblContact.setFont(new Font(Font.SERIF,Font.ITALIC+Font.BOLD,18));
lblAddress = new JLabel("Address");
lblAddress.setForeground(new Color(64,0,0));
lblAddress.setFont(new Font(Font.SERIF,Font.ITALIC+Font.BOLD,18));
lblMailId = new JLabel("Mail Id");
lblMailId.setForeground(new Color(64,0,0));
lblMailId.setFont(new Font(Font.SERIF,Font.ITALIC+Font.BOLD,18));
lblAge=new JLabel("Age");
lblAge.setForeground(new Color(64,0,0));
lblAge.setFont(new Font(Font.SERIF,Font.ITALIC+Font.BOLD,18));
lblGender=new JLabel("Gender");
lblGender.setForeground(new Color(64,0,0));
lblGender.setFont(new Font(Font.SERIF,Font.ITALIC+Font.BOLD,18));
lblF_Name=new JLabel("Father's Name");
lblF_Name.setForeground(new Color(64,0,0));
lblF_Name.setFont(new Font(Font.SERIF,Font.ITALIC+Font.BOLD,18));
txtId=new JTextField();
txtId.setEditable(false);
txtId.setForeground(new Color(49,49,49));
txtId.setBackground(new Color(192,192,192));
txtId.setFont(new Font(Font.SERIF,Font.ITALIC+Font.BOLD,18));
txtName=new JTextField();
txtName.setForeground(new Color(106,106,106));
txtName.setFont(new Font(Font.SERIF,Font.ITALIC+Font.BOLD,18));
txtContact=new JTextField();
txtContact.setForeground(new Color(106,106,106));
txtContact.setFont(new Font(Font.SERIF,Font.ITALIC+Font.BOLD,18));
txtarAddress=new JTextArea();
txtarAddress.setForeground(new Color(106,106,106));
txtarAddress.setFont(new Font(Font.SERIF,Font.ITALIC+Font.BOLD,18));
txtMailId=new JTextField();
txtMailId.setForeground(new Color(106,106,106));
txtMailId.setFont(new Font(Font.SERIF,Font.ITALIC+Font.BOLD,18));
txtAge=new JTextField();
txtAge.setForeground(new Color(106,106,106));
txtAge.setFont(new Font(Font.SERIF,Font.ITALIC+Font.BOLD,18));
txtF_Name=new JTextField();
txtF_Name.setForeground(new Color(106,106,106));
txtF_Name.setFont(new Font(Font.SERIF,Font.ITALIC+Font.BOLD,18));
rbGen_Male=new JRadioButton("Male");
rbGen_Male.setForeground(new Color(106,106,106));
rbGen_Male.setFont(new Font(Font.SERIF,Font.ITALIC+Font.BOLD,18));
rbGen_Female=new JRadioButton("Female");
rbGen_Female.setForeground(new Color(106,106,106));
rbGen_Female.setFont(new Font(Font.SERIF,Font.ITALIC+Font.BOLD,18));
bg=new ButtonGroup();
bg.add(rbGen_Male);bg.add(rbGen_Female);
p1.add(rbGen_Male);p1.add(rbGen_Female);
try
{
if(flag==true)//add new
{
rst=dc.executeQuery("select max(pat_id) from patient");
rst.next();
pat_id=rst.getInt(1)+1;
txtId.setText(pat_id+"");
dc.close();
btnSave=new JButton("Save");
}
else//edit
{
rst=dc.executeQuery(query);
rst.next();
txtId.setText(rst.getString(1));
txtName.setText(rst.getString(2));
txtAge.setText(rst.getString(3));
txtF_Name.setText(rst.getString(4));
if(rst.getString(5).equals("Male"))
rbGen_Male.setSelected(true);
else
rbGen_Female.setSelected(true);
txtarAddress.setText(rst.getString(6));
txtContact.setText(rst.getString("contact"));
txtMailId.setText(rst.getString("mail_id"));
btnSave=new JButton("Update");
}
}
catch(SQLException e)
{
e.printStackTrace();
}
btnDiscard=new JButton("Discard");
btnDiscard.setForeground(Color.white);
btnDiscard.setBackground(Color.red);
btnDiscard.setFont(new Font(Font.SERIF,Font.ITALIC,22));
btnDiscard.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
dispose();
}
});
btnSave.setForeground(Color.white);
btnSave.setBackground(Color.blue);
btnSave.setFont(new Font(Font.SERIF,Font.ITALIC,22));
btnSave.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
String s1=txtId.getText();
String s2=txtName.getText();
String s3=txtAge.getText();
String s4=txtF_Name.getText();
String s5="";
if(rbGen_Male.isSelected())
s5="Male";
else if(rbGen_Female.isSelected())
s5="Female";
String s6=txtarAddress.getText();
String s7=txtContact.getText();
String s8=txtMailId.getText();
if(flag==true)
dc.executeOther("Insert into patient values("+s1+",'"+s2+"',"+s3+",'"+s4+"','"+s5+"','"+s6+"','"+s7+"','"+s8+"')");
else
dc.executeOther("update patient set pat_name='"+s2+"',age="+s3+",father_name='"+s4+"',gender='"+s5+"',address='"+s6+"',contact='"+s7+"',mail_id='"+s8+"' where pat_id="+s1);
dispose();
fp.reload();
//fp.jsp.repaint();
//fp.repaint();
}
});
add(lblId);add(txtId);
add(lblName);add(txtName);
add(lblAge);add(txtAge);
add(lblF_Name);add(txtF_Name);
add(lblGender);add(p1);
add(lblAddress);add(txtarAddress);
add(lblContact);add(txtContact);
add(lblMailId);add(txtMailId);
add(btnSave);add(btnDiscard);
setSize(350,350);
setVisible(true);
setLocation(CommonMethods.getCenterPoint(getSize()));
}
}