-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate_medicine.java
More file actions
147 lines (144 loc) · 4.44 KB
/
Copy pathupdate_medicine.java
File metadata and controls
147 lines (144 loc) · 4.44 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
package chemist_shop;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
public class update_medicine extends JFrame implements ActionListener, ItemListener
{
Font f1 = new Font("Courier New", Font.ITALIC,26);
JLabel j1, j2, j3, j4, j5, j6, j7, j8, j9, j10, l;
JTextField t2, t3, t4, t5, t6, t7, t8, t9, t10;
JButton b1;
Choice ch1;
public update_medicine()
{
setSize(1000, 1000);
setLocation(100,100);
setLayout(new GridLayout(10,2));
j1 = new JLabel("Medicine ID");
j2 = new JLabel("Batch No.");
j3 = new JLabel("Description");
j4 = new JLabel("Manufacturing Date");
j5 = new JLabel("Expiry Date");
j6 = new JLabel("Salt");
j7 = new JLabel("Company");
j8 = new JLabel("Quantity");
j9 = new JLabel("ROL");
j10 = new JLabel("Price");
t2 = new JTextField(20);
t3 = new JTextField(100);
t4 = new JTextField(20);
t5 = new JTextField(20);
t6 = new JTextField(20);
t7 = new JTextField(20);
t8 = new JTextField(20);
t9 = new JTextField(20);
t10 = new JTextField(20);
j1.setFont(f1);
j2.setFont(f1);
j3.setFont(f1);
j4.setFont(f1);
j5.setFont(f1);
j6.setFont(f1);
j7.setFont(f1);
j8.setFont(f1);
j9.setFont(f1);
t2.setFont(f1);
t3.setFont(f1);
t4.setFont(f1);
t5.setFont(f1);
t6.setFont(f1);
t7.setFont(f1);
t8.setFont(f1);
t9.setFont(f1);
t10.setFont(f1);
ch1 = new Choice();
try
{
conn c1 = new conn();
ResultSet rs = c1.s.executeQuery("SELECT * FROM MEDICINE");
while(rs.next())
{
ch1.add(rs.getString("MEDICINE_ID"));
}
}
catch(Exception e)
{
e.printStackTrace();
}
ch1.addItemListener(this);
add(j1);
add(ch1);
add(j2);
add(t2);
add(j3);
add(t3);
add(j4);
add(t4);
add(j5);
add(t5);
add(j6);
add(t6);
add(j7);
add(t7);
add(j8);
add(t8);
add(j9);
add(t9);
add(j10);
add(t10);
b1 = new JButton("Update");
b1.addActionListener(this);
add(b1);
}
public void actionPerformed(ActionEvent ae)
{
int n = JOptionPane.showConfirmDialog(this, null, "Are you sure you want to update Medicine Record?", JOptionPane.YES_NO_OPTION);
if(n!=0)
return;
int y = Integer.parseInt(t2.getText());
int z = Integer.parseInt(t8.getText());
int w = Integer.parseInt(t9.getText());
float p = Float.parseFloat(t10.getText());
String q = "UPDATE MEDICINE SET BATCH_NO="+y+", DESCRIPTION='"+t3.getText()+"', MANU_DATE='"+t4.getText()+"', EXP_DATE='"+t5.getText()+"', SALT='"+t6.getText()+"', COMPANY='"+t7.getText()+"', QUANT="+z+", ROL="+w+", PRICE="+p+" WHERE MEDICINE_ID="+ch1.getSelectedItem();
try
{
conn c1 = new conn();
c1.s.executeUpdate(q);
}
catch(Exception e)
{
e.printStackTrace();
}
JOptionPane.showMessageDialog(null, "Medicine Record Updated");
}
public void itemStateChanged(ItemEvent ie)
{
String q1 = "SELECT * FROM MEDICINE WHERE MEDICINE_ID="+ch1.getSelectedItem();;
try
{
conn c = new conn();
ResultSet rs = c.s.executeQuery(q1);
if(rs.next())
{
t2.setText(rs.getString("BATCH_NO"));
t3.setText(rs.getString("DESCRIPTION"));
t4.setText(rs.getString("MANU_DATE"));
t5.setText(rs.getString("EXP_DATE"));
t6.setText(rs.getString("SALT"));
t7.setText(rs.getString("COMPANY"));
t8.setText(rs.getString("QUANT"));
t9.setText(rs.getString("ROL"));
t10.setText(rs.getString("PRICE"));
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
public static void main(String s[])
{
new update_medicine().setVisible(true);
}
}