/
DriverInfo.java
220 lines (194 loc) · 5.83 KB
/
DriverInfo.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
import java.lang.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
public class DriverInfo extends JFrame implements ActionListener
{
JLabel userid,name,phoneno,address;
JTextField useridText,nameText,phonenoText,phoneno2Text,addressText;
JButton logout,back,update,delete,changepassword;
JPanel panel;
String UserId;
public DriverInfo(String UserId)
{
super(" Driver Information ");
this.UserId=UserId;
this.setSize(800, 500);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
panel =new JPanel();
panel.setLayout(null);
panel.setBackground(Color.white);
userid=new JLabel(" ID : ");
userid.setBounds(100,130,100,50);
panel.add(userid);
useridText=new JTextField();
useridText.setBounds(230,130,200,50);
panel.add(useridText);
name=new JLabel(" Name : ");
name.setBounds(100,190,100,50);
panel.add(name);
nameText=new JTextField();
nameText.setBounds(230,190,200,50);
panel.add(nameText);
phonenoText=new JTextField("+880");
phonenoText.setBounds(230,250,50,50);
phonenoText.setEnabled(false);
panel.add(phonenoText);
phoneno=new JLabel("Phone Number :");
phoneno.setBounds(100,250,100,50);
panel.add(phoneno);
phoneno2Text=new JTextField();
phoneno2Text.setBounds(280,250,150,50);
panel.add(phoneno2Text);
address=new JLabel("ADDRESS :");
address.setBounds(100,310,100,50);
panel.add(address);
addressText = new JTextField();
addressText.setBounds(230,310,200,50);
panel.add(addressText);
logout=new JButton("Log Out");
logout.setBounds(500,10,250,50);
logout.setBackground(Color.red);
logout.addActionListener(this);
panel.add(logout);
back=new JButton("Back");
back.setBounds(500,380,250,50);
back.setBackground(Color.blue);
back.setForeground(Color.white);
back.addActionListener(this);
panel.add(back);
delete=new JButton("DELETE");
delete.setBounds(500,300,250,50);
delete.setBackground(Color.red);
delete.addActionListener(this);
panel.add(delete);
update=new JButton("update");
update.setBounds(500,220,250,50);
update.setBackground(Color.green);
update.addActionListener(this);
panel.add(update);
changepassword = new JButton("Change Password");
changepassword.setBounds(120,10,250,50);
changepassword.setBackground(Color.orange);
changepassword.addActionListener(this);
panel.add(changepassword);
this.add(panel);
}
public void actionPerformed(ActionEvent ae)
{
String ac=ae.getActionCommand();
if(ac.equals(logout.getText()))
{
LogIn ln=new LogIn();
ln.setVisible(true);
this.setVisible(false);
}
else if(ac.equals(back.getText()))
{
DriverHome ed=new DriverHome(UserId);
ed.setVisible(true);
this.setVisible(false);
}
else if(ac.equals(update.getText()))
{
myInfoUpdate();
}
else if(ac.equals(delete.getText()))
{
myInfoDelete();
}
else if(ac.equals(changepassword.getText()))
{
ChangePasswordD pd=new ChangePasswordD(UserId);
pd.setVisible(true);
this.setVisible(false);
}
}
public void autoInfoD(String UserId)
{
String load=UserId;
String query = "SELECT `Drivername`, `Phonenumber`, `Address` FROM `driver` WHERE `UserId`='"+load+"';";
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","");
Statement st= con.createStatement();
ResultSet rs= st.executeQuery(query);
boolean flag=false;
while(rs.next())
{
useridText.setText(UserId+"");
nameText.setText(rs.getString("Drivername"));
phonenoText.setText("+880");
phoneno2Text.setText(rs.getString("Phonenumber"));
addressText.setText(rs.getString("Address"));
flag=true;
useridText.setEnabled(false);
update.setEnabled(true);
delete.setEnabled(true);
}
if(!flag)
{
nameText.setText("");
phoneno2Text.setText("");
addressText.setText("");
JOptionPane.showMessageDialog(this,"Invalid ID");
}
rs.close();
st.close();
con.close();
}
catch(Exception ex)
{
System.out.println("Exception : " +ex.getMessage());
}
}
public void myInfoUpdate()
{
String newId = useridText.getText();
String newName= nameText.getText();
String newphone=phoneno2Text.getText();
String address=addressText.getText();
String query = "UPDATE driver SET Drivername='"+newName+"',Phonenumber = '"+newphone+"',Address = '"+address+"' WHERE userId='"+newId+"'";
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","");
Statement st=con.createStatement();
st.executeUpdate(query);
st.close();
con.close();
JOptionPane.showMessageDialog(this, "Update Done");
}
catch(Exception e)
{
System.out.println(e.getMessage());
JOptionPane.showMessageDialog(this, "Update Fail");
}
}
public void myInfoDelete()
{
String newId=UserId;
String query = "DELETE from driver WHERE userId='"+newId+"';";
String query2 = "DELETE from login WHERE userId='"+newId+"';";
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "");
Statement st=con.createStatement();
st.execute(query);
st.execute(query2);
st.close();
con.close();
JOptionPane.showMessageDialog(this, "Delete Done");
LogIn ln=new LogIn();
ln.setVisible(true);
this.setVisible(false);
}
catch(Exception ex)
{
JOptionPane.showMessageDialog(this, "Oops !!!");
}
}
}