-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMenuBarControll.java
More file actions
executable file
·181 lines (143 loc) · 4.61 KB
/
MenuBarControll.java
File metadata and controls
executable file
·181 lines (143 loc) · 4.61 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
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
import java.awt.HeadlessException;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Scanner;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
public class MenuBarControll implements ActionListener {
private JMenuItem open;
private JMenuItem log_in;
private DB_Interface di;
MenuBarControll(JMenuItem open, JMenuItem log_in)
{
this.open = open;
this.log_in = log_in;
System.out.println("MenuBar Controller 생성 완료..");
}
@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource() == open)
try {
open_file();
} catch (HeadlessException | SQLException e1) {
e1.printStackTrace();
}
else if(e.getSource() == log_in)
log_in();
}
private void log_in() {
// 로그인 창 띄움
JFrame frame = new JFrame();
JPanel panel = new JPanel();
JLabel idLabel = new JLabel("사원명");
JLabel pwdLabel = new JLabel("사원번호");
JTextField idInput = new JTextField();
JPasswordField pwdInput = new JPasswordField();
JButton loginButton = new JButton("로그인");
panel.setLayout(null);
idLabel.setBounds(20, 10, 60, 30);
pwdLabel.setBounds(20, 50, 60, 30);
idInput.setBounds(100, 10, 80, 30);
pwdInput.setBounds(100, 50, 80, 30);
loginButton.setBounds(200, 25, 80, 35);
panel.add(idLabel);
panel.add(pwdLabel);
panel.add(idInput);
panel.add(pwdInput);
panel.add(loginButton);
frame.add(panel);
frame.setTitle("직원 로그인");
frame.setSize(320, 130);
frame.setVisible(true);
// 로그인 버튼에 리스너 등록
loginButton.addActionListener(new ActionListener() {
@SuppressWarnings("static-access")
public void actionPerformed(ActionEvent e) {
if (e.getSource() == loginButton) {
String id, pass;
id = idInput.getText();
pass = new String(pwdInput.getPassword());
// 접속 성공,관련 테이블이 이미 존재한다면, 메뉴현황 초기화
if (di.log_in(id, pass)) {
frame.dispose();
String query = "select count(*) from ALL_TABLES where TABLE_NAME = 'MENU'";
ResultSet rs = di.executeQuery(query);
int n = 0 ;
try {
rs.next();
n = rs.getInt("count(*)");
if (n == 1)
{
di.initMenuPanel();
}
} catch (SQLException e1) {
di.closeStatementResultSet();
System.out.println(e1.getMessage());
}
di.closeStatementResultSet();
} else // 접속 실패
{
JOptionPane warning = new JOptionPane();
warning.showMessageDialog(null, "없는 계정이거나 비밀번호가 틀렸습니다.", "로그인 실패",
warning.WARNING_MESSAGE);
}
}
}
});
}
@SuppressWarnings({ "static-access" })
private void open_file() throws HeadlessException, SQLException {
File file;
JFileChooser chooser;
chooser = new JFileChooser();
int n = chooser.showOpenDialog(null);
if (n == JFileChooser.APPROVE_OPTION) {
file = chooser.getSelectedFile(); // 파일탐색기에 선택된 파일.
// 선택된 파일의 확장자가 txt인지 검사
String fileName = file.getName();
String ext = fileName.substring(fileName.lastIndexOf(".") + 1, fileName.length());
// 로그인 해야 파일 인풋 가능. 로그인 안되어 있으면 경고창 띄움.
if(di.getLoginStatus()){
if (ext.equals("txt"))
{
if(di.readFile(file)){
System.out.println("데이터베이스 테이블에 모든 데이터 입력 성공..");
}else{
JOptionPane warning = new JOptionPane();
warning.showMessageDialog(null, "입력 실패. \n1. 파일 내의 데이터가 정해진 포맷을 따르지 않거나,"
+ "\n2. 테이블과 데이터가 이미 데이터베이스에 존재함. ",
"warning", warning.WARNING_MESSAGE);
}
}
else
{
JOptionPane warning = new JOptionPane();
JOptionPane.showMessageDialog(null, "확장자가 txt인 파일만 열 수 있습니다.", "warning",
warning.WARNING_MESSAGE);
}
}
else{
JOptionPane warning = new JOptionPane();
JOptionPane.showMessageDialog(null, "먼저 로그인을 하려무나.", "warning",
warning.WARNING_MESSAGE);
}//else
}
}
public DB_Interface getDBInterface() {
return this.di;
}
public void setDBInterface(DB_Interface di)
{
this.di = di;
}
}