<% Option Explicit %>
<HTML xmlns="http://www.w3.org/1999/xhtml">
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=gb2312" />
<META NAME="Keywords" CONTENT="" />
<META NAME="Description" CONTENT="" />
<TITLE>编辑会员</TITLE>
<link rel="stylesheet" href="../Images/CssAdmin.css">
<script language="javascript" src="../inc/Admin.js"></script>
</HEAD>
<!--#include file="../../Include/Const.asp" -->
<!--#include file="../../Include/Conn1.asp" -->
<!--#include file="../../Include/Md5.asp"-->
<!--#include file="../CheckAdmin.asp"-->

<BODY>
<% 
dim Result
Result=request.QueryString("Result")
dim ID,UserName,UserRealName,UserSex,UserTel,UserQQ,UserAddr,UserCompany,isEnable,UserPass,vUserPass,UserMail,Purview,UserRegtime,UserRemark
ID=request.QueryString("ID")
if ID="" then ID=0
call UserEdit() 
%>

<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#628AE1">
  <tr>
    <td height="24" nowrap><font color="#FFFFFF"><img src="../Images/Explain.gif" width="18" height="18" border="0" align="absmiddle">&nbsp;<strong>会员：添加，修改会员信息</strong></font></td>
  </tr>
  <tr>
    <td height="24" align="center" nowrap  bgcolor="#FFFFFF"><a href="UserEdit.asp?Result=Add" >添加会员</a><font color="#0000FF">&nbsp;|&nbsp;</font><a href="UserList.asp">查看所有会员</a></td>    
  </tr>
</table>
<br>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#628AE1">
  <form name="editForm" method="post" action="UserEdit.asp?Action=SaveEdit&Result=<%=Result%>&ID=<%=ID%>" onSubmit="return CheckAdminEdit()">
  <tr>
    <td height="24" nowrap bgcolor="#FFFFFF"><table width="100%" border="0" cellpadding="0" cellspacing="0" id=editProduct idth="100%">

      <tr>
        <td width="120" height="20" align="right">&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td height="22" align="right">登 录 名：</td>
        <td><input name="UserName" type="text" class="textfield" id="UserName" style="WIDTH: 120;" value="<%=UserName%>" maxlength="16" <%if Result="Modify" then response.write ("readonly")%>>&nbsp;*&nbsp;</td>
      </tr>
      <tr>
        <td height="22" align="right">生　　效：</td>
        <td><input name="isEnable" type="checkbox" style="HEIGHT: 13px;WIDTH: 13px;" value="1" <%if isEnable or isEnable="" then response.write ("checked")%>></td>
      </tr>
      <tr>
        <td height="22" align="right">密　　码：</td>
        <td><input name="UserPass" type="UserPass" class="textfield" id="UserPass" maxlength="20" style="WIDTH: 120;">
          &nbsp;*&nbsp;6-16位字符，不填表未修改密码</td>
      </tr>
      <tr>
        <td height="22" align="right">确认密码：</td>
        <td><input name="vUserPass" type="UserPass" class="textfield" id="vUserPass" maxlength="20" style="WIDTH: 120;">          &nbsp;*</td>
      </tr>
      <tr>
        <td height="22" align="right">&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td height="22" align="right">公司名称：</td>
        <td><input name="UserCompany" type="text" class=textfield id="UserCompany" value="<%=UserCompany%>" size="40"></td>
      </tr>
      <tr>
        <td height="22" align="right">联 系 人：</td>
        <td><input name="UserRealName" type="text" class=textfield id="UserRealName" value="<%=UserRealName%>" size="20"></td>
      </tr>
      <tr>
        <td height="22" align="right">性　　别：</td>
        <td><select name="UserSex" id="UserSex">
            <option value="">请选择</option>
            <option value="男" <%if UserSex="男" then response.write("selected")%>>男</option>
            <option value="女" <%if UserSex="女" then response.write("selected")%>>女</option>
        </select></td>
      </tr>
      <tr>
        <td height="22" align="right">电　　话：</td>
        <td><input name="UserTel" type="text" class=textfield id="UserTel" style="width:150px;" value="<%=UserTel%>" size="20"></td>
      </tr>
      <tr>
        <td height="22" align="right">Q 　　Q：</td>
        <td><input name="UserQQ" type="text" class=textfield id="UserQQ" value="<%=UserQQ%>" size="20"></td>
      </tr>
      <tr>
        <td height="22" align="right">电子邮箱：</td>
        <td><input name="UserMail" type="text" class="textfield" id="UserMail"  value="<%=UserMail%>" size="40">
*&nbsp;</td>
      </tr>
      <tr>
        <td height="22" align="right">详细地址：</td>
        <td><input name="UserAddr" type="text" class=textfield id="UserAddr" style="FONT-SIZE: 12px; WIDTH: 350px" value="<%=UserAddr%>" size="50"></td>
      </tr>
      <tr>
        <td height="22" align="right">备　　注：</td>
        <td><textarea name="UserRemark" cols="50" rows="3" class="textfield" id="UserRemark" style="FONT-SIZE: 12px; WIDTH: 350px"><%=UserRemark%></textarea></td>
      </tr>
      
      <tr>
        <td height="30" align="right">&nbsp;</td>
        <td valign="bottom"><input name="submitSaveEdit" type="submit" class="button"  id="submitSaveEdit" value="保存" style="WIDTH: 60;" ></td>
      </tr>
      <tr>
        <td height="20" align="right">&nbsp;</td>
        <td valign="bottom">&nbsp;</td>
      </tr>
    </table></td>
  </tr>
  </form>
