-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathFrmAddEditMedicine.java
More file actions
214 lines (179 loc) · 6.02 KB
/
FrmAddEditMedicine.java
File metadata and controls
214 lines (179 loc) · 6.02 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
package hms;
import javax.swing.*;
import java.sql.*;
import java.awt.*;
import java.awt.event.*;
class FrmAddEditMedicine extends JInternalFrame
{
/**
*
*/
private static final long serialVersionUID = 1L;
JLabel lblId,lblName,lblCategory,lblUnit,lblPrice;
JTextField txtId,txtName,txtPrice;
JComboBox<String> jcbct;
JComboBox<String> jcbun;
JButton btnSave,btnDiscard;
DConnection dc;
ResultSet rst;
int md_id=0;
FrmAddEditMedicine(boolean flag,String query,FrmMedicines fd)
{
super("Add/Edit Medicine Category",true,true,true,true);
setResizable(false);
dc=new DConnection();
setLayout(new GridLayout(6,2));
lblId = new JLabel("Medicine Id");
lblId.setForeground(new Color(0,128,64));
lblId.setFont(new Font(Font.SERIF,Font.ITALIC+Font.BOLD,18));
lblName = new JLabel("Medicine Name");
lblName.setForeground(new Color(0,128,64));
lblName.setFont(new Font(Font.SERIF,Font.ITALIC+Font.BOLD,18));
lblCategory = new JLabel("Category");
lblCategory.setForeground(new Color(0,128,64));
lblCategory.setFont(new Font(Font.SERIF,Font.ITALIC+Font.BOLD,18));
lblUnit = new JLabel("Unit");
lblUnit.setForeground(new Color(0,128,64));
lblUnit.setFont(new Font(Font.SERIF,Font.ITALIC+Font.BOLD,18));
lblPrice = new JLabel("Price");
lblPrice.setForeground(new Color(0,128,64));
lblPrice.setFont(new Font(Font.SERIF,Font.ITALIC+Font.BOLD,18));
txtId=new JTextField();
txtId.setBackground(new Color(192,192,192));
txtId.setForeground(new Color(106,106,106));
txtId.setFont(new Font(Font.SERIF,Font.ITALIC+Font.BOLD,18));
txtId.setEditable(false);
txtName=new JTextField();
txtName.setForeground(new Color(106,106,106));
txtName.setFont(new Font(Font.SERIF,Font.ITALIC+Font.BOLD,18));
txtPrice=new JTextField();
txtPrice.setForeground(new Color(106,106,106));
txtPrice.setFont(new Font(Font.SERIF,Font.ITALIC+Font.BOLD,18));
jcbct=new JComboBox<String>();
jcbct.setForeground(new Color(106,106,106));
jcbct.setFont(new Font(Font.SERIF,Font.ITALIC+Font.BOLD,18));
try
{
rst=dc.executeQuery("select * from mcategory");
while(rst.next())
{
jcbct.addItem(rst.getString(2));
}
dc.close();
}
catch(SQLException e)
{
e.printStackTrace();
}
jcbun=new JComboBox<String>();
jcbun.setForeground(new Color(106,106,106));
jcbun.setFont(new Font(Font.SERIF,Font.ITALIC+Font.BOLD,18));
jcbun.addItem("pcs");
jcbun.addItem("kg");
jcbun.addItem("ltr");
jcbun.addItem("ml");
try
{
if(flag==true)//add new
{
rst=dc.executeQuery("select max(md_id) from medicine");
rst.next();
md_id=rst.getInt(1)+1;
txtId.setText(md_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));
jcbct.setSelectedItem(rst.getString(3));
jcbun.setSelectedItem(rst.getString(4));
txtPrice.setText(rst.getString(5));
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)
{ try{
String s1=txtId.getText();
String s2=txtName.getText();
String s4=(String)jcbun.getSelectedItem();
String s5=txtPrice.getText();
String s3=(String)jcbct.getSelectedItem();
int s6=0;
rst=dc.executeQuery("select ct_id from mcategory where ct_name='"+(String)jcbct.getSelectedItem()+"'");
rst.next();
s6=rst.getInt(1);
dc.close();
if(s1.isEmpty())
{
JOptionPane.showMessageDialog(fd,"Id can't be blank","Error",JOptionPane.ERROR_MESSAGE);
txtId.requestFocus();
return;
}
else if(s2.isEmpty())
{
JOptionPane.showMessageDialog(fd,"Name can't be blank","Error",JOptionPane.ERROR_MESSAGE);
txtName.requestFocus();
return;
}
else if(s3.isEmpty())
{
JOptionPane.showMessageDialog(fd,"Category can't be blank","Error",JOptionPane.ERROR_MESSAGE);
jcbct.requestFocus();
return;
}
else if(s4.isEmpty())
{
JOptionPane.showMessageDialog(fd,"Unit can't be blank","Error",JOptionPane.ERROR_MESSAGE);
jcbun.requestFocus();
return;
}
if(flag==true)
dc.executeOther("Insert into medicine values("+s1+",'"+s2+"','"+s3+"','"+s4+"','"+s5+"',"+s6+")");
else
dc.executeOther("update medicine set md_name='"+s2+"',md_cat='"+s3+"',unit='"+s4+"',price='"+s5+"',ct_id="+s6+" where md_id="+s1);
dispose();
fd.reload();
//fd.jsp.repaint();
//fd.repaint();
}
catch(SQLException e)
{
e.printStackTrace();
}
}
});
add(lblId);add(txtId);
add(lblName);add(txtName);
add(lblCategory);add(jcbct);
add(lblUnit);add(jcbun);
add(lblPrice);add(txtPrice);
add(btnSave);add(btnDiscard);
setSize(300,200);
setVisible(true);
setLocation(CommonMethods.getCenterPoint(getSize()));
}
}