-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathFrmAddEditPProcedure.java
More file actions
156 lines (143 loc) · 4.9 KB
/
FrmAddEditPProcedure.java
File metadata and controls
156 lines (143 loc) · 4.9 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
package hms;
import javax.swing.*;
import java.sql.*;
import java.awt.*;
import java.awt.event.*;
class FrmAddEditPProcedure extends JInternalFrame
{
/**
*
*/
private static final long serialVersionUID = 1L;
JLabel lblPProcedureId,lblPProcedureName,lblPCategory,lblPPrice,lblPDescription;
JTextField txtPProcedureId,txtPProcedureName,txtPPrice,txtPDescription;
JComboBox<String> jcbCn;
JButton btnSave,btnDiscard;
DConnection dc;
ResultSet rst;
int p_id=0;
FrmAddEditPProcedure(boolean flag,String query,FrmPProcedure fpp)
{
super("Add/Edit Procedure Procedure",true,true,true,true);
setResizable(false);
dc=new DConnection();
setLayout(new GridLayout(6,2));
lblPProcedureId = new JLabel("Procedure Id");
lblPProcedureId.setForeground(new Color(64,0,0));
lblPProcedureId.setFont(new Font(Font.SERIF,Font.ITALIC+Font.BOLD,18));
lblPProcedureName = new JLabel("Procedure Name");
lblPProcedureName.setForeground(new Color(64,0,0));
lblPProcedureName.setFont(new Font(Font.SERIF,Font.ITALIC+Font.BOLD,18));
lblPCategory = new JLabel("Category");
lblPCategory.setForeground(new Color(64,0,0));
lblPCategory.setFont(new Font(Font.SERIF,Font.ITALIC+Font.BOLD,18));
lblPPrice = new JLabel("Price");
lblPPrice.setForeground(new Color(64,0,0));
lblPPrice.setFont(new Font(Font.SERIF,Font.ITALIC+Font.BOLD,18));
lblPDescription = new JLabel("Description");
lblPDescription.setForeground(new Color(64,0,0));
lblPDescription.setFont(new Font(Font.SERIF,Font.ITALIC+Font.BOLD,18));
txtPProcedureId = new JTextField();
txtPProcedureId.setForeground(new Color(49,49,49));
txtPProcedureId.setBackground(new Color(192,192,192));
txtPProcedureId.setFont(new Font(Font.SERIF,Font.ITALIC+Font.BOLD,18));
txtPProcedureId.setEditable(false);
txtPProcedureName = new JTextField();
txtPProcedureName.setForeground(new Color(106,106,106));
txtPProcedureName.setFont(new Font(Font.SERIF,Font.ITALIC+Font.BOLD,18));
txtPPrice = new JTextField();
txtPPrice.setForeground(new Color(106,106,106));
txtPPrice.setFont(new Font(Font.SERIF,Font.ITALIC+Font.BOLD,18));
txtPDescription = new JTextField();
txtPDescription.setForeground(new Color(106,106,106));
txtPDescription.setFont(new Font(Font.SERIF,Font.ITALIC+Font.BOLD,18));
rst=dc.executeQuery("select * from pcat");
jcbCn=new JComboBox<String>();
try{
while(rst.next()){
jcbCn.addItem(rst.getString("pcat_name"));
}
}
catch(SQLException e){
e.printStackTrace();
}
try
{
if(flag==true)//add new
{
rst=dc.executeQuery("select max(p_id) from pprocedure");
rst.next();
p_id=rst.getInt(1)+1;
txtPProcedureId.setText(p_id+"");
dc.close();
btnSave=new JButton("Save");
}
else//edit
{
rst=dc.executeQuery(query);
rst.next();
txtPProcedureId.setText(rst.getString(1));
txtPProcedureName.setText(rst.getString(2));
txtPPrice.setText(rst.getString(3));
txtPDescription.setText(rst.getString(4));
jcbCn.setSelectedItem(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)
{
String s1=txtPProcedureId.getText();
String s2=txtPProcedureName.getText();
String s3=txtPPrice.getText();
String s4=txtPDescription.getText();
rst=dc.executeQuery("select pcat_id from pcat where pcat_name='"+(String)jcbCn.getSelectedItem()+"'");
int s5=0;
try{
while(rst.next()){
s5=rst.getInt("pcat_id");
}
}
catch(SQLException e){
e.printStackTrace();
}
if(flag==true)
dc.executeOther("Insert into pprocedure values("+s1+",'"+s2+"',"+s3+",'"+s4+"',"+s5+")");
else
dc.executeOther("update pprocedure set p_name='"+s2+"',price="+s3+",description='"+s4+"',pcat_id="+s5+" where p_id="+s1);
dispose();
fpp.reload();
//fpp.jsp.repaint();
//fpp.repaint();
}
});
add(lblPProcedureId);add(txtPProcedureId);
add(lblPProcedureName);add(txtPProcedureName);
add(lblPCategory);add(jcbCn);
add(lblPPrice);add(txtPPrice);
add(lblPDescription);add(txtPDescription);
add(btnSave);add(btnDiscard);
setSize(300,300);
setVisible(true);
setLocation(CommonMethods.getCenterPoint(getSize()));
}
}