----------------------------------------

//Employee_InsertForm.jsp

<%@ page language="java" contentType="text/html; charset=EUC-KR"

    pageEncoding="EUC-KR"%>

<%@ page import="com.test.*" %>    

<%


String insertOK = request.getParameter("insertOK");

if (insertOK == null) {

insertOK = "false";

}


StringBuilder cityLists = new StringBuilder();

StringBuilder buseoLists = new StringBuilder();

StringBuilder jikwiLists = new StringBuilder();


EmployeeDAO dao = new EmployeeDAO();

try {

dao.connect();

for (EmployeeDTO dto : dao.cityList()) {

cityLists.append(String.format("<option value=\"%d\">%s</option>", dto.getCity_id(), dto.getCity()));

}

for (EmployeeDTO dto : dao.buseoList()) {

buseoLists.append(String.format("<option value=\"%d\">%s</option>", dto.getBuseo_id(), dto.getBuseo()));

}

for (EmployeeDTO dto : dao.jikwiList()) {

jikwiLists.append(String.format("<option value=\"%d\">%s</option>", dto.getJikwi_id(), dto.getJikwi()));

}

}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">


<link rel="stylesheet"

href="http://code.jquery.com/ui/1.9.1/themes/base/jquery-ui.css" />

<script src="http://code.jquery.com/jquery-1.8.2.js"></script>

<script src="http://code.jquery.com/ui/1.9.1/jquery-ui.js"></script>

<script>

$(function() {

$("#ibsadate").datepicker({dateFormat:"yy-mm-dd"});

});

</script>


<script type="text/javascript">

//Ajax 전역 변수

var xmlReq;


