-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathFrmAddMedicines.java
More file actions
392 lines (349 loc) · 10.6 KB
/
FrmAddMedicines.java
File metadata and controls
392 lines (349 loc) · 10.6 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
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
package hms;
import javax.swing.*;
import java.sql.*;
import java.awt.*;
import java.awt.event.*;
import java.util.Date;
import java.awt.event.FocusListener;
class FrmAddMedicines extends JInternalFrame
{
/**
*
*/
private static final long serialVersionUID = 1L;
JLabel lblDate,lblPatient_id,lblIPD_no,lblRoom_no,lblMCategory,lblMedicine,lblPrice,lblQuantity,lblAmount;
JTextField txtDate,txtPatient_id,txtRoom_no,txtPrice,txtAmount;
JComboBox<String> jcbmc;
JComboBox<String> jcbmd;
TextField txtID,txtQuantity;
final DefaultListModel<String> model = new DefaultListModel<String>();
JScrollPane jsp1;
DConnection dc;
JButton btnSave,btnDiscard;
ResultSet rst;
Date date;
FocusListener myFocusListener;
FrmAddMedicines()
{
super("Add/Edit Category",true,true,true,true);
FrmAddMedicines p11=this;
Date date = new Date();
JList<String> list1=new JList<String>(model);
list1.setVisibleRowCount(5);
list1.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
setResizable(false);
dc=new DConnection();
JPanel p1=new JPanel(new GridLayout(10,2));
lblDate = new JLabel("Date");
lblIPD_no=new JLabel("IPD");
lblPatient_id=new JLabel("Patient name");
lblRoom_no=new JLabel("room number");
lblMCategory=new JLabel("Medicine category");
lblMedicine=new JLabel("medicine");
lblPrice=new JLabel("Price");
lblQuantity=new JLabel("quantity");
lblAmount=new JLabel("Amount");
txtDate = new JTextField(date.toString());
txtID=new TextField();
txtDate.setEditable(false);
txtPatient_id=new JTextField(""); txtPatient_id.setEditable(false);
txtRoom_no=new JTextField(""); txtRoom_no.setEditable(false);
txtPrice=new JTextField("0"); txtPrice.setEditable(false);
txtQuantity=new TextField("0");
txtAmount=new JTextField("0"); txtAmount.setEditable(false);
jcbmc=new JComboBox<String>(); jcbmc.setEditable(false);
jcbmd=new JComboBox<String>();
txtAmount.setText("0");
try{
int i=0;
ResultSet rst2=dc.executeQuery("select * from ipdpatient where dod = 'Not Discharged Yet' order by ipd_no");
while(rst2.next())
{
// model.add(i,rst.getString(2));
// i++;
ResultSet rst3=dc.executeQuery("select * from patient where pat_id="+rst2.getString("pat_id"));
rst3.next();
String s1=rst2.getString("ipd_no")+"-"+rst3.getString("pat_name");
model.add(i,s1);
i++;
}
}
catch(SQLException e)
{
e.printStackTrace();
}
btnSave=new JButton("save");
btnDiscard=new JButton("discard");
btnDiscard.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
dispose();
}
});
int cat=0;
try
{
rst=dc.executeQuery("select * from mcategory");
while(rst.next())
{
if(cat==0)
cat=rst.getInt(1);
jcbmc.addItem(rst.getString(2));
}
rst=dc.executeQuery("select * from medicine where ct_id="+cat);
while(rst.next())
{
jcbmd.addItem(rst.getString(2));
}
}
catch(SQLException e)
{
e.printStackTrace();
}
jcbmc.addItemListener(new ItemListener()
{
public void itemStateChanged(ItemEvent fe)
{
jcbmd.removeAllItems();
try
{
System.out.println((String)jcbmc.getSelectedItem());
rst=dc.executeQuery("select * from medicine where md_cat='"+(String)jcbmc.getSelectedItem()+"'");
while(rst.next())
{
jcbmd.addItem(rst.getString(2));
}
}
catch(SQLException e)
{
e.printStackTrace();
}
}
});
jcbmd.addFocusListener (new FocusListener ()
{
public void focusLost(FocusEvent e)
{
try
{
rst=dc.executeQuery("select price from medicine where md_cat='"+(String)jcbmc.getSelectedItem()+"'and md_name='"+(String)jcbmd.getSelectedItem()+"'");
if(rst.next()==true)
{
txtPrice.setText(rst.getString(1));
}
}
catch(SQLException le)
{
le.printStackTrace();
}
}
public void focusGained(FocusEvent e){}
});
txtQuantity.addTextListener(new TextListener()
{
public void textValueChanged(TextEvent te)
{
txtAmount.setText((Integer.parseInt(txtQuantity.getText())*Integer.parseInt(txtPrice.getText()))+"");
}
});
btnSave.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
String s1=(String)date.toString();
String s3="",s4="";
String s[]=((String)list1.getSelectedValue()).split("-");
ResultSet rst2=dc.executeQuery("select * from medicine where md_name='"+(String)jcbmd.getSelectedItem()+"'");
try{
rst2.next();
s3=rst2.getString("ct_id");
s4=rst2.getString("md_id");
}
catch(SQLException e){
}
int s5=Integer.parseInt(txtQuantity.getText());
int s6=Integer.parseInt(txtAmount.getText());
if(s4.isEmpty())
{
JOptionPane.showMessageDialog(null,"please enter medicine name","Error",JOptionPane.ERROR_MESSAGE);
jcbmc.requestFocus();
return;
}
dc.executeOther("Insert into ipdmedicine values('"+s1+"',"+s[0]+",'"+s3+"','"+s4+"',"+s5+","+s6+")");
dispose();
// null.reload();
//null.jsp.repaint();
//null.repaint();*/
}
});
txtID.addTextListener(new TextListener()
{
public void textValueChanged(TextEvent te)
{
int len=model.getSize();
int count=txtID.getText().length(),k=0;
if(count!=0)
{
list1.clearSelection();
int value[]={-1,-1,-1,-1};
for(int j=0;j<len;j++)
{
String s1=(String)model.getElementAt(j);
if(s1.length()>=count)
{
if(s1.substring(0,count).equalsIgnoreCase(txtID.getText()))
{
value[k]=j;
k++;
}
}
}
// list1.ensureIndexIsVisible(value[0]);
list1.setSelectedIndices(value);
}
else list1.clearSelection();
}
});
txtID.addFocusListener(new FocusListener()
{
public void focusGained(FocusEvent fe)
{
// txtPatient.setBackground(Color.yellow);
jsp1.setVisible(true);
p11.revalidate();
p11.setSize(p11.getSize().width+1,p11.getSize().height+1);
}
public void focusLost(FocusEvent fe)
{
jsp1.setVisible(false);
ResultSet rst;
if(list1.isSelectionEmpty()==false){
}
else{
String list_value[]=((String)list1.getSelectedValue()).split("-");
String s2=list_value[2];
ResultSet rst2=dc.executeQuery("select * from ipdpatient where ipd_no="+list_value[0]);
try{
rst2.next();//done to avoid duplicate name errors
rst=dc.executeQuery("select * from patient where pat_name='"+s2+"' and pat_id="+rst2.getString("pat_id"));
while(rst.next()){
txtPatient_id.setText(rst.getString("pat_name"));
txtRoom_no.setText(rst2.getString("room_number"));
}
}
catch(SQLException e){
}
}}
});
list1.addMouseListener(new MouseListener()
{
public void mouseClicked(MouseEvent me)
{
txtID.requestFocus();
String list_value[]=((String)list1.getSelectedValue()).split("-");
txtID.setText(list_value[0]);
txtPatient_id.setText(list_value[1]);
try{
ResultSet rst3=dc.executeQuery("select * from ipdpatient where ipd_no="+list_value[0]);
rst3.next();
txtRoom_no.setText(rst3.getString("room_number"));}
catch(SQLException e){
}
jsp1.setVisible(false);
}
public void mousePressed(MouseEvent me){}
public void mouseReleased(MouseEvent me){}
public void mouseEntered(MouseEvent me){}
public void mouseExited(MouseEvent me){}
});
list1.addKeyListener(new KeyListener()
{
public void keyTyped(KeyEvent ke)
{
}
public void keyPressed(KeyEvent ke)
{
if(ke.getKeyCode()==KeyEvent.VK_ENTER)
{
String list_value[]=((String)list1.getSelectedValue()).split("-");
txtID.setText(list_value[0]);
txtPatient_id.setText(list_value[1]);
try{
ResultSet rst3=dc.executeQuery("select * from ipdpatient where ipd_no="+list_value[0]);
rst3.next();
txtRoom_no.setText(rst3.getString("room_number"));}
catch(SQLException e){
}
jsp1.setVisible(false);
}
}
public void keyReleased(KeyEvent ke){}
});
txtID.addKeyListener(new KeyListener()
{
public void keyTyped(KeyEvent ke)
{
}
public void keyPressed(KeyEvent ke)
{// if(list1.)
if(ke.getKeyCode()==KeyEvent.VK_ENTER)
{
String list_value[]=((String)list1.getSelectedValue()).split("-");
txtID.setText(list_value[0]);
txtPatient_id.setText(list_value[1]);
try{
ResultSet rst3=dc.executeQuery("select * from ipdpatient where ipd_no="+list_value[0]);
rst3.next();
txtRoom_no.setText(rst3.getString("room_number"));}
catch(SQLException e){
}
jsp1.setVisible(false);
}
else if(ke.getKeyCode()==KeyEvent.VK_UP)
{
int index=list1.getSelectedIndex();
if(index!=0)
index-=1;
list1.setSelectedIndex(index);
String list_value[]=((String)list1.getSelectedValue()).split("-");
txtID.setText(list_value[0]);
}
else if(ke.getKeyCode()==KeyEvent.VK_DOWN)
{
int index=list1.getSelectedIndex();
if(index!=model.getSize())
index+=1;
list1.setSelectedIndex(index);
String list_value[]=((String)list1.getSelectedValue()).split("-");
txtID.setText(list_value[0]);
}
else if(ke.getKeyCode()==KeyEvent.VK_TAB)
{
String list_value[]=((String)list1.getSelectedValue()).split("-");
txtID.setText(list_value[0]);
jsp1.setVisible(false);
}
}
public void keyReleased(KeyEvent ke){}
});
jsp1=new JScrollPane(list1);
jsp1.setVisible(false);
p1.add(lblDate);p1.add(txtDate);
p1.add(lblIPD_no);p1.add(txtID);
p1.add(lblPatient_id);p1.add(txtPatient_id);
p1.add(lblRoom_no);p1.add(txtRoom_no);
p1.add(lblMCategory);p1.add(jcbmc);
p1.add(lblMedicine);p1.add(jcbmd);
p1.add(lblPrice);p1.add(txtPrice);
p1.add(lblQuantity);p1.add(txtQuantity);
p1.add(lblAmount);p1.add(txtAmount);
p1.add(btnSave);p1.add(btnDiscard);
add(p1,"Center");
add(jsp1,"East");
setSize(500,500);
setVisible(true);
setLocation(CommonMethods.getCenterPoint(getSize()));
jsp1.setVisible(false);
}
}