</table>
</BODY>
</HTML>
<%
sub UserEdit()
  dim Action,rsCheckAdd,rs,sql
  Action=request.QueryString("Action")
  if Action="SaveEdit" then '保存编辑会员信息
    set rs = server.createobject("adodb.recordset")
    if Result="Add" then '创建网站会员
      set rsCheckAdd = conn.execute("select UserName from Angel_user where UserName='" & trim(Request.Form("UserName")) & "'")
      if not (rsCheckAdd.bof and rsCheckAdd.eof) then '判断此会员名是否存在
        response.write "<script language=javascript> alert('" & trim(Request.Form("UserName")) & "会员已经存在，请换一个登录名再试试！');history.back(-1);</script>"
        response.end
      end if  
	  sql="select * from Angel_user"
      rs.open sql,conn,1,3
      rs.addnew
      if len(trim(Request.Form("UserName")))<1 or len(trim(Request.Form("UserPass")))>10  then
        response.write "<script language=javascript> alert('会员登录名必填，且字符数为1-10位！');history.back(-1);</script>"
        response.end
      end if	  
      if len(trim(Request.Form("UserPass")))<6 or len(trim(Request.Form("UserPass")))>16  then
        response.write "<script language=javascript> alert('会员密码必填，且字符数为6-16位！');history.back(-1);</script>"
        response.end
      end if
	  if Request.Form("UserPass")<>Request.Form("vUserPass") then 
        response.write "<script language=javascript> alert('两次输入的密码不一样！');history.back(-1);</script>"
        response.end
	  end if
      rs("UserName")=trim(Request.Form("UserName"))
	  if Request.Form("isEnable")=1 then
        rs("isEnable")=Request.Form("isEnable")
	  else
        rs("isEnable")=0
	  end if
	  rs("UserPass")=Md5(Request.Form("UserPass"))
	  rs("UserMail")=trim(Request.Form("UserMail"))
	  rs("UserRegtime")=now()
	  
	  rs("UserCompany")=trim(Request.Form("UserCompany"))
	  rs("UserRealName")=trim(Request.Form("UserRealName"))
	  rs("UserSex")=trim(Request.Form("UserSex"))
	  rs("UserTel")=trim(Request.Form("UserTel"))
	  rs("UserQQ")=trim(Request.Form("UserQQ"))
	  rs("UserAddr")=trim(Request.Form("UserAddr"))
	  rs("UserRemark")=trim(Request.Form("UserRemark"))
	end if  
	if Result="Modify" then '修改网站会员
      sql="select * from Angel_user where ID="&ID
      rs.open sql,conn,1,3
      rs("UserName")=trim(Request.Form("UserName"))
	  if Request.Form("isEnable")=1 then
        rs("isEnable")=Request.Form("isEnable")
	  else
        rs("isEnable")=0
	  end if
      if trim(Request.Form("UserPass"))<>"" then
	    if len(trim(Request.Form("UserPass")))<6 or len(trim(Request.Form("UserPass")))>20  then
          response.write "<script language=javascript> alert('会员密码必填，且字符数为6-20位！');history.back(-1);</script>"
          response.end
        end if
	    if Request.Form("UserPass")<>Request.Form("vUserPass") then 
          response.write "<script language=javascript> alert('两次输入的密码不一样！');history.back(-1);</script>"
          response.end
	    end if
	    rs("UserPass")=Md5(Request.Form("UserPass"))
	  end if
	  rs("UserMail")=trim(Request.Form("UserMail"))
	  rs("UserCompany")=trim(Request.Form("UserCompany"))
	  rs("UserRealName")=trim(Request.Form("UserRealName"))
	  rs("UserSex")=trim(Request.Form("UserSex"))
	  rs("UserTel")=trim(Request.Form("UserTel"))
	  rs("UserQQ")=trim(Request.Form("UserQQ"))
	  rs("UserAddr")=trim(Request.Form("UserAddr"))
	  rs("UserRemark")=trim(Request.Form("UserRemark"))
	end if
	rs.update
	rs.close
    set rs=nothing 
    response.write "<script language=javascript> alert('成功编辑网站会员！');location.replace('UserList.asp');</script>"
  else '提取会员信息
	if Result="Modify" then
      set rs = server.createobject("adodb.recordset")
      sql="select * from Angel_user where ID="& ID
      rs.open sql,conn,1,1
	  UserName=rs("UserName")
	  isEnable=rs("isEnable")
	  
	  UserMail=rs("UserMail")
	  
	  UserCompany=rs("UserCompany")
	  UserRealName=rs("UserRealName")
	  UserSex=rs("UserSex")
	  UserTel=rs("UserTel")
	  UserQQ=rs("UserQQ")
	  UserAddr=rs("UserAddr")
	  UserRemark=rs("UserRemark")
	  rs.close
      set rs=nothing 
	end if
  end if
end sub
  
%>
