<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!--#include file="../conn/conn.asp"-->
<!--#include file="../inc/Commoncode.asp"-->
<!--#include file="../inc/CommonFunction.asp"-->
<%SQLin
link="company_deptlist.asp"
%>
<!--#include file="checkcmember.asp" -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>部门管理-企业会员中心--<%=SiteTitle%></title>
<link href="../member/css.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="../js/input.js"></script>
<script language="JavaScript">
<!--
function fnRemoveBrank(strSource)
{
 return strSource.replace(/^\s*/,'').replace(/\s*$/,'');
}
function checkadd(theForm)
{
  if (fnRemoveBrank(theForm.name.value) == "")
  {
    alert("请输入部门名称!");
    theForm.name.focus();
    return (false);
  }
  if (fnRemoveBrank(theForm.principal.value) == "")
  {
    alert("请输入部门负责人!");
    theForm.principal.focus();
    return (false);
  }
  var objv = fnRemoveBrank(theForm.email.value);
  var pattern = /^([a-zA-Z0-9_-])+(\.([a-zA-Z0-9_-])+)*@([a-zA-Z0-9_-])+(\.([a-zA-Z0-9_-])+)+$/;
  flag = pattern.test(objv);
  if(!flag)
  {
    alert("电子邮件：格式不正确！请重新输入。");
	theForm.email.focus();
	return (false); 
  }  
 }
 function checkmodi(theForm)
{
  if (fnRemoveBrank(theForm.tempname.value) == "")
  {
    alert("请输入部门名称!");
    theForm.tempname.focus();
    return (false);
  }
  if (fnRemoveBrank(theForm.tempprincipal.value) == "")
  {
    alert("请输入部门负责人!");
    theForm.tempprincipal.focus();
    return (false);
  }
  var objv = fnRemoveBrank(theForm.tempemail.value);
  var pattern = /^([a-zA-Z0-9_-])+(\.([a-zA-Z0-9_-])+)*@([a-zA-Z0-9_-])+(\.([a-zA-Z0-9_-])+)+$/;
  flag = pattern.test(objv);
  if(!flag)
  {
    alert("电子邮件：格式不正确！请重新输入。");
	theForm.tempemail.focus();
	return (false); 
  }  
 }
 function checkdel(theForm)
{
 var j=0;
 var len=theForm.elements.length;
 for(var i=0;i<len;i++)
{
if (theForm.elements[i].name=="checks")
{ 
 if(theForm.elements[i].checked==true)
 {
  j=j+1;
  }
 }
 }
if(j==0)
{
 alert("请选择您需要删除的部门,再点击删除按钮!");
 return (false);
 }
}
 /**
*功能:表单及图层处理
*逻辑:点击修改时显示相关表单并赋值给表单
*参数：
*----tempid:流水号
*----tempname:部门名称
*----tempprincipal:部门负责人
*----tempemail:Email地址
*/
function initResetDept(tempid,tempname,tempprincipal,tempemail)
{
	modidept.tempid.value=tempid;
	modidept.tempname.value=tempname;
	modidept.tempprincipal.value=tempprincipal;
	modidept.tempemail.value=tempemail;
	ResetDeptDiv.style.display="";
}
-->
</script>
</head>
<body>
<div class="memmenul">
<div class="leftmenutit"><span>部门管理</span></div>
<%step=trim(request("step"))
Select Case step
	Case "Add"
		Call SaveAdd()
	Case "Modi"
		Call Savemodi()
	Case "Del"
		Call Del()
	Case Else
		Call main()
End Select
%>
</div>
<%CloseConn%>
<%Sub main()%>
<table width='98%' border='0' align='center' cellpadding='0' cellspacing='0' class="mtable">
<form action="company_deptlist.asp?step=Del" method="post" name="deldept" id="deldept" onsubmit="return checkdel(this)">
        <tr>
          <td width="18%" height="29" align="center"><strong>部门名称</strong></td>
          <td width="27%" align="center"><strong>负责人</strong></td>
          <td width="24%" align="center"><strong>E-mail</strong></td>
          <td width="22%" align="center"><strong>修改</strong></td>
          <td width="9%" align="center"><img height="12" src="../images/sel_ico.gif" width="13" /></td>
        </tr>
        <%
			  set rs=server.createobject("ADODB.Recordset")
              sql="select * from job_c_dept where dept_cmember='"&cmember_login&"'"
              rs.open sql,conn,1,1
			  if not rs.eof then 
			   for i=1 to rs.recordcount
			    if i mod 2 <>0 then
			     response.write "<TR class=runtr-w>"
				else
				 response.write "<TR class=runtr-y>"
				end if
				response.write "<TD width='18%' height=26 align=middle>"&rs("dept_name")&"</TD>"
			    response.write "<TD width='27%' align=middle>"&rs("dept_principal")&"</TD>"
				response.write "<TD width='24%' class=font-v11 align=middle><A href='mailto:"&rs("dept_email")&"'><U>"&rs("dept_email")&"</U></A></TD>"
			    response.write "<TD width='22%' align=middle><A style='CURSOR: hand' onclick=""initResetDept('"&rs("dept_id")&"','"&rs("dept_name")&"','"&rs("dept_principal")&"','"&rs("dept_email")&"');document.all('tempname').focus();""><U>修改</U></A></TD>"
			    response.write "<TD width='9%' align=middle><INPUT type='checkbox' value='"&rs("dept_id")&"' name='checks'></TD>"
			    response.write "</TR>"
			   rs.movenext
			   next
			  end if
			  rs.close
			  set rs=nothing
			  %>
			  <tr><td colspan="5" align="right" valign="middle"> <input name="Submit" type="button" class="inputs" value="新增部门" onclick="javascript:AddDeptDiv.style.display = ''" />
            &nbsp;&nbsp;
            <input name="Submit2" type="button" class="inputs" value="删除部门" onclick="document.deldept.submit();" /></td></tr>
       </form></table>
