---------------------------------------------
직원관리 프로젝트
-> 새 프로젝트 생성(Employee_20121119)
-> 메뉴 구성 추가
-> DBConn, EmployeeDTO, EmployeeDAO 클래스 이용.
-> emp.sql 쿼리를 먼저 실행해서 환경 구성할 것.
--------------------------------------
--지역 검색 쿼리
SELECT city_id, city FROM city ORDER BY city_id
--부서 검색 쿼리
SELECT buseo_id, buseo FROM buseo ORDER BY buseo_id
--직위 검색 쿼리
SELECT jikwi_id, jikwi FROM jikwi ORDER BY jikwi_id
--직위별 최소 기본급 검색 쿼리
SELECT min_basicpay FROM jikwi WHERE jikwi_id=9
--입력 쿼리
INSERT INTO emp (emp_id, name, ssn, ibsadate, city_id, tel, buseo_id, jikwi_id, basicpay, sudang)
VALUES (empSeq.nextval
, '홍길동'
, '771212-1022432'
, '1998-10-11'
, 6
, '011-2356-4528'
, 7
, 9
, 2610000
, 200000)
--직원 명단 출력 쿼리(emp 테이블이 아니라 empView 이용)
SELECT emp_id, name, ssn, TO_CHAR(ibsadate, 'YYYY-MM-DD') AS ibsadate
, city_id, city, tel, buseo_id, buseo, jikwi_id, jikwi, basicpay
, sudang, pay
FROM empView
ORDER BY emp_id ASC
--전체 직원수 출력 쿼리 (emp 테이블이나 empView나 결과 동일함)
SELECT COUNT(*) AS count
FROM emp
--검색 쿼리(emp 테이블이 아니라 empView 이용)
SELECT emp_id, name, ssn, TO_CHAR(ibsadate, 'YYYY-MM-DD') AS ibsadate
, city_id, city, tel, buseo_id, buseo, jikwi_id, jikwi, basicpay
, sudang, pay
FROM empView
WHERE emp_id = 1001
ORDER BY emp_id ASC
--수정 쿼리
UPDATE emp
SET name='새로운 이름'
, ssn='새로운 주민번호'
, ibsadate='새로운 입사일'
, city_id=1
, tel='새로운 전화번호'
, buseo_id=1
, jikwi_id=1
, basicpay=1
, sudang=1
WHERE emp_id=1001
--삭제 쿼리
DELETE emp
WHERE emp_id=1001
--직원용 ID(이름), PW(주민번호 뒷자리) 검사 쿼리
SELECT COUNT(*) AS count
FROM emp
WHERE name='이순신' AND SUBSTR(ssn, 8, 7)='1544236';
--직원 전용 employeeView
CREATE OR REPLACE VIEW employeeView
AS
SELECT emp_id, name, ibsadate, c.city_id AS city_id, city, tel, b.buseo_id AS buseo_id, buseo, j.jikwi_id AS jikwi_id, jikwi
FROM emp e, city c, buseo b, jikwi j
WHERE e.city_id=c.city_id AND e.buseo_id=b.buseo_id AND e.jikwi_id=j.jikwi_id
ORDER BY emp_id ASC;
--------------------------------------
--관리자 전용 테이블
CREATE TABLE empAdmin (
id VARCHAR2(20) --PK
,pw VARCHAR2(20) --암호화. encrypt() 사용자 정의 함수 이용.
);
ALTER TABLE empAdmin
ADD CONSTRAINT empAdmin_id_pk PRIMARY KEY(id);
INSERT INTO empAdmin (id, pw) VALUES ('admin', encrypt('1234', 'admin'));
INSERT INTO empAdmin (id, pw) VALUES ('hong', encrypt('1234', 'hong'));
COMMIT;
SELECT id, pw FROM empAdmin;
--관리자용 ID, PW 검사 쿼리
SELECT COUNT(*) AS count FROM empAdmin
WHERE id='admin' AND pw=encrypt('1234', 'admin');
--------------------------------------
//DBConn.java
//EmployeeDTO.java
//CityDTO.java
//BuseoDTO.java
//JikwiDTO.java
//EmployeeDAO.java
//CityDAO.java
//BuseoDAO.java
//JikwiDAO.java
//City.jsp -> 지역관리. 입력, 출력, 수정, 삭제 기능.
//Buseo.jsp -> 부서관리. 입력, 출력, 수정, 삭제 기능.
//Jikwi.jsp -> 직위관리. 입력, 출력, 수정, 삭제 기능.
//BasicStyle.css -> CSS 스타일 시트 전용.
//Employee_Select.jsp -> 직원관리. 출력 기능.
//Employee_Search.jsp -> 직원관리. 검색 기능.
//Employee_InsertForm.jsp -> 직원관리. 입력 폼 화면 구성. Ajax 요청 기능. jQuery 달력 기능.
//Employee_Insert.jsp -> 직원관리. 입력 액션 처리.
//Employee_UpdateForm.jsp -> 직원관리. 수정 폼 화면 구성.
//Employee_Update.jsp -> 직원관리. 수정 액션 처리.
//Employee_DeleteForm.jsp -> 직원관리. 삭제 폼 화면 구성.
//Employee_Delete.jsp -> 직원관리. 삭제 액션 처리.
//MinBasicPayCheck.jsp -> 직원관리 입력 폼에서 직위 선택시 최소기본급을 리턴하는 전용 페이지. Ajax 요청 기능.
//LoginForm.jsp -> 로그인 페이지. ID, PW 확인 및 세션 처리
//Logout.jsp -> 로그아웃 액션 처리.
//MainMenu.jsp -> 메인 메뉴 전용.
-------------------------------------------
//BasicStyle.css
@CHARSET "EUC-KR";
body {
color:#2f3743;
}
a { /* a 태그에만 적용 */
text-decoration: none; /* 글자의 장식 지정 없앰 */
color:gray; /* 글자색 */
}
a:hover { /* a 태그에 커서가 올려져 있을때만 적용 */
text-decoration: underline; /* 밑줄 장식 지정 */
color:red;
}
table.style00 td, table.style00 th
{
padding: 3px;
border-right-style: solid;
border-bottom-style: solid;
border-width: 1px;
border-color: #6980b8;
}
table.style00 td:hover
{
background-color:#d2d2d2;
}
.style1 { /* class 속성의 값이 style1인 경우만 적용 */
text-align:center; /* 가운데 정렬 */
}
.style2 { /* class 속성의 값이 style2인 경우만 적용 */
text-align:right; /* 오른쪽 정렬 */
}
#result {
overflow:auto; /* DIV 태그 내부에 스크롤 생성 */
height:300px;
}
------------------------------------------------------
//DBConn.java
package com.test;
import java.sql.*;
public class DBConn {
//Singleton pattern
private static Connection dbConn;
public static Connection getConnection()
throws SQLException, ClassNotFoundException {
if (dbConn == null) {
String url = "jdbc:oracle:thin:@localhost:1521:xe";
String user = "scott";
String pw = "tiger";
Class.forName("oracle.jdbc.driver.OracleDriver");
dbConn = DriverManager.getConnection(url, user, pw);
}
return dbConn;
}
public static void close()
throws SQLException {
if (dbConn != null) {
if (!dbConn.isClosed()) {
dbConn.close();
}
}
dbConn = null;
}
}
-------------------------------------------
//CityDTO.java
package com.test;
public class CityDTO {
private int city_id;
private String city;
public int getCity_id() {
return city_id;
}
public void setCity_id(int city_id) {
this.city_id = city_id;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
}
//CityDAO.java
package com.test;
import java.sql.*;
import java.util.*;
public class CityDAO {
Connection conn;
public void connect()
throws SQLException, ClassNotFoundException {
conn = DBConn.getConnection();
}
public void close()
throws SQLException {
DBConn.close();
conn = null;
}
public int add(String city)
throws SQLException {
int result = 0;
String sql = String.format("INSERT INTO city (city_id, city) VALUES (citySeq.nextval, '%s')", city);
Statement stmt = conn.createStatement();
result = stmt.executeUpdate(sql);
return result;
}
public ArrayList<CityDTO> lists()
throws SQLException {
ArrayList<CityDTO> arrayList
= new ArrayList<CityDTO>();
String sql = String.format("SELECT city_id, city FROM city ORDER BY city_id");
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(sql);
while(rs.next()) {
int city_id = rs.getInt("city_id");
String city = rs.getString("city");
CityDTO dto = new CityDTO();
dto.setCity_id(city_id);
dto.setCity(city);
arrayList.add(dto);
}
rs.close();
return arrayList;
}
/*public ArrayList<CityDTO> search(String key, String value)
throws SQLException {
ArrayList<CityDTO> arrayList
= new ArrayList<CityDTO>();
return arrayList;
}*/
public int modify(CityDTO dto)
throws SQLException {
int result = 0;
String sql = String.format("UPDATE city SET city='%s' WHERE city_id=%d", dto.getCity(), dto.getCity_id());
Statement stmt = conn.createStatement();
result = stmt.executeUpdate(sql);
return result;
}
public int remove(int city_id)
throws SQLException {
int result = 0;
String sql = String.format("DELETE city WHERE city_id=%d", city_id);
Statement stmt = conn.createStatement();
result = stmt.executeUpdate(sql);
return result;
}
}
//City.jsp
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<%@ page import="com.test.*" %>
<%
request.setCharacterEncoding("euc-kr");
String num = request.getParameter("num");
String name = request.getParameter("name");
String key = request.getParameter("key"); //액션 구분용 값
StringBuilder str = new StringBuilder();
CityDAO dao = new CityDAO();
try {
dao.connect();
if (key != null && key.equals("insert")) {
dao.add(name);
}
if (key != null && key.equals("update")) {
//수정 메소드 호출
CityDTO dto = new CityDTO();
dto.setCity_id(Integer.parseInt(num));
dto.setCity(name);
dao.modify(dto);
}
if (key != null && key.equals("delete")) {
//삭제 메소드 호출
dao.remove(Integer.parseInt(num));
}
for (CityDTO dto : dao.lists()) {
str.append(String.format("<tr>"));
str.append(String.format("<td class=\"style1\">%d</td>", dto.getCity_id()));
str.append(String.format("<td class=\"style1\">%s</td>", dto.getCity()));
str.append(String.format("</tr>"));
}
} catch(Exception e) {
System.out.println(e.toString());
} finally {
dao.close();
}
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>직원관리(JSP버전)</title>
<link rel="stylesheet" type="text/css" href="BasicStyle.css">
<script type="text/javascript">
function cityForm(status) {
var myForm = document.getElementById("myForm");
var num = document.getElementById("num");
var name = document.getElementById("name");
var key = document.getElementById("key");
var numMsg = document.getElementById("numMsg");
var nameMsg = document.getElementById("nameMsg");
numMsg.style.display = "none";
nameMsg.style.display = "none";
if (status == "insert") {
//이름 검사 (공백)
if(name.value == "") {
nameMsg.style.display = "inline";
return;
}
}
if (status == "delete") {
//번호 검사 (공백, 숫자)
if(num.value == "" || num.value.match(/[^0-9]/)) {
numMsg.style.display = "inline";
return;
}
}
if (status == "update") {
//번호 검사 (공백, 숫자)
//이름 검사 (공백)
if(num.value == "" || num.value.match(/[^0-9]/)) {
numMsg.style.display = "inline";
return;
}
if(name.value == "") {
nameMsg.style.display = "inline";
return;
}
}
key.value = status;
myForm.submit();
}
</script>
</head>
<body>
<div>
<div>
<h2>직원관리_지역관리</h2>
<div>
[<a href="Employee_Select.jsp">직원출력</a>]
[<a href="Employee_Search.jsp">직원검색</a>]
[<a href="Employee_InsertForm.jsp">직원입력</a>]
[<a href="Employee_UpdateForm.jsp">직원수정</a>]
[<a href="Employee_DeleteForm.jsp">직원삭제</a>]
[<a href="City.jsp">지역관리</a>]
[<a href="Buseo.jsp">부서관리</a>]
[<a href="Jikwi.jsp">직위관리</a>]
[<a href="Logout.jsp">로그아웃</a>]
</div>
<hr>
</div>
<div>
<form method="post" id="myForm">
<%-- 추가, 수정, 삭제 구분용 값을 서버로 전송 --%>
<input type="hidden" id="key" name="key" value="">
지역번호<input type="text" id="num" name="num"><span id="numMsg" style="color:red; display:none;">지역번호를 입력해야 합니다.</span><br>
지역이름<input type="text" id="name" name="name"><span id="nameMsg" style="color:red; display:none;">지역이름을 입력해야 합니다.</span><br>
[<a href="">전체출력</a>]
[<a href="javascript:cityForm('insert')">지역추가</a>]
[<a href="javascript:cityForm('update')">지역수정</a>]
[<a href="javascript:cityForm('delete')">지역삭제</a>]<br><br>
</form>
<table style="width:400px;" class="style00">
<tbody>
<tr>
<th>번호</th><th>지역</th>
</tr>
<%=str%>
</tbody>
</table>
</div>
</div>
</body>
</html>
-------------------------------------------
//지역관리 프로그램을 이용해서 부서관리로 만들 것.
//BuseoDTO.java
package com.test;
public class BuseoDTO {
private int buseo_id;
private String buseo;
public int getBuseo_id() {
return buseo_id;
}
public void setBuseo_id(int buseo_id) {
this.buseo_id = buseo_id;
}
public String getBuseo() {
return buseo;
}
public void setBuseo(String buseo) {
this.buseo = buseo;
}
}
//BuseoDAO.java
package com.test;
import java.sql.*;
import java.util.*;
public class BuseoDAO {
Connection conn;
public void connect()
throws SQLException, ClassNotFoundException {
conn = DBConn.getConnection();
}
public void close()
throws SQLException {
DBConn.close();
conn = null;
}
public int add(String buseo)
throws SQLException {
int result = 0;
String sql = String.format("INSERT INTO buseo (buseo_id, buseo) VALUES (buseoSeq.nextval, '%s')", buseo);
Statement stmt = conn.createStatement();
result = stmt.executeUpdate(sql);
return result;
}
public ArrayList<BuseoDTO> lists()
throws SQLException {
ArrayList<BuseoDTO> arrayList
= new ArrayList<BuseoDTO>();
String sql = String.format("SELECT buseo_id, buseo FROM buseo ORDER BY buseo_id");
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(sql);
while(rs.next()) {
int buseo_id = rs.getInt("buseo_id");
String buseo = rs.getString("buseo");
BuseoDTO dto = new BuseoDTO();
dto.setBuseo_id(buseo_id);
dto.setBuseo(buseo);
arrayList.add(dto);
}
rs.close();
return arrayList;
}
/*public ArrayList<BuseoDTO> search(String key, String value)
throws SQLException {
ArrayList<BuseoDTO> arrayList
= new ArrayList<BuseoDTO>();
return arrayList;
}*/
public int modify(BuseoDTO dto)
throws SQLException {
int result = 0;
String sql = String.format("UPDATE buseo SET buseo='%s' WHERE buseo_id=%d", dto.getBuseo(), dto.getBuseo_id());
Statement stmt = conn.createStatement();
result = stmt.executeUpdate(sql);
return result;
}
public int remove(int buseo_id)
throws SQLException {
int result = 0;
String sql = String.format("DELETE buseo WHERE buseo_id=%d", buseo_id);
Statement stmt = conn.createStatement();
result = stmt.executeUpdate(sql);
return result;
}
}
//Buseo.jsp
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<%@ page import="com.test.*" %>
<%
request.setCharacterEncoding("euc-kr");
String num = request.getParameter("num");
String name = request.getParameter("name");
String key = request.getParameter("key"); //액션 구분용 값
StringBuilder str = new StringBuilder();
BuseoDAO dao = new BuseoDAO();
try {
dao.connect();
if (key != null && key.equals("insert")) {
dao.add(name);
}
if (key != null && key.equals("update")) {
//수정 메소드 호출
BuseoDTO dto = new BuseoDTO();
dto.setBuseo_id(Integer.parseInt(num));
dto.setBuseo(name);
dao.modify(dto);
}
if (key != null && key.equals("delete")) {
//삭제 메소드 호출
dao.remove(Integer.parseInt(num));
}
for (BuseoDTO dto : dao.lists()) {
str.append(String.format("<tr>"));
str.append(String.format("<td class=\"style1\">%d</td>", dto.getBuseo_id()));
str.append(String.format("<td class=\"style1\">%s</td>", dto.getBuseo()));
str.append(String.format("</tr>"));
}
} catch(Exception e) {
System.out.println(e.toString());
} finally {
dao.close();
}
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>직원관리(JSP버전)</title>
<link rel="stylesheet" type="text/css" href="BasicStyle.css">
<script type="text/javascript">
function buseoForm(status) {
var myForm = document.getElementById("myForm");
var num = document.getElementById("num");
var name = document.getElementById("name");
var key = document.getElementById("key");
var numMsg = document.getElementById("numMsg");
var nameMsg = document.getElementById("nameMsg");
numMsg.style.display = "none";
nameMsg.style.display = "none";
if (status == "insert") {
//이름 검사 (공백)
if(name.value == "") {
nameMsg.style.display = "inline";
return;
}
}
if (status == "delete") {
//번호 검사 (공백, 숫자)
if(num.value == "" || num.value.match(/[^0-9]/)) {
numMsg.style.display = "inline";
return;
}
}
if (status == "update") {
//번호 검사 (공백, 숫자)
//이름 검사 (공백)
if(num.value == "" || num.value.match(/[^0-9]/)) {
numMsg.style.display = "inline";
return;
}
if(name.value == "") {
nameMsg.style.display = "inline";
return;
}
}
key.value = status;
myForm.submit();
}
</script>
</head>
<body>
<div>
<div>
<h2>직원관리_부서관리</h2>
<div>
[<a href="Employee_Select.jsp">직원출력</a>]
[<a href="Employee_Search.jsp">직원검색</a>]
[<a href="Employee_InsertForm.jsp">직원입력</a>]
[<a href="Employee_UpdateForm.jsp">직원수정</a>]
[<a href="Employee_DeleteForm.jsp">직원삭제</a>]
[<a href="City.jsp">지역관리</a>]
[<a href="Buseo.jsp">부서관리</a>]
[<a href="Jikwi.jsp">직위관리</a>]
[<a href="Logout.jsp">로그아웃</a>]
</div>
<hr>
</div>
<div>
<form method="post" id="myForm">
<%-- 추가, 수정, 삭제 구분용 값을 서버로 전송 --%>
<input type="hidden" id="key" name="key" value="">
부서번호<input type="text" id="num" name="num"><span id="numMsg" style="color:red; display:none;">부서번호를 입력해야 합니다.</span><br>
부서이름<input type="text" id="name" name="name"><span id="nameMsg" style="color:red; display:none;">부서이름을 입력해야 합니다.</span><br>
[<a href="">전체출력</a>]
[<a href="javascript:buseoForm('insert')">부서추가</a>]
[<a href="javascript:buseoForm('update')">부서수정</a>]
[<a href="javascript:buseoForm('delete')">부서삭제</a>]<br><br>
</form>
<table style="width:400px;" class="style00">
<tbody>
<tr>
<th>번호</th><th>부서</th>
</tr>
<%=str%>
</tbody>
</table>
</div>
</div>
</body>
</html>
-------------------------------------------
//지역관리 프로그램을 이용해서 직위관리로 만들 것.
//JikwiDTO.java
package com.test;
public class JikwiDTO {
private int jikwi_id;
private String jikwi;
public int getJikwi_id() {
return jikwi_id;
}
public void setJikwi_id(int jikwi_id) {
this.jikwi_id = jikwi_id;
}
public String getJikwi() {
return jikwi;
}
public void setJikwi(String jikwi) {
this.jikwi = jikwi;
}
}
//JikwiDAO.java
package com.test;
import java.sql.*;
import java.util.*;
public class JikwiDAO {
Connection conn;
public void connect()
throws SQLException, ClassNotFoundException {
conn = DBConn.getConnection();
}
public void close()
throws SQLException {
DBConn.close();
conn = null;
}
public int add(String jikwi)
throws SQLException {
int result = 0;
String sql = String.format("INSERT INTO jikwi (jikwi_id, jikwi) VALUES (jikwiSeq.nextval, '%s')", jikwi);
Statement stmt = conn.createStatement();
result = stmt.executeUpdate(sql);
return result;
}
public ArrayList<JikwiDTO> lists()
throws SQLException {
ArrayList<JikwiDTO> arrayList
= new ArrayList<JikwiDTO>();
String sql = String.format("SELECT jikwi_id, jikwi FROM jikwi ORDER BY jikwi_id");
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(sql);
while(rs.next()) {
int jikwi_id = rs.getInt("jikwi_id");
String jikwi = rs.getString("jikwi");
JikwiDTO dto = new JikwiDTO();
dto.setJikwi_id(jikwi_id);
dto.setJikwi(jikwi);
arrayList.add(dto);
}
rs.close();
return arrayList;
}
/*public ArrayList<JikwiDTO> search(String key, String value)
throws SQLException {
ArrayList<JikwiDTO> arrayList
= new ArrayList<JikwiDTO>();
return arrayList;
}*/
public int modify(JikwiDTO dto)
throws SQLException {
int result = 0;
String sql = String.format("UPDATE jikwi SET jikwi='%s' WHERE jikwi_id=%d", dto.getJikwi(), dto.getJikwi_id());
Statement stmt = conn.createStatement();
result = stmt.executeUpdate(sql);
return result;
}
public int remove(int jikwi_id)
throws SQLException {
int result = 0;
String sql = String.format("DELETE jikwi WHERE jikwi_id=%d", jikwi_id);
Statement stmt = conn.createStatement();
result = stmt.executeUpdate(sql);
return result;
}
}
//Jikwi.jsp
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<%@ page import="com.test.*" %>
<%
request.setCharacterEncoding("euc-kr");
String num = request.getParameter("num");
String name = request.getParameter("name");
String key = request.getParameter("key"); //액션 구분용 값
StringBuilder str = new StringBuilder();
JikwiDAO dao = new JikwiDAO();
try {
dao.connect();
if (key != null && key.equals("insert")) {
dao.add(name);
}
if (key != null && key.equals("update")) {
//수정 메소드 호출
JikwiDTO dto = new JikwiDTO();
dto.setJikwi_id(Integer.parseInt(num));
dto.setJikwi(name);
dao.modify(dto);
}
if (key != null && key.equals("delete")) {
//삭제 메소드 호출
dao.remove(Integer.parseInt(num));
}
for (JikwiDTO dto : dao.lists()) {
str.append(String.format("<tr>"));
str.append(String.format("<td class=\"style1\">%d</td>", dto.getJikwi_id()));
str.append(String.format("<td class=\"style1\">%s</td>", dto.getJikwi()));
str.append(String.format("</tr>"));
}
} catch(Exception e) {
System.out.println(e.toString());
} finally {
dao.close();
}
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>직원관리(JSP버전)</title>
<link rel="stylesheet" type="text/css" href="BasicStyle.css">
<script type="text/javascript">
function jikwiForm(status) {
var myForm = document.getElementById("myForm");
var num = document.getElementById("num");
var name = document.getElementById("name");
var key = document.getElementById("key");
var numMsg = document.getElementById("numMsg");
var nameMsg = document.getElementById("nameMsg");
numMsg.style.display = "none";
nameMsg.style.display = "none";
if (status == "insert") {
//이름 검사 (공백)
if(name.value == "") {
nameMsg.style.display = "inline";
return;
}
}
if (status == "delete") {
//번호 검사 (공백, 숫자)
if(num.value == "" || num.value.match(/[^0-9]/)) {
numMsg.style.display = "inline";
return;
}
}
if (status == "update") {
//번호 검사 (공백, 숫자)
//이름 검사 (공백)
if(num.value == "" || num.value.match(/[^0-9]/)) {
numMsg.style.display = "inline";
return;
}
if(name.value == "") {
nameMsg.style.display = "inline";
return;
}
}
key.value = status;
myForm.submit();
}
</script>
</head>
<body>
<div>
<div>
<h2>직원관리_직위관리</h2>
<div>
[<a href="Employee_Select.jsp">직원출력</a>]
[<a href="Employee_Search.jsp">직원검색</a>]
[<a href="Employee_InsertForm.jsp">직원입력</a>]
[<a href="Employee_UpdateForm.jsp">직원수정</a>]
[<a href="Employee_DeleteForm.jsp">직원삭제</a>]
[<a href="City.jsp">지역관리</a>]
[<a href="Buseo.jsp">부서관리</a>]
[<a href="Jikwi.jsp">직위관리</a>]
[<a href="Logout.jsp">로그아웃</a>]
</div>
<hr>
</div>
<div>
<form method="post" id="myForm">
<%-- 추가, 수정, 삭제 구분용 값을 서버로 전송 --%>
<input type="hidden" id="key" name="key" value="">
직위번호<input type="text" id="num" name="num"><span id="numMsg" style="color:red; display:none;">직위번호를 입력해야 합니다.</span><br>
직위이름<input type="text" id="name" name="name"><span id="nameMsg" style="color:red; display:none;">직위이름을 입력해야 합니다.</span><br>
[<a href="">전체출력</a>]
[<a href="javascript:jikwiForm('insert')">직위추가</a>]
[<a href="javascript:jikwiForm('update')">직위수정</a>]
[<a href="javascript:jikwiForm('delete')">직위삭제</a>]<br><br>
</form>
<table style="width:400px;" class="style00">
<tbody>
<tr>
<th>번호</th><th>직위</th>
</tr>
<%=str%>
</tbody>
</table>
</div>
</div>
</body>
</html>
-------------------------------------------
//Employee_Select.jsp
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<%@ page import="com.test.*" %>
<%
String order = request.getParameter("order");
if (order == null) {
order = "emp_id";
}
String direction = request.getParameter("direction");
if (direction == null) {
direction = "asc";
}
//제목을 기준으로 정렬시키기 위해서 추가한 부분
String urlEmp_id = "";
String urlName = "";
String urlSsn = "";
String urlIbsadate = "";
String urlCity = "";
String urlTel = "";
String urlBuseo = "";
String urlJikwi = "";
String urlBasicpay = "";
String urlSudang = "";
String urlPay = "";
//제목을 기준으로 정렬시키기 위해서 추가한 부분
if (order.equals("emp_id") && direction.equals("asc")) {
urlEmp_id = "Employee_Select.jsp?order=emp_id&direction=desc";
} else {
urlEmp_id = "Employee_Select.jsp?order=emp_id&direction=asc";
}
if (order.equals("name") && direction.equals("asc")) {
urlName = "Employee_Select.jsp?order=name&direction=desc";
} else {
urlName = "Employee_Select.jsp?order=name&direction=asc";
}
if (order.equals("ssn") && direction.equals("asc")) {
urlSsn = "Employee_Select.jsp?order=ssn&direction=desc";
} else {
urlSsn = "Employee_Select.jsp?order=ssn&direction=asc";
}
if (order.equals("ibsadate") && direction.equals("asc")) {
urlIbsadate = "Employee_Select.jsp?order=ibsadate&direction=desc";
} else {
urlIbsadate = "Employee_Select.jsp?order=ibsadate&direction=asc";
}
if (order.equals("city") && direction.equals("asc")) {
urlCity = "Employee_Select.jsp?order=city&direction=desc";
} else {
urlCity = "Employee_Select.jsp?order=city&direction=asc";
}
if (order.equals("tel") && direction.equals("asc")) {
urlTel = "Employee_Select.jsp?order=tel&direction=desc";
} else {
urlTel = "Employee_Select.jsp?order=tel&direction=asc";
}
if (order.equals("buseo") && direction.equals("asc")) {
urlBuseo = "Employee_Select.jsp?order=buseo&direction=desc";
} else {
urlBuseo = "Employee_Select.jsp?order=buseo&direction=asc";
}
if (order.equals("jikwi") && direction.equals("asc")) {
urlJikwi = "Employee_Select.jsp?order=jikwi&direction=desc";
} else {
urlJikwi = "Employee_Select.jsp?order=jikwi&direction=asc";
}
if (order.equals("basicpay") && direction.equals("asc")) {
urlBasicpay = "Employee_Select.jsp?order=basicpay&direction=desc";
} else {
urlBasicpay = "Employee_Select.jsp?order=basicpay&direction=asc";
}
if (order.equals("sudang") && direction.equals("asc")) {
urlSudang = "Employee_Select.jsp?order=sudang&direction=desc";
} else {
urlSudang = "Employee_Select.jsp?order=sudang&direction=asc";
}
if (order.equals("pay") && direction.equals("asc")) {
urlPay = "Employee_Select.jsp?order=pay&direction=desc";
} else {
urlPay = "Employee_Select.jsp?order=pay&direction=asc";
}
StringBuilder str = new StringBuilder();
String count = "0";
EmployeeDAO dao = new EmployeeDAO();
try {
dao.connect();
count = String.valueOf(dao.count());
String orders = String.format("ORDER BY %s %s", order, direction);
for (EmployeeDTO dto : dao.lists(orders)) {
str.append(String.format("<tr>"));
str.append(String.format("<td class=\"style1\">%d</td>", dto.getEmp_id()));
str.append(String.format("<td class=\"style1\">%s</td>", dto.getName()));
str.append(String.format("<td class=\"style1\">%s</td>", dto.getSsn()));
str.append(String.format("<td class=\"style1\">%s</td>", dto.getIbsadate()));
str.append(String.format("<td class=\"style1\">%s</td>", dto.getCity()));
str.append(String.format("<td class=\"style1\">%s</td>", dto.getTel()));
str.append(String.format("<td class=\"style1\">%s</td>", dto.getBuseo()));
str.append(String.format("<td class=\"style1\">%s</td>", dto.getJikwi()));
str.append(String.format("<td class=\"style2\">%,d</td>", dto.getBasicpay()));
str.append(String.format("<td class=\"style2\">%,d</td>", dto.getSudang()));
str.append(String.format("<td class=\"style2\">%,d</td>", dto.getPay()));
str.append(String.format("</tr>"));
}
}catch(Exception e){
System.out.println(e.toString());
}finally{
dao.close();
}
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>직원관리(JSP버전)</title>
<link rel="stylesheet" type="text/css" href="BasicStyle.css">
</head>
<body>
<div>
<div>
<h2>직원관리_직원출력</h2>
<div>
[<a href="Employee_Select.jsp">직원출력</a>]
[<a href="Employee_Search.jsp">직원검색</a>]
[<a href="Employee_InsertForm.jsp">직원입력</a>]
[<a href="Employee_UpdateForm.jsp">직원수정</a>]
[<a href="Employee_DeleteForm.jsp">직원삭제</a>]
[<a href="City.jsp">지역관리</a>]
[<a href="Buseo.jsp">부서관리</a>]
[<a href="Jikwi.jsp">직위관리</a>]
[<a href="Logout.jsp">로그아웃</a>]
</div>
<hr>
</div>
<div>
<h3>전체 직원수 : <%=count%>명</h3>
<div id="result">
<table style="width:900px;" class="style00">
<tbody>
<tr>
<th><a href="<%=urlEmp_id%>">사번</a></th>
<th><a href="<%=urlName%>">이름</a></th>
<th><a href="<%=urlSsn%>">주민번호</a></th>
<th><a href="<%=urlIbsadate%>">입사일</a></th>
<th><a href="<%=urlCity%>">지역</a></th>
<th><a href="<%=urlTel%>">전화번호</a></th>
<th><a href="<%=urlBuseo%>">부서</a></th>
<th><a href="<%=urlJikwi%>">직위</a></th>
<th><a href="<%=urlBasicpay%>">기본급</a></th>
<th><a href="<%=urlSudang%>">수당</a></th>
<th><a href="<%=urlPay%>">급여</a></th>
</tr>
<%=str%>
</tbody>
</table>
</div>
</div>
</div>
</body>
</html>
--------------------------------------------
'Java > JSP & Servlet' 카테고리의 다른 글
[20121121] 7일차 (직원관리) (0) | 2012.12.04 |
---|---|
[20121120] 6일차 (직원관리) (0) | 2012.12.04 |
[20121116] 4일차 (회원관리 + 성적처리) (0) | 2012.12.04 |
[20121115] 3일차 (JSP와 JDBC 연동, DTO클래스와 DAO클래스 연동 코딩) (0) | 2012.11.15 |
[20121114] 2일차 (POST 전송방식, GET 전송방식, forward(), sendRedirect()) (0) | 2012.11.15 |
WRITTEN BY