
<%@ page contentType="text/html;charset=GB2312" %>
<jsp:useBean id="login" class="a1.Login" scope="session" >
</jsp:useBean>
<jsp:useBean id="book" class="a1.BuyBook" scope="session" >
</jsp:useBean>
<jsp:useBean id="orderform" class="a1.OrderForm" scope="page" >
</jsp:useBean>
<%! //处理字符串的方法：
  public String codeString(String s)
    { String str=s;
       try{byte b[]=str.getBytes("ISO-8859-1");
           str=new String(b);
           return str;
         }
      catch(Exception e)
         { return str;
         }
    }
%>
<HTML>
<BODY ><Font size=1>
<%@ include file="head.jsp" %>
<% //如果客户直接进入该页面将被转向登录页面。
   if(session.isNew())
    {response.sendRedirect("userLogin.jsp"); 
    }
   //如果没有成功登录将被转向登录页面
   String success=login.getSuccess();
         if(success==null)
         {success="";
         } 
   if(!(success.equals("ok")))
     {response.sendRedirect("userLogin.jsp"); 
     }
%>
<%String str=response.encodeURL("buybook.jsp");
%>
<FORM action="<%=str%>" Method="post" >
  <P>输入要订购的书的序列号:
  <Input type=text name="id">
  <Input type=submit name="g" value="提交">
</Form>
<jsp:setProperty  name= "book"  property="id"  param="id" />
 查询到如下记录：<BR>
<% StringBuffer b=book.getMessageBybook_id();
%>
<%=b%>
<P>如果准备订购该书，请填写订单，点击"添加到订单"按钮<BR>
 <%if((book.getId())!=0)
   {%> <FORM action="<%=str%>" method=post>
       <BR>您的用户名<Input TYPE=text name=logname value="<%=login.getLogname()%>" >*
       <BR>您的密码<Input TYPE=password name=password>*
       <BR>订购数量<Input TYPE=text name=mount value=1>(单位：册)
       <Input type=submit name="k" value="提交订单">
       </FORM>
   <%}
 %>
 <% if((book.getId())!=0)
     { String name=request.getParameter("logname");//获取在表单中提交的用户名。
        if(name==null)
           {name="";
           }
       name=codeString(name);
      String word=request.getParameter("password");//获取在表单中提交的密码。
        if(word==null)
           {word="";
           }
       word=codeString(word);
       String mount=request.getParameter("mount");//获取在表单中提交的密码。
       mount=codeString(mount);
       //判断提交的名字和密码是否正确：
       //如果正确就初始化orderform的值，并添加数据到订单。
       if((name.equals(login.getLogname()))&&(word.equals(login.getPassword())))
         {  
         %>
  <jsp:setProperty  name= "orderform"  property="logname" value="<%=login.getLogname()%>"/>
  <jsp:setProperty  name= "orderform"  property="realname" value="<%=login.getRealname()%>"/> 
        <jsp:setProperty  name= "orderform"  
                        property="order_number" value="<%=book.getOrder_number()%>"/> 
         <jsp:setProperty  name= "orderform" 
                        property="book_name" value="<%=book.getBook_name()%>"/> 
         <jsp:setProperty  name= "orderform"  property="mount" value="<%=mount%>"/>
         <jsp:setProperty  name= "orderform"  property="phone" value="<%=login.getPhone()%>"/> 
      <jsp:setProperty  name= "orderform"  property="address" value="<%=login.getAddress()%>"/>
         <% String ms=orderform.setOrderBook();
            out.print("<BR>"+ms);
         }
       else
        { out.print("<BR>"+"您必须输入正确的密码和用户名");
        }
     }
 %>
</Font>
</BODY>
</HTML>