<%@ page contentType="text/html; charset=gbk" language="java" %>
<%@ page import="mediastore.web.global.*"%>
<%@ page import="mediastore.web.form.*"%>
<%@ page import="java.util.*"%>
<%@ page import="java.text.*"%>

<script language="JavaScript">
//去掉空格
function Trim(str){
 if(str.charAt(0) == " "){
  str = str.slice(1);
  str = Trim(str); 
 }
 return str;
}

//判断是否是空
function isEmpty(pObj,errMsg){
 var obj = eval(pObj);
 if( obj == null || Trim(obj.value) == ""){
  if (errMsg == null || errMsg =="")
   alert("输入为空");
  else
   alert(errMsg); 
  obj.focus(); 
  return false;
 }
 return true;
}

//判断是否是整数
function isNumber(pObj,errMsg){
 var obj = eval(pObj);
 strRef = "1234567890";
 if(!isEmpty(pObj,errMsg))return false;
 for (i=0;i<obj.value.length;i++) {
  tempChar= obj.value.substring(i,i+1);
  if (strRef.indexOf(tempChar,0)==-1) {
   if (errMsg == null || errMsg =="")
    alert("数据不符合要求，请检查");
   else
    alert(errMsg);
   if(obj.type=="text") 
    obj.focus(); 
   return false; 
  }
 }
 return true;
}

//判断是否是小数
function isFloat(pObj,errMsg){
 var obj = eval(pObj);
 strRef = "1234567890.";
 if(!isEmpty(pObj,errMsg))return false;
 for (i=0;i<obj.value.length;i++) {
  tempChar= obj.value.substring(i,i+1);
  if (strRef.indexOf(tempChar,0)==-1) {
   if (errMsg == null || errMsg =="")
    alert("数据不符合要求，请检查");
   else
    alert(errMsg);
   if(obj.type=="text") 
    obj.focus(); 
   return false; 
  }
 }
 return true;
}

function searchMemberRec()
{
	if(isNumber(document.form2.memberid)==false)
	{
		document.form2.action = "memberManage.do";
		document.form2.submit();
	}
	else
	{
		document.form2.action = "memberManageSearchOne.do";
		document.form2.submit();
	}
}
function searchMemberAll()
{
	document.form2.action = "memberManage.do";
	document.form2.submit();
}
function addMemberRec()
{
	if(Trim(document.form1.membername.value)=='' || document.form1.membername.value==null)
	{
		if(confirm("确定要添加一个没有会员名称的会员吗？")) 
		{
			document.form1.action = "memberManageAddOne.do";
			document.form1.submit();
		}
	}
	else
	{
		document.form1.action = "memberManageAddOne.do";
		document.form1.submit();
	}
}
function deleteOneMember(memberid)
{
	if(confirm("确定要删除该会员吗？")) 
	{
		document.form2.memberid.value = memberid;
		document.form2.action = "memberManageDelOne.do";
		document.form2.submit();
	}
}

function updateDiscount(method, memberid)
{
	//alert(document.all.pointselect.value);
	var point = document.all.pointselect.value;
	document.form1.action = "memberManageAdjustDis.do?memberid="+memberid+"&point="+point+"&method="+method+"&";
	document.form1.submit();
}

function setDiscount()
{
	if(isFloat(document.form3.totalpay)==false)
	{
		document.form3.action = "memberManage.do";
		document.form3.submit();
	}
	else
	{
		document.form3.action = "memberManageSetDiscount.do";
		document.form3.submit();
	}
}

</script>


<table width="768" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr> 
    <td width="5" rowspan="4" class="trtable"></td>
    <td width="6" bgcolor="#214984" height="1"></td>
    <td rowspan="4" bgcolor="#214984" width="1" height="1"></td>
    <td bgcolor="#214984" class="10p" colspan="2" height="1"></td>
    <td rowspan="4" width="1" bgcolor="#214984" height="1"></td>
    <td bgcolor="#214984" width="5" height="1"></td>
    <td width="5" rowspan="4" class="trtable"></td>
  </tr>
  <tr> 
    <td width="6"></td>
    <td width="379" height="20" class="mainhead">会员管理</td>
    <td class="mainhead" width="379" height="20">&nbsp;</td>
    <td width="5"></td>
  </tr>
<tr> 
    <td width="6"></td>
    <td valign="top" colspan="2"> 
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
        
        <tr> 
          <td height="300" align="center" valign="top">   
          
<%
	MemberManageFB mmfb = (MemberManageFB)request.getAttribute(Globals.REQUEST_MEMBERMANAGE);
	List memberList = mmfb.getMemberList();
	String orderStr = mmfb.getOrderStr();
