-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCreate_NewChannel.java
More file actions
188 lines (149 loc) · 6.64 KB
/
Create_NewChannel.java
File metadata and controls
188 lines (149 loc) · 6.64 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
package hospital_management;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import java.util.logging.Level;
import java.util.logging.Logger;
public class Create_NewChannel extends JFrame {
private JLabel lab1 = new JLabel("CHANNEL NO ");
private JTextField tf = new JTextField();
private JLabel lab2 = new JLabel("Doctor Name");
private JComboBox<String> cb = new JComboBox<>();
private JLabel lab3 = new JLabel("Patient Name ");
private JComboBox<String> cb1 = new JComboBox<>();
private JLabel lab4 = new JLabel("Room NO ");
private JTextField tf3 = new JTextField();
private JLabel lab5 = new JLabel("CHANNEL Date ");
private JTextField cb2 = new JTextField();
private JPanel pan = new JPanel();
private JButton create = new JButton("Create");
private JButton cancel = new JButton("Cancel");
private JButton close = new JButton("Close");
// private JTextArea ta = new JTextArea();
public Create_NewChannel() {
autoID();
dloader();
ploader();
pan.setBackground(Color.cyan);
pan.add(lab1);
pan.add(tf);
pan.add(lab2);
pan.add(cb);
pan.add(lab3);
pan.add(cb1);
pan.add(lab4);
pan.add(tf3);
pan.add(lab5);
pan.add(cb2);
// pan.add(ta);
pan.setLayout(new GridLayout(8, 2, 5, 6));
create.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
Class.forName("com.mysql.cj.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost/java_project", "root", "1234");
Statement stmt=(Statement)con.createStatement();
String insert=("insert into channel VALUES('" + tf.getText() + "','" + cb.getSelectedItem() + "','" + cb1.getSelectedItem() +
"','" + tf3.getText() + "','"+ cb2.getText() +"')");
stmt.executeUpdate(insert);
JOptionPane.showMessageDialog(null, "ADDED SUCCESSFULLY!");
// Code to save the channel
} catch (ClassNotFoundException ex) {
Logger.getLogger(Create_NewChannel.class.getName()).log(Level.SEVERE, null, ex);
} catch (SQLException ex) {
Logger.getLogger(Create_NewChannel.class.getName()).log(Level.SEVERE, null, ex);
}
}
});
cancel.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
tf.setText("");
tf3.setText("");
cb2.setText("");
cb.setSelectedItem(null);
cb1.setSelectedItem(null);
// Code to clear form fields
}
});
close.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
new Recieption();
setVisible(false);
// Code to close the current window and go back to the reception window
}
});
pan.add(create);
pan.add(cancel);
pan.add(close);
add(pan);
setTitle("HOSPITAL");
setSize(500, 400);
setVisible(true);
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// Load doctor and patient data
}
public void dloader() {
try {
Class.forName("com.mysql.cj.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost/java_project", "root", "1234");
PreparedStatement pst = con.prepareStatement("SELECT * FROM doctor");
ResultSet rs = pst.executeQuery();
cb.removeAllItems();
while (rs.next()) {
cb.addItem(rs.getString(1));
}
} catch (ClassNotFoundException ex) {
Logger.getLogger(Create_NewChannel.class.getName()).log(Level.SEVERE, null, ex);
} catch (SQLException ex) {
Logger.getLogger(Create_NewChannel.class.getName()).log(Level.SEVERE, null, ex);
}
}
public void ploader() {
try {
Class.forName("com.mysql.cj.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost/java_project", "root", "1234");
PreparedStatement pst = con.prepareStatement("SELECT * FROM patient");
ResultSet rs = pst.executeQuery();
cb1.removeAllItems();
while (rs.next()) {
cb1.addItem(rs.getString(2));
}
} catch (ClassNotFoundException ex) {
Logger.getLogger(Create_NewChannel.class.getName()).log(Level.SEVERE, null, ex);
} catch (SQLException ex) {
Logger.getLogger(Create_NewChannel.class.getName()).log(Level.SEVERE, null, ex);
}
}
public void autoID() {
try {
// Load the MySQL JDBC driver
Class.forName("com.mysql.cj.jdbc.Driver");
// Establish a connection to the database
Connection con = DriverManager.getConnection("jdbc:mysql://localhost/java_project", "root", "1234");
// Prepare a statement to retrieve the maximum channelNo from the channel table
PreparedStatement pst = con.prepareStatement("SELECT MAX(channelNo) FROM channel");
// Execute the query and retrieve the result set
ResultSet rs = pst.executeQuery();
rs.next();
// Get the maximum channelNo value from the result set
String maxchannelNo = rs.getString("MAX(channelNo)");
// Check if the maximum channelNo is null
if (maxchannelNo == null) {
// If it's null, set the ID to "CH001"
tf.setText("CH001");
} else {
// Extract the numeric portion of the maximum channelNo and increment it
long n = Long.parseLong(maxchannelNo.substring(2));
n++;
// Format the incremented number as a three-digit string and set the ID
tf.setText("CH" + String.format("%03d", n));
}
} catch (ClassNotFoundException ex) {
Logger.getLogger(PatientRegistrationForm.class.getName()).log(Level.SEVERE, null, ex);
} catch (SQLException ex) {
Logger.getLogger(PatientRegistrationForm.class.getName()).log(Level.SEVERE, null, ex);
}
}
}