-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathHuman
More file actions
84 lines (75 loc) · 2.45 KB
/
Human
File metadata and controls
84 lines (75 loc) · 2.45 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
package GUI;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import com.toedter.calendar.JCalendar;
import Business.ConnectDB;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.awt.*;
import java.util.Calendar;
import java.util.Date;
public class EmployeeGUI extends JFrame {
JFrame f = new JFrame();
JLabel lbID = new JLabel("Id");
JTextField tfID = new JTextField(10);
JLabel lbName = new JLabel("Name");
JTextField tfName = new JTextField(10);
JLabel lbBirthday = new JLabel("Birthday");
JCalendar clBirthday = new JCalendar();
//JTextField tfBirthday = new JTextField(10);
JLabel lbRate = new JLabel("Rate");
JTextField tfRate = new JTextField(10);
JLabel blDep = new JLabel("Department");
String Depart[] = {"VKU","DTU","DUT"};
JComboBox cbdepart = new JComboBox(Depart);
JButton btSignUp = new JButton("Sign Up");
public EmployeeGUI() {
f.setLocation(500,200);
f.setLayout(new GridLayout(6,2));
Container cont = f.getContentPane();
cont.add(lbID);
cont.add(tfID);
cont.add(lbName);
cont.add(tfName);
cont.add(lbBirthday);
cont.add(clBirthday);
cont.add(lbRate);
cont.add(tfRate);
cont.add(blDep);
cont.add(cbdepart);
cont.add(btSignUp);
btSignUp.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
//covert string sang date trong java
SimpleDateFormat formatter1=new SimpleDateFormat("dd/MM/yyyy");
try {
//Date birthday=formatter1.parse(tfBirthday.getText());
Date selectedDate = (Date) clBirthday.getDate();
java.sql.Date birthday = convertUtilToSql(selectedDate);
ConnectDB conn = new ConnectDB();
int record = conn.executeDB("Insert into Employee values('"+tfID.getText()+"','"+tfName.getText()+"','"+birthday+"','"+tfRate.getText()+"','"+cbdepart.getSelectedItem().toString()+"')");
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
});
f.pack();
f.setSize(500,500);
f.setVisible(true);
}
private static java.sql.Date convertUtilToSql(java.util.Date uDate) {
java.sql.Date sDate = new java.sql.Date(uDate.getTime());
return sDate;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
new EmployeeGUI();
}
}