-
Notifications
You must be signed in to change notification settings - Fork 0
/
ApplyLeaveStudent.java
169 lines (154 loc) · 5.92 KB
/
ApplyLeaveStudent.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
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import java.awt.Font;
import javax.swing.JLabel;
import javax.swing.JFrame;
import java.awt.Color;
import java.text.*;
import net.proteanit.sql.DbUtils;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import com.toedter.calendar.JDateChooser;
class ApplyLeaveStudent extends JFrame implements ActionListener
{
//2 combobox, 1 date chooser , 2 buttons
JButton sumbitBtn, cancelBtn;
JDateChooser dateChooser;
JComboBox rollNoComboBox,durationComboBox, timeComboBox;
String[] rollNoList;
ResultSet rs;
Connection c;
Statement st;
JScrollPane scrollPane;
JLabel mainLabel,rollNoLabel,dateLabel,durationLabel;
JDateChooser DOB;
ApplyLeaveStudent()
{
this.setTitle("Apply Student Leave");
this.setFont(new Font("serif",Font.BOLD,50));
this.setLayout(null);
mainLabel=new JLabel("Apply Student Leave:");
mainLabel.setBounds(120, 50, 250, 30);
mainLabel.setFont(new Font("serif", Font.BOLD, 25));
this.add(mainLabel);
rollNoLabel=new JLabel("Rollno:");
rollNoLabel.setBounds(80, 100, 250, 30);
rollNoLabel.setFont(new Font("serif", Font.BOLD, 20));
this.add(rollNoLabel);
rollNoList=getRollNoFromDB();
rollNoComboBox=new JComboBox(rollNoList);
rollNoComboBox.setBounds(80,130,250,30);
rollNoComboBox.addActionListener(this);
this.add(rollNoComboBox);
dateLabel=new JLabel("Date:");
dateLabel.setBounds(80, 160, 250, 30);
dateLabel.setFont(new Font("serif", Font.BOLD, 20));
this.add(dateLabel);
DOB=new JDateChooser();
DOB.setBounds(80,190,250,30);
this.add(DOB);
durationLabel=new JLabel("Duration:");
durationLabel.setBounds(80, 220, 250, 30);
durationLabel.setFont(new Font("serif", Font.BOLD, 20));
this.add(durationLabel);
String[] durationList={"Full Day", "Half Day"};
durationComboBox=new JComboBox(durationList);
durationComboBox.setBounds(80,250,250,30);
this.add(durationComboBox);
sumbitBtn=new JButton("Submit");
sumbitBtn.setBackground(Color.WHITE);
sumbitBtn.setForeground(Color.BLACK);
sumbitBtn.setBounds(100,350,120,30);
sumbitBtn.setFont(new Font("serif", Font.PLAIN, 25));
sumbitBtn.addActionListener(this);
this.add(sumbitBtn);
cancelBtn=new JButton("Back");
cancelBtn.setBackground(Color.WHITE);
cancelBtn.setForeground(Color.BLACK);
cancelBtn.setBounds(280,350,120,30);
cancelBtn.setFont(new Font("serif", Font.PLAIN, 25));
cancelBtn.addActionListener(this);
this.add(cancelBtn);
this.setSize(500,500);
this.setLocationRelativeTo(null);
this.setVisible(true);
}
public void actionPerformed(ActionEvent a)
{
if(a.getSource()==cancelBtn)
{
this.setVisible(false);
}
else if(a.getSource()==sumbitBtn)
{
insertStudentLeaveIntoDB();
}
}
String[] getRollNoFromDB()
{
String[] a={};
try
{
Class.forName("com.mysql.cj.jdbc.Driver");
Connection c = DriverManager.getConnection("jdbc:mysql://localhost:3306/universitymanagementsystem", "root", "root");
//name varchar(30), fatherName varchar(30),rollNo varchar (10),dob varchar(40),address varchar(100),phone varchar(30),email varchar(20),classX varchar(30),classXII varchar(30),aadhar varchar(30),course varchar(30),branch varchar(30));
Statement st=c.createStatement();
String selectAllQuery="select rollNo from student;";
rs=st.executeQuery(selectAllQuery);
ArrayList<String> s=new ArrayList<>();
int size=0;
while (rs.next())
{
size++;
s.add(rs.getString(1));
}
a=new String[size];
for(int i =0;i<size;i++)
{
a[i] = s.get(i);
}
c.close();
return a;
}
catch (Exception e)
{
e.printStackTrace();
JOptionPane.showMessageDialog(null, e.toString());
}
return a;
}
public void insertStudentLeaveIntoDB()
{
String empID, date, duration;
empID=(String)rollNoComboBox.getSelectedItem();
date=DateFormat.getDateInstance().format(DOB.getDate());
duration=(String)durationComboBox.getSelectedItem();
try
{
Class.forName("com.mysql.cj.jdbc.Driver");
Connection c = DriverManager.getConnection("jdbc:mysql://localhost:3306/universitymanagementsystem", "root", "root");
//name varchar(30), fatherName varchar(30),rollNo varchar (10),dob varchar(40),address varchar(100),phone varchar(30),email varchar(20),classX varchar(30),classXII varchar(30),aadhar varchar(30),course varchar(30),branch varchar(30));
Statement st=c.createStatement();
String selectAllQuery="insert into studentleave values('"+empID+"','"+date+"','"+duration+"');";
st.execute(selectAllQuery);
JOptionPane.showMessageDialog(null, "inserted Successfully");
}
catch (Exception e)
{
e.printStackTrace();
JOptionPane.showMessageDialog(null, e.toString());
}
}
public static void main(String[] args)
{
new ApplyLeaveStudent();
}
}