-
Notifications
You must be signed in to change notification settings - Fork 0
/
UpdateMedicine.java
404 lines (356 loc) · 12.1 KB
/
UpdateMedicine.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
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
393
394
395
396
397
398
399
400
401
402
403
404
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.*;
import javax.swing.table.DefaultTableModel;
import java.sql.*;
import java.sql.ResultSet;
public class UpdateMedicine extends JFrame implements ActionListener
{
JFrame jf;
JTextField t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12;
JLabel l1,l2,l3,l4,l5,l6,l7,l8,l9,l10,l11,l12,ln;
JButton b0,b1,b2,b3;
JComboBox msname,tabtype;
String s,sid1,tabt;
Font f;
Connection con;
PreparedStatement ps;
Statement stmt;
ResultSet rs;
DefaultTableModel model = new DefaultTableModel();
JTable tabGrid = new JTable(model);
JScrollPane scrlPane = new JScrollPane(tabGrid);
UpdateMedicine()
{
jf=new JFrame();
f = new Font("Times New Roman",Font.BOLD,20);
jf.setLayout(null);
ln=new JLabel("Update Medicine");
ln.setFont(new Font("Times New Roman",Font.BOLD,25));
ln.setForeground(Color.blue);
ln.setBounds(300,30,300,40);
jf.add(ln);
l1 = new JLabel("Medicine Batch no*");
//l1.setFont(f);
l1.setBounds(50,100,200,25);
jf.add(l1);
t1 = new JTextField(20);
t1.setBounds(250,100,100,25);t1.setToolTipText("Enter medicine batch no");
jf.add(t1);
l2 = new JLabel("Medicine name*");
//l2.setFont(f);
l2.setBounds(50,140,200,25);
jf.add(l2);
t2 = new JTextField(20);
t2.setBounds(250,140,200,25);t2.setToolTipText("Enter medicine name");
jf.add(t2);
l3 = new JLabel("Medicine company*");
//l3.setFont(f);
l3.setBounds(50,180,200,25);
jf.add(l3);
t3 = new JTextField(20);
t3.setBounds(250,180,200,25);t3.setToolTipText("Enter medicine company");
jf.add(t3);
l4 = new JLabel("Medicine quantity*");
//l4.setFont(f);
l4.setBounds(50,220,200,25);
jf.add(l4);
t4= new JTextField(20);
t4.setBounds(250,220,100,25);t4.setToolTipText("Enter medicine quantity");
jf.add(t4);
l5= new JLabel("Med expiry date*");
//l5.setFont(f);
l5.setBounds(50,260,250,25);
jf.add(l5);
t5= new JTextField(20);
t5.setBounds(250,260,100,25);t5.setToolTipText("Enter medicine expiry date");
jf.add(t5);
l6= new JLabel("Med purchase date*");
//l6.setFont(f);
l6.setBounds(50,300,260,25);
jf.add(l6);
t6= new JTextField(20);
t6.setBounds(250,300,100,25);t6.setToolTipText("Enter medicine expiry date");
jf.add(t6);
l7 = new JLabel("Medicine type*");
//l7.setFont(f);
l7.setBounds(470,100,200,25);
jf.add(l7);
t7 = new JTextField(20);
t7.setBounds(720,100,100,25);t7.setToolTipText("Enter medicine type");
jf.add(t7);
tabtype=new JComboBox();
tabtype.addItem("--type--");
tabtype.addItem("Tablet");
tabtype.addItem("Capsule");
tabtype.addItem("Syrup");
tabtype.addItem("Insulin");
tabtype.addItem("Cream");
tabtype.addItem("Balm");
tabtype.addItem("Drop");
tabtype.addItem("Granul");
tabtype.addItem("Oil");
tabtype.addItem("Powder");
tabtype.setBounds(600,100,100,25);tabtype.setToolTipText("Select medicine type");
jf.add(tabtype);
tabtype.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
tabt =(String)tabtype.getSelectedItem();
t7.setText(tabt);
}
});
l8= new JLabel("Medicine purchase price*");
//l8.setFont(f);
l8.setBounds(470,140,220,25);
jf.add(l8);
t8 = new JTextField(20);
t8.setBounds(720,140,100,25);t8.setToolTipText("Enter medicine purchase price");
jf.add(t8);
l9 = new JLabel("Medicine sale price*");
// l9.setFont(f);
l9.setBounds(470,180,200,25);
jf.add(l9);
t9 = new JTextField(20);
t9.setBounds(720,180,100,25);t9.setToolTipText("Enter medicine sale price");
jf.add(t9);
l10 = new JLabel("Medicine rack no*");
//l10.setFont(f);
l10.setBounds(470,220,200,25);
jf.add(l10);
t10 = new JTextField(20);
t10.setBounds(720,220,100,25);t10.setToolTipText("Enter medicine rack no");
jf.add(t10);
l11 = new JLabel("Supplier name*");
//l11.setFont(f);
l11.setBounds(470,260,180,25);
jf.add(l11);
t11 = new JTextField(20);
t11.setBounds(720,260,100,25);
jf.add(t11);
l12 = new JLabel("Supplier id");
// l12.setFont(f);
l12.setBounds(470,300,180,25);
jf.add(l12);
t12 = new JTextField(20);
t12.setBounds(720,300,100,25);
jf.add(t12);
msname=new JComboBox();
msname.setBounds(600,260,110,25);msname.setToolTipText("select medicine supplier name");
jf.add(msname);
msname.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
s =(String)msname.getSelectedItem();
t11.setText(s);
}
});
try
{
Class.forName("com.mysql.jdbc.Driver");
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/medical_store","root","");
System.out.println("Connected to database.");
ps=con.prepareStatement("select sid,sname from supplier");
rs=ps.executeQuery();
while(rs.next())
{
sid1=rs.getString(1);
String sname1=rs.getString(2);
msname.addItem(sname1);
}
con.close();
}
catch(SQLException se)
{
System.out.println(se);
}
catch(Exception e)
{
System.out.println(e);
}
b0 = new JButton("Open",new ImageIcon("images//open.png"));
b0.setBounds(150,330,110,35);b0.setToolTipText("click to open medicine details");
jf.add(b0);b0.addActionListener(this);
b1 = new JButton("Update",new ImageIcon("images//update.png"));
b1.setBounds(300,330,110,35);b1.setToolTipText("click to update medicine details");
jf.add(b1); b1.addActionListener(this);
b2= new JButton("Clear",new ImageIcon("images//clear.png"));
b2.setBounds(450,330,110,35);b2.setToolTipText("click to clear all textfields");
jf.add(b2); b2.addActionListener(this);
b3 = new JButton("All",new ImageIcon("images//all.png"));
b3.setBounds(600,330,110,35);b3.setToolTipText("click to view all medicine details");
jf.add(b3); b3.addActionListener(this);
scrlPane.setBounds(0,380,900,600);
jf.add(scrlPane);
tabGrid.setFont(new Font ("Times New Roman",0,15));
model.addColumn("M_BNO");
model.addColumn("M_NAME");
model.addColumn("M_COMPANY");
model.addColumn("M_QUANTITY");
model.addColumn("M_EXPDATE");
model.addColumn("M_PURDATE");
model.addColumn("M_TYPE");
model.addColumn("M_SALEPRICE");
model.addColumn("M_PURPRICE");
model.addColumn("M_RACKNO");
model.addColumn("M_SID");
model.addColumn("M_SNAME");
jf.setTitle("Update Medicine ");
jf.setSize(900,700);
jf.setLocation(20,20);
jf.setResizable(false);
jf.getContentPane().setBackground(Color.cyan);
jf.setVisible(true);
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==b0)
{
if(((t1.getText()).equals(""))&&((t2.getText()).equals("")))
{
JOptionPane.showMessageDialog(this,"Please enter medicine batchno or name !","Warning!!!",JOptionPane.WARNING_MESSAGE);
}
else
{
try
{//fetch
int foundrec = 0;
Class.forName("com.mysql.jdbc.Driver");
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/medical_store","root","");
System.out.println("Connected to database.");
ps=con.prepareStatement("Select sid from supplier where sname='"+s+"'");
rs=ps.executeQuery();
while(rs.next())
{
String sid1=rs.getString(1);
t12.setText(sid1);
}
ps=con.prepareStatement("select * from medicine where mname='"+t2.getText()+"' or mbno='"+t1.getText()+"' ");
rs=ps.executeQuery();
while(rs.next())
{
t1.setText(rs.getString(1));
t2.setText(rs.getString(2));
t3.setText(rs.getString(3));
t4.setText(rs.getString(4));
t5.setText(rs.getString(5));
t6.setText(rs.getString(6));
t7.setText(rs.getString(7));
t8.setText(rs.getString(8));
t9.setText(rs.getString(9));
t10.setText(rs.getString(10));
t12.setText(rs.getString(11));
t11.setText(rs.getString(12));
foundrec = 1;
}
if (foundrec == 0)
{
JOptionPane.showMessageDialog(null,"Record is not available","Dialogs",JOptionPane.WARNING_MESSAGE);
}
con.close();
}
catch(SQLException se)
{
System.out.println(se);
JOptionPane.showMessageDialog(null,"SQL Error:"+se);
}
catch(Exception e)
{
System.out.println(e);
JOptionPane.showMessageDialog(null,"Error:"+e);
}
}
}
else if(ae.getSource()==b1)
{
try
{
if(((t1.getText()).equals(""))||((t2.getText()).equals(""))||((t3.getText()).equals(""))||((t4.getText()).equals(""))||((t5.getText()).equals(""))||((t6.getText()).equals(""))||((t7.getText()).equals(""))||((t8.getText()).equals(""))||((t9.getText()).equals(""))||((t10.getText()).equals(""))||((t11.getText()).equals("")))
{
JOptionPane.showMessageDialog(this,"* Detail are Missing !","Warning!!!",JOptionPane.WARNING_MESSAGE);
}
else
{
Class.forName("com.mysql.jdbc.Driver");
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/medical_store","root","");
System.out.println("Connected to database.");
stmt=con.createStatement();
String str1="UPDATE medicine SET mbno='"+t1.getText()+"',mname='"+t2.getText()+"',mcompany='"+t3.getText()+"',mqty='"+t4.getText()+"',mexpdate='"+t5.getText()+"',mpurdate='"+t6.getText()+"',mtype='"+t7.getText()+"',mpurprice='"+t8.getText()+"',msaleprice='"+t9.getText()+"',mrackno='"+t10.getText()+"',sid='"+t12.getText()+"',sname='"+t11.getText()+"' where mbno='"+t1.getText()+"'or mname='"+t2.getText()+"'";
stmt.executeUpdate(str1);
JOptionPane.showMessageDialog(null, "Record is updated");
t1.setText("");
t2.setText("");
t3.setText("");
t4.setText("");
t5.setText("");
t6.setText("");
t7.setText("");
t8.setText("");
t9.setText("");
t10.setText("");
t11.setText("");
t12.setText("");
con.close();
}
}
catch(SQLException se)
{
System.out.println(se);
JOptionPane.showMessageDialog(null,"SQL Error:"+se);
}
catch(Exception e)
{
System.out.println(e);
JOptionPane.showMessageDialog(null,"Error:"+e);
}
}
else if(ae.getSource()==b2)
{ t1.setText("");
t2.setText("");
t3.setText("");
t4.setText("");
t5.setText("");
t6.setText("");
t7.setText("");
t8.setText("");
t9.setText("");
t10.setText("");
t11.setText("");
t12.setText("");
}
else if(ae.getSource()==b3)
{//list
int r = 0;
try
{
Class.forName("com.mysql.jdbc.Driver");
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/medical_store","root","");
System.out.println("Connected to database.");
stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
rs = stmt.executeQuery("SELECT * from medicine" );
while(rs.next())
{
model.insertRow(r++, new Object[]{rs.getString(1),rs.getString(2),rs.getString(3),rs.getString(4),rs.getString(5),rs.getString(6),rs.getString(7),rs.getString(8),rs.getString(9),rs.getString(10),rs.getString(11),rs.getString(12) });
}
con.close();
}
catch(SQLException se)
{
System.out.println(se);
JOptionPane.showMessageDialog(null,"SQL Error:"+se);
}
catch(Exception e)
{
System.out.println(e);
JOptionPane.showMessageDialog(null,"Error:"+e);
}
}
}
public static void main(String args[])
{
new UpdateMedicine();
}
}