%>

    	<form name="form1" method="post" action="" >
    	<font color=#215385><b>添加会员</b></font>
    	<IMG src="images/line1.gif" border=0>
    	<br>
    	<input type="hidden" name="orderStr"  value="<%=orderStr%>">
    	<TABLE width="100%" border="1" cellpadding="3" cellspacing="0" bordercolor="#FFFFFF" class="mailtable"> 
	  <tr>
            <td  align="right" width=25%> 
                <b>会员名称:</b>
            </td>
            <td width=35%>
            	<INPUT class=none  name="membername" type="text" size="30" value="新会员" onKeyDown="if(event.keyCode==13) addMemberRec();">
            </td>
            <td width=35%>
            <input name=addmember type=button value="添加" onClick="addMemberRec()">
            </td>
          </tr>
	</TABLE>
	</form>
	

    	<form name="form3" method="post" action="" >
    	<font color=#215385><b>折扣设置</b></font>
    	<IMG src="images/line1.gif" border=0>
    	<br>
    	<input type="hidden" name="orderStr"  value="<%=orderStr%>">
    	<TABLE width="100%" border="1" cellpadding="3" cellspacing="0" bordercolor="#FFFFFF" class="mailtable"> 
	  <tr>
            <td align=center>
            	将“购物折前总值”大于
            	<INPUT class=none name="totalpay" type="text" size="10" onKeyDown="if(event.keyCode==13) setDiscount();">
            	元的会员的“<font color=red>折扣</font>”设置为
            	<SELECT size=1 name="discount1" >
            	<%
            		for(int i=0; i<10; i++)
            		{
            	%>
            		<option value='<%=i%>' ><%=i%></option>
		<%
			}
		%>
            	</SELECT>点
            	<SELECT size=1 name="discount2" >
            	<%
            		for(int i=0; i<10; i++)
            		{
            	%>
            		<option value='<%=i%>' ><%=i%></option>
		<%
			}
		%>
            	</SELECT>折
            	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            	<input name=setdiscount type=button value="设置" onClick="setDiscount()">
            </td>
          </tr>
	</TABLE>
	<br>
	</form>
	
    	<form name="form2" method="post" action="" >
    	<font color=#215385><b>查询会员</b></font>
    	<IMG src="images/line1.gif" border=0>
    	<br>
    	<input type="hidden" name="orderStr"  value="<%=orderStr%>">
    	<TABLE width="100%" border="1" cellpadding="3" cellspacing="0" bordercolor="#FFFFFF" class="mailtable"> 
	  <tr>
            <td  align="right" width=25%> 
                <b>会员标识:</b>
            </td>
            <td width=35%>
            	<INPUT class=none  name="memberid" type="text" size="30" onKeyDown="if(event.keyCode==13) searchMemberRec();">
            </td>
            <td width=35%>
            <input name=searchmember type=button value="查询" onClick="searchMemberRec()">
            &nbsp;&nbsp;&nbsp;&nbsp;
            <input name=searchall type=button value="查询所有会员" onClick="searchMemberAll()">
            </td>
          </tr>
	</TABLE>
	<br>
	</form>	
	
	<br>
<%
	NumberFormat nf = NumberFormat.getNumberInstance();
	nf.setMaximumFractionDigits(2);
%>
	<font color=#215385><b>会员列表</b></font>
	<IMG src="images/line1.gif" border=0>
	<TABLE width="100%" border="1" cellpadding="3" cellspacing="0" bordercolor="#FFFFFF" class="mailtable">  
		<tr bgcolor="#C2CEDC">
		<th>会员标识</th>
		<th>会员名称</th>
		<th>购物折前总值</th>
		<th>折扣</th>
		<th><SELECT name="pointselect">
			<option value="5">0.5</option>
			<option value="2">0.2</option>
			<option value="1">0.1</option>
			</SELECT>
		</th>
		<th>创建时间</th>
		<th>最近一次购物时间</th>
		<th>删除</th>
		</tr>
		
		<%
		int index = 0;
	      	mediastore.web.form.MemberInfo tmpMemberInfo = null;
	      	
	      	for (index=0; index<memberList.size(); index++)
		{
	      		tmpMemberInfo = (mediastore.web.form.MemberInfo)memberList.get(index);
	      	%>
	        <tr <%if((index%2)==1){%>bgcolor="#CAE4F4"<%}%> >
	        <td align=center><%= tmpMemberInfo.getMemberId() %></td>
	        <td align=center><%= tmpMemberInfo.getMemberName() %></td>
	        <td align=center><%= nf.format(tmpMemberInfo.getTotalPayment())%></td>
	        <td align=center><%= nf.format(tmpMemberInfo.getDiscount()*10)%></td>
		<td align=center><a href="javascript:updateDiscount('add','<%=tmpMemberInfo.getMemberId()%>') "><IMG src="images/up.gif" border=0 alt='提高折扣'></a><a href="javascript:updateDiscount('sub','<%=tmpMemberInfo.getMemberId()%>') "><IMG src="images/down.gif" border=0 alt='降低折扣'></a>
	        </td>
	        <td align=center>
	        <% 
	        	String tmpCreateTime = tmpMemberInfo.getCreateTime();
	        	if(tmpCreateTime==null)tmpCreateTime="";
	        	if(tmpCreateTime.length() >= 19)
	        	{
	        %>
	        		<%= tmpCreateTime.substring(0,19) %>
	        <%
	        	}
	        %>
	        </td>
	        <td align=center>
	        <% 
	        	String tmpRecentBuyTime = tmpMemberInfo.getRecentBuyTime();
	        	if(tmpRecentBuyTime==null)tmpRecentBuyTime="";
	        	if(tmpRecentBuyTime.length() >= 19)
	        	{
	        %>
	        		<%=tmpRecentBuyTime.substring(0,19)%>
	        <%
	        	}
	        %>
	        </td>
	        <td align=center>
	        	<a href="javascript:deleteOneMember('<%=tmpMemberInfo.getMemberId()%>') "><IMG src="images/delto.gif" border=0></a>
	        </td>
	        </tr>
	        <%
	
	      	}
	        %>
	</TABLE>

	<p><center>
	会员总数：<font color="red"><%=mmfb.getTotalMemberNum()%></font>

    	</center><p>
    	



	</td>
        </tr>
        <tr> 
          <td valign="middle" align="center">&nbsp;</td>
        </tr>

      </table>
      
    </td>
    <td width="5"></td>
  </tr>
  <tr> 
    <td width="6"></td>
    <td colspan="2" class="mainhead">&nbsp;</td>
    <td width="5"></td>
  </tr>
  <tr> 
    <td colspan="8" bgcolor="#214984" height="2"></td>
  </tr>
</table>

