<% Option Explicit %>
<!--#include file="../../Inc/Cls_DB.asp" -->
<!--#include file="../../Inc/Md5.asp" -->
<!--#include file="../../Inc/Const.asp" -->
<%
Dim DBC,Conn
Set DBC = New DataBaseClass
Set Conn = DBC.OpenConnection()
Set DBC = Nothing
%>
<!--#include file="../../Inc/Session.asp" -->
<!--#include file="../../Inc/CheckPopedom.asp" -->
<%
if Not JudgePopedomTF(Session("Name"),"P0803") then Call ReturnError()
%>
<html>
<head>
<link href="../Inc/ModeWindow.css" rel="stylesheet" type="text/css">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>添加会员</title>
</head>

<body leftmargin="0" topmargin="0">
<form action="" method="post" name="UserAddSForm">
<table width="100%"  border="0" cellspacing="5" cellpadding="0">
  <tr>
    <td height="10" colspan="5"></td>
    </tr>
  <tr>
    <td width="6%">&nbsp;</td>
    <td width="17%">会 员 名</td>
    <td colspan="3"><input name="MemName" type="text" id="MemName" style="width:90%" value="<%=Request("MemName")%>"></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>密&nbsp;&nbsp;&nbsp;&nbsp;码</td>
    <td colspan="3"><input name="Password" type="password" id="Password" style="width:90%"></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>确认密码</td>
    <td colspan="3"><input name="PasswordTF" type="password" id="PasswordTF" style="width:90%"></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>会 员 组</td>
    <td colspan="3"><select name="GroupID" id="GroupID" style="width:90%">
	<option value="0" <%If Request("GroupID") = "" or  Request("GroupID") = "0" then Response.Write("selected") end if%>> </option>
	<%
		Dim SelGroupObj
		Set SelGroupObj = Conn.Execute("Select GroupID,Name from MemGroup order by PopLevel desc")
		do while not SelGroupObj.eof 
	%>
	<option value="<%=SelGroupObj("GroupID")%>" <%If Cstr(Request("GroupID"))=Cstr(SelGroupObj("GroupID")) then Response.Write("selected") end if%>><%=SelGroupObj("Name")%></option>
	<%
		SelGroupObj.MoveNext
		Loop
		SelGroupObj.Close
		Set SelGroupObj = Nothing
	%>
    </select></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>真实姓名</td>
    <td colspan="3"><input name="Name" type="text" id="Name" style="width:90%" value="<%=Request("Name")%>"></td>
  </tr>
  <tr valign="middle">
    <td>&nbsp;</td>
    <td>锁&nbsp;&nbsp;&nbsp;&nbsp;定</td>
    <td width="32%"><input type="radio" name="Lock" value="1" <%If Request("Lock") = "1" then Response.Write("checked") end if%>>
      是
        <input name="Lock" type="radio" value="0" <%If Request("Lock") = "0" or Request("Lock") = "" then Response.Write("checked") end if%>>
        否</td>
    <td width="9%">性别</td>
    <td width="36%"><input name="Sex" type="radio" value="0" <%If Request("Sex") = "0" or Request("Sex") = "" then Response.Write("checked") end if%>>男
      <input type="radio" name="Sex" value="1" <%If Request("Sex") = "1" then Response.Write("checked") end if%>>女</td>
  </tr>
  <tr>
    <td height="10" colspan="5"></td>
    </tr>
  <tr>
    <td colspan="5"><div align="center">
        <input type="submit" name="Submit" value=" 添 加 ">
        <input name="action" type="hidden" id="action" value="add">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <input type="button" name="Submit2" value=" 取 消 " onClick="window.close();">
    </div></td>
    </tr>
</table>
</form>
</body>
</html>
<%
If  Request.Form("action") = "add" then
    Dim UserAddObj,UserAddSql,ChooseMemNameObj,MemNameStr
	If Request.Form("MemName")="" or isnull(Request.Form("MemName")) then
		Response.Write("<script>alert(""请填写会员登录名"");</script>")
		Response.End
	Else
		MemNameStr = Replace(Replace(Request.Form("MemName"),"""",""),"'","")
	End If
	Set ChooseMemNameObj = Conn.Execute("Select ID from Members where MemName='"&MemNameStr&"'")
	If Not ChooseMemNameObj.eof then
		Response.Write("<script>alert(""此会员登录名已经存在,请修改"");</script>")
		Response.End
	End If
	ChooseMemNameObj.Close
	Set ChooseMemNameObj = Nothing
	If Request.Form("Password")="" or isnull("Password") then
		Response.Write("<script>alert(""请输入会员登录密码"");</script>")
		Response.End
	End If
	If Len(Request.Form("Password")) < 6 then
		Response.Write("<script>alert(""会员登录密码不能少于六位"");</script>")
		Response.End
	End If
	If Cstr(Request.Form("Password"))<>Cstr(Request.Form("PasswordTF")) then
		Response.Write("<script>alert(""密码与确认密码不同"");</script>")
		Response.End
	End If
	If Request.Form("Name")="" or isnull(Request.Form("Name")) then
		Response.Write("<script>alert(""请填写会员真实姓名"");</script>")
		Response.End
	End If
	Set UserAddObj = Server.CreateObject("Adodb.RecordSet")
		UserAddSql = "Select * from Members where 1=0"
		UserAddObj.Open UserAddSql,Conn,3,3
		UserAddObj.AddNew
		UserAddObj("MemName") = Replace(Replace(Request.Form("MemName"),"""",""),"'","")
		UserAddObj("Password") = md5(Request.Form("Password"),16)
		UserAddObj("GroupID") = Request.Form("GroupID")
		UserAddObj("Name") = Replace(Replace(Request.Form("Name"),"""",""),"'","")
		If Request.Form("Lock") = "0" then
			UserAddObj("Lock") = "0"
		Else
			UserAddObj("Lock") = "1"
		End If
		If Request.Form("Sex") = "0" then
			UserAddObj("Sex") = "0"
		Else
			UserAddObj("Sex") = "1"
		End If
		UserAddObj("RegTime") = Now()
		UserAddObj("LastLoginIP") = Request.ServerVariables("REMOTE_ADDR")
		UserAddObj("LastLoginTime") = Now()
		UserAddObj.Update
		UserAddObj.Close
		Set UserAddObj = Nothing
		Response.Write("<script>alert(""会员添加成功"");dialogArguments.location.reload();window.close();</script>")
		Response.End
End If
%>