-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDeleteInstructorAccount.java
240 lines (197 loc) · 5.9 KB
/
DeleteInstructorAccount.java
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
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.sql.*;
public class DeleteInstructorAccount extends JFrame implements ActionListener, MouseListener
{
private JLabel LabelInstructorID,WelcomeLabel,LabelBackGroundImage;
private JTextField InstructorIDTF;
private JButton buttonDelete,buttonBack;
private JPanel panel;
private int InstructorId;
private boolean flagDB, flagInvalid, flagCount;
private int AdminId;
public DeleteInstructorAccount(int AdminId)
{
super("Delect Instructor Account Page");
this.AdminId = AdminId;
Color lightButton = new Color(71, 92, 150);
Color lightBlue = new Color(172, 166, 255);
this.setSize(600, 650);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLocationRelativeTo(null);
panel = new JPanel();
panel.setLayout(null);
panel.setBackground(Color.WHITE);
ImageIcon img = new ImageIcon("icon.jpg");
this.setIconImage(img.getImage());
LabelBackGroundImage = new JLabel();
LabelBackGroundImage.setBounds(0,0, 600,200);
ImageIcon imgThisImg = new ImageIcon("logInBackground.JPG");
LabelBackGroundImage.setIcon(imgThisImg);
panel.add(LabelBackGroundImage);
LabelInstructorID = new JLabel("Enter Instructor Id :");
LabelInstructorID.setBounds(150, 210, 150, 25);
LabelInstructorID.setFont(new Font("Tahoma", Font.PLAIN, 15));
LabelInstructorID.setForeground(Color.BLACK);
panel.add(LabelInstructorID);
InstructorIDTF = new JTextField();
InstructorIDTF.setBounds(300, 210, 120, 25);
panel.add(InstructorIDTF);
buttonDelete = new JButton("Delete");
buttonDelete.setBounds(150,300,120,30);
buttonDelete.setFont(new Font("Ariel", Font.PLAIN, 15));
buttonDelete.setForeground(Color.BLACK);
buttonDelete.setBackground(lightButton);
buttonDelete.addActionListener(this);
buttonDelete.addMouseListener(this);
panel.add(buttonDelete);
buttonBack = new JButton("Back");
buttonBack.setBounds(300,300,120,30);
buttonBack.setFont(new Font("Ariel", Font.PLAIN, 15));
buttonBack.setForeground(Color.BLACK);
buttonBack.setBackground(lightButton);
buttonBack.addActionListener(this);
buttonBack.addMouseListener(this);
panel.add(buttonBack);
WelcomeLabel = new JLabel(" Logged in as : Admin");
WelcomeLabel.setBounds(215, 520, 200, 20);
WelcomeLabel.setFont(new Font("Tahoma", Font.PLAIN, 15));
WelcomeLabel.setForeground(Color.BLACK);
panel.add(WelcomeLabel);
WelcomeLabel = new JLabel(" ID : "+AdminId);
WelcomeLabel.setBounds(255, 550, 200, 20);
WelcomeLabel.setFont(new Font("Tahoma", Font.PLAIN, 15));
WelcomeLabel.setForeground(Color.BLACK);
panel.add(WelcomeLabel);
this.add(panel);
}
public void actionPerformed(ActionEvent ae){}
public void mouseEntered(MouseEvent me){}
public void mouseExited(MouseEvent me){}
public void mouseReleased(MouseEvent me){}
public void mousePressed(MouseEvent me){}
public void mouseClicked(MouseEvent me)
{
JButton b = (JButton) me.getComponent();
if(b==buttonDelete)
{
System.out.println("buttonDelete");
if(InstructorIDTF.getText().isEmpty())
{
JOptionPane.showMessageDialog(this, "Please Enter ID");
}
else
{
try{
InstructorId = Integer.parseInt(InstructorIDTF.getText());
flagInvalid=true;
}catch(Exception e)
{
flagInvalid=false;
JOptionPane.showMessageDialog(this, "Invalid ID");
}
if(flagCount && flagInvalid)
{
DelectAcc();
}
else
{
JOptionPane.showMessageDialog(this, "ID Not Found");
}
if(flagDB)
{
Back();
}
}
}
else if(b==buttonBack)
{
DeleteAccount delete = new DeleteAccount(AdminId);
try{
this.setVisible(false);
delete.setVisible(true);
}catch(Exception ex){}
}
}
public void DelectAcc()
{
Connection con =null;
Statement st = null;
String DeleteFromAccounts = "DELETE FROM accounts WHERE UserId="+InstructorId+";";
String DeleteFromInstructor = "DELETE FROM instructoracc WHERE UserId="+InstructorId+";";
try
{
Class.forName("com.mysql.jdbc.Driver");
System.out.println("driver loaded");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/Group8F","root","");
System.out.println("connection done");
st = con.createStatement();
System.out.println("statement created");
st.executeUpdate(DeleteFromAccounts);
st.executeUpdate(DeleteFromInstructor);
st.close();
con.close();
flagDB=true;
}
catch(Exception e)
{
JOptionPane.showMessageDialog(this,"No Account Found");
System.out.println(e.getMessage());
}
}
public void Back()
{
JOptionPane.showMessageDialog(this,"Account Deletion Success");
if(flagDB)
{
DeleteAccount delete = new DeleteAccount(AdminId);
try{
this.setVisible(false);
delete.setVisible(true);
}catch(Exception ex){}
}
}
public void CheckInstructorId()
{
String queryInstructorId ="SELECT `UserId` FROM `instructoracc` WHERE UserId ="+ InstructorId+";";
Connection con=null;
Statement st = null;
ResultSet rs = null;
try{
Class.forName("com.mysql.jdbc.Driver");
System.out.println("driver loaded");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/Group8F","root","");
System.out.println("connection done");
st = con.createStatement();
System.out.println("statement created");
rs = st.executeQuery(queryInstructorId);
System.out.println("results received");
while(rs.next())
{
int mID = rs.getInt("UserId");
if(InstructorId==mID){
flagCount=true;
}
}
System.out.println("Instructor count "+flagCount);
}
catch(Exception ex)
{
System.out.println("Exception : " +ex.getMessage());
}
finally
{
try
{
if(rs!=null)
rs.close();
if(st!=null)
st.close();
if(con!=null)
con.close();
}
catch(Exception ex){}
}
}
}