<!--#include file="Inc/SysProduct.asp" -->
<!--#include file="inc/Skin_css.asp"-->
<%
UserName=session("UserName")			'登陆用户id
Receiver=request.form("Receiver")			'必填字段
Sex=request.form("Sex")			'
Phone=request.form("Phone")		'必填字段
Add=request.form("Add")	'必填字段
Notes=request.form("Notes")			
Email=request.form("Email")			
Subject=request.form("Subject")
CompanyName=request.form("CompanyName")			
Fax=request.form("Fax")		
if UserName="" then 
    UserName="游客" 
end if
if Add="" then
	Add=null
end if
if Fax="" then
	Fax=null
end if


'判断购物车是否为空
ProductList = Session("ProductList")
if productlist="" then
 response.redirect "error.asp?error=007"
 response.end
else
  sql_product="select * from Product where Product_Id in ("&productlist&") order by Product_Id"
  Set rs_order = conn.Execute(sql_product)
end if

BranchID="0022"
CoNo="000040"

'交易日期，格式：YYYYMMDD
yy=right(year(date),2)
mm=right("00"&month(date),2)
dd=right("00"&day(date),2)
riqi=yy & mm & dd

'生成订单号所有所需元素,格式为：小时，分钟，秒
xiaoshi=right("00"&hour(time),2)
fenzhong=right("00"&minute(time),2)
miao=right("00"&second(time),2)

'产生外部和内部定单号
BillNo=xiaoshi & fenzhong & miao
inBillNo=yy & mm & dd & "-" & xiaoshi & fenzhong & miao

Set rsadd=server.createobject("adodb.recordset")
rsadd.Open "select * from OrderList" ,conn,1,3
Set rsdetail=server.createobject("adodb.recordset")
rsdetail.Open "select * from OrderDetail" ,conn,1,3

'事务定义开始
'conn.Begintrans

'操作之一开始写入订单列表信息
rsadd.AddNew 
rsadd("UserName")=UserName
rsadd("OrderNum")=inBillNo
rsadd("Receiver")=Receiver
rsadd("Sex")=Sex
rsadd("Phone")=Phone
rsadd("Add")=Add
rsadd("RecTime")=now()
if Subject<>"" then rsadd("Subject")=Subject
if Email<>"" then rsadd("Email")=Email
if CompanyName<>"" then rsadd("CompanyName")=CompanyName
if Fax<>"" then rsadd("Fax")=Fax
if Notes<>"" then rsadd("Notes")=Notes
if error>0 then
	response.write " 操作订单列表生成错误！！"
    return
end if
rsadd("Flag")="No"
rsadd.Update


While Not rs_order.EOF '把购买的产品资料读出来，写入定单详细资料表中

 rsdetail.AddNew 
 rsdetail("UserName")=UserName		'下单用户号
 rsdetail("OrderNum")=inBillNo		'订单号码
 rsdetail("Product_Id")=rs_order("Product_Id")		'产品编码
 rsdetail("OrderTime")=Now()

 IF ERROR>0 THEN
	response.write "操作订单详细信息表生成错误！！"
	RETURN
 END if
 rsdetail.Update
 rs_order.MoveNext
Wend
'事务操作结束
'conn.CommitTrans

rsdetail.close
set rsdetail=nothing
rsadd.close
set rsadd=nothing
rs_order.close
set rs_order=nothing
Session("ProductList") =""
%>
<!-- #include file="Head.asp" -->
<TABLE class="xmtable" border=0 align="center" cellPadding=0 cellSpacing=12 bgcolor="#FFFFFF">
  <tr> 
    <td  height="450" valign="top" Class="tdbg_left">
    <!--left-->
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
              <tr> 
                <td height="10"><table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
                    <tr> 
                      <td> 
                        <% call ShowUserLogin() %>
                      </td>
                    </tr>
                  </table></td>
              </tr>
              <tr> 
                <td height="5"></td>
              </tr>
            </table>
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
              <tr> 
                <td height="34" class="title_left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;产品列表</td>
              </tr>
              <tr> 
                <td height="5"></td>
              </tr>
              <tr> 
                <td height="10"><table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
                    <tr> 
                      <td> 
                        <% call ShowSmallClass_Tree() %>
                      </td>
                    </tr>
                  </table></td>
              </tr>
              <tr> 
                <td height="5"></td>
              </tr>
            </table> 
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
              <tr> 
                <td height="34" class="title_left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;产品搜索</td>
              </tr>
              <tr> 
                <td height="5"></td>
              </tr>
              <tr> 
                <td height="10"><table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
                    <tr> 
                      <td> 
                        <% call ShowSearch(1) %>
                      </td>
                    </tr>
                  </table></td>
              </tr>
              <tr> 
                <td height="5"></td>
              </tr>
            </table>
          </td>
    <TD width=1 background=images/MainLine.gif></TD>  
    <td valign="top" bgcolor="#FFFFFF">
    <!--middle-->
      <table Class=border width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
              <tr> 
                <td height="206" valign="top">
                <TABLE cellSpacing=0 cellPadding=0 width="100%" 
                                border=0>
                    <TBODY>
                      <TR>
                        <TD width=98 class="title_c">在线询价</TD>
                        <TD width="555" class="title_right">　</TD>
                      </TR>
                    </TBODY>
                </TABLE>
                  <table border="0" cellspacing="1" cellpadding="0" align="center" valign=absmiddle width="90%" bgcolor="B0266D">
                    <tr bgcolor="eeeeee"> 
                      <td height="56" align="center"  bgcolor="eeeeee"><font color="B0266D">谢谢您，询价提交成功，请您记住您的询价号码，以便查询。</font></td>
                    </tr>
                    <tr bgcolor="#FFFFFF"> 
                      <td width="100%" align="center" valign="middle"><br>
                        感谢您咨询我们的产品!<b><br>
                        <br>
                        </b><font color="B0266D">您的询价号码是:</font><b><font color="B0266D"><b><%=inBillNo%></b><br>
                        <br>
                        </font> 
                        <br>
                        </b></td>
                    </tr>
                  </table> </td>
              </tr>
            </table>          
       </td>
    <TD width=1 background=images/MainLine.gif></TD>    
    <TD width="79" > </TD>
  </tr>
</table>
<!-- #include file="Inc/Foot.asp" -->
</BODY></HTML>