function myFunc() {

var myForm = document.getElementById("myForm");

//문제) 데이터 검사 과정 추가할 것.

var name = document.getElementById("name");

var ssn = document.getElementById("ssn");

var ibsadate = document.getElementById("ibsadate");

var tel = document.getElementById("tel");

var basicpay = document.getElementById("basicpay");

var sudang = document.getElementById("sudang");

var nameMsg = document.getElementById("nameMsg");

var ssnMsg = document.getElementById("ssnMsg");

var ibsadateMsg = document.getElementById("ibsadateMsg");

var telMsg = document.getElementById("telMsg");

var basicpayMsg = document.getElementById("basicpayMsg");

var sudangMsg = document.getElementById("sudangMsg");

nameMsg.style.display = "none";

ssnMsg.style.display = "none";

ibsadateMsg.style.display = "none";

telMsg.style.display = "none";

basicpayMsg.style.display = "none";

sudangMsg.style.display = "none";

//빈칸 검사

if(name.value == ""){

nameMsg.style.display = "inline";

return;

}

if(ssn.value == ""){

ssnMsg.style.display = "inline";

return;

}

if(ibsadate.value == ""){

ibsadateMsg.style.display = "inline";

return;

}

if(tel.value == ""){

telMsg.style.display = "inline";

return;

}

if(basicpay.value == ""){

basicpayMsg.style.display = "inline";

return;

}

//숫자 검사

if (basicpay.value.match(/[^0-9]/)){

basicpayMsg.style.display = "inline";

return;

if(sudang.value == ""){

sudangMsg.style.display = "inline";

return;

}

if (sudang.value.match(/[^0-9]/)){

sudangMsg.style.display = "inline";

return;

//데이터 전송

myForm.submit();

}

function msg() {

if (<%=insertOK%>) {

alert("입력이 완료되었습니다.");

}

}

function minBasicPayCheck(obj) {

var jikwi_id = obj.options[obj.selectedIndex];

xmlReq = new XMLHttpRequest(); //IE7.0 이상

var url = "MinBasicPayCheck.jsp";

var postString = "jikwi_id="+jikwi_id.value;

xmlReq.onreadystatechange = callBack;

xmlReq.open("POST", url, true);

xmlReq.setRequestHeader("Content-Type"

, "application/x-www-form-urlencoded; charset=euc-kr");

xmlReq.send(postString);

}

function callBack() {

if (xmlReq.readyState == 4) {

if (xmlReq.status == 200) {

printData();

}

}

}

function printData() {

var result = xmlReq.responseText;

var minBasicPay = document.getElementById("minBasicPay");

minBasicPay.innerHTML = result;

}

</script>


</head>

<body onload="msg()">

<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 action="Employee_Insert.jsp" method="post" id="myForm">

<table>

<tr>

<td>이름</td>

<td><input type="text" id="name" name="name"><span id="nameMsg" style="color:red; display:none;">이름를 채워야 합니다.</span></td>

</tr>

<tr>

<td>주민번호(YYMMDD-NNNNNNN)</td>

<td><input type="text" id="ssn" name="ssn"><span id="ssnMsg" style="color:red; display:none;">주민번호를 채워야 합니다.</span></td>

</tr>

<tr>

<td>입사일(YYYY-MM-DD)</td>

<td><input type="text" id="ibsadate" name="ibsadate"><span id="ibsadateMsg" style="color:red; display:none;">입사일을 채워야 합니다.</span></td>

</tr>

<tr>

<td>지역</td>

<td><select style="width:154px;" id="city_id" name="city_id"><%=cityLists%></select></td>

</tr>

<tr>

<td>전화번호</td>

<td><input type="text" id="tel" name="tel"><span id="telMsg" style="color:red; display:none;">전화번호를 채워야 합니다.</span></td>

</tr>

<tr>

<td>부서</td>

<td><select style="width:154px;" id="buseo_id" name="buseo_id"><%=buseoLists%></select></td>

</tr>

<tr>

<td>직위</td>

<td><select style="width:154px;" id="jikwi_id" name="jikwi_id" onchange="minBasicPayCheck(this)"><%=jikwiLists%></select></td>

</tr>

<tr>

<td>기본급(최소 <span id="minBasicPay">????</span> 이상)</td>

<td><input type="text" id="basicpay" name="basicpay"><span id="basicpayMsg" style="color:red; display:none;">기본급은 숫자로만 채워야 합니다.</span></td>

</tr>

<tr>

<td>수당</td>

<td><input type="text" id="sudang" name="sudang"><span id="sudangMsg" style="color:red; display:none;">수당은 숫자로만 채워야 합니다.</span></td>

</tr>

</table>

[<a href="javascript:myFunc()">입력</a>]

</form>

</div>

</div>

</body>

</html>



//Employee_Insert.jsp

<%@ page language="java" contentType="text/html; charset=EUC-KR"

    pageEncoding="EUC-KR"%>

<%@ page import="com.test.*"%>

<%

//문제) 직원 입력 과정 추가할 것.

//한글 인코딩 처리 필요

//데이터 수신

//DAO 객체 생성

//데이터베이스 연결

//DTO 객체 생성

//INSERT 쿼리 메소드 호출

request.setCharacterEncoding("euc-kr");

String name = request.getParameter("name");

String ssn = request.getParameter("ssn");

String ibsadate = request.getParameter("ibsadate");

String city_id = request.getParameter("city_id");

String tel = request.getParameter("tel");

String buseo_id = request.getParameter("buseo_id");

String jikwi_id = request.getParameter("jikwi_id");

String basicpay = request.getParameter("basicpay");

String sudang = request.getParameter("sudang");

EmployeeDAO dao = new EmployeeDAO();

try {

dao.connect();

EmployeeDTO dto = new EmployeeDTO();

dto.setName(name);

dto.setSsn(ssn);

dto.setIbsadate(ibsadate);

dto.setCity_id(Integer.parseInt(city_id));

dto.setTel(tel);

dto.setBuseo_id(Integer.parseInt(buseo_id));

dto.setJikwi_id(Integer.parseInt(jikwi_id));

dto.setBasicpay(Integer.parseInt(basicpay));

dto.setSudang(Integer.parseInt(sudang));

dao.add(dto);

}catch(Exception e){

System.out.println(e.toString());

}finally{

dao.close();

}

//입력 과정이 모두 끝나면 입력 폼 페이지로 돌아가도록 함.

String url = String.format("Employee_InsertForm.jsp?insertOK=true");

response.sendRedirect(url);

%>




//MinBasicPayCheck.jsp

<%@ page language="java" contentType="text/html; charset=EUC-KR"

    pageEncoding="EUC-KR"%>

<%@ page import="com.test.*" %>    

<%

String jikwi_id = request.getParameter("jikwi_id");


EmployeeDAO dao = new EmployeeDAO();

int minBasicPay = 0;

try {

dao.connect();

minBasicPay = dao.minBasicPay(Integer.parseInt(jikwi_id));

}catch(Exception e) {

System.out.println(e.toString());

}finally{

dao.close();

}

out.write(String.format("%,d", minBasicPay));

%>



------------------------------------------------------

//Employee_DeleteForm.jsp

<%@ page language="java" contentType="text/html; charset=EUC-KR"

    pageEncoding="EUC-KR"%>

<%@ page import="com.test.*" %>    

<%

String deleteOK = request.getParameter("deleteOK");

if (deleteOK == null) {

deleteOK = "false";

}


String url = "deleteCancel()";

String value = request.getParameter("value");

if (value == null) {

value = "";

}

StringBuilder str = new StringBuilder();

EmployeeDAO dao = new EmployeeDAO();

try {

dao.connect();

String wheres = String.format("WHERE emp_id='%s'", value);

String orders = "";

for (EmployeeDTO dto : dao.searchLists(wheres,orders)) {

url = "deleteOk()";

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">


<script type="text/javascript">

function search() {

var myForm = document.getElementById("myForm");

//문제) 데이터 검사 과정 추가할 것.

//데이터 전송

myForm.submit();

}

function deleteOk() {

//확인 버튼 선택한 경우만 삭제 진행

if (confirm("현재 자료를 삭제하시겠습니까?")) {

//삭제 페이지로 이동. emp_id 전달.

var emp_id = document.getElementById("value");

window.location.href = "Employee_Delete.jsp?emp_id="+emp_id.value;

}

}


function deleteCancel() {

alert("삭제 대상을 검색해야 합니다.");

}

function msg() {

if (<%=deleteOK%>) {

alert("삭제가 완료되었습니다.");

}

}

</script>


</head>

<body onload="msg()">

<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="get" id="myForm">

사번

<input type="text" style="width:200px;"

name="value" id="value" value="<%=value%>">

[<a href="javascript:search()">검색</a>]

[<a href="javascript:<%=url%>">삭제</a>]

<span id="searchMsg" style="color:red;display:none;">사번을 채워야 합니다.</span>

</form>

<table style="width:900px;" class="style00">

<tbody>

<tr>

<th>사번</th>

<th>이름</th>

<th>주민번호</th>

<th>입사일</th>

<th>지역</th>

<th>전화번호</th>

<th>부서</th>

<th>직위</th>

<th>기본급</th>

<th>수당</th>

<th>급여</th>

</tr>

<%=str%>

</tbody>

</table>

</div>

</div>

</body>

</html>





//Employee_Delete.jsp

<%@ page language="java" contentType="text/html; charset=EUC-KR"

    pageEncoding="EUC-KR"%>

<%@ page import="com.test.*" %>    

<%

//emp_id 수신

//EmployeeDAO 객체 생성

//데이터 연결

//DELETE 쿼리 메소드 호출 -> remove()

String emp_id = request.getParameter("emp_id");

EmployeeDAO dao = new EmployeeDAO();

try {

dao.connect();

dao.remove(Integer.parseInt(emp_id));

}catch(Exception e){

System.out.println(e.toString());

}finally{

dao.close();

}


//삭제 작업이 모두 완료되면 삭제 폼 페이지로 이동

String url = String.format("Employee_DeleteForm.jsp?deleteOK=true");

response.sendRedirect(url);


%>




--------------------------------------------------------

//Employee_UpdateForm.jsp

<%@ page language="java" contentType="text/html; charset=EUC-KR"

    pageEncoding="EUC-KR"%>

<%@ page import="com.test.*" %>      

<%

String value = request.getParameter("value");

if (value == null) {

value = "";

}


EmployeeDAO dao = new EmployeeDAO();

String name = "";

String ssn = "";

String ibsadate = "";

String tel = "";

String basicpay = "";

String sudang = "";

int city_id = 0;

int buseo_id = 0;

int jikwi_id = 0;

StringBuilder cityLists = new StringBuilder();

StringBuilder buseoLists = new StringBuilder();

StringBuilder jikwiLists = new StringBuilder();

try {

dao.connect();

String wheres = String.format("WHERE emp_id='%s'", value);

String orders = "";

for (EmployeeDTO dto : dao.searchLists(wheres,orders)) {

name = dto.getName();

ssn = dto.getSsn();

ibsadate = dto.getIbsadate();

tel = dto.getTel();

basicpay = String.valueOf(dto.getBasicpay());

sudang = String.valueOf(dto.getSudang());

city_id = dto.getCity_id();

buseo_id = dto.getBuseo_id();

jikwi_id = dto.getJikwi_id();

}

for (EmployeeDTO dto : dao.cityList()) {

if (city_id == dto.getCity_id()) {

cityLists.append(String.format("<option value=\"%d\" selected=\"selected\">%s</option>", dto.getCity_id(), dto.getCity()));

} else {

cityLists.append(String.format("<option value=\"%d\">%s</option>", dto.getCity_id(), dto.getCity()));

}

}

for (EmployeeDTO dto : dao.buseoList()) {

if (buseo_id == dto.getBuseo_id()) {

buseoLists.append(String.format("<option value=\"%d\" selected=\"selected\">%s</option>", dto.getBuseo_id(), dto.getBuseo()));

} else {

buseoLists.append(String.format("<option value=\"%d\">%s</option>", dto.getBuseo_id(), dto.getBuseo()));

}

}

for (EmployeeDTO dto : dao.jikwiList()) {

if (jikwi_id == dto.getJikwi_id()) {

jikwiLists.append(String.format("<option value=\"%d\" selected=\"selected\">%s</option>", dto.getJikwi_id(), dto.getJikwi()));

} else {

jikwiLists.append(String.format("<option value=\"%d\">%s</option>", dto.getJikwi_id(), dto.getJikwi()));

}

}

}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 search() {

var myForm = document.getElementById("myForm");

//문제) 데이터 검사 과정 추가할 것.

var emp_id = document.getElementById("emp_id");

var searchValue = document.getElementById("value");

emp_id.value = searchValue.value;

//데이터 전송

myForm.submit();

}

//문제) 직위 변경시 최소 기본급 메시지 수정되는 부분 작성. Ajax.

</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="get" id="myForm">

사번

<input type="text" style="width:200px;"

name="value" id="value" value="<%=value%>">

[<a href="javascript:search()">검색</a>]

<span id="searchMsg" style="color:red;display:none;">사번을 채워야 합니다.</span>

</form>

<form action="Employee_Update.jsp" method="post" id="myForm">

<input type="hidden" id="emp_id" name="emp_id" value="">

<table>

<tr>

<td>이름</td>

<td><input type="text" id="name" name="name" value="<%=name%>"><span id="nameMsg" style="color:red; display:none;">이름를 채워야 합니다.</span></td>

</tr>

<tr>

<td>주민번호(YYMMDD-NNNNNNN)</td>

<td><input type="text" id="ssn" name="ssn" value="<%=ssn%>"><span id="ssnMsg" style="color:red; display:none;">주민번호를 채워야 합니다.</span></td>

</tr>

<tr>

<td>입사일(YYYY-MM-DD)</td>

<td><input type="text" id="ibsadate" name="ibsadate" value="<%=ibsadate%>"><span id="ibsadateMsg" style="color:red; display:none;">입사일을 채워야 합니다.</span></td>

</tr>

<tr>

<td>지역</td>

<td><select style="width:154px;" id="city_id" name="city_id"><%=cityLists%></select></td>

</tr>

<tr>

<td>전화번호</td>

<td><input type="text" id="tel" name="tel" value="<%=tel%>"><span id="telMsg" style="color:red; display:none;">전화번호를 채워야 합니다.</span></td>

</tr>

<tr>

<td>부서</td>

<td><select style="width:154px;" id="buseo_id" name="buseo_id"><%=buseoLists%></select></td>

</tr>

<tr>

<td>직위</td>

<td><select style="width:154px;" id="jikwi_id" name="jikwi_id" onchange="minBasicPayCheck(this)"><%=jikwiLists%></select></td>

</tr>

<tr>

<td>기본급(최소 <span id="minBasicPay">????</span> 이상)</td>

<td><input type="text" id="basicpay" name="basicpay" value="<%=basicpay%>"><span id="basicpayMsg" style="color:red; display:none;">기본급은 숫자로만 채워야 합니다.</span></td>

</tr>

<tr>

<td>수당</td>

<td><input type="text" id="sudang" name="sudang" value="<%=sudang%>"><span id="sudangMsg" style="color:red; display:none;">수당은 숫자로만 채워야 합니다.</span></td>

</tr>

</table>

[<a href="javascript:myFunc()">수정</a>]

</form>

</div>

</div>

</body>

</html>




//Employee_Update.jsp

<%@ page language="java" contentType="text/html; charset=EUC-KR"

    pageEncoding="EUC-KR"%>

<%

//한글 인코딩 처리

//데이터 수신

//emp_id, name, ...., sudang

//EmployeeDAO 객체 생성

//데이터베이스 연결]

//EmployeeDTO 객체 생성-> setter 호출

//UPDATE 쿼리 메소드 호출 -> dto 객체 전달

//수정 작업이 모두 끝나면 수정 폼 페이지로 이동


%>




--------------------------------------------------------



WRITTEN BY
빨강꼬마

,