<table width="98%" border="0" cellspacing="0" cellpadding="0" class="mtable" align="center" id="AddDeptDiv" style="display:none">
<FORM name="adddept" action="company_deptlist.asp?step=Add" method="post" onSubmit="return checkadd(this)">
  <tr>
    <td class="tdcolor">新增部门资料</td>
  </tr>
  <tr>
    <td>部门名称：<INPUT name=name id="name" size=12 maxLength=25>
	负责人：<INPUT id=principal maxLength=25 size=8 name=principal> 
	E-mail：<INPUT id=email maxLength=100 size=16 name=email>
	<INPUT style="FONT-SIZE: 11px; FONT-FAMILY: Verdana" class="inputs" type=submit value=确定 name=Enter> 
    <INPUT style="FONT-SIZE: 11px; FONT-FAMILY: Verdana" class="inputs" onClick="javascript:AddDeptDiv.style.display = 'none'" type=reset value=取消 name=Cancel></td>
  </tr>
</FORM>
</table>

<table width="98%" border="0" cellspacing="0" cellpadding="0" class="mtable" align="center" id="ResetDeptDiv" style="display:none">
<FORM name="modidept" action="company_deptlist.asp?step=Modi" method=post onSubmit="return checkmodi(this)">
  <tr>
    <td class="tdcolor">修改部门资料</td>
  </tr>
  <INPUT type=hidden name=tempid>
  <tr>
    <td>部门名称：<INPUT maxLength=30 size=12 name=tempname>
	负责人：<INPUT maxLength=20 size=8 name=tempprincipal>
	E-mail：<INPUT maxLength=40 size=14 name=tempemail> <INPUT style="FONT-SIZE: 11px; FONT-FAMILY: Verdana" type=submit value=确定 name=Enter2 class="inputs"> 
            <INPUT style="FONT-SIZE: 11px; FONT-FAMILY: Verdana" onClick="javascript:ResetDeptDiv.style.display = 'none'" type=reset value=取消 name=Cancel2 class="inputs"></td>
  </tr>
</FORM>
</table>
<%End Sub%>
<%
Sub SaveAdd()
  dept_name=CheckStr(trim(request("name")))
  dept_principal=CheckStr(trim(request("principal")))
  dept_email=CheckStr(trim(request("email")))
  sql="select * from job_c_dept where dept_name='"&dept_name&"' and dept_cmember='"&cmember_login&"'"
  set rs=server.CreateObject("adodb.recordset") 
  rs.open sql,conn,1,3
'  response.Write(rs.recordcount)
  if rs.bof and rs.eof then
  rs.addnew
  rs("dept_name")=dept_name
  rs("dept_principal")=dept_principal
  rs("dept_email")=dept_email
  rs("dept_cmember")=cmember_login
  rs.update
  rs.close
  set rs=nothing
  else
  response.write "<script language=javascript>alert('错误：部门名称已存在！');location.href='javascript:history.back()';</script>"
  response.end 
  end if
response.redirect link
response.end
End Sub
Sub Savemodi()
  dept_id=CheckStr(trim(request("tempid")))
  dept_name=CheckStr(trim(request("tempname")))
  dept_principal=CheckStr(trim(request("tempprincipal")))
  dept_email=CheckStr(trim(request("tempemail")))
  sql="select * from job_c_dept where dept_id="&dept_id
  set rs=server.CreateObject("adodb.recordset")
  rs.open sql,conn,1,3
  rs("dept_name")=dept_name
  rs("dept_principal")=dept_principal
  rs("dept_email")=dept_email
  rs.update
  rs.close
  set rs=nothing
response.redirect link
response.end
End Sub
Sub Del()
  checks=trim(request("checks"))
  dept=split(checks,",")
  for i=0 to ubound(dept)
   dept_id=Chkint(trim(dept(i)))
   conn.execute("delete from job_c_dept where dept_id="&dept_id)
  next
response.redirect link
response.end
End Sub
%>