-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.java
142 lines (134 loc) · 4.96 KB
/
App.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
package Leave_management;
import java.util.Scanner;
import org.json.simple.parser.ParseException;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class App {
static Scanner ob=new Scanner(System.in);
public static int roll=0;
public static String username="";
public static void logindetails(Connection conn) throws SQLException, IOException, ParseException, java.text.ParseException {
System.out.println("---------------------------------");
System.out.println("----Your In a Login Page----");
System.out.println("---------------------------------");
System.out.println("Enter Your Username:");
username=ob.next();
ob.nextLine();
System.out.println("Enter Your userid:");
roll=ob.nextInt();
ob.nextLine();
System.out.println("Enter Your password");
String password=ob.next();
System.out.println("Enter Your Role:(Employee,HR)");
String role=ob.next();
String sql="select password from signup where rollno=? AND password=? AND role=?";
PreparedStatement pt=conn.prepareStatement(sql);
pt.setInt(1, roll);
pt.setString(2, password);
pt.setString(3, role);
ResultSet rs=pt.executeQuery();
if(rs.next()) {
if(role.charAt(0)=='h' || role.charAt(0)=='H')
{
System.out.println("---------------------------------");
System.out.println("Your'e Successfully Logged in!...");
System.out.println("---------------------------------");
System.out.println("---YOUR IN A HR PAGE---");
Hr h=new Hr();
h.hrdetails(conn);
}
else if(role.charAt(0)=='E' || role.charAt(0)=='e') {
System.out.println("---------------------------------");
System.out.println("Your'e Successfully Logged in!...");
System.out.println("---------------------------------");
System.out.println("---YOUR IN A EMPLOYEE PAGE---");
Employee emp=new Employee();
emp.leaveDetails(conn);
}
else {
System.out.println("Give Ur Role Properly:");
logindetails(conn);
}
}
else {
System.out.println("Your username and password not correct...");
System.out.println("Try again!");
logindetails(conn);
}
}
public static void signdetails(Connection conn) throws SQLException, IOException, ParseException, java.text.ParseException {
System.out.println("-------------------------------");
System.out.println("---YOUR IN A SIGNUP PAGE---");
System.out.println("-------------------------------");
System.out.println("Enter Your username:");
username=ob.next();
ob.nextLine();
System.out.println("Enter Your Roll No:");
roll=ob.nextInt();
System.out.println("Enter Your Phone Number:");
long pno=ob.nextLong();
System.out.println("Enter Your Email:");
ob.nextLine();
String email=ob.nextLine();
System.out.println("Enter Your Role:(Employee,HR)");
String role=ob.next();
System.out.println("Enter Your New Password:");
String password=ob.next();
System.out.println("Enter Your Re-Password:");
String repassword=ob.next();
if(password.length()>=8 && password.equals(repassword))
{
String sql="Insert Into signup(name,rollno,phonenumber,emailid,role,password)values(?,?,?,?,?,?)";
PreparedStatement pt=conn.prepareStatement(sql);
pt.setString(1,username);
pt.setInt(2, roll);
pt.setLong(3, pno);
pt.setString(4, email);
pt.setString(5, role);
pt.setString(6, password);
pt.execute(); // Execute the prepared statement with parameters
System.out.println("---------------------------------");
System.out.println("---Signup Successfully---");
System.out.println("---------------------------------");
logindetails(conn); // After signup, proceed to login
}
else {
System.out.println("Plse Enter Your Password!...correctly");
signdetails(conn);
return;
}
}
public static void main(String[] args) {
try {
Class.forName("com.mysql.cj.jdbc.Driver");
Connection conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/leave_management","root","password");
System.out.println("---------------------------------");
System.out.println("---WELCOME TO LEAVE MANAGEMENT SYSTEM---");
System.out.println("---------------------------------");
System.out.println("1.Login page");
System.out.println("2.Signup page");
System.out.println("---------------------------------");
System.out.println("Enter Your Choice Here:");
int pin=ob.nextInt();
switch(pin) {
case 1:
logindetails(conn);
break;
case 2:
signdetails(conn);
break;
default:
System.out.println("Enter a Number 1 or 2");
}
conn.close();
}
catch(Exception e) {
e.printStackTrace();
}
}
}