-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathEditDoc.java
More file actions
248 lines (196 loc) · 9.33 KB
/
EditDoc.java
File metadata and controls
248 lines (196 loc) · 9.33 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
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import java.sql.*;
import javax.swing.border.BevelBorder;
class EditDoc
{
String name;
String address;
String phone;
String specialisation;
JFrame editframe;
JPanel formpanel, editpane, menubuttonpane;
JButton menubutton;
EditDoc()
{
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
JFrame editframe = new JFrame("Edit");
editframe.setExtendedState(JFrame.MAXIMIZED_BOTH);
editframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
editframe.setLayout(null);
// CREATE HEADERPANEL JPANEL
JPanel headerpanel = new JPanel();
headerpanel.setLayout(null);
headerpanel.setBounds(10,10,screenSize.width-20,100);
//headerpanel.setBackground(Color.cyan);
headerpanel.setBorder(new BevelBorder(BevelBorder.RAISED));
// CREATE HEADERPANELSH JPANEL
JPanel headerpanelsh = new JPanel();
headerpanelsh.setLayout(null);
headerpanelsh.setBounds(16,16,screenSize.width-20,100);
headerpanelsh.setBackground(new Color(200, 200, 200));
// CREATE HEADING JLABEL
JLabel heading = new JLabel("SIMPSONS MILITARY HOSPITAL");
Font font = new Font("Garamond", Font.BOLD, 35);
heading.setFont(font);
heading.setForeground(new Color(0, 255, 226));
heading.setBounds(screenSize.width-700,40,700,45);
JLabel heading1 = new JLabel("SIMPSONS MILITARY HOSPITAL");
Font font1 = new Font("Garamond", Font.BOLD, 35);
heading1.setFont(font1);
heading1.setForeground(new Color(0, 126, 112));
heading1.setBounds(screenSize.width-697,43,700,45);
ImageIcon image = new ImageIcon("C:\\Users\\diabolicfeak\\Documents\\NetBeansProjects\\hms\\src\\Images\\logo.png");
JLabel label = new JLabel("", image, JLabel.CENTER);
JPanel panel = new JPanel(new BorderLayout());
panel.add( label, BorderLayout.CENTER );
panel.setBounds(50,15,100,90);
//FOOTER JPANEL
JButton aboutus = new JButton("About Us");
aboutus.setBounds((screenSize.width/2)-120,650,100,30);
aboutus.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
new AboutUs();
}
});
editframe.add(aboutus);
JButton contactus = new JButton("Contact Us");
contactus.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
new ContactUs();
}
});
contactus.setBounds((screenSize.width/2)+10,650,100,30);
editframe.add(contactus);
editpane = new JPanel();
editpane.setLayout(null);
editpane.setBounds(500,120,400,200);
menubuttonpane = new JPanel();
menubuttonpane.setLayout(null);
menubuttonpane.setBounds(510,120,400,50);
final JTextField idfield = new JTextField("Enter ID");
idfield.setBounds(10,10,150,30);
JButton editbutton = new JButton("Edit");
editbutton.setBounds(170,10,150,30);
menubutton = new JButton("View ");
menubutton.setBounds(120,10,150,30);
menubuttonpane.add(menubutton);
menubuttonpane.setVisible(false);
editpane.add(idfield);
editpane.add(editbutton);
editframe.add(editpane);
editframe.add(menubuttonpane);
editframe.add(panel);
editframe.add(heading);
editframe.add(heading1);
editframe.add(headerpanel);
editframe.add(headerpanelsh);
formpanel = new JPanel();
formpanel.setBounds(350,150,600,900);
formpanel.setLayout(null);
editbutton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
PreparedStatement pstmt = null;
try {
// Connection conn=DriverManager.getConnection(
// "jdbc:ucanaccess://C:\\Users\\diabolicfeak\\Documents\\NetBeansProjects\\hms\\src\\Database\\Hospital.accdb");
Connection conn = DriverManager.getConnection(
"jdbc:mysql://localhost/hms",
"root",
"root"
);
// Connection conn=DriverManager.getConnection("jdbc:odbc:hospital");
int a = Integer.parseInt(idfield.getText());
String query = "select * FROM doctors WHERE id = ?";
pstmt = conn.prepareStatement(query); // create a statement
pstmt.setInt(1, a); // set input parameter 1
ResultSet rs = pstmt.executeQuery(); // execute insert statement
rs.next();
name = rs.getString("DocName");
specialisation = rs.getString("Specialisation");
address = rs.getString("Address");
phone = rs.getString("PNumber");
editform(name, specialisation, address, phone, a);
} catch (Exception e) {
e.printStackTrace();
}
}
});
editframe.add(formpanel);
editframe.setVisible(true);
}
public void editform(String name, String specialisation, String address, String phone, final int a)
{
// EDITFORM
final JTextField namefield = new JTextField(name);
namefield.setBounds(200,60,280,40);
formpanel.add(namefield);
final JTextField specialisationfield = new JTextField(specialisation);
specialisationfield.setBounds(200,110,280,40);
formpanel.add(specialisationfield);
final JTextField addressfield = new JTextField(address);
addressfield.setBounds(200,160,280,40);
formpanel.add(addressfield);
final JTextField phonefield = new JTextField(phone);
phonefield.setBounds(200,210,280,40);
formpanel.add(phonefield);
JButton formeditbutton = new JButton("Submit");
formeditbutton.setBounds(225,380,230,40);
formeditbutton.setVisible(true);
formpanel.add(formeditbutton);
editpane.setVisible(false);
menubuttonpane.setVisible(true);
formpanel.repaint();
// SECOND ONCLICK
formeditbutton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
PreparedStatement pstmt = null;
try {
// Connection conn=DriverManager.getConnection(
// "jdbc:ucanaccess://C:\\Users\\diabolicfeak\\Documents\\NetBeansProjects\\hms\\src\\Database\\Hospital.accdb");
Connection conn = DriverManager.getConnection(
"jdbc:mysql://localhost/hms",
"root",
"root"
);
String query = "UPDATE doctors SET DocName=?, Specialisation=?, Address=?, Pnumber=? WHERE id=?";
pstmt = conn.prepareStatement(query); // create a statement
pstmt.setString(1, namefield.getText()); // set input parameter 1
pstmt.setString(2, specialisationfield.getText()); // set input parameter 2
pstmt.setString(3, addressfield.getText()); // set input parameter 3
pstmt.setString(4, phonefield.getText());
pstmt.setInt(5, a);
pstmt.executeUpdate(); // execute insert statement
JOptionPane.showMessageDialog(null, "Successfully entered details");
} catch (Exception e) {
e.printStackTrace();
}
}
});
menubutton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
new MenuPage();
editframe.setVisible(false);
}
});
}
public static void main(String ar[])
{
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new EditDoc();
}});
}
}