<!--#include file="Admin_Common.asp"-->
<!--#include file="../Include/PowerEasy.Bankroll.asp"-->
<!--#include file="../Include/PowerEasy.ConsumeLog.asp"-->
<!--#include file="../Include/PowerEasy.SendMail.asp"-->
<!--#include file="../Include/PowerEasy.SMS.asp"-->
<!--#include file="../Include/PowerEasy.Orders.asp"-->
<!--#include file="../Include/PowerEasy.Base64.asp"-->
<!--#include file="../Include/PowerEasy.MD5_New.asp"-->
<%
'**************************************************************
' Software name: PowerEasy SiteWeaver
' Web: http://www.powereasy.net
' Copyright (C) 2005－2008 佛山市动易网络科技有限公司 版权所有
'**************************************************************

Const NeedCheckComeUrl = True   '是否需要检查外部访问

Const PurviewLevel = 2      '0--不检查，1--超级管理员，2--普通管理员
Const PurviewLevel_Channel = 0   '0--不检查，1--频道管理员，2--栏目总编，3--栏目管理员
Const PurviewLevel_Others = ""   '其他权限

Dim arrOrderStatus, arrDeliverStatus
Dim OrderStatus, PayStatus, DeliverStatus
Dim sqlOrder, sqlMoney, sqlMoney2, strResultTips, IsSameUserName, ResultType, IsAgent

'检查管理员操作权限
If AdminPurview > 1 Then
    arrPurview(0) = CheckPurview_Other(AdminPurview_Others, "Order_View")
    arrPurview(1) = CheckPurview_Other(AdminPurview_Others, "Order_Confirm")
    arrPurview(2) = CheckPurview_Other(AdminPurview_Others, "Order_Modify")
    arrPurview(3) = CheckPurview_Other(AdminPurview_Others, "Order_Del")
    arrPurview(4) = CheckPurview_Other(AdminPurview_Others, "Order_Payment")
    arrPurview(5) = CheckPurview_Other(AdminPurview_Others, "Order_Invoice")
    arrPurview(6) = CheckPurview_Other(AdminPurview_Others, "Order_Deliver")
    arrPurview(7) = CheckPurview_Other(AdminPurview_Others, "Order_Download")
    arrPurview(8) = CheckPurview_Other(AdminPurview_Others, "Order_SendCard")
    arrPurview(9) = CheckPurview_Other(AdminPurview_Others, "Order_End")
    arrPurview(10) = CheckPurview_Other(AdminPurview_Others, "Order_Transfer")
    arrPurview(11) = CheckPurview_Other(AdminPurview_Others, "Order_Print")
    arrPurview(12) = CheckPurview_Other(AdminPurview_Others, "Order_Count")
    arrPurview(13) = CheckPurview_Other(AdminPurview_Others, "Order_Refund")
    arrPurview(14) = CheckPurview_Other(AdminPurview_Others, "AddPayment")
    arrPurview(15) = CheckPurview_Other(AdminPurview_Others, "AgentPayment")
    For PurviewIndex = 0 To 15
        If arrPurview(PurviewIndex) = True Then
            PurviewPassed = True
            Exit For
        End If
    Next
    If PurviewPassed = False Then
        Response.Write "<br><p align='center'><font color='red' style='font-size:9pt'>对不起，你没有此项操作的权限。</font></p>"
        Call WriteEntry(6, AdminName, "越权操作")
        Response.End
    End If
End If

IsSameUserName = PE_CLng(Trim(Request("IsSameUserName")))
OrderStatus = PE_CLng(Trim(Request("OrderStatus")))
PayStatus = PE_CLng(Trim(Request("PayStatus")))
DeliverStatus = PE_CLng(Trim(Request("DeliverStatus")))

If IsSameUserName = 0 Then
    IsSameUserName = 1
End If

strFileName = "Admin_Order.asp?SearchType=" & SearchType & "&Field=" & strField & "&Keyword=" & Keyword

arrOrderStatus = Array("<font color='red'>等待确认</font>", "<font color='red'>等待确认</font>", "<font color='blue'>已经确认</font>", "<font color='blue'>已经确认</font>", "<font color='gray'>已结清</font>")
arrDeliverStatus = Array("<font color='red'>配送中</font>", "<font color='red'>配送中</font>", "<font color='blue'>已发货</font>", "<font color='green'>已签收</font>")

Select Case Action
Case "ShowOrder"
    Call outhead
    Call ShowOrder
Case "PrintOrder"
    Call outhead3
    Call ShowOrder
Case "ConfirmOrder"
    Call outhead
    Call ConfirmOrder
Case "CancelConfirm"
    Call outhead
    Call CancelConfirm
Case "ModifyOrder"
    Call outhead
    Call ModifyOrder
Case "SaveModifyOrder"
    Call outhead
    Call SaveModifyOrder
Case "DelOrder"
    Call outhead
    Call DelOrder
Case "RemitAndPay"
    Call outhead
    Call RemitAndPay
Case "DoRemitAndPay"
    Call outhead
    Call DoRemitAndPay
Case "AgentPayment"
    Call outhead
    Call AgentPayment
Case "SendGoods", "ReturnGoods"
    Call outhead
    Call Deliver
Case "SaveSend", "SaveReturn"
    Call outhead
    Call SaveDeliver
Case "Invoice"
    Call outhead
    Call Invoice
Case "SaveInvoice"
    Call outhead
    Call SaveInvoice
Case "EndOrder"
    Call outhead
    Call EndOrder
Case "Transfer"
    Call outhead
    Call Transfer
Case "SaveTransfer"
    Call outhead
    Call SaveTransfer
Case "Received"
    Call outhead
    Call Received
Case "Refund"
    Call outhead
    Call Refund
Case "DoRefund"
    Call outhead
    Call DoRefund
Case "EnableDownload", "CancelDownload"
    Call outhead
    Call EnableDownload
Case "SendCard"
    Call outhead
    Call SendCard
Case "outExcel"
    Call GetSqlStr
    Call outHead2
    Call outExcel
Case "ShowSearchForm"
    Call outhead
    Call ShowSearchForm
Case Else
    Call GetSqlStr
    Call outhead
    Call main
End Select
If FoundErr = True Then
    Call WriteErrMsg(ErrMsg, ComeUrl)
End If
Response.Write "</body></html>"
Call CloseConn


Sub GetSqlStr()
    If Action = "outExcel" Then
        If (SearchType = 10 And Keyword <> "" And strField = "ProductName") Or (SearchType = 99 And Trim(Request("ProductName")) <> "") Then
            If IsSameUserName = 1 Then
                sqlOrder = "select  O.OrderFormID,O.OrderFormNum,O.InputTime,O.UserName,O.ClientID,C.ClientName,O.MoneyTotal,O.MoneyReceipt,O.NeedInvoice,O.Invoiced,O.InvoiceContent,O.Status,O.DeliverStatus,O.ContacterName,O.Phone,O.Address,O.ZipCode,O.Email,O.Mobile,O.AgentName,O.BeginDate,O.PaymentType,O.DeliverType,O.Remark from PE_Product P inner join (Pe_OrderFormItem I inner join (PE_OrderForm O left join PE_Client C On O.ClientID = C.ClientID) on I.OrderFormID = O.OrderFormID) on P.ProductID = I.ProductID"
            Else
                sqlOrder = "select  O.OrderFormID,O.OrderFormNum,O.InputTime,T.UserName,O.ClientID,C.ClientName,O.MoneyTotal,O.MoneyReceipt,O.NeedInvoice,O.Invoiced,O.InvoiceContent,O.Status,O.DeliverStatus,O.ContacterName,O.Phone,O.Address,O.ZipCode,O.Email,O.Mobile,O.AgentName,O.BeginDate,O.PaymentType,O.DeliverType,O.Remark from PE_Product P inner join (Pe_OrderFormItem I inner join ((select * from PE_OrderForm K inner join (select UserName,max(InputTime) as BDate from PE_Orderform group by UserName) T on K.UserName=T.UserName and K.InputTime=T.BDate) O left join PE_Client C On O.ClientID = C.ClientID) on I.OrderFormID = O.OrderFormID) on P.ProductID = I.ProductID"
            End If
        Else
            If IsSameUserName = 1 Then
                sqlOrder = "select O.OrderFormID,O.OrderFormNum,O.InputTime,O.UserName,O.ClientID,C.ClientName,O.MoneyTotal,O.MoneyReceipt,O.NeedInvoice,O.Invoiced,O.InvoiceContent,O.Status,O.DeliverStatus,O.ContacterName,O.Phone,O.Address,O.ZipCode,O.Email,O.Mobile,O.AgentName,O.BeginDate,O.PaymentType,O.DeliverType,O.Remark from PE_OrderForm O left join PE_Client C on O.ClientID=C.ClientID"
            Else
                sqlOrder = "select O.OrderFormID,O.OrderFormNum,K.InputTime,O.UserName,O.ClientID,C.ClientName,O.MoneyTotal,O.MoneyReceipt,O.NeedInvoice,O.Invoiced,O.InvoiceContent,O.Status,O.DeliverStatus,O.ContacterName,O.Phone,O.Address,O.ZipCode,O.Email,O.Mobile,O.AgentName,O.BeginDate,O.PaymentType,O.DeliverType,O.Remark from  (select * from PE_OrderForm O inner join (select UserName,max(InputTime) as BDate from PE_Orderform group by UserName) T on O.UserName=T.UserName and O.InputTime=T.BDate) K left join PE_Client C on K.ClientID=C.ClientID"
            End If
        End If
    Else
        If (SearchType = 10 And strField = "ProductName") Or (SearchType = 99 And Trim(Request("ProductName")) <> "") Then
            If IsSameUserName = 1 Then
                sqlOrder = "select  O.OrderFormID,O.OrderFormNum,O.ContacterName,O.Phone,O.Address,O.ZipCode,O.Email,O.Mobile,O.InputTime,O.UserName,O.ClientID,C.ShortedForm as ClientName,O.AgentName,O.MoneyTotal,O.MoneyReceipt,O.Remark,O.NeedInvoice,O.Invoiced,O.Status,O.DeliverStatus from PE_Product P inner join (Pe_OrderFormItem I inner join (PE_OrderForm O left join PE_Client C On O.ClientID = C.ClientID) on I.OrderFormID = O.OrderFormID) on P.ProductID = I.ProductID"
            Else
                sqlOrder = "select  O.OrderFormID,O.OrderFormNum,O.ContacterName,O.Phone,O.Address,O.ZipCode,O.Email,O.Mobile,O.InputTime,T.UserName,O.ClientID,C.ShortedForm as ClientName,O.AgentName,O.MoneyTotal,O.MoneyReceipt,O.Remark,O.NeedInvoice,O.Invoiced,O.Status,O.DeliverStatus from PE_Product P inner join (Pe_OrderFormItem I inner join ((select * from PE_OrderForm K inner join (select UserName,max(InputTime) as BDate from PE_Orderform group by UserName) T on K.UserName=T.UserName and K.InputTime=T.BDate) O left join PE_Client C On O.ClientID = C.ClientID) on I.OrderFormID = O.OrderFormID) on P.ProductID = I.ProductID"
            End If
        Else
            If IsSameUserName = 1 Then
                sqlOrder = "select O.OrderFormID,O.OrderFormNum,O.InputTime,O.UserName,O.AgentName,O.ClientID,C.ShortedForm as ClientName,O.MoneyTotal,O.MoneyReceipt,O.Remark,O.ContacterName,O.Phone,O.Address,O.ZipCode,O.Email,O.Mobile,O.NeedInvoice,O.Invoiced,O.Status,O.DeliverStatus from PE_OrderForm O left join PE_Client C on O.ClientID=C.ClientID "
            Else
                sqlOrder = "select O.OrderFormID,O.OrderFormNum,O.InputTime,O.UserName,O.AgentName,O.ClientID,O.MoneyTotal,O.MoneyReceipt,O.Remark,O.NeedInvoice,O.Invoiced,O.ContacterName,O.Phone,O.Address,O.ZipCode,O.Email,O.Mobile,O.Status,O.DeliverStatus,C.ShortedForm as ClientName from (select K.* from PE_OrderForm K inner join (select UserName,max(InputTime) as BDate from PE_Orderform group by UserName) T on K.UserName=T.UserName and K.InputTime=T.BDate) O left join PE_Client C on O.ClientID=C.ClientID"
            End If
        End If
    End If

    Select Case SearchType
    Case 0
        sqlOrder = sqlOrder & " order by O.OrderFormID desc"
        sqlMoney = "select sum(MoneyTotal) from PE_OrderForm"
        sqlMoney2 = "select sum(MoneyReceipt) from PE_OrderForm"
        strResultTips = "所有订单"
    Case 1
        sqlOrder = sqlOrder & " where datediff(" & PE_DatePart_D & ",O.InputTime," & PE_Now & ")<1 order by O.OrderFormID desc"
        sqlMoney = "select sum(MoneyTotal) from PE_OrderForm where datediff(" & PE_DatePart_D & ",InputTime," & PE_Now & ")<1"
        sqlMoney2 = "select sum(MoneyReceipt) from PE_OrderForm where datediff(" & PE_DatePart_D & ",InputTime," & PE_Now & ")<1"
        strResultTips = "今天的新订单"
    Case 2
        sqlOrder = sqlOrder & " where datediff(" & PE_DatePart_D & ",O.InputTime," & PE_Now & ")<10 order by O.OrderFormID desc"
        sqlMoney = "select sum(MoneyTotal) from PE_OrderForm where datediff(" & PE_DatePart_D & ",InputTime," & PE_Now & ")<10"
        sqlMoney2 = "select sum(MoneyReceipt) from PE_OrderForm where datediff(" & PE_DatePart_D & ",InputTime," & PE_Now & ")<10"
        strResultTips = "最近10天内的新订单"
    Case 3
        sqlOrder = sqlOrder & " where datediff(" & PE_DatePart_M & ",O.InputTime," & PE_Now & ")<1 order by OrderFormID desc"
        sqlMoney = "select sum(MoneyTotal) from PE_OrderForm where datediff(" & PE_DatePart_M & ",InputTime," & PE_Now & ")<1"
        sqlMoney2 = "select sum(MoneyReceipt) from PE_OrderForm where datediff(" & PE_DatePart_M & ",InputTime," & PE_Now & ")<1"
        strResultTips = "最近一月内的新订单"
    Case 4
        sqlOrder = sqlOrder & " where O.Status=1 order by OrderFormID desc"
        sqlMoney = "select sum(MoneyTotal) from PE_OrderForm where Status=1"
        sqlMoney2 = "select sum(MoneyReceipt) from PE_OrderForm where Status=1"
        strResultTips = "未确认的订单"
    Case 5
        sqlOrder = sqlOrder & " where O.MoneyTotal>0 and O.MoneyReceipt=0 order by OrderFormID desc"
        sqlMoney = "select sum(MoneyTotal) from PE_OrderForm where MoneyTotal>0 and MoneyReceipt=0"
        sqlMoney2 = "select sum(MoneyReceipt) from PE_OrderForm where MoneyTotal>0 and MoneyReceipt=0"
        strResultTips = "未付款的订单"
    Case 6
        sqlOrder = sqlOrder & " where O.MoneyTotal>O.MoneyReceipt order by OrderFormID desc"
        sqlMoney = "select sum(MoneyTotal) from PE_OrderForm where MoneyTotal>MoneyReceipt"
        sqlMoney2 = "select sum(MoneyReceipt) from PE_OrderForm where MoneyTotal>MoneyReceipt"
        strResultTips = "未付清的订单"
    Case 7
        sqlOrder = sqlOrder & " where O.MoneyTotal<=O.MoneyReceipt and O.DeliverStatus<=1 order by OrderFormID desc"
        sqlMoney = "select sum(MoneyTotal) from PE_OrderForm where MoneyTotal<=MoneyReceipt and DeliverStatus<=1"
        sqlMoney2 = "select sum(MoneyReceipt) from PE_OrderForm where MoneyTotal<=MoneyReceipt and DeliverStatus<=1"
        strResultTips = "未送货的订单"
    Case 8
        sqlOrder = sqlOrder & " where O.MoneyTotal<=O.MoneyReceipt and O.DeliverStatus=2 order by OrderFormID desc"
        sqlMoney = "select sum(MoneyTotal) from PE_OrderForm where MoneyTotal<=MoneyReceipt and DeliverStatus=2"
        sqlMoney2 = "select sum(MoneyReceipt) from PE_OrderForm where MoneyTotal<=MoneyReceipt and DeliverStatus=2"
        strResultTips = "未签收的订单"
    Case 9
        sqlOrder = sqlOrder & " where O.NeedInvoice=" & PE_True & " and O.Invoiced=" & PE_False & " order by OrderFormID desc"
        sqlMoney = "select sum(MoneyTotal) from PE_OrderForm where NeedInvoice=" & PE_True & " and Invoiced=" & PE_False & ""
        sqlMoney2 = "select sum(MoneyReceipt) from PE_OrderForm where NeedInvoice=" & PE_True & " and Invoiced=" & PE_False & ""
        strResultTips = "未开发票的订单"
    Case 11
        sqlOrder = sqlOrder & " where O.MoneyTotal<=O.MoneyReceipt and O.DeliverStatus=3 and O.Status>1 and O.Status<4 order by OrderFormID desc"
        sqlMoney = "select sum(MoneyTotal) from PE_OrderForm where MoneyTotal<=MoneyReceipt and DeliverStatus=3 and Status>1 and Status<4"
        sqlMoney2 = "select sum(MoneyReceipt) from PE_OrderForm where MoneyTotal<=MoneyReceipt and DeliverStatus=2 and Status>1 and Status<4"
        strResultTips = "未结清的订单"
    Case 12
        sqlOrder = sqlOrder & " where O.Status=4 order by OrderFormID desc"
        sqlMoney = "select sum(MoneyTotal) from PE_OrderForm where Status=4"
        sqlMoney2 = "select sum(MoneyReceipt) from PE_OrderForm where Status=4"
        strResultTips = "已结清的订单"
    Case 13
        sqlOrder = sqlOrder & " where O.DeliverStatus = 2 order by OrderFormID desc"
        sqlMoney = "select sum(MoneyTotal) from PE_OrderForm where DeliverStatus = 2"
        sqlMoney2 = "select sum(MoneyReceipt) from PE_OrderForm where DeliverStatus = 2"
        strResultTips = "已发货的订单"
    Case 14
        sqlOrder = sqlOrder & " where O.DeliverStatus = 3 order by OrderFormID desc"
        sqlMoney = "select sum(MoneyTotal) from PE_OrderForm where DeliverStatus = 3"
        sqlMoney2 = "select sum(MoneyReceipt) from PE_OrderForm where DeliverStatus = 3"
        strResultTips = "已签收的订单"
    Case 10
        If Keyword = "" Then
            sqlOrder = sqlOrder & " order by O.OrderFormID desc"
            sqlMoney = "select sum(MoneyTotal) from PE_OrderForm"
            sqlMoney2 = "select sum(MoneyReceipt) from PE_OrderForm"
            strResultTips = "所有订单"
        Else
            Select Case strField
            Case "OrderFormNum"
                sqlOrder = sqlOrder & " where O.OrderFormNum like '%" & Keyword & "%' order by O.OrderFormID desc"
                sqlMoney = "select sum(MoneyTotal) from PE_OrderForm where OrderFormNum like '%" & Keyword & "%'"
                sqlMoney2 = "select sum(MoneyReceipt) from PE_OrderForm where OrderFormNum like '%" & Keyword & "%'"
                strResultTips = "订单编号中含有“ <font color=red> " & Keyword & " </font> ”的订单"
            Case "ClientName"
                sqlOrder = sqlOrder & " where C.ClientName like '%" & Keyword & "%' order by O.OrderFormID desc"
                strResultTips = "客户名称中含有“ <font color=red>" & Keyword & "</font> ”的订单"
            Case "UserName"
                sqlOrder = sqlOrder & " where O.UserName like '%" & Keyword & "%' order by O.OrderFormID desc"
                strResultTips = "用户名中含有“ <font color=red>" & Keyword & "</font> ”的订单"
            Case "AgentName"
                sqlOrder = sqlOrder & " where O.AgentName='" & Keyword & "' order by O.OrderFormID desc"
                strResultTips = "“ <font color=red>" & Keyword & "</font> ”代理的订单"
            Case "ContacterName"
                sqlOrder = sqlOrder & " where O.ContacterName like '%" & Keyword & "%' order by O.OrderFormID desc"
                strResultTips = "收货人姓名中含有“ <font color=red>" & Keyword & "</font> ”的订单"
            Case "Address"
                sqlOrder = sqlOrder & " where O.Address like '%" & Keyword & "%' order by O.OrderFormID desc"
                strResultTips = "联系地址中含有“ <font color=red>" & Keyword & "</font> ”的订单"
            Case "Phone"
                sqlOrder = sqlOrder & " where O.Phone like '%" & Keyword & "%' order by O.OrderFormID desc"
                strResultTips = "联系电话中含有“ <font color=red>" & Keyword & "</font> ”的订单"
            Case "DateAndTime"
                If IsDate(Keyword) = True Then
                    sqlOrder = sqlOrder & " where DateDiff(" & PE_DatePart_D & ",O.InputTime,'" & Keyword & "')=0 order by O.OrderFormID desc"
                    strResultTips = "<font color=red>" & Year(Keyword) & "-" & Month(Keyword) & "-" & Day(Keyword) & "</font> 下单的订单"
                Else
                    FoundErr = True
                    ErrMsg = ErrMsg & "<li>查询的下单时间格式不正确！</li>"
                End If
            Case "Remark"
                sqlOrder = sqlOrder & " where O.Remark like '%" & Keyword & "%' order by O.OrderFormID desc"
                strResultTips = "备注/留言中含有“ <font color=red>" & Keyword & "</font> ”的订单"
            Case "InvoiceContent"
                sqlOrder = sqlOrder & " where O.InvoiceContent like '%" & Keyword & "%' order by O.OrderFormID desc"
                strResultTips = "发票信息含有“ <font color=red>" & Keyword & "</font> ”的订单"
            Case "ProductName"
                sqlOrder = sqlOrder & " where P.ProductName like '%" & Keyword & "%' order by O.OrderFormID desc"
                strResultTips = "订单的商品名称中含有“ <font color=red>" & Keyword & "</font> ”的订单"
            Case "QQ"
                If Action = "outExcel" Then
                    sqlOrder = "select  O.OrderFormID,O.OrderFormNum,O.InputTime,O.UserName,O.ClientID,C.ClientName,O.MoneyTotal,O.MoneyReceipt,O.Remark,O.NeedInvoice,O.Invoiced,O.InvoiceContent,O.Status,O.DeliverStatus,O.ContacterName,O.Phone,O.Address,O.ZipCode,O.Email,O.Mobile,O.AgentName,O.BeginDate,O.PaymentType,O.DeliverType,O.Remark from PE_Contacter T inner join (PE_User U inner join (PE_OrderForm O left join PE_Client C On C.ClientID = O.ClientID) on U.UserName = O.UserName) on T.ClientID = U.ClientID where T.QQ = '" & Keyword & "' order by O.OrderFormID desc"
                Else
                    sqlOrder = "select  O.OrderFormID,O.OrderFormNum,O.InputTime,O.UserName,O.ClientID,C.ShortedForm as ClientName,O.MoneyTotal,O.MoneyReceipt,O.Remark,O.NeedInvoice,O.Invoiced,O.Status,O.DeliverStatus from PE_Contacter T inner join (PE_User U inner join (PE_OrderForm O left join PE_Client C On C.ClientID = O.ClientID) on U.UserName = O.UserName) on T.ClientID = U.ClientID where T.QQ = '" & Keyword & "' order by O.OrderFormID desc"
                End If
                strResultTips = "用户的QQ为“ <font color=red>" & Keyword & "</font> ”的订单"
            End Select
        End If
    Case 99
        strResultTips = "订单复杂查询结果"
        Dim BeginID, EndID, BeginDate, EndDate, MinMoney, MaxMoney, OrderFormNum, ClientName, UserName, AgentName, ContacterName, Address, Phone, Mobile, Remark, ProductName
        BeginID = PE_CLng(Trim(Request("BeginID")))
        EndID = PE_CLng(Trim(Request("EndID")))
        BeginDate = Trim(Request("BeginDate"))
        EndDate = Trim(Request("EndDate"))
        MinMoney = PE_CDbl(Trim(Request("MinMoney")))
        MaxMoney = PE_CDbl(Trim(Request("MaxMoney")))

        OrderFormNum = ReplaceBadChar(Trim(Request("OrderFormNum")))
        ClientName = ReplaceBadChar(Trim(Request("ClientName")))
        UserName = ReplaceBadChar(Trim(Request("UserName")))
        AgentName = ReplaceBadChar(Trim(Request("AgentName")))
        ContacterName = ReplaceBadChar(Trim(Request("ContacterName")))
        Address = ReplaceBadChar(Trim(Request("Address")))
        Phone = ReplaceBadChar(Trim(Request("Phone")))
        Mobile = ReplaceBadChar(Trim(Request("Mobile")))
        Remark = ReplaceBadChar(Trim(Request("Remark")))
        ProductName = ReplaceBadChar(Trim(Request("ProductName")))
        IsAgent = PE_CLng(Trim(Request("IsAgent")))
        ResultType = PE_CLng(Trim(Request("ResultType")))

        strFileName = "Admin_Order.asp?SearchType=99&BeginID=" & BeginID & "&EndID=" & EndID & "&BeginDate=" & BeginDate & "&EndDate=" & EndDate & "&MinMoney=" & MinMoney & "&MaxMoney=" & MaxMoney
        strFileName = strFileName & "&OrderStatus=" & OrderStatus & "&PayStatus=" & PayStatus & "&DeliverStatus=" & DeliverStatus & "&OrderFormNum=" & OrderFormNum & "&ClientName=" & ClientName
        strFileName = strFileName & "&UserName=" & UserName & "&AgentName=" & AgentName & "&ContacterName=" & ContacterName & "&Address=" & Address & "&Phone=" & Phone
        strFileName = strFileName & "&Mobile=" & Mobile & "&Remark=" & Remark & "&ProductName=" & ProductName

        sqlOrder = sqlOrder & " where 1=1"
        If BeginID > 0 Then
            sqlOrder = sqlOrder & " And O.OrderFormID>=" & BeginID
        End If
        If EndID > 0 Then
            sqlOrder = sqlOrder & " And O.OrderFormID<=" & EndID
        End If

        If BeginDate <> "" Then
            BeginDate = PE_CDate(BeginDate)
            If SystemDatabaseType = "SQL" Then
                sqlOrder = sqlOrder & " And O.InputTime>='" & BeginDate & "'"
            Else
                sqlOrder = sqlOrder & " And O.InputTime>=#" & BeginDate & "#"
            End If
        End If
        If EndDate <> "" Then
            EndDate = PE_CDate(EndDate)
            If SystemDatabaseType = "SQL" Then
                sqlOrder = sqlOrder & " And O.InputTime<='" & EndDate & "'"
            Else
                sqlOrder = sqlOrder & " And O.InputTime<=#" & EndDate & "#"
            End If
        End If
        If MinMoney > 0 Then
            sqlOrder = sqlOrder & " And O.MoneyTotal>=" & MinMoney
        End If
        If MaxMoney > 0 Then
            sqlOrder = sqlOrder & " And O.MoneyTotal<=" & MaxMoney
        End If
        If OrderStatus >= 0 Then
            sqlOrder = sqlOrder & " And O.Status=" & OrderStatus
        End If
        If PayStatus >= 0 Then
            Select Case PayStatus
            Case 0
                sqlOrder = sqlOrder & " And O.MoneyTotal>0 And O.MoneyReceipt=0"
            Case 1
                sqlOrder = sqlOrder & " And O.MoneyTotal>O.MoneyReceipt And O.MoneyReceipt>0"
            Case 2
                sqlOrder = sqlOrder & " And O.MoneyTotal<=O.MoneyReceipt"
            End Select
        End If
        If DeliverStatus >= 0 Then
            sqlOrder = sqlOrder & " And O.DeliverStatus=" & DeliverStatus
        End If
        If OrderFormNum <> "" Then
            sqlOrder = sqlOrder & " And O.OrderFormNum like '%" & OrderFormNum & "%'"
        End If
        If ClientName <> "" Then
            sqlOrder = sqlOrder & " And C.ClientName like '%" & ClientName & "%'"
        End If
        If UserName <> "" Then
            sqlOrder = sqlOrder & " And O.UserName like '%" & UserName & "%'"
        End If
        If AgentName <> "" And IsAgent <> 2 Then
            sqlOrder = sqlOrder & " And O.AgentName='" & AgentName & "'"
        End If
        If ContacterName <> "" Then
            sqlOrder = sqlOrder & " And O.ContacterName like '%" & ContacterName & "%'"
        End If
        If Address <> "" Then
            sqlOrder = sqlOrder & " And O.Address like '%" & Address & "%'"
        End If
        If Phone <> "" Then
            sqlOrder = sqlOrder & " And O.Phone like '%" & Phone & "%'"
        End If
        If Mobile <> "" Then
            sqlOrder = sqlOrder & " And O.Mobile like '%" & Mobile & "%'"
        End If
        If Remark <> "" Then
            sqlOrder = sqlOrder & " And O.Remark like '%" & Remark & "%'"
        End If
        If ProductName <> "" Then
            sqlOrder = sqlOrder & " And P.ProductName like '%" & ProductName & "%'"
        End If
        If IsAgent = 2 Then
            sqlOrder = sqlOrder & " And O.AgentName=''"
        End If
        If AgentName = "" And IsAgent = 1 Then
            sqlOrder = sqlOrder & " And O.AgentName<>''"
        End If
        sqlOrder = sqlOrder & " order by O.OrderFormID desc"

    Case Else
        FoundErr = True
        ErrMsg = ErrMsg & "<li>错误的参数！</li>"
    End Select
End Sub

Sub outhead()
    Response.Write "<html><head><title>订单处理</title>"
    Response.Write "<meta http-equiv='Content-Type' content='text/html; charset=gb2312'>"
    Response.Write "<link rel='stylesheet' href='Admin_Style.css' type='text/css'>"
    Call ShowJS_Main("订单")
    Response.Write "</head>"
    Response.Write "<body leftmargin='2' topmargin='0' marginwidth='0' marginheight='0'>"
    Response.Write "<table width='100%' border='0' align='center' cellpadding='2' cellspacing='1' Class='border'>"
    Call ShowPageTitle("订 单 处 理", 10201)
    Response.Write "    <tr class='tdbg' height='30'> "
    Response.Write "  <form name='form1' action='Admin_Order.asp' method='get'>"
    Response.Write "      <td>快速查询："
    Response.Write "      <select size=1 name='SearchType' onChange='javascript:submit()'>"
    Response.Write "          <option value='0'"
    If SearchType = 0 Then Response.Write " selected"
    Response.Write ">所有订单</option>"
    Response.Write "          <option value='1'"
    If SearchType = 1 Then Response.Write " selected"
    Response.Write ">今天的新订单</option>"
    Response.Write "          <option value='2'"
    If SearchType = 2 Then Response.Write " selected"
    Response.Write ">最近10天内的新订单</option>"
    Response.Write "          <option value='3'"
    If SearchType = 3 Then Response.Write " selected"
    Response.Write ">最近一月内的新订单</option>"
    Response.Write "          <option value='4'"
    If SearchType = 4 Then Response.Write " selected"
    Response.Write ">未确认的订单</option>"
    Response.Write "          <option value='5'"
    If SearchType = 5 Then Response.Write " selected"
    Response.Write ">未付款的订单</option>"
    Response.Write "          <option value='6'"
    If SearchType = 6 Then Response.Write " selected"
    Response.Write ">未付清的订单</option>"
    Response.Write "          <option value='7'"
    If SearchType = 7 Then Response.Write " selected"
    Response.Write ">未送货的订单</option>"
    Response.Write "          <option value='8'"
    If SearchType = 8 Then Response.Write " selected"
    Response.Write ">未签收的订单</option>"
    Response.Write "          <option value='9'"
    If SearchType = 9 Then Response.Write " selected"
    Response.Write ">未开发票的订单</option>"
    Response.Write "          <option value='11'"
    If SearchType = 11 Then Response.Write " selected"
    Response.Write ">未结清的订单</option>"
    Response.Write "          <option value='12'"
    If SearchType = 12 Then Response.Write " selected"
    Response.Write ">已结清的订单</option>"
    Response.Write "          <option value='13'"
    If SearchType = 13 Then Response.Write " selected"
    Response.Write ">已发货的订单</option>"
    Response.Write "          <option value='14'"
    If SearchType = 14 Then Response.Write " selected"
    Response.Write ">已签收的订单</option>"
    Response.Write "        </select>&nbsp;&nbsp;&nbsp;&nbsp;<a href='Admin_Order.asp'>订单处理首页</a>"
    Response.Write "    </td>"
    Response.Write "  </form>"
    Response.Write "  <form name='form2' method='post' action='Admin_Order.asp'>"
    Response.Write "    <td><b>高级查询：</b>"
    Response.Write "      <select name='Field' id='Field'>"
    Response.Write "      <option value='OrderFormNum'>订单编号</option>"
    Response.Write "      <option value='ClientName' selected>客户名称</option>"
    Response.Write "      <option value='UserName'>用户名</option>"
    Response.Write "      <option value='AgentName'>代理商</option>"
    Response.Write "      <option value='ContacterName'>收货人</option>"
    Response.Write "      <option value='Address'>联系地址</option>"
    Response.Write "      <option value='Phone'>联系电话</option>"
    Response.Write "      <option value='DateAndTime'>下单时间</option>"
    Response.Write "      <option value='Remark'>备注/留言</option>"
    Response.Write "      <option value='InvoiceContent'>发票信息</option>"
    Response.Write "      <option value='ProductName'>商品名称</option>"
    Response.Write "      <option value='QQ'>客户QQ</option>"
    Response.Write "      </select>"
    Response.Write "      <input name='Keyword' type='text' id='Keyword' size='20' maxlength='30'>"
    Response.Write "      <input type='submit' name='Submit2' value=' 查 询 '>"
    Response.Write "      <input name='SearchType' type='hidden' id='SearchType' value='10'>&nbsp;&nbsp;&nbsp;&nbsp;<a href='Admin_Order.asp?Action=ShowSearchForm'><b>复杂查询</b></a>"
    Response.Write " </td>"
    Response.Write "</form>"
    Response.Write "</tr>"
    Response.Write "</table>"
    Response.Write "<br>"
End Sub


Sub outHead2()
    Response.Write "<html><head>" & vbCrLf
    Response.ContentType = "application/vnd.ms-excel" & vbCrLf
    Response.AddHeader "Content-Disposition", "attachment"
    Response.Write "<meta http-equiv=""Content-Language"" content=""zh-cn"">" & vbCrLf
    Response.Write "<meta http-equiv=""Content-Type"" content=""text/html; charset=gb2312"">" & vbCrLf
    Response.Write "<title>定单列表</title>" & vbCrLf
    Response.Write "<body>" & vbCrLf
End Sub

Sub outhead3()
    Response.Write "<html><head><title>订单处理</title>"
    Response.Write "<meta http-equiv='Content-Type' content='text/html; charset=gb2312'>"
    Response.Write "<link rel='stylesheet' href='Admin_Style.css' type='text/css'>"
    Response.Write "</head>"
    Response.Write "<body leftmargin='2' topmargin='0' marginwidth='0' marginheight='0'>"
    Response.Write "<br>"
End Sub

Sub main()
    Dim rsOrderList
    Dim MoneyTotal, MoneyReceipt
    MoneyTotal = 0
    MoneyReceipt = 0
    
    Response.Write "<table width='100%'><tr><td align='left'><img src='images/img_u.gif' align='absmiddle'>您现在的位置：<a href='Admin_Order.asp'>订单处理</a>&nbsp;&gt;&gt;&nbsp;"
    Response.Write strResultTips
    Response.Write "</td></tr></table>"
    If FoundErr = True Then Exit Sub

    
    Response.Write "<table width='100%' border='0' cellpadding='0' cellspacing='0'>"
    Response.Write "  <tr>"
    If ResultType = 1 Then
    
    End If
    Response.Write "  <form name='myform' method='Post' action='Admin_Order.asp' onsubmit=""return confirm('确定要删除选定的订单吗？');"">"
    Response.Write "     <td>"
    Response.Write "       <table width='100%'  border='0' cellspacing='1' cellpadding='2' class='border'>"
    Response.Write "         <tr align='center' class='title'>"
    Response.Write "           <td width='30'>选中</td>"
    Response.Write "           <td width='110'>订单编号</td>"
    If ResultType = 2 Then
        If IsAgent = 1 Then
            Response.Write "           <td width='80'>代理商</td>"
        End If
        Response.Write "           <td width='80'>收货人姓名</td>"
        Response.Write "           <td width='90'>联系电话</td>"
        Response.Write "           <td width='90'>收货人手机</td>"
        Response.Write "           <td width='280'>收货人地址</td>"
        Response.Write "           <td width='60'>邮政编码</td>"
        Response.Write "           <td width='100'>下单时间</td>"
    Else
        Response.Write "           <td>客户名称</td>"
        Response.Write "           <td>用户名</td>"
        Response.Write "           <td width='120'>下单时间</td>"
        Response.Write "           <td width='70'>订单金额</td>"
        Response.Write "           <td width='70'>收款金额</td>"
        Response.Write "           <td width='30'>需要<br>发票</td>"
        Response.Write "           <td width='30'>已开<br>发票</td>"
        Response.Write "           <td width='50'>订单状态</td>"
        Response.Write "           <td width='50'>付款状态</td>"
        Response.Write "           <td width='50'>物流状态</td>"
    End If
    Response.Write "         </tr>"
    Set rsOrderList = Server.CreateObject("Adodb.RecordSet")
    rsOrderList.Open sqlOrder, Conn, 1, 1
    If rsOrderList.BOF And rsOrderList.EOF Then
        totalPut = 0
        Response.Write "<tr class='tdbg' height='50'><td colspan='20' align='center'>没有任何符合条件的订单！</td></tr>"
    Else
        totalPut = rsOrderList.RecordCount
        If CurrentPage < 1 Then
            CurrentPage = 1
        End If
        If (CurrentPage - 1) * MaxPerPage > totalPut Then
            If (totalPut Mod MaxPerPage) = 0 Then
                CurrentPage = totalPut \ MaxPerPage
            Else
                CurrentPage = totalPut \ MaxPerPage + 1
            End If
        End If
        If CurrentPage > 1 Then
            If (CurrentPage - 1) * MaxPerPage < totalPut Then
                rsOrderList.Move (CurrentPage - 1) * MaxPerPage
            Else
                CurrentPage = 1
            End If
        End If

        Dim i
        i = 0
        Do While Not rsOrderList.EOF
            Response.Write "         <tr align='center' class='tdbg' onmouseout=""this.className='tdbg'"" onmouseover=""this.className='tdbgmouseover'"">"
            Response.Write "           <td width='30'><input name='OrderFormID' type='checkbox' onclick='unselectall()' id='OrderFormID' value='" & rsOrderList("OrderFormID") & "'></td>"
            Response.Write "           <td width='110'><a href='Admin_Order.asp?Action=ShowOrder&OrderFormID=" & rsOrderList("OrderFormID") & "'>" & rsOrderList("OrderFormNum") & "</a></td>"
            If ResultType = 2 Then
                If IsAgent = 1 Then
                    Response.Write "       <td><a href='Admin_User.asp?Action=Show&InfoType=6&UserName=" & rsOrderList("AgentName") & "'>" & rsOrderList("AgentName") & "</a></td>"
                End If
                Response.Write "           <td>" & rsOrderList("ContacterName") & "</td>"
                Response.Write "           <td>" & rsOrderList("Phone") & "</td>"
                Response.Write "           <td>" & rsOrderList("Mobile") & "</td>"
                Response.Write "           <td>" & rsOrderList("Address") & "</td>"
                Response.Write "           <td>" & rsOrderList("ZipCode") & "</td>"
                Response.Write "           <td>" & FormatDateTime(rsOrderList("InputTime"), 2) & "</td>"
            Else
                Response.Write "           <td><a href='Admin_Client.asp?Action=Show&InfoType=2&ClientID=" & rsOrderList("ClientID") & "'>" & PE_HTMLEncode(rsOrderList("ClientName")) & "</a></td>"
                Response.Write "           <td><a href='Admin_User.asp?Action=Show&InfoType=0&UserName=" & rsOrderList("UserName") & "'>" & rsOrderList("UserName") & "</a></td>"
                Response.Write "           <td width='120'>" & rsOrderList("InputTime") & "</td>"
                Response.Write "           <td width='70' align='right'>" & FormatNumber(rsOrderList("MoneyTotal"), 2, vbTrue, vbFalse, vbTrue) & "</td>"
                Response.Write "           <td width='70' align='right'>"
                If rsOrderList("MoneyReceipt") < rsOrderList("MoneyTotal") Then
                    Response.Write "<font color='red'>" & FormatNumber(rsOrderList("MoneyReceipt"), 2, vbTrue, vbFalse, vbTrue) & "</font>"
                Else
                    Response.Write FormatNumber(rsOrderList("MoneyReceipt"), 2, vbTrue, vbFalse, vbTrue)
                End If
                Response.Write "</td>"
                Response.Write "           <td width='30'>"
                If rsOrderList("NeedInvoice") = True Then
                    Response.Write "<font color='red'>√</font>"
                End If
                Response.Write "</td>"
                Response.Write "           <td width='30'>"
                If rsOrderList("NeedInvoice") = True Then
                    If rsOrderList("Invoiced") = True Then
                        Response.Write "√"
                    Else
                        Response.Write "<font color='red'>×</font>"
                    End If
                End If
                Response.Write "</td>"
                
                Response.Write "           <td width='50'>" & arrOrderStatus(rsOrderList("Status")) & "</td>"
                Response.Write "           <td width='50'>" & GetPayStatus(rsOrderList("MoneyTotal"), rsOrderList("MoneyReceipt")) & "</td>"
                Response.Write "           <td width='50'>" & arrDeliverStatus(rsOrderList("DeliverStatus")) & "</td>"
            End If
            Response.Write "</tr>"
             
            MoneyTotal = MoneyTotal + rsOrderList("MoneyTotal")
            MoneyReceipt = MoneyReceipt + rsOrderList("MoneyReceipt")
            i = i + 1
            If i >= MaxPerPage Then Exit Do
            rsOrderList.MoveNext
        Loop
    End If
    rsOrderList.Close
    Set rsOrderList = Nothing
    If AdminPurview = 1 Or arrPurview(12) = True Then
        Response.Write "         <tr align='center' class='tdbg' onmouseout=""this.className='tdbg'"" onmouseover=""this.className='tdbgmouseover'"">"
        Response.Write "           <td colspan='5' align='right'><b>本页合计：</b></td>"
        Response.Write "           <td align='right'>" & FormatNumber(MoneyTotal, 2, vbTrue, vbFalse, vbTrue) & "</td>"
        Response.Write "           <td align='right'>" & FormatNumber(MoneyReceipt, 2, vbTrue, vbFalse, vbTrue) & "</td>"
        Response.Write "           <td colspan='5'>&nbsp;</td>"
        Response.Write "         </tr>"
        
        Dim dblCount, rsCount, dblCount2
        If SearchType < 10 Or strField = "OrderFormNum" Then
            Set rsCount = Conn.Execute(sqlMoney)
            If IsNull(rsCount(0)) Then
                dblCount = 0
            Else
                dblCount = rsCount(0)
            End If
            Set rsCount = Nothing
            Set rsCount = Conn.Execute(sqlMoney2)
            If IsNull(rsCount(0)) Then
                dblCount2 = 0
            Else
                dblCount2 = rsCount(0)
            End If
            Set rsCount = Nothing
            
            Response.Write "         <tr align='center' class='tdbg' onmouseout=""this.className='tdbg'"" onmouseover=""this.className='tdbgmouseover'"">"
            Response.Write "           <td colspan='5' align='right'><b>本次查询合计：</b></td>"
            Response.Write "           <td align='right'>" & FormatNumber(dblCount, 2, vbTrue, vbFalse, vbTrue) & "</td>"
            Response.Write "           <td align='right'>" & FormatNumber(dblCount2, 2, vbTrue, vbFalse, vbTrue) & "</td>"
            Response.Write "           <td colspan='5'>&nbsp;</td>"
            Response.Write "         </tr>"
        End If
        
        Set rsCount = Conn.Execute("select sum(MoneyTotal) from PE_OrderForm")
        If IsNull(rsCount(0)) Then
            dblCount = 0
        Else
            dblCount = rsCount(0)
        End If
        Set rsCount = Nothing
        Set rsCount = Conn.Execute("select sum(MoneyReceipt) from PE_OrderForm")
        If IsNull(rsCount(0)) Then
            dblCount2 = 0
        Else
            dblCount2 = rsCount(0)
        End If
        Set rsCount = Nothing
        
        Response.Write "         <tr align='center' class='tdbg' onmouseout=""this.className='tdbg'"" onmouseover=""this.className='tdbgmouseover'"">"
        Response.Write "           <td colspan='5' align='right'><b>总计金额：</b></td>"
        Response.Write "           <td align='right'>" & FormatNumber(dblCount, 2, vbTrue, vbFalse, vbTrue) & "</td>"
        Response.Write "           <td align='right'>" & FormatNumber(dblCount2, 2, vbTrue, vbFalse, vbTrue) & "</td>"
        Response.Write "           <td colspan='5'>&nbsp;</td>"
        Response.Write "         </tr>"
    End If
    Response.Write "       </table>"
    Response.Write "       <table width='100%' border='0' cellpadding='0' cellspacing='0'>"
    Response.Write "        <tr>"
    Response.Write "            <td width='200' height='30'><input name='chkAll' type='checkbox' id='chkAll' onclick='CheckAll(this.form)' value='checkbox'> 选中本页显示的所有订单</td>"
    Response.Write "            <td> <input name='Action' type='hidden' id='Action' value='DelOrder'> <input type='submit' name='Submit' value='删除选定的订单'> </td>"
    Response.Write "        </tr>"
    Response.Write "       </table>"
    Response.Write "</td>"
    Response.Write "</form></tr></table>"
    Response.Write ShowPage(strFileName, totalPut, MaxPerPage, CurrentPage, True, True, "个订单", True)
End Sub

Sub ShowSearchForm()
    Call PopCalendarInit
    Response.Write "<script language='javascript'>" & vbCrLf
    Response.Write "function SelectAgent(){" & vbCrLf
    Response.Write "    var arr=showModalDialog('Admin_SourceList.asp?TypeSelect=AgentList','','dialogWidth:600px; dialogHeight:450px; help: no; scroll: yes; status: no');" & vbCrLf
    Response.Write "    if (arr != null){" & vbCrLf
    Response.Write "        document.formSearch.AgentName.value=arr;" & vbCrLf
    Response.Write "    }" & vbCrLf
    Response.Write "}" & vbCrLf
    Response.Write "</script>" & vbCrLf
    Response.Write "<form method='Get' name='formSearch' action='Admin_Order.asp'>"
    Response.Write "<table width='100%' border='0' cellpadding='2' cellspacing='1' class='border'>"
    Response.Write "<tr class='title' align='center'><td colspan='6'>订 单 复 杂 查 询</td></tr>"
    Response.Write "<tr class='tdbg'><td width='120' class='tdbg5' align='right'>ＩＤ范围：</td><td>起始ＩＤ<input type='text' name='BeginID'  size='10' value=''>&nbsp;终止ＩＤ<input type='text' name='EndID'  size='10' value=''></td></tr>"
    Response.Write "<tr class='tdbg'><td width='120' class='tdbg5' align='right'>日期范围：</td><td>起始日期<input type='text' name='BeginDate' id='BeginDate' size='10' maxlength='10'><a style='cursor:hand;' onClick='PopCalendar.show(document.formSearch.BeginDate, ""yyyy-mm-dd"", null, null, null, ""11"");'><img src='Images/Calendar.gif' border='0' Style='Padding-Top:10px' align='absmiddle'></a>&nbsp;结束日期<input type='text' name='EndDate' id='EndDate' size='10' maxlength='10'><a style='cursor:hand;' onClick='PopCalendar.show(document.formSearch.EndDate, ""yyyy-mm-dd"", null, null, null, ""11"");'><img src='Images/Calendar.gif' border='0' Style='Padding-Top:10px' align='absmiddle'></a></td></tr>"
    Response.Write "<tr class='tdbg'><td width='120' class='tdbg5' align='right'>金额范围：</td><td><input type='text' name='MinMoney'  size='10' value=''> 至 <input type='text' name='MaxMoney'  size='10' value=''></td></tr>"
    Response.Write "<tr class='tdbg'><td width='120' class='tdbg5' align='right'>订单状态：</td><td><input type='radio' name='OrderStatus' value='1'>等待确认&nbsp;&nbsp;<input type='radio' name='OrderStatus' value='2'>已经确认&nbsp;&nbsp;<input type='radio' name='OrderStatus' value='4'>已经结清&nbsp;&nbsp;<input type='radio' name='OrderStatus' value='-1' checked>所有状态</td></tr>"
    Response.Write "<tr class='tdbg'><td width='120' class='tdbg5' align='right'>付款状态：</td><td><input type='radio' name='PayStatus' value='0'>等待付款&nbsp;&nbsp;<input type='radio' name='PayStatus' value='1'>已付定金&nbsp;&nbsp;<input type='radio' name='PayStatus' value='2'>已经付清&nbsp;&nbsp;<input type='radio' name='PayStatus' value='-1' checked>所有状态</td></tr>"
    Response.Write "<tr class='tdbg'><td width='120' class='tdbg5' align='right'>物流状态：</td><td><input type='radio' name='DeliverStatus' value='1'>配送中&nbsp;&nbsp;&nbsp;&nbsp;<input type='radio' name='DeliverStatus' value='2'>已发货&nbsp;&nbsp;&nbsp;&nbsp;<input type='radio' name='DeliverStatus' value='3'>已签收&nbsp;&nbsp;&nbsp;&nbsp;<input type='radio' name='DeliverStatus' value='-1' checked>所有状态</td></tr>"
    Response.Write "<tr class='tdbg'><td width='120' class='tdbg5' align='right'>订单编号：</td><td><input type='text' name='OrderFormNum'  size='30' value=''></td></tr>"
    Response.Write "<tr class='tdbg'><td width='120' class='tdbg5' align='right'>客户名称：</td><td><input type='text' name='ClientName'  size='30' value=''></td></tr>"
    Response.Write "<tr class='tdbg'><td width='120' class='tdbg5' align='right'>用户名：</td><td><input type='text' name='UserName'  size='30' value=''></td></tr>"
    Response.Write "<tr class='tdbg'><td width='120' class='tdbg5' align='right'>代理商：</td><td><input type='text' name='AgentName'  size='30' value=''><input type='button' name='aaa' value='...' onclick='SelectAgent()'></td></tr>"
    Response.Write "<tr class='tdbg'><td width='120' class='tdbg5' align='right'>收货人姓名：</td><td><input type='text' name='ContacterName'  size='30' value=''></td></tr>"
    Response.Write "<tr class='tdbg'><td width='120' class='tdbg5' align='right'>联系地址：</td><td><input type='text' name='Address'  size='30' value=''></td></tr>"
    Response.Write "<tr class='tdbg'><td width='120' class='tdbg5' align='right'>联系电话：</td><td><input type='text' name='Phone'  size='30' value=''></td></tr>"
    Response.Write "<tr class='tdbg'><td width='120' class='tdbg5' align='right'>手机号：</td><td><input type='text' name='Mobile'  size='30' value=''></td></tr>"
    Response.Write "<tr class='tdbg'><td width='120' class='tdbg5' align='right'>备注留言：</td><td><input type='text' name='Remark'  size='30' value=''></td></tr>"
    Response.Write "<tr class='tdbg'><td width='120' class='tdbg5' align='right'>商品名称：</td><td><select name='ProductName'>" & GetProductName_Option() & "</select></td></tr>"
    Response.Write "<tr class='tdbg'><td width='120' class='tdbg5' align='right'>是否代理商订单：</td><td><input type='radio' name='IsAgent' value='1'>是&nbsp;&nbsp;&nbsp;&nbsp;<input type='radio' name='IsAgent' value='2' >否&nbsp;&nbsp;&nbsp;&nbsp;<input type='radio' name='IsAgent' value='0' Checked>所有</td></tr>"
    Response.Write "<tr class='tdbg'><td width='120' class='tdbg5' align='right'>用户名是否允许重复：</td><td><input type='radio' name='IsSameUserName' value='1' Checked>是&nbsp;&nbsp;&nbsp;&nbsp;<input type='radio' name='IsSameUserName' value='2' >否&nbsp;&nbsp;&nbsp;&nbsp;</td></tr>"
    Response.Write "<tr class='tdbg'><td width='120' class='tdbg5' align='right'>查询结果显示的信息：</td><td><input type='radio' name='ResultType' value='1' Checked>订单信息&nbsp;&nbsp;&nbsp;&nbsp;<input type='radio' name='ResultType' value='2'>收货人信息&nbsp;&nbsp;&nbsp;&nbsp;</td></tr>"
    Response.Write "<tr class='tdbg' height='40' align='center'><td colspan='6'><input name='SearchType' type='hidden' id='SearchType' value='99'><input name='Action' type='hidden' value='Manage'><input type='submit' name='Submit'  value=' 查 询 '> "
    If AdminPurview = 1 Or arrPurview(12) = True Then
        Response.Write "<input type='submit' name='Submit2'  value='导出到EXCEL' onclick=""document.formSearch.Action.value='outExcel';"">"
    End If
    Response.Write "</td></tr></table></form>"

End Sub

Function GetProductName_Option()
    Dim strProductName, sql, rsProductName
    Set rsProductName = Server.CreateObject("adodb.recordset")
    sql = "select distinct ProductName from PE_Product"
    rsProductName.Open sql, Conn, 1, 3
    strProductName = "<option value=''>请选择</option>"
    If rsProductName.EOF Then
        strProductName = strProductName & ""
    Else
        Do While Not rsProductName.EOF
            strProductName = strProductName & "<option value=" & rsProductName(0) & ">" & rsProductName(0) & "</option>"
            rsProductName.MoveNext
        Loop
    End If
    GetProductName_Option = strProductName
    rsProductName.Close
    Set rsProductName = Nothing
End Function

Sub ShowOrder()
    Dim OrderFormID
    OrderFormID = Trim(Request("OrderFormID"))
    If OrderFormID = "" Then
        FoundErr = True
        ErrMsg = ErrMsg & "<li>请指定OrderFormID！</li>"
        Exit Sub
    Else
        OrderFormID = PE_CLng(OrderFormID)
    End If

    Dim rsOrder, sqlOrder, strOrderInfo
    sqlOrder = "select O.*,C.ClientName from PE_OrderForm O left join PE_Client C on O.ClientID=C.ClientID where OrderFormID=" & OrderFormID & ""
    Set rsOrder = Conn.Execute(sqlOrder)
    If rsOrder.BOF And rsOrder.EOF Then
        FoundErr = True
        ErrMsg = ErrMsg & "<li>找不到指定的订单！</li>"
        rsOrder.Close
        Set rsOrder = Nothing
        Exit Sub
    End If

    Response.Write "<table width='100%' border='0' align='center' cellpadding='2' cellspacing='1' class='border'>"
    Response.Write "  <tr align='center' class='title'>"
    Response.Write "    <td height='22'><b>订 单 信 息</b>（订单编号：" & rsOrder("OrderFormNum") & "）</td>"
    Response.Write "  </tr>"
    Response.Write "  <tr>"
    Response.Write "    <td height='25'><table width='100%'  border='0' cellpadding='2' cellspacing='0'>"
    Response.Write "      <tr class='tdbg'>"
    Response.Write "        <td width='18%'>客户名称：<a href='Admin_Client.asp?Action=Show&InfoType=2&ClientID=" & rsOrder("ClientID") & "'><font color='red'>" & rsOrder("ClientName") & "</a></td>"
    Response.Write "        <td width='20%'>用 户 名：<a href='Admin_User.asp?Action=Show&UserName=" & rsOrder("UserName") & "'><font color='red'>" & rsOrder("UserName") & "</a></td>"
    Response.Write "        <td width='20%'>代 理 商：<a href='Admin_User.asp?Action=Show&InfoType=6&UserName=" & rsOrder("AgentName") & "'><font color='red'>" & rsOrder("AgentName") & "</a></td>"
    Response.Write "        <td width='18%'>购买日期：<font color='red'>" & rsOrder("BeginDate") & "</font></td>"
    Response.Write "        <td width='24%'>下单时间：<font color='red'>" & rsOrder("InputTime") & "</font></td>"
    Response.Write "      </tr>"
    Response.Write "      <tr class='tdbg'>"
    Response.Write "        <td width='18%'>需要发票："
    If rsOrder("NeedInvoice") = True Then
        Response.Write "√"
    Else
        Response.Write "<font color='red'>×</font>"
    End If
    Response.Write "</td>"
    Response.Write "        <td width='20%'>已开发票："
    If rsOrder("Invoiced") = True Then
        Response.Write "√"
    Else
        Response.Write "<font color='red'>×</font>"
    End If
    Response.Write "</td>"
    Response.Write "        <td width='20%'>订单状态：" & arrOrderStatus(rsOrder("Status")) & "</td>"
    Response.Write "        <td width='18%'>付款情况：" & GetPayStatus(rsOrder("MoneyTotal"), rsOrder("MoneyReceipt")) & "</td>"
    Response.Write "        <td width='24%'>物流状态：" & arrDeliverStatus(rsOrder("DeliverStatus")) & "</td>"
    Response.Write "      </tr>"
    Response.Write "    </table>      </td>"
    Response.Write "  </tr>"
    Response.Write "  <tr align='center'>"
    Response.Write "    <td height='25'><table width='100%' border='0' align='center' cellpadding='2' cellspacing='1'>"
    Response.Write "        <tr class='tdbg'>"
    Response.Write "          <td width='12%' class='tdbg5' align='right'>收货人姓名：</td>"
    Response.Write "          <td width='38%'>" & PE_HTMLEncode(rsOrder("ContacterName")) & "</td>"
    Response.Write "          <td width='12%' class='tdbg5' align='right'>联系电话：</td>"
    Response.Write "          <td width='38%'>" & PE_HTMLEncode(rsOrder("Phone")) & "</td>"
    Response.Write "        </tr>"
    Response.Write "        <tr class='tdbg' valign='top'>"
    Response.Write "          <td width='12%' class='tdbg5' align='right'>收货人地址：</td>"
    Response.Write "          <td width='38%'>" & PE_HTMLEncode(rsOrder("Address")) & "</td>"
    Response.Write "          <td width='12%' class='tdbg5' align='right'>邮政编码：</td>"
    Response.Write "          <td width='38%'>" & rsOrder("ZipCode") & "</td>"
    Response.Write "        </tr>"
    Response.Write "        <tr class='tdbg'>"
    Response.Write "          <td width='12%' class='tdbg5' align='right'>收货人邮箱：</td>"
    Response.Write "          <td width='38%'>" & PE_HTMLEncode(rsOrder("Email")) & "</td>"
    Response.Write "          <td width='12%' class='tdbg5' align='right'>收货人手机：</td>"
    Response.Write "          <td width='38%'>" & PE_HTMLEncode(rsOrder("Mobile")) & "</td>"
    Response.Write "        </tr>"
    Response.Write "        <tr class='tdbg'>"
    Response.Write "          <td width='12%' class='tdbg5' align='right'>付款方式：</td>"
    Response.Write "          <td width='38%'>" & GetPaymentType(rsOrder("PaymentType")) & "</td>"
    Response.Write "          <td width='12%' class='tdbg5' align='right'>送货方式：</td>"
    Response.Write "          <td width='38%'>" & GetDeliverType(rsOrder("DeliverType")) & "</td>"
    Response.Write "        </tr>"
    Response.Write "        <tr class='tdbg' valign='top'>"
    Response.Write "          <td width='12%' class='tdbg5' align='right'>发票信息：</td>"
    Response.Write "          <td width='38%'>"
    If rsOrder("NeedInvoice") = True Then Response.Write PE_HTMLEncode(rsOrder("InvoiceContent"))
    Response.Write "</td>"
    Response.Write "          <td width='12%' class='tdbg5' align='right'>备注/留言：</td>"
    Response.Write "          <td width='38%'>" & PE_HTMLEncode(rsOrder("Remark")) & "</td>"
    Response.Write "        </tr>"
    Response.Write "    </table></td>"
    Response.Write "  </tr>"
    Response.Write "  <tr><td>"
    Response.Write "<table width='100%' border='0' align='center' cellpadding='2' cellspacing='1' bgcolor='#0099FF'>"
    Response.Write "  <tr align='center' class='tdbg2' height='25'>"
    Response.Write "    <td><b>商 品 名 称</b></td>"
    Response.Write "    <td width='45'><b>单位</b></td>"
    Response.Write "    <td width='55'><b>数量</b></td>"
    Response.Write "    <td width='65'><b>原价</b></td>"
    Response.Write "    <td width='65'><b>实价</b></td>"
    Response.Write "    <td width='65'><b>指定价</b></td>"
    Response.Write "    <td width='85'><b>金 额</b></td>"
    Response.Write "    <td width='65'><b>服务期限</b></td>"
    Response.Write "    <td width='45'><b>备注</b></td>"
    Response.Write "  </tr>"

    Dim dblPrice, dblAmount, dblSubtotal, dblTotal, TotalPresentExp, TotalPresentMoney, TotalPresentPoint, HaveSoft, HaveCard
    Dim rsOrderItem, rsCard
    dblSubtotal = 0
    dblTotal = 0
    TotalPresentExp = 0
    TotalPresentMoney = 0
    TotalPresentPoint = 0
    HaveSoft = False
    HaveCard = False
    Set rsOrderItem = Conn.Execute("select I.ItemID,P.ProductID,P.ProductName,P.ProductKind,I.SaleType,I.PresentExp,I.PresentMoney,I.PresentPoint,I.Price_Original,I.Price,I.TruePrice,I.Amount,P.Unit,I.BeginDate,I.ServiceTerm,I.Remark from PE_OrderFormItem I inner join PE_Product P on I.ProductID=P.ProductID where I.OrderFormID=" & rsOrder("OrderFormID") & " order by I.ItemID")
    Do While Not rsOrderItem.EOF
        dblPrice = rsOrderItem("TruePrice")
        dblAmount = rsOrderItem("Amount")
        dblSubtotal = dblPrice * dblAmount
        dblTotal = dblTotal + dblSubtotal
        TotalPresentExp = TotalPresentExp + rsOrderItem("PresentExp") * rsOrderItem("Amount")
        TotalPresentMoney = TotalPresentMoney + rsOrderItem("PresentMoney") * rsOrderItem("Amount")
        TotalPresentPoint = TotalPresentPoint + rsOrderItem("PresentPoint") * rsOrderItem("Amount")
        If rsOrderItem("ProductKind") = 2 Then
            HaveSoft = True
        ElseIf rsOrderItem("ProductKind") = 3 Then
            Set rsCard = Conn.Execute("select top 1 CardID from PE_Card where ProductID=" & rsOrderItem("ProductID") & " and OrderFormItemID=" & rsOrderItem("ItemID") & "")
            If rsCard.BOF And rsCard.EOF Then
                HaveCard = True
            End If
            Set rsCard = Nothing
        End If
        
        Response.Write "  <tr valign='middle' class='tdbg' height='20'>"
        Response.Write "    <td width='*'><a href='Admin_Product.asp?Action=Show&ProductID=" & rsOrderItem("ProductID") & "' target='_blank'>" & rsOrderItem("ProductName") & "</a>"
        Select Case rsOrderItem("SaleType")
        Case 1 '正常销售
        
        Case 2 '换购
            Response.Write " <font color='red'>（换购）</font>"
        Case 3 '赠送
            Response.Write " <font color='red'>（赠送）</font>"
        Case 4 '批发
            Response.Write " <font color='red'>（批发）</font>"
        End Select
            
        Response.Write "</td>"
        Response.Write "    <td width='45' align=center>" & rsOrderItem("Unit") & "</td>"
        Response.Write "    <td width='55' align='center'>" & dblAmount & "</td>"
        Response.Write "    <td width='65' align='right'>" & FormatNumber(rsOrderItem("Price_Original"), 2, vbTrue, vbFalse, vbTrue) & "</td>"
        Response.Write "    <td width='65' align='right'>" & FormatNumber(rsOrderItem("Price"), 2, vbTrue, vbFalse, vbTrue) & "</td>"
        Response.Write "    <td width='65' align='right'>" & FormatNumber(dblPrice, 2, vbTrue, vbFalse, vbTrue) & "</td>"
        Response.Write "    <td width='85' align='right'>" & FormatNumber(dblSubtotal, 2, vbTrue, vbFalse, vbTrue) & "</td>"
        Response.Write "    <td width='65' align=center>"
        If rsOrderItem("ServiceTerm") > 0 Then
            If DateAdd("yyyy", rsOrderItem("ServiceTerm"), rsOrderItem("BeginDate")) <= Now() Then
                Response.Write "<font color='red'>"
            End If
        End If
        Select Case rsOrderItem("ServiceTerm")
        Case -1
            Response.Write "无限期"
        Case 0
            Response.Write "无"
        Case 1
            Response.Write "一年"
        Case 2
            Response.Write "两年"
        Case 3
            Response.Write "三年"
        Case 4
            Response.Write "四年"
        Case 5
            Response.Write "五年"
        Case Else
            Response.Write "未知"
        End Select
        Response.Write "</td>"
        Response.Write "    <td align=center width='45'>"
        If rsOrderItem("Remark") <> "" Then
            Response.Write "<a href='#' title='" & rsOrderItem("Remark") & "'>查看</a>"
        End If
        Response.Write "</td>"
        Response.Write "  </tr>"
        rsOrderItem.MoveNext
    Loop
    rsOrderItem.Close
    Set rsOrderItem = Nothing

    Response.Write "  <tr class='tdbg' height='30' >"
    Response.Write "    <td colspan='6' align='right'><b>合计：</b></td>"
    Response.Write "    <td align='right'><b>" & FormatNumber(dblTotal, 2, vbTrue, vbFalse, vbTrue) & "</b></td>"
    Response.Write "    <td colspan='3'> </td>"
    Response.Write "  </tr>"
    
    Dim Discount_Payment, Charge_Deliver, strTotalMoney
    Discount_Payment = rsOrder("Discount_Payment")
    Charge_Deliver = rsOrder("Charge_Deliver")
    
    Response.Write "    <tr class='tdbg'>" & vbCrLf
    Response.Write "      <td colspan='4'>付款方式折扣率：" & Discount_Payment & "%"
    strTotalMoney = "实际金额：(" & dblTotal & "×" & Discount_Payment & "%"
    If Discount_Payment > 0 And Discount_Payment < 100 Then
        dblTotal = dblTotal * Discount_Payment / 100
    End If
    Response.Write "&nbsp;&nbsp;&nbsp;&nbsp;运费：" & Charge_Deliver & " 元"
    strTotalMoney = strTotalMoney & "＋" & Charge_Deliver & ")"
    dblTotal = dblTotal + Charge_Deliver
    
    Response.Write "&nbsp;&nbsp;&nbsp;&nbsp;税率：" & TaxRate & "%&nbsp;&nbsp;&nbsp;&nbsp;价格含税："
    If IncludeTax = True Then
        Response.Write "是"
        If rsOrder("NeedInvoice") <> True Then
            strTotalMoney = strTotalMoney & "×(1-" & TaxRate & "%)"
            dblTotal = dblTotal * (100 - TaxRate) / 100
        Else
            strTotalMoney = strTotalMoney & "×100%"
        End If
    Else
        Response.Write "否"
        If rsOrder("NeedInvoice") = True Then
            strTotalMoney = strTotalMoney & "×(1+" & TaxRate & "%)"
            dblTotal = dblTotal * (100 + TaxRate) / 100
        Else
            strTotalMoney = strTotalMoney & "×100%"
        End If
    End If
    strTotalMoney = strTotalMoney & "＝" & FormatNumber(dblTotal, 2, vbTrue, vbFalse, vbTrue) & " 元"
    Response.Write "<br>" & strTotalMoney

    Response.Write "<br>返还 <font color='red'>" & rsOrder("PresentMoney") + TotalPresentMoney & "</font> 元现金券，赠送 <font color='red'>" & rsOrder("PresentExp") + TotalPresentExp & "</font> 点积分，赠送 <font color='red'>" & rsOrder("PresentPoint") + TotalPresentPoint & "</font> " & PointUnit & PointName
    
    Response.Write "    </td>" & vbCrLf
    Response.Write "    <td colspan='2' align='right'><b>实际金额：</b></td>" & vbCrLf
    Response.Write "    <td align=right><b> ￥" & FormatNumber(dblTotal, 2, vbTrue, vbFalse, vbTrue) & "</b></td>" & vbCrLf
    Response.Write "    <td colspan='3' align='left'><b>已付款：</b>￥"
    If rsOrder("MoneyReceipt") < rsOrder("MoneyTotal") Then
        Response.Write "<font color='red'>" & FormatNumber(rsOrder("MoneyReceipt"), 2, vbTrue, vbFalse, vbTrue) & "</font><br>"
        Response.Write "<font color='blue'><b>尚欠款：</b>￥" & FormatNumber(rsOrder("MoneyTotal") - rsOrder("MoneyReceipt"), 2, vbTrue, vbFalse, vbTrue) & "</font>"
    Else
        Response.Write FormatNumber(rsOrder("MoneyReceipt"), 2, vbTrue, vbFalse, vbTrue)
    End If
    Response.Write "</b></td></tr>"
    
    Response.Write "</table></td>"
    Response.Write "  </tr>"
    

    If Action = "ShowOrder" Then
        Response.Write "  <tr height='50'>"
        Response.Write "    <td align='center'>"
        
        If AdminPurview = 1 Or arrPurview(2) = True Then
            Response.Write "      <input type='button' name='Submit' value='修改订单' onClick=""window.location.href='Admin_Order.asp?Action=ModifyOrder&OrderFormID=" & rsOrder("OrderFormID") & "'"">&nbsp;"
        End If
        If AdminPurview = 1 Or arrPurview(1) = True Then
            If rsOrder("Status") = 1 Then
                Response.Write "<input type='button' name='Submit' value='确认订单' onClick=""divConfirmOrder.style.visibility='visible';"">"
            Else
                If rsOrder("Status") < 4 And rsOrder("MoneyReceipt") < rsOrder("MoneyTotal") Then
                    Response.Write "&nbsp;<input type='button' name='Submit' value='取消确认' onClick=""window.location.href='Admin_Order.asp?Action=CancelConfirm&OrderFormID=" & rsOrder("OrderFormID") & "'"">"
                End If
            End If
        End If
        If AdminPurview = 1 Or arrPurview(3) = True Then
            If rsOrder("Status") < 4 And rsOrder("MoneyReceipt") = 0 Then
                Response.Write "&nbsp;<input type='button' name='Submit' value='删除订单' onClick=""javascript:if(confirm('确定要删除此订单吗？')){window.location.href='Admin_Order.asp?Action=DelOrder&OrderFormID=" & rsOrder("OrderFormID") & "';}"">"
            End If
        End If
        If rsOrder("MoneyReceipt") < rsOrder("MoneyTotal") Then
            If AdminPurview = 1 Or arrPurview(4) = True Then
                Response.Write "&nbsp;<input type='button' name='Submit' value='银行汇款支付' onClick=""window.location.href='Admin_Order.asp?Action=RemitAndPay&OrderFormID=" & rsOrder("OrderFormID") & "'"">"
            End If
            If AdminPurview = 1 Or arrPurview(14) = True Then
                If rsOrder("UserName") <> "" Then
                    Response.Write "&nbsp;<input type='button' name='Submit' value='虚拟货币支付' onClick=""window.location.href='Admin_User.asp?Action=AddPayment&UserName=" & rsOrder("UserName") & "&OrderFormID=" & rsOrder("OrderFormID") & "'"">"
                ElseIf rsOrder("ClientID") > 0 Then
                    Response.Write "&nbsp;<input type='button' name='Submit' value='虚拟货币支付' onClick=""window.location.href='Admin_Client.asp?Action=AddPayment&ClientID=" & rsOrder("ClientID") & "&OrderFormID=" & rsOrder("OrderFormID") & "'"">"
                End If
            End If
            If AdminPurview = 1 Or arrPurview(15) = True Then
                If rsOrder("AgentName") <> "" Then
                    Response.Write "&nbsp;<input type='button' name='Submit' value='代理商余额支付' onClick=""javascript:if(confirm('确定要支付此订单吗？')){window.location.href='Admin_Order.asp?Action=AgentPayment&OrderFormID=" & rsOrder("OrderFormID") & "';}"">"
                End If
            End If
        End If
        If AdminPurview = 1 Or arrPurview(13) = True Then
            If rsOrder("MoneyReceipt") > 0 Then
                Response.Write "&nbsp;<input type='button' name='Submit' value='退 款' onClick=""window.location.href='Admin_Order.asp?Action=Refund&OrderFormID=" & rsOrder("OrderFormID") & "'"">"
            End If
        End If
        If AdminPurview = 1 Or arrPurview(7) = True Then
            If HaveSoft = True Then
                If rsOrder("EnableDownload") = False Then
                    Response.Write "&nbsp;<input type='button' name='Submit' value='开通下载' onClick=""javascript:if(confirm('确定要开通此订单中的软件类商品下载权限吗？')){window.location.href='Admin_Order.asp?Action=EnableDownload&OrderFormID=" & rsOrder("OrderFormID") & "';}"">"
                Else
                    Response.Write "&nbsp;<input type='button' name='Submit' value='取消下载' onClick=""window.location.href='Admin_Order.asp?Action=CancelDownload&OrderFormID=" & rsOrder("OrderFormID") & "'"">"
                End If
            End If
        End If
        If AdminPurview = 1 Or arrPurview(8) = True Then
            If HaveCard = True Then
                Response.Write "&nbsp;<input type='button' name='Submit' value='交付充值卡' onClick=""divSendCard.style.visibility='visible';"">"
            End If
        End If
        If AdminPurview = 1 Or arrPurview(6) = True Then
            Select Case rsOrder("DeliverStatus")
            Case 0, 1
                Response.Write "&nbsp;<input type='button' name='Submit' value=' 发 货 ' onClick=""window.location.href='Admin_Order.asp?Action=SendGoods&OrderFormID=" & rsOrder("OrderFormID") & "'"">"
            Case 2
                Response.Write "&nbsp;<input type='button' name='Submit' value='客户已签收' onClick=""javascript:if(confirm('确定客户已经签收了吗？')){window.location.href='Admin_Order.asp?Action=Received&OrderFormID=" & rsOrder("OrderFormID") & "';}"">"
            Case 3
                Response.Write "&nbsp;<input type='button' name='Submit' value='客户退货' onClick=""window.location.href='Admin_Order.asp?Action=ReturnGoods&OrderFormID=" & rsOrder("OrderFormID") & "'"">"
            End Select
        End If
        If AdminPurview = 1 Or arrPurview(5) = True Then
            If rsOrder("NeedInvoice") = True Then
                Response.Write "&nbsp;<input type='button' name='Submit' value=' 开发票 ' onClick=""window.location.href='Admin_Order.asp?Action=Invoice&OrderFormID=" & rsOrder("OrderFormID") & "'"">"
            End If
        End If
        'Response.Write "<br>"
        If AdminPurview = 1 Or arrPurview(9) = True Then
            If (rsOrder("Status") = 2 Or rsOrder("Status") = 3) And rsOrder("MoneyReceipt") >= rsOrder("MoneyTotal") And rsOrder("DeliverStatus") > 1 Then
                Response.Write "&nbsp;<input type='button' name='Submit' value='结清订单' onClick=""javascript:if(confirm('确定要结清此订单吗？一旦结清，将不能再对此订单做任何修改。')){window.location.href='Admin_Order.asp?Action=EndOrder&OrderFormID=" & rsOrder("OrderFormID") & "';}"">"
            End If
        End If
        If AdminPurview = 1 Or arrPurview(10) = True Then
            Response.Write "&nbsp;<input type='button' name='Submit' value='订单过户' onClick=""window.location.href='Admin_Order.asp?Action=Transfer&OrderFormID=" & rsOrder("OrderFormID") & "'"">"
        End If
        If AdminPurview = 1 Or arrPurview(11) = True Then
            Response.Write "&nbsp;<input type='button' name='Submit' value='打印订单' onClick=""window.location.href='Admin_Order.asp?Action=PrintOrder&OrderFormID=" & rsOrder("OrderFormID") & "'"">"
        End If
        If IsOfficial Then
            Response.Write "&nbsp;<input type='button' name='Submit' value='生成序列号' onClick=""window.location.href='Admin_SiteKey.asp?Action=CreateKey&OrderFormID=" & rsOrder("OrderFormID") & "'"">"
        End If
        If rsOrder("UserName") <> "" Then
            Response.Write "     <input type='button' name='Submit' value='手机短信' onClick=""window.location.href='Admin_SMS.asp?SendTo=Member&InceptType=2&UserName=" & rsOrder("UserName") & "'"">"
        End If
        Response.Write "</td>"
        Response.Write "  </tr>"
    End If
    Response.Write "</table>"
    Response.Write "<br><b>注：</b>“<font color='blue'>原价</font>”指商品的原始零售价，“<font color='green'>实价</font>”指系统根据 <a href='Admin_Help_Price.asp' target='_blank'>最终价格计算公式表</a> 自动计算出来的商品最终价格，“<font color='red'>指定价</font>”指管理员手动指定的最终价格。商品的最终销售价格以“指定价”为准。<br>"

    If Action = "PrintOrder" Then
        Response.Write "<br><br><table width='100%' id='Panel'><tr><td align='center'><input type='button' name='Print' value=' 打 印… ' onClick=""Panel.style.display='none';window.print()"">"
        Response.Write "&nbsp;&nbsp;&nbsp;&nbsp;<input type='button' name='View' value='查看订单' onClick=""window.location.href='Admin_Order.asp?Action=ShowOrder&OrderFormID=" & rsOrder("OrderFormID") & "'""></td></tr></table>"
        Exit Sub
    End If

    Response.Write "<div id='divConfirmOrder' style='Z-INDEX: 1000; VISIBILITY: hidden; Left:150px; Top:300px; WIDTH: 300px;HEIGHT: 100px;  POSITION: absolute; BACKGROUND-COLOR: #9cc5f8'>"
    Response.Write "<table width='100%'>"
    Response.Write "<form name='form8' method='post' action='Admin_Order.asp'>"
    Response.Write "<tr><td>请仔细检查此订单的所有信息，特别是实际销售价、售后服务期限等信息，确定无误后点“确认订单”按钮，否则请点击“取消”按钮。</td></tr>"
    Response.Write "<tr><td>"
    If EnableSMS = True Then
        Response.Write "<input type='checkbox' name='SendSMSToUser' value='Yes'" & GetPrevChoiceValue("SendSMSToUser_OrderConfirm") & ">同时发送手机短信通知会员订单已经确认<br><input type='checkbox' name='SendSMSToContacter' value='Yes'" & GetPrevChoiceValue("SendSMSToContacter_OrderConfirm") & ">同时发送手机短信通知收货人订单已经确认<br>"
    End If
    Response.Write "<input type='checkbox' name='SendMessageToUser' value='Yes' checked>同时使用站内短信通知会员订单已经确认<br><input type='checkbox' name='SendEmailToUser' value='Yes'>同时使用Email通知会员订单已经确认<br><input type='checkbox' name='SendEmailToContacter' value='Yes'>同时使用Email通知收货人订单已经确认</td></tr>"
    Response.Write "<tr><td align='center'><input type='submit' name='submit' value='确认订单'>&nbsp;&nbsp;&nbsp;&nbsp;<input type='button' name='hide' value=' 取 消 ' onClick=""divConfirmOrder.style.visibility='hidden';""><input type='hidden' name='Action' value='ConfirmOrder'><input type='hidden' name='OrderFormID' value='" & OrderFormID & "'></td></tr>"
    Response.Write "</form></table></div>"

    Response.Write "<div id='divSendCard' style='Z-INDEX: 1000; VISIBILITY: hidden; Left:350px; Top:300px; WIDTH: 300px;HEIGHT: 100px;  POSITION: absolute; BACKGROUND-COLOR: #9cc5f8'>"
    Response.Write "<table width='100%'>"
    Response.Write "<form name='form8' method='post' action='Admin_Order.asp'>"
    Response.Write "<tr><td>充值卡卡号和密码一旦交付就不能再收回！确定无误后点“确认交付”按钮，否则请点击“取消”按钮。</td></tr>"
    Response.Write "<tr><td>"
    If EnableSMS = True Then
        Response.Write "<input type='checkbox' name='SendSMSToUser' value='Yes'" & GetPrevChoiceValue("SendSMSToUser_SendCard") & ">同时发送手机短信通知会员已经交付充值卡<br><input type='checkbox' name='SendSMSToContacter' value='Yes'" & GetPrevChoiceValue("SendSMSToContacter_SendCard") & ">同时发送手机短信通知收货人已经交付充值卡<br>"
    End If
    Response.Write "<input type='checkbox' name='SendMessageToUser' value='Yes' checked>同时使用站内短信通知会员已经交付充值卡<br><input type='checkbox' name='SendEmailToUser' value='Yes'>同时使用Email通知会员已经交付充值卡<br><input type='checkbox' name='SendEmailToContacter' value='Yes'>同时使用Email通知收货人已经交付充值卡</td></tr>"
    Response.Write "<tr><td align='center'><input type='submit' name='submit' value='确认交付'>&nbsp;&nbsp;&nbsp;&nbsp;<input type='button' name='hide' value=' 取 消 ' onClick=""divSendCard.style.visibility='hidden';""><input type='hidden' name='Action' value='SendCard'><input type='hidden' name='OrderFormID' value='" & OrderFormID & "'></td></tr>"
    Response.Write "</form></table></div>"

    Response.Write "<script language='javascript'>" & vbCrLf
    Response.Write "var tID=0;" & vbCrLf
    Response.Write "function ShowTabs(ID){" & vbCrLf
    Response.Write "  if(ID!=tID){" & vbCrLf
    Response.Write "    TabTitle[tID].className='title5';" & vbCrLf
    Response.Write "    TabTitle[ID].className='title6';" & vbCrLf
    Response.Write "    Tabs[tID].style.display='none';" & vbCrLf
    Response.Write "    Tabs[ID].style.display='';" & vbCrLf
    Response.Write "    tID=ID;" & vbCrLf
    Response.Write "  }" & vbCrLf
    Response.Write "}" & vbCrLf
    Response.Write "</script>" & vbCrLf

    Response.Write "<table width='100%' border='0' cellpadding='0' cellspacing='0'><tr align='center' height='24'>" & vbCrLf
    Response.Write "  <td id='TabTitle' class='title6' onclick='ShowTabs(0)'>付款信息</td>" & vbCrLf
    Response.Write "  <td id='TabTitle' class='title5' onclick='ShowTabs(1)'>发票记录</td>" & vbCrLf
    Response.Write "  <td id='TabTitle' class='title5' onclick='ShowTabs(2)'>发退货记录</td>" & vbCrLf
    Response.Write "  <td id='TabTitle' class='title5' onclick='ShowTabs(3)'>过户记录</td>" & vbCrLf
    If IsOfficial Then
        Response.Write "  <td id='TabTitle' class='title5' onclick='ShowTabs(4)'>相关序列号</td>" & vbCrLf
    End If
    Response.Write "  <td>&nbsp;</td>" & vbCrLf
    Response.Write "</tr></table>" & vbCrLf

    Response.Write "<table width='100%' border='0' cellpadding='2' cellspacing='1' class='border' id='Tabs' style='display:'>" & vbCrLf
    Response.Write "  <tr align='center' class='title'>" & vbCrLf
    Response.Write "    <td width='80'>客户名称</td>" & vbCrLf
    Response.Write "    <td width='60'>用户名</td>" & vbCrLf
    Response.Write "    <td width='120'>交易时间</td>" & vbCrLf
    Response.Write "    <td width='60'>交易方式</td>" & vbCrLf
    Response.Write "    <td width='50'>币种</td>" & vbCrLf
    Response.Write "    <td width='60'>支出金额</td>" & vbCrLf
    Response.Write "    <td>备注/说明</td>" & vbCrLf
    Response.Write "    <td width='40'>操作</td>" & vbCrLf
    Response.Write "  </tr>" & vbCrLf

    Dim rsBankroll, sqlBankroll, TotalIncome, TotalPayout
    sqlBankroll = "select B.*,C.ShortedForm as ClientName from PE_BankrollItem B left join PE_Client C on B.ClientID=C.ClientID "
    sqlBankroll = sqlBankroll & " where OrderFormID=" & OrderFormID & " and Money<0 order by ItemID desc"
    Set rsBankroll = Conn.Execute(sqlBankroll)
    If rsBankroll.BOF And rsBankroll.EOF Then
        Response.Write "<tr class='tdbg'><td colspan='20' height='50' align='center'>没有相关付款记录</td></tr>" & vbCrLf
    Else
        Do While Not rsBankroll.EOF
            TotalPayout = TotalPayout + rsBankroll("Money")

            Response.Write "  <tr class='tdbg' onmouseout=""this.className='tdbg'"" onmouseover=""this.className='tdbgmouseover'"">" & vbCrLf
            Response.Write "    <td width='80' align='center'><a href='Admin_Client.asp?Action=Show&InfoType=3&ClientID=" & rsBankroll("ClientID") & "'>" & PE_HTMLEncode(rsBankroll("ClientName")) & "</a></td>" & vbCrLf
            Response.Write "    <td width='60' align='center'>" & rsBankroll("UserName") & "</td>" & vbCrLf
            Response.Write "    <td width='120' align='center'>" & rsBankroll("DateAndTime") & "</td>" & vbCrLf
            Response.Write "    <td width='60' align='center'>"
            Select Case rsBankroll("MoneyType")
            Case 1
                Response.Write "现金"
            Case 2
                Response.Write "银行汇款"
            Case 3
                Response.Write "在线支付"
            Case 4
                Response.Write "虚拟货币"
            End Select
            Response.Write "</td>" & vbCrLf
            Response.Write "    <td width='50' align='center'>"
            Select Case rsBankroll("CurrencyType")
            Case 1
                Response.Write "人民币"
            Case 2
                Response.Write "美元"
            Case 3
                Response.Write "其他"
            End Select
            Response.Write "</td>" & vbCrLf
            Response.Write "    <td width='60' align='right'>" & FormatNumber(rsBankroll("Money"), 2, vbTrue, vbFalse, vbTrue) & "</td>" & vbCrLf
            Response.Write "    <td>" & rsBankroll("Remark") & "</td>" & vbCrLf
            Response.Write "    <td align='center' width='40'><a href='Admin_Bankroll.asp?Action=ShowDetail&ItemID=" & rsBankroll("ItemID") & "'>查看</a></td>" & vbCrLf
            Response.Write "  </tr>" & vbCrLf

            rsBankroll.MoveNext
        Loop
    End If
    rsBankroll.Close
    Set rsBankroll = Nothing

    Response.Write "  <tr class='tdbg' onmouseout=""this.className='tdbg'"" onmouseover=""this.className='tdbgmouseover'"">" & vbCrLf
    Response.Write "    <td colspan='5' align='right'>合计金额：</td>" & vbCrLf
    Response.Write "    <td align='right'>" & FormatNumber(TotalPayout, 2, vbTrue, vbFalse, vbTrue) & "</td>" & vbCrLf
    Response.Write "    <td colspan='3' align='center'> </td>" & vbCrLf
    Response.Write "  </tr>" & vbCrLf
    Response.Write "</table>" & vbCrLf
    
    Response.Write "<table width='100%' border='0' cellpadding='2' cellspacing='1' class='border' id='Tabs' style='display:none'>" & vbCrLf
    Response.Write "  <tr align='center' class='title'>" & vbCrLf
    Response.Write "    <td width='80'>日期</td>" & vbCrLf
    Response.Write "    <td width='80'>发票类型</td>" & vbCrLf
    Response.Write "    <td width='80'>发票号码</td>" & vbCrLf
    Response.Write "    <td>发票抬头</td>" & vbCrLf
    Response.Write "    <td width='60'>发票金额</td>" & vbCrLf
    Response.Write "    <td width='60'>开票人</td>" & vbCrLf
    Response.Write "    <td width='60'>录入员</td>" & vbCrLf
    Response.Write "    <td width='120'>录入时间</td>" & vbCrLf
    Response.Write "    <td width='40'>操作</td>" & vbCrLf
    Response.Write "  </tr>" & vbCrLf

    Dim rsInvoice
    Set rsInvoice = Conn.Execute("select * from PE_InvoiceItem where OrderFormID=" & OrderFormID & " order by InvoiceID")
    If rsInvoice.BOF And rsInvoice.EOF Then
        Response.Write "<tr class='tdbg'><td colspan='20' height='50' align='center'>没有相关发票记录</td></tr>" & vbCrLf
    Else
        Do While Not rsInvoice.EOF
            Response.Write "  <tr class='tdbg' onmouseout=""this.className='tdbg'"" onmouseover=""this.className='tdbgmouseover'"">" & vbCrLf
            Response.Write "    <td width='80' align='center'>" & rsInvoice("InvoiceDate") & "</td>" & vbCrLf
            Response.Write "    <td width='80' align='center'>"
            Select Case rsInvoice("InvoiceType")
            Case 0
                Response.Write "地税普通发票"
            Case 1
                Response.Write "国税普通发票"
            Case 2
                Response.Write "增值税发票"
            End Select
            Response.Write "</td>" & vbCrLf
            Response.Write "    <td width='80' align='center'><a href='Admin_Invoice.asp?Action=Show&InvoiceID=" & rsInvoice("InvoiceID") & "'>" & rsInvoice("InvoiceNum") & "</a></td>" & vbCrLf
            Response.Write "    <td>" & rsInvoice("InvoiceTitle") & "</td>" & vbCrLf
            Response.Write "    <td width='60' align='right'>" & rsInvoice("TotalMoney") & "</td>" & vbCrLf
            Response.Write "    <td width='60' align='center'>" & rsInvoice("Drawer") & "</td>" & vbCrLf
            Response.Write "    <td width='60' align='center'>" & rsInvoice("Inputer") & "</td>" & vbCrLf
            Response.Write "    <td width='120' align='center'>" & rsInvoice("InputTime") & "</td>" & vbCrLf
            Response.Write "    <td width='40' align='center'><a href='Admin_Invoice.asp?Action=Show&InvoiceID=" & rsInvoice("InvoiceID") & "'>查看</a></td>" & vbCrLf
            Response.Write "  </tr>" & vbCrLf

            rsInvoice.MoveNext
        Loop
    End If
    rsInvoice.Close
    Set rsInvoice = Nothing
    Response.Write "</table>" & vbCrLf
    
    Response.Write "<table width='100%' border='0' cellpadding='2' cellspacing='1' class='border' id='Tabs' style='display:none'>" & vbCrLf
    Response.Write "  <tr align='center' class='title'>" & vbCrLf
    Response.Write "    <td width='80'>日期</td>" & vbCrLf
    Response.Write "    <td width='80'>发货/客户退货</td>" & vbCrLf
    Response.Write "    <td width='80'>快递公司名</td>" & vbCrLf
    Response.Write "    <td width='80'>快递单号</td>" & vbCrLf
    Response.Write "    <td width='60'>经手人</td>" & vbCrLf
    Response.Write "    <td width='60'>录入员</td>" & vbCrLf
    Response.Write "    <td width='60'>客户已签收</td>" & vbCrLf
    Response.Write "    <td>备注/退货原因</td>" & vbCrLf
    Response.Write "    <td width='40'>操作</td>" & vbCrLf
    Response.Write "  </tr>" & vbCrLf

    Dim rsDeliver
    Set rsDeliver = Conn.Execute("select * from PE_DeliverItem where OrderFormID=" & OrderFormID & " order by DeliverID")
    If rsDeliver.BOF And rsDeliver.EOF Then
        Response.Write "<tr class='tdbg'><td colspan='20' height='50' align='center'>没有相关发退货记录</td></tr>" & vbCrLf
    Else
        Do While Not rsDeliver.EOF
            Response.Write "  <tr class='tdbg' onmouseout=""this.className='tdbg'"" onmouseover=""this.className='tdbgmouseover'"">" & vbCrLf
            Response.Write "    <td width='80' align='center'>" & rsDeliver("DeliverDate") & "</td>" & vbCrLf
            Response.Write "    <td width='80' align='center'>"
            If rsDeliver("DeliverDirection") = 1 Then
                Response.Write "发货"
            Else
                Response.Write "<font color='red'>退货</font>"
            End If
            Response.Write "</td>" & vbCrLf
            Response.Write "    <td width='80' align='center'>" & rsDeliver("ExpressCompany") & "</td>" & vbCrLf
            Response.Write "    <td width='80' align='center'>" & rsDeliver("ExpressNumber") & "</td>" & vbCrLf
            Response.Write "    <td width='60' align='center'>" & rsDeliver("HandlerName") & "</td>" & vbCrLf
            Response.Write "    <td width='60' align='center'>" & rsDeliver("Inputer") & "</td>" & vbCrLf
            Response.Write "    <td width='60' align='center'>"
            If rsDeliver("Received") = True Then
                Response.Write "<font color='red'><b>√</b></font>"
            End If
            Response.Write "</td>" & vbCrLf
            Response.Write "    <td>" & rsDeliver("Remark") & "</td>" & vbCrLf
            Response.Write "    <td width='40' align='center'><a href='Admin_Deliver.asp?Action=ShowDetail&DeliverID=" & rsDeliver("DeliverID") & "'>查看</a></td>" & vbCrLf
            Response.Write "  </tr>" & vbCrLf

            rsDeliver.MoveNext
        Loop
    End If
    rsDeliver.Close
    Set rsDeliver = Nothing
    Response.Write "</table>" & vbCrLf

    Response.Write "<table width='100%' border='0' cellpadding='2' cellspacing='1' class='border' id='Tabs' style='display:none'>"
    Response.Write "  <tr align='center' class='title'>"
    Response.Write "    <td width='120'>时间</td>"
    Response.Write "    <td width='60'>过户人</td>"
    Response.Write "    <td width='60'>过户给</td>"
    Response.Write "    <td width='40'>过户费</td>"
    Response.Write "    <td width='60'>付款人</td>"
    Response.Write "    <td>备注</td>"
    Response.Write "    <td width='60'>经手人</td>"
    Response.Write "  </tr>"
    Dim rsTransfer

    Set rsTransfer = Conn.Execute("select * from PE_TransferItem where OrderFormID=" & OrderFormID & " order by ItemID desc")
    If rsTransfer.BOF And rsTransfer.EOF Then
        Response.Write "<tr class='tdbg' height='50'><td colspan='20' align='center'>没有相关过户记录</td></tr>"
    Else
        Do While Not rsTransfer.EOF
            Response.Write "  <tr class='tdbg' onmouseout=""this.className='tdbg'"" onmouseover=""this.className='tdbgmouseover'"">"
            Response.Write "    <td width='120' align='center'>" & rsTransfer("DateAndTime") & "</td>"
            Response.Write "    <td width='60' align='center'>" & rsTransfer("OwnerUserName") & "</td>"
            Response.Write "    <td width='60' align='center'>" & rsTransfer("TargetUserName") & "</td>"
            Response.Write "    <td width='40' align='center'>" & rsTransfer("Poundage") & "</td>"
            Response.Write "    <td width='60' align='center'>" & rsTransfer("PayerUserName") & "</td>"
            Response.Write "    <td>" & rsTransfer("Remark") & "</td>"
            Response.Write "    <td width='60' align='center'>" & rsTransfer("Inputer") & "</td>"
            Response.Write "  </tr>"
            rsTransfer.MoveNext
        Loop
    End If
    rsTransfer.Close
    Set rsTransfer = Nothing

    Response.Write "</table>"

    If IsOfficial Then
        Response.Write "<table width='100%' border='0' cellpadding='2' cellspacing='1' class='border' id='Tabs' style='display:none'>" & vbCrLf
        Response.Write "  <tr align='center' class='title'>" & vbCrLf
        Response.Write "    <td width='150'>对应的产品</td>" & vbCrLf
        Response.Write "    <td width='150'>绑定的域名</td>" & vbCrLf
        Response.Write "    <td width='120'>生成时间</td>" & vbCrLf
        Response.Write "    <td width='80'>截止日期</td>" & vbCrLf
        Response.Write "    <td width='80'>管理员</td>" & vbCrLf
        Response.Write "    <td>说明</td>" & vbCrLf
        Response.Write "    <td width='50'>状态</td>" & vbCrLf
        Response.Write "    <td width='50'>操作</td>" & vbCrLf
        Response.Write "  </tr>" & vbCrLf

        Dim rsSiteKey, arrEdition, arrTemp
        arrEdition = Array("CMS 2006标准版", "CMS 2006专业版", "CMS 2006企业版", "eShop 2006标准版", "eShop 2006专业版", "eShop 2006企业版", "CRM 2006标准版", "CRM 2006专业版", "CRM 2006企业版", "问卷调查系统")
        Set rsSiteKey = Conn.Execute("select * from PE_SiteKey where OrderFormID=" & OrderFormID & " order by CreateTime Desc")
        If rsSiteKey.BOF And rsSiteKey.EOF Then
            Response.Write "<tr class='tdbg'><td colspan='20' height='50' align='center'>没有相关序列号</td></tr>" & vbCrLf
        Else
            Do While Not rsSiteKey.EOF
                Response.Write "  <tr class='tdbg' onmouseout=""this.className='tdbg'"" onmouseover=""this.className='tdbgmouseover'"">" & vbCrLf
                Response.Write "    <td width='150' align='left'>"
                Select Case rsSiteKey("SystemVersion")
                Case 403
                    Response.Write "动易4.03"
                    Select Case rsSiteKey("SystemEdition")
                    Case "1"
                        Response.Write "个人"
                    Case "3"
                        Response.Write "企业"
                    End Select
                    Select Case rsSiteKey("DatabaseType")
                    Case "1"
                        Response.Write "Access版"
                    Case "2"
                        Response.Write "SQL版"
                    End Select
                Case 2005
                    Response.Write "动易2005"
                    Select Case rsSiteKey("SystemEdition")
                    Case "1"
                        Response.Write "个人"
                    Case "2"
                        Response.Write "标准"
                    Case "3"
                        Response.Write "企业"
                    Case "4"
                        Response.Write "学校"
                    Case "5"
                        Response.Write "政府"
                    Case "9"
                        Response.Write "全能"
                    End Select
                    Select Case rsSiteKey("DatabaseType")
                    Case 1
                        Response.Write "Access版"
                    Case 2
                        Response.Write "SQL版"
                    End Select
                Case 2006
                    Response.Write "动易"
                    arrTemp = Split(rsSiteKey("SystemEdition"), "|")
                    Response.Write arrEdition(CLng(arrTemp(0)) - 1)
                    If arrTemp(1) = "1" Then
                        Response.Write "+SDMS"
                    End If
                    If arrTemp(2) = "1" Then
                        Response.Write "+Equipment"
                    End If
                    If arrTemp(3) = "1" Then
                        Response.Write "+HR"
                    End If
                    If arrTemp(4) = "1" Then
                        Response.Write "+SD"
                    End If
                    If arrTemp(5) = "1" Then
                        Response.Write "+House"
                    End If
                End Select
                Response.Write "</td>" & vbCrLf
                Response.Write "    <td width='150' align='center'>" & rsSiteKey("SiteUrl") & "</td>" & vbCrLf
                Response.Write "    <td width='120' align='center'>" & rsSiteKey("CreateTime") & "</td>" & vbCrLf
                Response.Write "    <td width='80' align='center'>" & rsSiteKey("EndDate") & "</td>" & vbCrLf
                Response.Write "    <td width='60' align='center'>" & rsSiteKey("Creater") & "</td>" & vbCrLf
                Response.Write "    <td>" & rsSiteKey("Remark") & "</td>" & vbCrLf
                Response.Write "    <td width='50' align='center'>"
                If rsSiteKey("Disabled") = False Then
                    Response.Write "正常"
                Else
                    Response.Write "<font color='red'>被禁用</font>"
                End If
                Response.Write "    </td>" & vbCrLf
                Response.Write "    <td width='50' align='center'>"
                If AdminPurview = 1 Then
                    Response.Write "<a href='Admin_SiteKey.asp?Action=Del&ID=" & rsSiteKey("ID") & "' onclick=""return confirm('确定要删除此序列号吗？')"">删除</a><br>"
                End If
                If rsSiteKey("Disabled") = False Then
                    Response.Write "<a href='Admin_SiteKey.asp?Action=Disable&ID=" & rsSiteKey("ID") & "'>禁用</a>"
                Else
                    Response.Write "<a href='Admin_SiteKey.asp?Action=Enable&ID=" & rsSiteKey("ID") & "'>启用</a>"
                End If
                Response.Write "    </td>" & vbCrLf
                Response.Write "  </tr>" & vbCrLf

                rsSiteKey.MoveNext
            Loop
        End If
        rsSiteKey.Close
        Set rsSiteKey = Nothing
        Response.Write "</table>" & vbCrLf
    End If
    
    Response.Write "<br>"
    Response.Write "<b><font color='#0000FF'>订单处理流程：</font></b>①客户下单 --&gt; ②修改订单 --&gt; ③确认订单 --&gt; ④添加汇款信息/添加支付信息 --&gt; ⑤开通下载、发货，开发票 --&gt; ⑥结清订单<br>"
    Response.Write "<br>"
    Response.Write "<b><font color='#0000FF'>①客户下单</font></b>——指客户在前台选购商品，并生成订单。<br>"
    Response.Write "<font color='#0000FF'><b>②修改订单</b></font>——指根据与客户联系，确认有关订单信息是否正确，录入与客户谈定的实际销售价及服务期限等。<br>"
    Response.Write "<b><font color='#0000FF'>③确认订单</font></b>——指确认订单正确无误后，将此订单锁定以防客户修改订单内容。<font color='#006600'>订单一旦被确认后，客户就不可再修改或删除，管理员也不能修改订单中的商品数据。</font><br>"
    Response.Write "<b><font color='#0000FF'>④银行汇款支付</font></b>——指确认客户从银行汇的款项到账后，为客户录入汇款信息，<font color='red'>然后支付此订单费用。</font><br>"
    Response.Write "<b><font color='#0000FF'>&nbsp;&nbsp;虚拟货币支付</font></b>——指从客户的资金余额中直接扣除款项用于支付此订单费用。<br> "
    Response.Write "<b><font color='#0000FF'>⑤发货</font></b>——指录入此订单的发货信息<br><b><font color='#0000FF'>&nbsp;&nbsp;开通下载</font></b>——指对此订单中的软件类商品开通下载权限。<br><b><font color='#0000FF'>&nbsp;&nbsp;交付充值卡</font></b>——指对此订单中的点卡类商品交付卡号和密码。<br>"
    Response.Write "<b><font color='#0000FF'>⑥结清订单</font></b>——指当以上步骤都完成后，客户也已经付清此订单的所有款项后，将此订单结清。结清时，返还现金券并赠送积分。<font color='#FF0000'>结清后，此订单的所有相关信息都不可再修改。</font><br> "
    Response.Write "<b><font color='#0000FF'>⑦订单过户</font></b>——指将某个客户的订单过户给另一客户。但相关的资金明细情况仍为原客户的。<br>"
End Sub

Sub RemitAndPay()

    If AdminPurview > 1 And arrPurview(4) = False Then
        Response.Write "<br><p align='center'><font color='red' style='font-size:9pt'>对不起，你没有此项操作的权限。</font></p>"
        Call WriteEntry(6, AdminName, "越权操作")
        Exit Sub
    End If
    
    Dim OrderFormID, Money, trs
    Dim rsOrder, sqlOrder
    OrderFormID = Trim(Request("OrderFormID"))
    If OrderFormID = "" Then
        FoundErr = True
        ErrMsg = ErrMsg & "<li>请指定订单ID</li>"
        Exit Sub
    Else
        OrderFormID = PE_CLng(OrderFormID)
    End If
    
    sqlOrder = "select O.OrderFormNum,O.UserName,C.ClientName,O.Status,O.MoneyTotal,O.MoneyReceipt from PE_OrderForm O left join PE_Client C on O.ClientID=C.ClientID where OrderFormID=" & OrderFormID
    Set rsOrder = Conn.Execute(sqlOrder)
    If rsOrder.BOF And rsOrder.EOF Then
        FoundErr = True
        ErrMsg = ErrMsg & "<li>找不到指定的订单！</li>"
        rsOrder.Close
        Set rsOrder = Nothing
        Exit Sub
    End If
    If rsOrder("MoneyTotal") <= rsOrder("MoneyReceipt") Then
        FoundErr = True
        ErrMsg = ErrMsg & "<li>此订单已经付清，无需再添加汇款记录！</li>"
        rsOrder.Close
        Set rsOrder = Nothing
        Exit Sub
    End If
    Money = rsOrder("MoneyTotal") - rsOrder("MoneyReceipt")

    Response.Write "<form name='form4' method='post' action='Admin_Order.asp' onsubmit=""return confirm('确定所输入的信息都完全正确吗？一旦输入就不可更改哦！')"">"
    Response.Write "  <table width='100%' border='0' cellpadding='2' cellspacing='1' class='border'>"
    Response.Write "    <tr align='center' class='title'>"
    Response.Write "      <td height='22' colspan='2'><b>添 加 订 单 汇 款 信 息</b></td>"
    Response.Write "    </tr>"
    Response.Write "    <tr class='tdbg'>"
    Response.Write "      <td width='15%' class='tdbg5' align='right'>客户名称：</td>"
    Response.Write "      <td>" & PE_HTMLEncode(rsOrder("ClientName")) & "</td>"
    Response.Write "    </tr>"
    Response.Write "    <tr class='tdbg'>"
    Response.Write "      <td width='15%' class='tdbg5' align='right'>用户名：</td>"
    Response.Write "      <td>" & rsOrder("UserName") & "</td>"
    Response.Write "    </tr>"
        
    Response.Write "    <tr class='tdbg'>"
    Response.Write "      <td width='15%' class='tdbg5' align='right'>支付内容：</td>"
    Response.Write "      <td><table  border='0' cellspacing='2' cellpadding='0'>"
    Response.Write "        <tr class='tdbg'>"
    Response.Write "          <td width='15%' class='tdbg5' align='right'>订单编号：</td>"
    Response.Write "          <td>" & rsOrder("OrderFormNum") & "</td>"
    Response.Write "          <td>&nbsp;</td>"
    Response.Write "        </tr>"
    Response.Write "        <tr class='tdbg'>"
    Response.Write "          <td width='15%' class='tdbg5' align='right'>订单金额：</td>"
    Response.Write "          <td>" & rsOrder("MoneyTotal") & "元</td>"
    Response.Write "          <td><font color='#0000FF'>此笔汇款将直接用于支付此订单的费用。</font></td>"
    Response.Write "        </tr>"
    Response.Write "        <tr class='tdbg'>"
    Response.Write "          <td width='15%' class='tdbg5' align='right'>已 付 款：</td>"
    Response.Write "          <td>" & rsOrder("MoneyReceipt") & "元</td>"
    Response.Write "          <td>&nbsp;</td>"
    Response.Write "        </tr>"
    Response.Write "      </table>"
    Response.Write "      </td>"
    Response.Write "    </tr>"
    rsOrder.Close
    Set rsOrder = Nothing

    Response.Write "    <tr class='tdbg'>"
    Response.Write "      <td width='15%' class='tdbg5' align='right'>汇款日期：</td>"
    Response.Write "      <td><input name='ReceiptDate' type='text' id='ReceiptDate' value='" & Date & "' size='15' maxlength='30'></td>"
    Response.Write "    </tr>"
    Response.Write "    <tr class='tdbg'>"
    Response.Write "      <td width='15%' class='tdbg5' align='right'>汇款金额：</td>"
    Response.Write "      <td><input name='Money' type='text' id='Money' value='" & Money & "' size='10' maxlength='10'> 元</td>"
    Response.Write "    </tr>"
    Response.Write "    <tr class='tdbg'>"
    Response.Write "      <td width='15%' class='tdbg5' align='right'>汇入银行：</td>"
    Response.Write "      <td><select name='Bank' id='Bank'>"
    Dim rsBank
    Set rsBank = Conn.Execute("select BankShortName,IsDefault from PE_Bank where IsDisabled=" & PE_False & " order by OrderID")
    Do While Not rsBank.EOF
        Response.Write "<option value='" & rsBank(0) & "'"
        If rsBank(1) = True Then Response.Write " selected"
        Response.Write ">" & rsBank(0) & "</option>"
        rsBank.MoveNext
    Loop
    Set rsBank = Nothing
    
    Response.Write "      </select></td>"
    Response.Write "    </tr>"
    Response.Write "    <tr class='tdbg'>"
    Response.Write "      <td width='15%' class='tdbg5' align='right'>备注：</td>"
    Response.Write "      <td><input name='Remark' type='text' id='Remark' size='50' maxlength='200'></td>"
    Response.Write "    </tr>"
    Response.Write "    <tr class='tdbg'>"
    Response.Write "      <td width='15%' class='tdbg5' align='right'>通知会员：</td><td>"
    If EnableSMS = True Then
        Response.Write "      <input type='checkbox' name='SendSMSToUser' value='Yes'" & GetPrevChoiceValue("SendSMSToUser_ReceiptMoney") & ">同时发送手机短信通知会员已经收到汇款<br>"
        Response.Write "      <input type='checkbox' name='SendSMSToContacter' value='Yes'" & GetPrevChoiceValue("SendSMSToContacter_ReceiptMoney") & ">同时发送手机短信通知收货人已经收到汇款<br>"
    End If
    Response.Write "      <input type='checkbox' name='SendMessageToUser' value='Yes' checked>同时使用站内短信通知会员已经收到汇款<br>"
    Response.Write "      <input type='checkbox' name='SendEmailToUser' value='Yes'>同时使用Email通知会员已经收到汇款<br>"
    Response.Write "      <input type='checkbox' name='SendEmailToContacter' value='Yes'>同时使用Email通知收货人已经收到汇款"
    Response.Write "      </td>"
    Response.Write "    </tr>"
    Response.Write "    <tr class='tdbg'>"
    Response.Write "      <td height='30' colspan='2'><b><font color='#FF0000'>注意：汇款信息一旦录入，就不能再修改或删除！所以在保存之前确认输入无误！</font></b></td>"
    Response.Write "    </tr>"
    Response.Write "    <tr align='center' class='tdbg'>"
    Response.Write "      <td height='30' colspan='2'><input name='Action' type='hidden' id='Action' value='DoRemitAndPay'>"
    Response.Write "      <input name='OrderFormID' type='hidden' id='OrderFormID' value='" & OrderFormID & "'>"
    Response.Write "      <input type='submit' name='Submit' value=' 保存汇款信息 '></td>"
    Response.Write "    </tr>"
    Response.Write "  </table>"
    Response.Write "</form>"
End Sub

Sub DoRemitAndPay()
    If AdminPurview > 1 And arrPurview(4) = False Then
        Response.Write "<br><p align='center'><font color='red' style='font-size:9pt'>对不起，你没有此项操作的权限。</font></p>"
        Call WriteEntry(6, AdminName, "越权操作")
        Exit Sub
    End If
    
    Dim OrderFormID, Money, ReceiptDate, Bank, Remark
    Dim rsOrder, rsBankroll, ItemID, trs
    OrderFormID = Trim(Request("OrderFormID"))
    Money = PE_CDbl(Trim(Request("Money")))
    ReceiptDate = Trim(Request("ReceiptDate"))
    Bank = Trim(Request("Bank"))
    Remark = Trim(Request("Remark"))
    If OrderFormID = "" Then
        FoundErr = True
        ErrMsg = ErrMsg & "<li>请指定订单ID！</li>"
    Else
        OrderFormID = PE_CLng(OrderFormID)
    End If
    If Money <= 0 Then
        FoundErr = True
        ErrMsg = ErrMsg & "<li>请输入汇款金额！</li>"
    End If
    If ReceiptDate = "" Then
        FoundErr = True
        ErrMsg = ErrMsg & "<li>请输入汇款日期！</li>"
    Else
        ReceiptDate = CDate(ReceiptDate)
    End If
    If Bank = "" Then
        FoundErr = True
        ErrMsg = ErrMsg & "<li>请输入银行名称！</li>"
    End If

    
    If FoundErr = True Then Exit Sub
    
    Set rsOrder = Server.CreateObject("adodb.recordset")
    rsOrder.Open "select * from PE_OrderForm where OrderFormID=" & OrderFormID & "", Conn, 1, 3
    If Not (rsOrder.BOF And rsOrder.EOF) Then
        If rsOrder("UserName") <> "" Then
            Conn.Execute ("update PE_User set Balance=Balance+" & Money & " where UserName='" & rsOrder("UserName") & "'")
        Else
            If rsOrder("ClientID") > 0 Then
                Conn.Execute ("update PE_Client set Balance=Balance+" & Money & " where ClientID=" & rsOrder("ClientID") & "")
            End If
        End If

        ' 向资金明细表中添加收入记录
        Call AddBankrollItem(AdminName, rsOrder("UserName"), rsOrder("ClientID"), Money, 2, Bank, 0, 1, 0, 0, Remark, ReceiptDate)
        
        If rsOrder("MoneyReceipt") < rsOrder("MoneyTotal") Then
            rsOrder("MoneyReceipt") = rsOrder("MoneyReceipt") + Money
            If rsOrder("Status") <= 2 Then
                rsOrder("Status") = 3
            End If
            rsOrder.Update
            If rsOrder("UserName") <> "" Then
                Conn.Execute ("update PE_User set Balance=Balance-" & Money & " where UserName='" & rsOrder("UserName") & "'")
            Else
                If rsOrder("ClientID") > 0 Then
                    Conn.Execute ("update PE_Client set Balance=Balance-" & Money & " where ClientID=" & rsOrder("ClientID") & "")
                End If
            End If
                    
            '向资金明细表中添加支出记录
            Call AddBankrollItem(AdminName, rsOrder("UserName"), rsOrder("ClientID"), Money, 4, "", 0, 2, OrderFormID, 0, "支付订单费用，订单号：" & rsOrder("OrderFormNum"), Now())
        End If
    End If
    Dim strMsg
    strMsg = "保存汇款信息成功！"
    
    Response.Cookies(Site_Sn)("SendSMSToUser_ReceiptMoney") = Trim(Request("SendSMSToUser"))
    Response.Cookies(Site_Sn)("SendSMSToContacter_ReceiptMoney") = Trim(Request("SendSMSToContacter"))

    strMsg = strMsg & SendMessageOfOrder(MessageOfReceiptMoney, "已经收到汇款", rsOrder)
    strMsg = strMsg & SendEmailOfOrder("收到汇款通知", EmailOfReceiptMoney, "已经收到汇款", rsOrder)
    rsOrder.Close
    Set rsOrder = Nothing

    Call WriteSuccessMsg(strMsg, "Admin_Order.asp?Action=ShowOrder&OrderFormID=" & OrderFormID & "")
    If ErrMsg <> "" Then
        FoundErr = True
    End If
End Sub

Sub AgentPayment()
    If AdminPurview > 1 And arrPurview(15) = False Then
        Response.Write "<br><p align='center'><font color='red' style='font-size:9pt'>对不起，你没有此项操作的权限。</font></p>"
        Call WriteEntry(6, AdminName, "越权操作")
        Exit Sub
    End If
    
    Dim OrderFormID, rsOrder, dblTotal, Discount_Payment, Charge_Deliver
    Dim Money, Margin, AgentBalance
    Dim rsOrderItem, rsBankroll, ItemID, dblAmount, dblSubtotal, Price_Agent
    Dim rsAgent, AgentClientID, Discount_Member, AgentGroupSetting, IsRepeatDiscount
    OrderFormID = Trim(Request("OrderFormID"))
    If OrderFormID = "" Then
        FoundErr = True
        ErrMsg = ErrMsg & "<li>请指定订单ID！</li>"
    Else
        OrderFormID = PE_CLng(OrderFormID)
    End If
    If FoundErr = True Then Exit Sub

    Set rsOrder = Server.CreateObject("adodb.recordset")
    rsOrder.Open "select * from PE_OrderForm where OrderFormID=" & OrderFormID & "", Conn, 1, 3
    If Not (rsOrder.BOF And rsOrder.EOF) Then
        If rsOrder("AgentName") <> "" And rsOrder("MoneyReceipt") < rsOrder("MoneyTotal") Then
            Set rsAgent = Conn.Execute("select U.Balance,U.ClientID,G.GroupSetting,U.SpecialPermission,U.UserSetting from PE_User U inner join PE_UserGroup G On U.GroupID = G.GroupID where UserName='" & rsOrder("AgentName") & "'")
            If rsAgent.BOF And rsAgent.EOF Then
                FoundErr = True
                ErrMsg = ErrMsg & "<li>找不到指定的代理商！</li>"
            Else
                AgentBalance = rsAgent("Balance")
                AgentClientID = rsAgent("ClientID")
                If rsAgent("SpecialPermission") Then
                    AgentGroupSetting = Split(rsAgent("UserSetting"), ",")
                Else
                    AgentGroupSetting = Split(rsAgent("GroupSetting"), ",")
                End If
                Discount_Member = PE_CDbl(AgentGroupSetting(11))
                IsRepeatDiscount = PE_CLng(AgentGroupSetting(12))
            End If
            Set rsAgent = Nothing
            If FoundErr = True Then
                rsOrder.Close
                Set rsOrder = Nothing
                Exit Sub
            End If

            '计算代理差额
            If rsOrder("AgentName") <> rsOrder("UserName") Then
                Set rsOrderItem = Conn.Execute("select I.SaleType,P.Price_Original,P.Price,I.TruePrice,I.Amount,I.SubTotal,P.Price_Agent from PE_OrderFormItem I inner join PE_Product P on I.ProductID=P.ProductID where I.OrderFormID=" & OrderFormID & " order by I.ItemID")
                Do While Not rsOrderItem.EOF
                    dblAmount = rsOrderItem("Amount")
                    If rsOrderItem("SaleType") = 1 Then
                        If rsOrderItem("Price_Agent") > 0 Then '如果指定了代理价
                            Price_Agent = rsOrderItem("Price_Agent")
                        Else
                            If Discount_Member = 100 Then
                                Price_Agent = rsOrderItem("Price")
                            Else
                                If IsRepeatDiscount = 1 Then '如可以享受折上折优惠
                                    Price_Agent = rsOrderItem("Price") * Discount_Member / 100
                                Else
                                    If rsOrderItem("Price_Original") * Discount_Member / 100 <= rsOrderItem("Price") Then
                                        Price_Agent = rsOrderItem("Price_Original") * Discount_Member / 100
                                    Else
                                        Price_Agent = rsOrderItem("Price")
                                    End If
                                End If
                            End If
                        End If
                        dblSubtotal = Price_Agent * dblAmount
                    Else
                        dblSubtotal = rsOrderItem("SubTotal")
                    End If
                    dblTotal = dblTotal + dblSubtotal
                    rsOrderItem.MoveNext
                Loop
                Set rsOrderItem = Nothing
                Discount_Payment = rsOrder("Discount_Payment")
                Charge_Deliver = rsOrder("Charge_Deliver")
                If Discount_Payment > 0 And Discount_Payment < 100 Then
                    dblTotal = dblTotal * Discount_Payment / 100
                End If
                dblTotal = dblTotal + Charge_Deliver
                If IncludeTax = True Then
                    If rsOrder("NeedInvoice") <> True Then
                        dblTotal = dblTotal * (100 - TaxRate) / 100
                    End If
                Else
                    If rsOrder("NeedInvoice") = True Then
                        dblTotal = dblTotal * (100 + TaxRate) / 100
                    End If
                End If
                dblTotal = Round(dblTotal, 2)
                Margin = rsOrder("MoneyTotal") - dblTotal
            Else
                Margin = 0
            End If
            If Margin < 0 Then Margin = 0

            Money = rsOrder("MoneyTotal") - rsOrder("MoneyReceipt")
            If AgentBalance < Money - Margin Then
                FoundErr = True
                ErrMsg = ErrMsg & "<li>代理商资金余额小于支出金额！</li>"
            End If
            If FoundErr = True Then
                rsOrder.Close
                Set rsOrder = Nothing
                Exit Sub
            End If

            rsOrder("MoneyReceipt") = rsOrder("MoneyTotal")
            If rsOrder("Status") <= 2 Then
                rsOrder("Status") = 3
            End If
            rsOrder.Update
            Conn.Execute ("update PE_User set Balance=Balance-" & Money & " where UserName='" & rsOrder("AgentName") & "'")
                    
            '向资金明细表中添加支出记录
            Call AddBankrollItem(AdminName, rsOrder("AgentName"), AgentClientID, Money, 4, "", 0, 2, OrderFormID, 0, "支付订单费用，订单号：" & rsOrder("OrderFormNum"), Now())


            If Margin <> 0 Then
                Conn.Execute ("update PE_User set Balance=Balance+" & Margin & " where UserName='" & rsOrder("AgentName") & "'")
                ' 向资金明细表中添加收入记录
                Call AddBankrollItem(AdminName, rsOrder("AgentName"), AgentClientID, Margin, 4, "", 0, 1, OrderFormID, 0, "返还代理订单差额，订单号：" & rsOrder("OrderFormNum"), Now())
            End If
        End If
    End If
    Dim strMsg
    strMsg = "代理商余额支付成功！"
    rsOrder.Close
    Set rsOrder = Nothing
    Call WriteSuccessMsg(strMsg, "Admin_Order.asp?Action=ShowOrder&OrderFormID=" & OrderFormID & "")
End Sub

Sub ModifyOrder()
    If AdminPurview > 1 And arrPurview(2) = False Then
        Response.Write "<br><p align='center'><font color='red' style='font-size:9pt'>对不起，你没有此项操作的权限。</font></p>"
        Call WriteEntry(6, AdminName, "越权操作")
        Exit Sub
    End If

    Dim OrderFormID
    Dim rsOrder, sqlOrder
    Dim rsProduct, strProduct
    OrderFormID = Trim(Request("OrderFormID"))
    If OrderFormID = "" Then
        FoundErr = True
        ErrMsg = ErrMsg & "<li>请指定订单ID！</li>"
    Else
        OrderFormID = PE_CLng(OrderFormID)
    End If
    If FoundErr = True Then Exit Sub
    
    sqlOrder = "select O.*,C.ClientName from PE_OrderForm O left join PE_Client C on O.ClientID=C.ClientID where OrderFormID=" & OrderFormID & ""
    Set rsOrder = Conn.Execute(sqlOrder)
    If rsOrder.BOF And rsOrder.EOF Then
        FoundErr = True
        ErrMsg = ErrMsg & "<li>找不到指定的订单！</li>"
        rsOrder.Close
        Set rsOrder = Nothing
        Exit Sub
    End If
    
    Response.Write "<script language='javascript'>" & vbCrLf
    Response.Write "function SelectAgent(){" & vbCrLf
    Response.Write "    var arr=showModalDialog('Admin_SourceList.asp?TypeSelect=AgentList','','dialogWidth:600px; dialogHeight:450px; help: no; scroll: yes; status: no');" & vbCrLf
    Response.Write "    if (arr != null){" & vbCrLf
    Response.Write "        document.myform.AgentName.value=arr;" & vbCrLf
    Response.Write "    }" & vbCrLf
    Response.Write "}" & vbCrLf
    Response.Write "</script>" & vbCrLf
    Response.Write "<form name='myform' method='post' action='Admin_Order.asp'>" & vbCrLf
    Response.Write "<table width='100%' border='0' align='center' cellpadding='2' cellspacing='1' class='border'>" & vbCrLf
    Response.Write "  <tr align='center' class='title'>" & vbCrLf
    Response.Write "    <td height='22'><b>修 改 订 单 信 息</b>（订单编号：" & rsOrder("OrderFormNum") & "）</td>" & vbCrLf
    Response.Write "  </tr>" & vbCrLf
    Response.Write "  <tr>" & vbCrLf
    Response.Write "    <td height='25'><table width='100%'  border='0' cellpadding='2' cellspacing='0'>" & vbCrLf
    Response.Write "      <tr class='tdbg'>" & vbCrLf
    Response.Write "        <td colspan='2'>客户名称：<a href='Admin_Client.asp?Action=Show&InfoType=2&ClientID=" & rsOrder("ClientID") & "'><font color='red'>" & PE_HTMLEncode(rsOrder("ClientName")) & "</a></a></td>"
    Response.Write "        <td width='20%'>用 户 名：<a href='Admin_User.asp?Action=Show&UserName=" & rsOrder("UserName") & "'><font color='red'>" & rsOrder("UserName") & "</a></a></td>"
    Response.Write "        <td colspan='2'>下单时间：<font color='red'>" & rsOrder("InputTime") & "</font></td>"
    Response.Write "      <tr class='tdbg'>" & vbCrLf
    Response.Write "      <tr class='tdbg'>" & vbCrLf
    Response.Write "        <td width='20%'>需要发票："
    If rsOrder("NeedInvoice") = True Then
        Response.Write "√"
    Else
        Response.Write "<font color='red'>×</font>"
    End If
    Response.Write "</td>"
    Response.Write "        <td width='20%'>已开发票："
    If rsOrder("Invoiced") = True Then
        Response.Write "√"
    Else
        Response.Write "<font color='red'>×</font>"
    End If
    Response.Write "</td>"
    Response.Write "        <td width='20%'>订单状态：" & arrOrderStatus(rsOrder("Status")) & "</td>"
    Response.Write "        <td width='20%'>付款情况：" & GetPayStatus(rsOrder("MoneyTotal"), rsOrder("MoneyReceipt")) & "</td>"
    Response.Write "        <td width='20%'>物流状态：" & arrDeliverStatus(rsOrder("DeliverStatus")) & "</td>"
    Response.Write "      </tr>"
    Response.Write "    </table>      </td>"
    Response.Write "  </tr>"
    
    Response.Write "  <tr>"
    Response.Write "    <td height='25'><table width='100%' border='0' align='center' cellpadding='2' cellspacing='1'>"
    Response.Write "    <tr class='tdbg'>"
    Response.Write "      <td width='12%' class='tdbg5' align='right'>收货人姓名：</td>"
    Response.Write "      <td width='38%'><input name='ContacterName' type='text' id='ContacterName' value='" & PE_HTMLEncode(rsOrder("ContacterName")) & "' size='20' maxlength='50'></td>"
    Response.Write "      <td width='12%' class='tdbg5' align='right'>联系电话：</td>"
    Response.Write "      <td width='38%'><input name='Phone' type='text' id='Phone' value='" & PE_HTMLEncode(rsOrder("Phone")) & "' size='30' maxlength='50'></td>"
    Response.Write "    </tr>"
    Response.Write "    <tr class='tdbg'>"
    Response.Write "      <td width='12%' class='tdbg5' align='right'>收货人地址：</td>"
    Response.Write "      <td width='38%'><input name='Address' id='Address' value='" & PE_HTMLEncode(rsOrder("Address")) & "' size=50 maxlength='255'></td>"
    Response.Write "      <td width='12%' class='tdbg5' align='right'>邮政编码：</td>"
    Response.Write "      <td width='38%'><input name='ZipCode' type='text' id='ZipCode' value='" & rsOrder("ZipCode") & "' size='30' maxlength='6'></td>"
    Response.Write "    </tr>"
    Response.Write "    <tr class='tdbg'>"
    Response.Write "      <td width='12%' class='tdbg5' align='right'>收货人邮箱：</td>"
    Response.Write "      <td width='38%'><input name='Email' type='text' id='Email' value='" & PE_HTMLEncode(rsOrder("Email")) & "'  size='30' maxlength='100'></td>"
    Response.Write "      <td width='12%' class='tdbg5' align='right'>收货人手机：</td>"
    Response.Write "      <td width='38%'><input name='Mobile' type='text' id='Mobile' value='" & PE_HTMLEncode(rsOrder("Mobile")) & "' size='30' maxlength='30'></td>"
    Response.Write "    </tr>"
    Response.Write "    <tr class='tdbg'>"
    Response.Write "      <td width='12%' class='tdbg5' align='right'>代 理 商：</td>"
    Response.Write "      <td width='38%'><input name='AgentName' type='text' id='AgentName' value='" & PE_HTMLEncode(rsOrder("AgentName")) & "' size='30' maxlength='30' readonly><input type='button' name='aaa' value='...' onclick='SelectAgent()'></td>"
    Response.Write "      <td width='12%' class='tdbg5' align='right'>购买日期：</td>"
    Response.Write "      <td width='38%'><input name='BeginDate' type='text' id='BeginDate' value='" & rsOrder("BeginDate") & "' size='30' maxlength='30'></td>"
    Response.Write "    </tr>"
    
    
    Response.Write "    <tr class='tdbg'>"
    Response.Write "      <td width='12%' class='tdbg5' align='right'>付款方式：</td>"
    Response.Write "      <td width='38%'><select name='PaymentType'"
    If rsOrder("Status") > 1 Then Response.Write " disabled"
    Response.Write ">"
    Dim rsPaymentType
    Set rsPaymentType = Conn.Execute("select * from PE_PaymentType order by OrderID")
    Do While Not rsPaymentType.EOF
        Response.Write "<option value='" & rsPaymentType("TypeID") & "'"
        If rsPaymentType("TypeID") = rsOrder("PaymentType") Then Response.Write " selected"
        Response.Write ">" & rsPaymentType("TypeName") & "</option>"
        rsPaymentType.MoveNext
    Loop
    Set rsPaymentType = Nothing
    Response.Write "      </select></td>"
    
    Response.Write "      <td width='12%' class='tdbg5' align='right'>送货方式：</td>"
    Response.Write "      <td width='38%'><select name='DeliverType'"
    If rsOrder("Status") > 1 Then Response.Write " disabled"
    Response.Write ">"
    Dim rsDeliverType
    Set rsDeliverType = Conn.Execute("select * from PE_DeliverType order by OrderID")
    Do While Not rsDeliverType.EOF
        Response.Write "<option value='" & rsDeliverType("TypeID") & "'"
        If rsDeliverType("TypeID") = rsOrder("DeliverType") Then Response.Write " selected"
        Response.Write ">" & rsDeliverType("TypeName") & "</option>"
        rsDeliverType.MoveNext
    Loop
    Set rsDeliverType = Nothing
    Response.Write "      </select></td>"
    Response.Write "      </tr>"
    
    Response.Write "    <tr class='tdbg'>"
    Response.Write "      <td width='12%' class='tdbg5' align='right'>发票信息：</td>"
    Response.Write "      <td width='38%'>        <textarea name='InvoiceContent' cols='30' rows='4' id='InvoiceContent'>" & PE_ConvertBR(PE_HTMLEncode(rsOrder("InvoiceContent"))) & "</textarea>"
    Response.Write "        <input name='NeedInvoice' type='checkbox' id='NeedInvoice' value='Yes'"
    If rsOrder("NeedInvoice") = True Then Response.Write " checked"
    Response.Write ">需要发票</td>"
    Response.Write "      <td width='12%' class='tdbg5' align='right'>备注：</td>"
    Response.Write "      <td width='38%'><textarea name='Remark' cols='32' rows='4' id='Remark'>" & PE_ConvertBR(PE_HTMLEncode(rsOrder("Remark"))) & "</textarea></td>"
    Response.Write "    </tr>"
    Response.Write "  </table>"
    Response.Write "</td></tr>"
    Response.Write "    <tr class='tdbg'>"
    Response.Write "      <td>"
    Response.Write "   <table  border='0' cellspacing='1' cellpadding='0' width='100%'>"
    Response.Write "          <tr align='center' class='tdbg2'>"
    Response.Write "            <td>商品名称</td>"
    Response.Write "            <td>单位</td>"
    Response.Write "            <td>数 量</td>"
    Response.Write "            <td>原价</td>"
    Response.Write "            <td>实价</td>"
    Response.Write "            <td>指定价</td>"
    Response.Write "            <td>服务期限</td>"
    Response.Write "            <td>备 注</td>"
    Response.Write "          </tr>"
    
    Dim rsOrderItem, iCount
    Set rsOrderItem = Conn.Execute("select I.ItemID,P.ProductName,P.Unit,I.SaleType,I.Amount,I.Price_Original,I.Price,I.TruePrice,I.PresentExp,I.BeginDate,I.ServiceTerm,I.Remark from PE_OrderFormItem I inner join PE_Product P on I.ProductID=P.ProductID where I.OrderFormID=" & rsOrder("OrderFormID") & " order by I.ItemID")
    Do While Not rsOrderItem.EOF
        Response.Write "          <tr align='center'>"
        Response.Write "            <td><input type='text' name='ProductName' value='" & rsOrderItem("ProductName")
        Select Case rsOrderItem("SaleType")
        Case 1 '正常销售
        
        Case 2 '换购
            Response.Write " （换购）"
        Case 3 '赠送
            Response.Write " （赠送）"
        Case 4 '批发
            Response.Write " （批发）"
        End Select
        Response.Write "' size='40' disabled></td>"
        Response.Write "            <td><input name='Unit' type='text' value='" & rsOrderItem("Unit") & "' size='4' style='text-align: center;' disabled></td>"
        Response.Write "            <td><input name='Amount' type='text' value='" & rsOrderItem("Amount") & "' size='6' style='text-align: center;' disabled></td>"
        Response.Write "            <td><input name='Price_Original' type='text' value='" & rsOrderItem("Price_Original") & "' size='8' style='text-align: right;' disabled></td>"
        Response.Write "            <td><input name='Price' type='text' value='" & rsOrderItem("Price") & "' size='8' style='text-align: right;' disabled></td>"
        Response.Write "            <td><input name='TruePrice_" & rsOrderItem("ItemID") & "' type='text' value='" & rsOrderItem("TruePrice") & "' size='8' maxlength='10'"
        If rsOrder("Status") > 1 Then Response.Write " disabled"
        Response.Write " style='text-align: right;'></td>"
        Response.Write "            <td><select name='ServiceTerm_" & rsOrderItem("ItemID") & "'"
        If rsOrder("Status") > 1 Then Response.Write " disabled"
        Response.Write ">"
        Response.Write "              <option value='0'"
        If rsOrderItem("ServiceTerm") = 0 Then Response.Write " selected"
        Response.Write ">无</option>"
        Response.Write "              <option value='1'"
        If rsOrderItem("ServiceTerm") = 1 Then Response.Write " selected"
        Response.Write ">一年</option>"
        Response.Write "              <option value='2'"
        If rsOrderItem("ServiceTerm") = 2 Then Response.Write " selected"
        Response.Write ">两年</option>"
        Response.Write "              <option value='3'"
        If rsOrderItem("ServiceTerm") = 3 Then Response.Write " selected"
        Response.Write ">三年</option>"
        Response.Write "              <option value='4'"
        If rsOrderItem("ServiceTerm") = 4 Then Response.Write " selected"
        Response.Write ">四年</option>"
        Response.Write "              <option value='5'"
        If rsOrderItem("ServiceTerm") = 5 Then Response.Write " selected"
        Response.Write ">五年</option>"
        Response.Write "              <option value='-1'"
        If rsOrderItem("ServiceTerm") = -1 Then Response.Write " selected"
        Response.Write ">终生</option>"
        Response.Write "            </select></td>"
        Response.Write "            <td><input name='Remark_" & rsOrderItem("ItemID") & "' type='text' id='ItemRemark' value='" & rsOrderItem("Remark") & "' size='20' maxlength='200'></td>"
        Response.Write "          </tr>"
        rsOrderItem.MoveNext
    Loop
    Set rsOrderItem = Nothing

    Response.Write "      </table></td>"
    Response.Write "    </tr>"
    Response.Write "    <tr class='tdbg'>"
    Response.Write "      <td height='35' colspan='6' align='center'><input name='OrderFormID' type='hidden' id='OrderFormID' value='" & OrderFormID & "'>"
    Response.Write "        <input name='Status' type='hidden' id='Status' value='" & rsOrder("Status") & "'>"
    Response.Write "        <input name='Action' type='hidden' id='Action' value='SaveModifyOrder'>"
    Response.Write "          <input type='submit' name='submit' value=' 保存订单 '>&nbsp;&nbsp;&nbsp;"
    Response.Write "<input type='button' name='Submit' value=' 取 消 ' onclick=""window.location.href='Admin_Order.asp?Action=ShowOrder&OrderFormID=" & OrderFormID & "';"">"
    Response.Write "</td>"
    Response.Write "    </tr>"
    Response.Write "  </table><br><b>注：</b>“<font color='blue'>原价</font>”指商品的原始零售价，“<font color='green'>实价</font>”指系统根据 <a href='Admin_Help_Price.asp' target='_blank'>最终价格计算公式表</a> 自动计算出来的商品最终价格。您也可以手动指定与“实价”不同的最终销售价格。"
    Response.Write "</form>"

    rsOrder.Close
    Set rsOrder = Nothing
End Sub

Sub Transfer()
    If AdminPurview > 1 And arrPurview(10) = False Then
        Response.Write "<br><p align='center'><font color='red' style='font-size:9pt'>对不起，你没有此项操作的权限。</font></p>"
        Call WriteEntry(6, AdminName, "越权操作")
        Exit Sub
    End If
    
    Dim OrderFormID
    OrderFormID = Trim(Request("OrderFormID"))
    If OrderFormID = "" Then
        FoundErr = True
        ErrMsg = ErrMsg & "<li>请指定OrderFormID！</li>"
    Else
        OrderFormID = PE_CLng(OrderFormID)
    End If
    If FoundErr = True Then Exit Sub
    
    Dim rsOrder, sqlOrder
    sqlOrder = "select O.OrderFormNum,O.UserName,C.ClientName from PE_OrderForm O left join PE_Client C on O.ClientID=C.ClientID where OrderFormID=" & OrderFormID & ""
    Set rsOrder = Conn.Execute(sqlOrder)
    If rsOrder.BOF And rsOrder.EOF Then
        FoundErr = True
        ErrMsg = ErrMsg & "<li>找不到指定的订单！</li>"
        rsOrder.Close
        Set rsOrder = Nothing
        Exit Sub
    End If

    Response.Write "<form name='form5' method='post' action='Admin_Order.asp'>"
    Response.Write "  <table width='100%' border='0' align='center' cellpadding='2' cellspacing='1' class='border'>"
    Response.Write "    <tr align='center' class='title'>"
    Response.Write "      <td height='22' colspan='2'><b>订 单 过 户</b></td>"
    Response.Write "    </tr>"
    Response.Write "    <tr class='tdbg'>"
    Response.Write "      <td width='15%' class='tdbg5' align='right'>订单编号：</td>"
    Response.Write "      <td>" & rsOrder("OrderFormNum") & "</td>"
    Response.Write "    </tr>"
    Response.Write "    <tr class='tdbg'>"
    Response.Write "      <td width='15%' class='tdbg5' align='right'>当前客户：</td>"
    Response.Write "      <td>" & PE_HTMLEncode(rsOrder("ClientName")) & "</td>"
    Response.Write "    </tr>"
    Response.Write "    <tr class='tdbg'>"
    Response.Write "      <td width='15%' class='tdbg5' align='right'>当前会员：</td>"
    Response.Write "      <td>" & rsOrder("UserName") & "</td>"
    Response.Write "    </tr>"
    Response.Write "    <tr class='tdbg'>"
    Response.Write "      <td width='15%' class='tdbg5' align='right'>欲过户给：</td>"
    Response.Write "      <td><input name='TargetUser' type='text' id='TargetUser' size='20' maxlength='30'> 请输入目标会员的用户名</td>"
    Response.Write "    </tr>"
    Response.Write "    <tr class='tdbg'>"
    Response.Write "      <td width='15%' class='tdbg5' align='right'>手续费：</td>"
    Response.Write "      <td><input name='Poundage' type='text' id='Poundage' size='10' maxlength='10'> 元</td>"
    Response.Write "    </tr>"
    Response.Write "    <tr class='tdbg'>"
    Response.Write "      <td width='15%' class='tdbg5' align='right'>手续费支付者：</td>"
    Response.Write "      <td><input name='Payer' type='radio' value='1' checked>订单当前所有者&nbsp;&nbsp;&nbsp;&nbsp;<input name='Payer' type='radio' value='2'>过户对象</td>"
    Response.Write "    </tr>"
    Response.Write "    <tr class='tdbg'>"
    Response.Write "      <td width='15%' class='tdbg5' align='right'>备注：</td>"
    Response.Write "      <td><input name='Remark' type='text' id='Remark' size='50' maxlength='50'></td>"
    Response.Write "    </tr>"
    Response.Write "    <tr align='center' class='tdbg' height='50'>"
    Response.Write "      <td colspan='2'><input name='Action' type='hidden' id='Action' value='SaveTransfer'>"
    Response.Write "        <input name='OrderFormID' type='hidden' id='OrderFormID' value='" & OrderFormID & "'>"
    Response.Write "      <input type='submit' name='Submit' value=' 确 定 '></td>"
    Response.Write "    </tr>"
    Response.Write "  </table>"
    Response.Write "</form>"
    
    rsOrder.Close
    Set rsOrder = Nothing
End Sub

Sub EnableDownload()
    If AdminPurview > 1 And arrPurview(7) = False Then
        Response.Write "<br><p align='center'><font color='red' style='font-size:9pt'>对不起，你没有此项操作的权限。</font></p>"
        Call WriteEntry(6, AdminName, "越权操作")
        Exit Sub
    End If
    
    Dim OrderFormID
    Dim rsOrder, sqlOrder
    OrderFormID = Trim(Request("OrderFormID"))
    If OrderFormID = "" Then
        FoundErr = True
        ErrMsg = ErrMsg & "<li>请指定OrderFormID！</li>"
    Else
        OrderFormID = PE_CLng(OrderFormID)
    End If
    
    If FoundErr = True Then Exit Sub
    
    If Action = "EnableDownload" Then
        Conn.Execute ("update PE_OrderForm set EnableDownload=" & PE_True & " where OrderFormID=" & OrderFormID & "")
    Else
        Conn.Execute ("update PE_OrderForm set EnableDownload=" & PE_False & " where OrderFormID=" & OrderFormID & "")
    End If
    Call CloseConn
    Response.Redirect "Admin_Order.asp?Action=ShowOrder&OrderFormID=" & OrderFormID
End Sub

Sub SendCard()
    If AdminPurview > 1 And arrPurview(8) = False Then
        Response.Write "<br><p align='center'><font color='red' style='font-size:9pt'>对不起，你没有此项操作的权限。</font></p>"
        Call WriteEntry(6, AdminName, "越权操作")
        Exit Sub
    End If
    
    Dim OrderFormID
    OrderFormID = Trim(Request("OrderFormID"))
    If OrderFormID = "" Then
        FoundErr = True
        ErrMsg = ErrMsg & "<li>请指定OrderFormID！</li>"
    Else
        OrderFormID = PE_CLng(OrderFormID)
    End If
    If FoundErr = True Then Exit Sub
    
    Dim rsOrderItem, rsCard, sqlCard, trs, i, HaveOtherProduct, strCardInfo, strCardInfo2
    HaveOtherProduct = False
    Set rsCard = Server.CreateObject("Adodb.Recordset")
    Set rsOrderItem = Conn.Execute("select I.ItemID,P.ProductID,P.ProductName,P.ProductKind,I.Amount from PE_OrderFormItem I inner join PE_Product P on I.ProductID=P.ProductID where I.OrderFormID=" & OrderFormID & " order by I.ItemID")
    Do While Not rsOrderItem.EOF
        If rsOrderItem("ProductKind") = 3 Then
            Set trs = Conn.Execute("select top 1 CardID from PE_Card where ProductID=" & rsOrderItem("ProductID") & " and OrderFormItemID=" & rsOrderItem("ItemID") & "")
            If trs.BOF And trs.EOF Then
                sqlCard = "select top " & rsOrderItem("Amount") & " * from PE_Card where ProductID=" & rsOrderItem("ProductID") & " and OrderFormItemID=0 order by CardID"
                rsCard.Open sqlCard, Conn, 1, 3
                If rsCard.RecordCount < rsOrderItem("Amount") Then
                    FoundErr = True
                    ErrMsg = ErrMsg & "<li>" & rsOrderItem("ProductName") & "的充值卡数量已经不够交付！请先去充值卡管理中添加有关充值卡。</li>"
                Else
                    strCardInfo = strCardInfo & "<br><br><table width='80%' align='center' cellspacing='1' cellpadding='2'><tr class='title' align='center'><td>商品名称</td><td>充值卡类型</td><td>充值卡卡号</td><td>充值卡密码</td><td>充值卡面值</td><td>充值卡点数</td><td>充值截止日期</td></tr>"
                    Do While Not rsCard.EOF
                        rsCard("OrderFormItemID") = rsOrderItem("ItemID")
                        rsCard.Update

                        strCardInfo = strCardInfo & "<tr class='tdbg' align='center'><td>" & rsOrderItem("Productname") & "</td>"
                        strCardInfo = strCardInfo & "<td>"
                        If rsCard("CardType") = 0 Then
                            strCardInfo = strCardInfo & "本站充值卡"
                        Else
                            strCardInfo = strCardInfo & "<font color='blue'>其他公司卡</font>"
                        End If
                        strCardInfo = strCardInfo & "</td>"
                        strCardInfo = strCardInfo & "<td>" & rsCard("CardNum") & "</td>"
                        strCardInfo = strCardInfo & "<td>" & Base64decode(rsCard("Password")) & "</td>"
                        strCardInfo = strCardInfo & "<td>" & rsCard("Money") & "</td>"
                        strCardInfo = strCardInfo & "<td>" & GetValidNum(rsCard("ValidNum"), rsCard("ValidUnit")) & arrCardUnit(rsCard("ValidUnit")) & "</td>"
                        strCardInfo = strCardInfo & "<td>" & rsCard("EndDate") & "</td></tr>"
                        
                        strCardInfo2 = strCardInfo2 & "卡号：" & rsCard("CardNum") & vbCrLf
                        strCardInfo2 = strCardInfo2 & "密码：" & Base64decode(rsCard("Password")) & vbCrLf & vbCrLf

                        rsCard.MoveNext
                    Loop
                    strCardInfo = strCardInfo & "</table><br><br>"
                    Conn.Execute ("update PE_Product set Stocks=Stocks-" & rsOrderItem("Amount") & ",OrderNum=OrderNum-" & rsOrderItem("Amount") & " where ProductID=" & rsOrderItem("ProductID") & "")
                End If
                rsCard.Close
            End If
        Else
            HaveOtherProduct = True
        End If
        rsOrderItem.MoveNext
    Loop
    Set rsOrderItem = Nothing
    Set rsCard = Nothing
    Dim strMsg
    
    If FoundErr = False Then
        strMsg = "已经成功向客户交付了此订单中的点卡类商品的充值卡！"
        Dim rsOrder, sqlOrder
        Set rsOrder = Server.CreateObject("Adodb.RecordSet")
        sqlOrder = "select * from PE_OrderForm where OrderFormID=" & OrderFormID
        rsOrder.Open sqlOrder, Conn, 1, 3
        If rsOrder.BOF And rsOrder.EOF Then
            FoundErr = True
            ErrMsg = ErrMsg & "<li>找不到指定的订单！</li>"
            rsOrder.Close
            Set rsOrder = Nothing
        End If
        If HaveOtherProduct = False Then
            rsOrder("DeliverStatus") = 2
            rsOrder.Update
        End If
        EmailOfSendCard = Replace(EmailOfSendCard, "{$CardInfo}", strCardInfo)
        MessageOfSendCard = Replace(MessageOfSendCard, "{$CardInfo}", strCardInfo2)

        Response.Cookies(Site_Sn)("SendSMSToUser_SendCard") = Trim(Request("SendSMSToUser"))
        Response.Cookies(Site_Sn)("SendSMSToContacter_SendCard") = Trim(Request("SendSMSToContacter"))

        
        strMsg = strMsg & SendMessageOfOrder(MessageOfSendCard, "已经交付充值卡", rsOrder)
        strMsg = strMsg & SendEmailOfOrder("交付充值卡通知", EmailOfSendCard, "已经交付充值卡", rsOrder)
        rsOrder.Close
        Set rsOrder = Nothing
        Call WriteSuccessMsg(strMsg, "Admin_Order.asp?Action=ShowOrder&OrderFormID=" & OrderFormID & "")
    End If
End Sub

Sub Invoice()
    If AdminPurview > 1 And arrPurview(5) = False Then
        Response.Write "<br><p align='center'><font color='red' style='font-size:9pt'>对不起，你没有此项操作的权限。</font></p>"
        Call WriteEntry(6, AdminName, "越权操作")
        Exit Sub
    End If
    
    Dim OrderFormID
    Dim rsOrder, sqlOrder
    OrderFormID = Trim(Request("OrderFormID"))
    If OrderFormID = "" Then
        FoundErr = True
        ErrMsg = ErrMsg & "<li>参数不足！</li>"
        Exit Sub
    Else
        OrderFormID = PE_CLng(OrderFormID)
    End If
    sqlOrder = "select O.ClientID,O.OrderFormNum,O.UserName,C.ClientName,O.Status,O.MoneyTotal,O.MoneyReceipt,O.NeedInvoice,O.InvoiceContent,O.Invoiced from PE_OrderForm O left join PE_Client C on O.ClientID=C.ClientID where OrderFormID=" & OrderFormID
    Set rsOrder = Conn.Execute(sqlOrder)
    If rsOrder.BOF And rsOrder.EOF Then
        FoundErr = True
        ErrMsg = ErrMsg & "<li>找不到指定的订单！</li>"
    Else
        If rsOrder("NeedInvoice") = False Then
            FoundErr = True
            ErrMsg = ErrMsg & "<li>此订单不需要开发票！</li>"
        End If
    End If
    If FoundErr = True Then
        rsOrder.Close
        Set rsOrder = Nothing
        Exit Sub
    End If
    
    Response.Write "<form name='form4' method='post' action='Admin_Order.asp' onSubmit=""return confirm('确定录入的发票信息都正确无误了吗？');"">"
    Response.Write "  <table width='100%' border='0' cellpadding='2' cellspacing='1' class='border'>"
    Response.Write "    <tr align='center' class='title'>"
    Response.Write "      <td height='22' colspan='2'><b>录 入 开 发 票 信 息</b></td>"
    Response.Write "    </tr>"
    Response.Write "    <tr class='tdbg'>"
    Response.Write "      <td width='15%' class='tdbg5' align='right'>客户名称：</td>"
    Response.Write "      <td>" & PE_HTMLEncode(rsOrder("ClientName")) & "</td>"
    Response.Write "    </tr>"
    Response.Write "    <tr class='tdbg'>"
    Response.Write "      <td width='15%' class='tdbg5' align='right'>用户名：</td>"
    Response.Write "      <td>" & rsOrder("UserName") & "</td>"
    Response.Write "    </tr>"
    Response.Write "    <tr class='tdbg'>"
    Response.Write "      <td width='15%' class='tdbg5' align='right'>订单编号：</td>"
    Response.Write "      <td>" & rsOrder("OrderFormNum") & "</td>"
    Response.Write "    </tr>"
    Response.Write "    <tr class='tdbg'>"
    Response.Write "      <td width='15%' class='tdbg5' align='right'>订单金额：</td>"
    Response.Write "      <td>" & rsOrder("MoneyTotal") & "元</td>"
    Response.Write "    </tr>"
    Response.Write "    <tr class='tdbg'>"
    Response.Write "      <td width='15%' class='tdbg5' align='right'>已 付 款：</td>"
    Response.Write "      <td>" & rsOrder("MoneyReceipt") & "元</td>"
    Response.Write "    </tr>"
    Response.Write "    <tr class='tdbg'>"
    Response.Write "      <td width='15%' class='tdbg5' align='right'>发票信息：</td>"
    Response.Write "      <td>" & PE_HTMLEncode(rsOrder("InvoiceContent")) & "</td>"
    Response.Write "    </tr>"
    Response.Write "    <tr class='tdbg'>"
    Response.Write "      <td width='15%' class='tdbg5' align='right'>开票日期：</td>"
    Response.Write "      <td><input name='InvoiceDate' type='text' id='InvoiceDate' value='" & Date & "' size='15' maxlength='30'></td>"
    Response.Write "    </tr>"
    Response.Write "    <tr class='tdbg'>"
    Response.Write "      <td width='15%' class='tdbg5' align='right'>发票类型：</td>"
    Response.Write "      <td><select name='InvoiceType'><option value='0'>地税普通发票</option><option value='1'>国税普通发票</option><option value='2'>增值税发票</option></select></td>"
    Response.Write "    </tr>"
    Response.Write "    <tr class='tdbg'>"
    Response.Write "      <td width='15%' class='tdbg5' align='right'>发票号码：</td>"
    Response.Write "      <td><input name='InvoiceNum' type='text' id='InvoiceNum' value='' size='15' maxlength='30'></td>"
    Response.Write "    </tr>"
    Response.Write "    <tr class='tdbg'>"
    Response.Write "      <td width='15%' class='tdbg5' align='right'>发票抬头：</td>"
    Response.Write "      <td><input name='InvoiceTitle' type='text' id='InvoiceTitle' value='" & PE_HTMLEncode(rsOrder("ClientName")) & "' size='50' maxlength='50'></td>"
    Response.Write "    </tr>"
    Response.Write "    <tr class='tdbg'>"
    Response.Write "      <td width='15%' class='tdbg5' align='right'>发票内容：</td>"
    Response.Write "      <td><textarea name='InvoiceContent' rows='4' cols='50'>" & rsOrder("InvoiceContent") & "</textarea></td>"
    Response.Write "    </tr>"
    Response.Write "    <tr class='tdbg'>"
    Response.Write "      <td width='15%' class='tdbg5' align='right'>发票金额：</td>"
    Response.Write "      <td><input name='TotalMoney' type='text' id='TotalMoney' value='" & rsOrder("MoneyReceipt") & "' size='15' maxlength='15'></td>"
    Response.Write "    </tr>"
    Response.Write "    <tr class='tdbg'>"
    Response.Write "      <td width='15%' class='tdbg5' align='right'>开 票 人：</td>"
    Response.Write "      <td><input name='Drawer' type='text' id='Drawer' value='" & AdminName & "' size='15' maxlength='30'></td>"
    Response.Write "    </tr>"
    Response.Write "    <tr class='tdbg'>"
    Response.Write "      <td width='15%' class='tdbg5' align='right'>通知会员：</td><td>"
    If EnableSMS = True Then
        Response.Write "      <input type='checkbox' name='SendSMSToUser' value='Yes'" & GetPrevChoiceValue("SendSMSToUser_Invoice") & ">同时发送手机短信通知会员已经开具发票<br>"
        Response.Write "      <input type='checkbox' name='SendSMSToContacter' value='Yes'" & GetPrevChoiceValue("SendSMSToContacter_Invoice") & ">同时发送手机短信通知收货人已经开具发票<br>"
    End If
    Response.Write "      <input type='checkbox' name='SendMessageToUser' value='Yes' checked>同时使用站内短信通知会员已经开具发票<br><input type='checkbox' name='SendEmailToUser' value='Yes'>同时使用Email通知会员已经开具发票<br><input type='checkbox' name='SendEmailToContacter' value='Yes'>同时使用Email通知收货人已经开具发票</td>"
    Response.Write "    </tr>"
    Response.Write "    <tr align='center' class='tdbg'>"
    Response.Write "      <td height='30' colspan='2'><input name='Action' type='hidden' id='Action' value='SaveInvoice'>"
    Response.Write "      <input name='ClientID' type='hidden' id='ClientID' value='" & rsOrder("ClientID") & "'>"
    Response.Write "      <input name='OrderFormID' type='hidden' id='OrderFormID' value='" & OrderFormID & "'>"
    Response.Write "      <input name='UserName' type='hidden' id='UserName' value='" & rsOrder("UserName") & "'>"
    Response.Write "      <input type='submit' name='Submit' value=' 保 存 '></td>"
    Response.Write "    </tr>"
    Response.Write "  </table>"
    Response.Write "</form>"
    rsOrder.Close
    Set rsOrder = Nothing
End Sub

Sub SaveInvoice()
    If AdminPurview > 1 And arrPurview(5) = False Then
        Response.Write "<br><p align='center'><font color='red' style='font-size:9pt'>对不起，你没有此项操作的权限。</font></p>"
        Call WriteEntry(6, AdminName, "越权操作")
        Exit Sub
    End If
    
    Dim OrderFormID, ClientID, UserName, InvoiceType, InvoiceNum, InvoiceDate, InvoiceTitle, InvoiceContent, TotalMoney, Drawer
    OrderFormID = PE_CLng(Trim(Request("OrderFormID")))
    InvoiceType = PE_CLng(Trim(Request("InvoiceType")))
    UserName = Trim(Request("UserName"))
    InvoiceNum = Trim(Request("InvoiceNum"))
    InvoiceDate = Trim(Request("InvoiceDate"))
    InvoiceTitle = Trim(Request("InvoiceTitle"))
    InvoiceContent = Trim(Request("InvoiceContent"))
    TotalMoney = PE_CDbl(Trim(Request("TotalMoney")))
    Drawer = Trim(Request("Drawer"))
    
    If OrderFormID <= 0 Then
        FoundErr = True
        ErrMsg = ErrMsg & "<li>请指定OrderFormID！</li>"
    End If
    If Not IsDate(InvoiceDate) Then
        FoundErr = True
        ErrMsg = ErrMsg & "<br><li>开发票日期格式不对！</li>"
    End If
    If TotalMoney <= 0 Then
        FoundErr = True
        ErrMsg = ErrMsg & "<li>请输入发票总金额！</li>"
    End If
    
    If FoundErr = True Then Exit Sub
    
    Dim rsOrder, sqlOrder
    Dim strMsg
    Set rsOrder = Server.CreateObject("Adodb.RecordSet")
    sqlOrder = "select * from PE_OrderForm where OrderFormID=" & OrderFormID
    rsOrder.Open sqlOrder, Conn, 1, 3
    If rsOrder.BOF And rsOrder.EOF Then
        FoundErr = True
        ErrMsg = ErrMsg & "<li>找不到指定的订单！</li>"
        rsOrder.Close
        Set rsOrder = Nothing
    End If
    ClientID = rsOrder("ClientID")
    rsOrder("Invoiced") = True
    rsOrder.Update
    strMsg = "成功开具发票"
    strMsg = strMsg & SendMessageOfOrder(MessageOfInvoice, "已经开具发票", rsOrder)
    strMsg = strMsg & SendEmailOfOrder("开具发票通知", EmailOfInvoice, "已经开具发票", rsOrder)
    rsOrder.Close
    Set rsOrder = Nothing

    Response.Cookies(Site_Sn)("SendSMSToUser_Invoice") = Trim(Request("SendSMSToUser"))
    Response.Cookies(Site_Sn)("SendSMSToContacter_Invoice") = Trim(Request("SendSMSToContacter"))

    Dim rsInvoiceItem
    Set rsInvoiceItem = Server.CreateObject("adodb.recordset")
    rsInvoiceItem.Open "select top 1 * from PE_InvoiceItem", Conn, 1, 3
    rsInvoiceItem.AddNew
    rsInvoiceItem("OrderFormID") = OrderFormID
    rsInvoiceItem("ClientID") = ClientID
    rsInvoiceItem("UserName") = UserName
    rsInvoiceItem("InvoiceType") = InvoiceType
    rsInvoiceItem("InvoiceNum") = InvoiceNum
    rsInvoiceItem("InvoiceDate") = InvoiceDate
    rsInvoiceItem("InvoiceTitle") = InvoiceTitle
    rsInvoiceItem("InvoiceContent") = InvoiceContent
    rsInvoiceItem("TotalMoney") = TotalMoney
    rsInvoiceItem("Drawer") = Drawer
    rsInvoiceItem("Inputer") = AdminName
    rsInvoiceItem("InputTime") = Now()
    rsInvoiceItem.Update
    rsInvoiceItem.Close
    Set rsInvoiceItem = Nothing
        
    Call WriteSuccessMsg(strMsg, "Admin_Order.asp?Action=ShowOrder&OrderFormID=" & OrderFormID & "")
    If ErrMsg <> "" Then
        FoundErr = True
    End If
End Sub

Sub Deliver()
    If AdminPurview > 1 And arrPurview(6) = False Then
        Response.Write "<br><p align='center'><font color='red' style='font-size:9pt'>对不起，你没有此项操作的权限。</font></p>"
        Call WriteEntry(6, AdminName, "越权操作")
        Exit Sub
    End If
    
    Dim OrderFormID
    Dim rsOrder, sqlOrder
    OrderFormID = Trim(Request("OrderFormID"))
    If OrderFormID = "" Then
        FoundErr = True
        ErrMsg = ErrMsg & "<li>参数不足！</li>"
        Exit Sub
    Else
        OrderFormID = PE_CLng(OrderFormID)
    End If
    sqlOrder = "select O.OrderFormNum,O.ContacterName,O.UserName,C.ClientName,O.Status,O.MoneyTotal,O.MoneyReceipt,O.DeliverType from PE_OrderForm O left join PE_Client C on O.ClientID=C.ClientID where OrderFormID=" & OrderFormID
    Set rsOrder = Conn.Execute(sqlOrder)
    If rsOrder.BOF And rsOrder.EOF Then
        FoundErr = True
        ErrMsg = ErrMsg & "<li>找不到指定的订单！</li>"
        rsOrder.Close
        Set rsOrder = Nothing
        Exit Sub
    End If
    Dim arrStr(4)
    If Action = "SendGoods" Then
        arrStr(0) = "发 货"
        arrStr(1) = "发货"
        arrStr(2) = "备&nbsp;&nbsp;&nbsp;&nbsp;注"
        arrStr(3) = "SaveSend"
    Else
        arrStr(0) = "退 货"
        arrStr(1) = "收货"
        arrStr(2) = "退货原因"
        arrStr(3) = "SaveReturn"
    End If
    
    Response.Write "<form name='form4' method='post' action='Admin_Order.asp' onSubmit=""return confirm('确定录入的发货信息都正确无误了吗？');"">"
    Response.Write "  <table width='100%' border='0' cellpadding='2' cellspacing='1' class='border'>"
    Response.Write "    <tr align='center' class='title'>"
    Response.Write "      <td height='22' colspan='2'><b>录 入 " & arrStr(0) & " 信 息</b></td>"
    Response.Write "    </tr>"
    Response.Write "    <tr class='tdbg'>"
    Response.Write "      <td width='15%' class='tdbg5' align='right'>客户名称：</td>"
    Response.Write "      <td>" & PE_HTMLEncode(rsOrder("ClientName")) & "</td>"
    Response.Write "    </tr>"
    Response.Write "    <tr class='tdbg'>"
    Response.Write "      <td width='15%' class='tdbg5' align='right'>用户名：</td>"
    Response.Write "      <td>" & rsOrder("UserName") & "</td>"
    Response.Write "    </tr>"
    Response.Write "    <tr class='tdbg'>"
    Response.Write "      <td width='15%' class='tdbg5' align='right'>收货人姓名：</td>"
    Response.Write "      <td>" & PE_HTMLEncode(rsOrder("ContacterName")) & "</td>"
    Response.Write "    </tr>"
    Response.Write "    <tr class='tdbg'>"
    Response.Write "      <td width='15%' class='tdbg5' align='right'>订单编号：</td>"
    Response.Write "      <td>" & rsOrder("OrderFormNum") & "</td>"
    Response.Write "    </tr>"
    Response.Write "    <tr class='tdbg'>"
    Response.Write "      <td width='15%' class='tdbg5' align='right'>订单金额：</td>"
    Response.Write "      <td>" & rsOrder("MoneyTotal") & "元</td>"
    Response.Write "    </tr>"
    Response.Write "    <tr class='tdbg'>"
    Response.Write "      <td width='15%' class='tdbg5' align='right'>已 付 款：</td>"
    Response.Write "      <td>" & rsOrder("MoneyReceipt") & "元</td>"
    Response.Write "    </tr>"
    Response.Write "    <tr class='tdbg'>"
    Response.Write "      <td width='15%' class='tdbg5' align='right'>送货方式：</td>"
    Response.Write "      <td>" & GetDeliverType(rsOrder("DeliverType")) & "&nbsp;&nbsp;&nbsp;&nbsp;<font color='blue'>客户指定的送货方式</font></td>"
    Response.Write "    </tr>"
    Response.Write "    <tr class='tdbg'>"
    Response.Write "      <td width='15%' class='tdbg5' align='right'>" & arrStr(1) & "日期：</td>"
    Response.Write "      <td><input name='DeliverDate' type='text' id='DeliverDate' value='" & Date & "' size='15' maxlength='30'></td>"
    Response.Write "    </tr>"
    If Action = "SendGoods" Then
        Response.Write "    <tr class='tdbg'>"
        Response.Write "      <td width='15%' class='tdbg5' align='right'>快递公司：</td>"
        Response.Write "      <td><input name='ExpressCompany' type='text' id='ExpressCompany' value='' size='15' maxlength='30'> &lt;&lt; <select name='CompanyList' onchange='document.form4.ExpressCompany.value=this.value;'>" & GetAllExpressCompany() & "</select></td>"
        Response.Write "    </tr>"
        Response.Write "    <tr class='tdbg'>"
        Response.Write "      <td width='15%' class='tdbg5' align='right'>快递单号：</td>"
        Response.Write "      <td><input name='ExpressNumber' type='text' id='ExpressNumber' value='' size='15' maxlength='30'></td>"
        Response.Write "    </tr>"
    End If
    Response.Write "    <tr class='tdbg'>"
    Response.Write "      <td width='15%' class='tdbg5' align='right'>经 手 人：</td>"
    Response.Write "      <td><input name='HandlerName' type='text' id='HandlerName' value='" & AdminName & "' size='30' maxlength='50'></td>"
    Response.Write "    </tr>"
    Response.Write "    <tr class='tdbg'>"
    Response.Write "      <td width='15%' class='tdbg5' align='right'>" & arrStr(2) & "：</td>"
    Response.Write "      <td><input name='Remark' type='text' id='Remark' value='' size='50' maxlength='200'></td>"
    Response.Write "    </tr>"
    If Action = "SendGoods" Then
        Response.Write "    <tr class='tdbg'>"
        Response.Write "      <td width='15%' class='tdbg5' align='right'>通知会员：</td><td>"
        If EnableSMS = True Then
            Response.Write "      <input type='checkbox' name='SendSMSToUser' value='Yes'" & GetPrevChoiceValue("SendSMSToUser_Deliver") & ">同时发送手机短信通知会员已经发货<br>"
            Response.Write "      <input type='checkbox' name='SendSMSToContacter' value='Yes'" & GetPrevChoiceValue("SendSMSToContacter_Deliver") & ">同时发送手机短信通知收货人已经发货<br>"
        End If
        Response.Write "      <input type='checkbox' name='SendMessageToUser' value='Yes' checked>同时使用站内短信通知会员已经发货<br><input type='checkbox' name='SendEmailToUser' value='Yes'>同时使用Email通知会员已经发货<br><input type='checkbox' name='SendEmailToContacter' value='Yes'>同时使用Email通知收货人已经发货</td>"
        Response.Write "    </tr>"
    End If
    Response.Write "    <tr align='center' class='tdbg'>"
    Response.Write "      <td height='30' colspan='2'><input name='Action' type='hidden' id='Action' value='" & arrStr(3) & "'>"
    Response.Write "      <input name='OrderFormID' type='hidden' id='OrderFormID' value='" & OrderFormID & "'>"
    Response.Write "      <input type='submit' name='Submit' value=' 保 存 '></td>"
    Response.Write "    </tr>"
    Response.Write "  </table>"
    Response.Write "</form>"
    rsOrder.Close
    Set rsOrder = Nothing
End Sub


Sub SaveDeliver()
    If AdminPurview > 1 And arrPurview(6) = False Then
        Response.Write "<br><p align='center'><font color='red' style='font-size:9pt'>对不起，你没有此项操作的权限。</font></p>"
        Call WriteEntry(6, AdminName, "越权操作")
        Exit Sub
    End If
    
    Dim OrderFormID, DeliverDate, ExpressCompany, ExpressNumber, HandlerName, Remark

    OrderFormID = Trim(Request("OrderFormID"))
    DeliverDate = Trim(Request("DeliverDate"))
    ExpressCompany = Trim(Request("ExpressCompany"))
    HandlerName = Trim(Request("HandlerName"))
    ExpressNumber = Trim(Request("ExpressNumber"))
    Remark = Trim(Request("Remark"))
    If OrderFormID = "" Then
        FoundErr = True
        ErrMsg = ErrMsg & "<li>请指定OrderFormID！</li>"
    Else
        OrderFormID = PE_CLng(OrderFormID)
    End If
    If DeliverDate = "" Then
        FoundErr = True
        ErrMsg = ErrMsg & "<li>请输入发货时间！</li>"
    ElseIf IsDate(DeliverDate) = False Then
        FoundErr = True
        ErrMsg = ErrMsg & "<li>发货时间格式不正确！</li>"
    Else
        DeliverDate = CDate(DeliverDate)
    End If
    If Action = "SaveSend" And ExpressCompany = "" Then
        FoundErr = True
        ErrMsg = ErrMsg & "<li>请输入快递公司名！</li>"
    End If
    If HandlerName = "" Then
        FoundErr = True
        ErrMsg = ErrMsg & "<li>请输入发货人姓名！</li>"
    End If
    
    If FoundErr = True Then Exit Sub
    
    Dim rsOrder, sqlOrder
    Dim strMsg, UserName
    Set rsOrder = Server.CreateObject("Adodb.RecordSet")
    sqlOrder = "select * from PE_OrderForm where OrderFormID=" & OrderFormID
    rsOrder.Open sqlOrder, Conn, 1, 3
    If rsOrder.BOF And rsOrder.EOF Then
        FoundErr = True
        ErrMsg = ErrMsg & "<li>找不到指定的订单！</li>"
        rsOrder.Close
        Set rsOrder = Nothing
        Exit Sub
    End If
    UserName = rsOrder("UserName")
    If Action = "SaveSend" Then
        rsOrder("DeliverStatus") = 2
        rsOrder.Update
    Else
        rsOrder("DeliverStatus") = 1
        rsOrder.Update
        strMsg = "保存退货信息成功！"
    End If
    Response.Cookies(Site_Sn)("SendSMSToUser_Deliver") = Trim(Request("SendSMSToUser"))
    Response.Cookies(Site_Sn)("SendSMSToContacter_Deliver") = Trim(Request("SendSMSToContacter"))
    
    Dim rsDeliver, sqlDeliver, rsOrderItem, rsProduct
    sqlDeliver = "select top 1 * from PE_DeliverItem"
    Set rsDeliver = Server.CreateObject("Adodb.RecordSet")
    rsDeliver.Open sqlDeliver, Conn, 1, 3
    rsDeliver.AddNew
    rsDeliver("OrderFormID") = OrderFormID
    If Action = "SaveSend" Then
        rsDeliver("DeliverDirection") = 1  '发货
        Set rsOrderItem = Conn.Execute("select ProductID,Amount from PE_OrderFormItem where OrderFormID=" & OrderFormID & "")
        Do While Not rsOrderItem.EOF
            Conn.Execute ("update PE_Product set Stocks=Stocks-" & rsOrderItem(1) & ",OrderNum=OrderNum-" & rsOrderItem(1) & " where ProductID=" & rsOrderItem(0) & "")
            rsOrderItem.MoveNext
        Loop
        Set rsOrderItem = Nothing
    Else
        rsDeliver("DeliverDirection") = 2  '退货
        Set rsOrderItem = Conn.Execute("select ProductID,Amount from PE_OrderFormItem where OrderFormID=" & OrderFormID & "")
        Do While Not rsOrderItem.EOF
            Conn.Execute ("update PE_Product set Stocks=Stocks+" & rsOrderItem(1) & ",OrderNum=OrderNum+" & rsOrderItem(1) & " where ProductID=" & rsOrderItem(0) & "")
            Set rsProduct = Conn.Execute("Select PresentMoney,PresentPoint,PresentExp From PE_Product where ProductID=" & rsOrderItem(0) & "")
            Conn.Execute ("update PE_User Set Balance=Balance-" & rsProduct(0) & ",UserPoint=UserPoint-" & rsProduct(1) & ",UserExp=UserExp-" & rsProduct(2) & " where UserName='" & UserName & "'")
            rsOrderItem.MoveNext
        Loop
        Set rsOrderItem = Nothing
        Set rsProduct = Nothing
    End If
    rsDeliver("DeliverDate") = DeliverDate
    rsDeliver("ExpressCompany") = ExpressCompany
    rsDeliver("ExpressNumber") = ExpressNumber
    rsDeliver("HandlerName") = HandlerName
    rsDeliver("Inputer") = AdminName
    rsDeliver("Remark") = Remark
    rsDeliver.Update
    rsDeliver.Close
    Set rsDeliver = Nothing

    If Action = "SaveSend" Then
        Conn.Execute ("update PE_Client set GroupID = 1 where GroupID=0 and ClientID =" & PE_Clng(rsOrder("ClientID")))
        strMsg = "保存发货信息成功！"
        strMsg = strMsg & SendMessageOfOrder(MessageOfDeliver, "已经发货", rsOrder)
        strMsg = strMsg & SendEmailOfOrder("发货通知", EmailOfDeliver, "已经发货", rsOrder)
    End If
    rsOrder.Close
    Set rsOrder = Nothing
    
    Call WriteSuccessMsg(strMsg, "Admin_Order.asp?Action=ShowOrder&OrderFormID=" & OrderFormID & "")
    If ErrMsg <> "" Then
        FoundErr = True
    End If
    
End Sub


Sub Received()
    If AdminPurview > 1 And arrPurview(6) = False Then
        Response.Write "<br><p align='center'><font color='red' style='font-size:9pt'>对不起，你没有此项操作的权限。</font></p>"
        Call WriteEntry(6, AdminName, "越权操作")
        Exit Sub
    End If
    
    Dim rsDeliver, OrderFormID
    OrderFormID = Trim(Request("OrderFormID"))
    If OrderFormID = "" Then
        FoundErr = True
        ErrMsg = ErrMsg & "<li>请指定OrderFormID！</li>"
    Else
        OrderFormID = PE_CLng(OrderFormID)
    End If
    If FoundErr = True Then Exit Sub
    
    Set rsDeliver = Server.CreateObject("adodb.recordset")
    rsDeliver.Open "select Received from PE_DeliverItem where OrderFormID=" & OrderFormID & " and Received=" & PE_False & "", Conn, 1, 3
    If Not (rsDeliver.BOF And rsDeliver.EOF) Then
        rsDeliver("Received") = True
        rsDeliver.Update
    End If
    rsDeliver.Close
    Set rsDeliver = Nothing
    
    If FoundErr = True Then Exit Sub
    
    Conn.Execute ("update PE_OrderForm set DeliverStatus=3 where OrderFormID=" & OrderFormID & "")
    Call CloseConn
    Response.Redirect "Admin_Order.asp?Action=ShowOrder&OrderFormID=" & OrderFormID
End Sub

Sub Refund()
    If AdminPurview > 1 And arrPurview(13) = False Then
        Response.Write "<br><p align='center'><font color='red' style='font-size:9pt'>对不起，你没有此项操作的权限。</font></p>"
        Call WriteEntry(6, AdminName, "越权操作")
        Exit Sub
    End If
    
    Dim OrderFormID, trs
    Dim rsOrder, sqlOrder
    OrderFormID = Trim(Request("OrderFormID"))
    If OrderFormID = "" Then
        FoundErr = True
        ErrMsg = ErrMsg & "<li>请指定订单ID</li>"
        Exit Sub
    Else
        OrderFormID = PE_CLng(OrderFormID)
    End If
    
    sqlOrder = "select O.OrderFormNum,O.UserName,C.ClientName,O.Status,O.MoneyTotal,O.MoneyReceipt from PE_OrderForm O left join PE_Client C on O.ClientID=C.ClientID where OrderFormID=" & OrderFormID
    Set rsOrder = Conn.Execute(sqlOrder)
    If rsOrder.BOF And rsOrder.EOF Then
        FoundErr = True
        ErrMsg = ErrMsg & "<li>找不到指定的订单！</li>"
        rsOrder.Close
        Set rsOrder = Nothing
        Exit Sub
    End If
    If rsOrder("MoneyReceipt") <= 0 Then
        FoundErr = True
        ErrMsg = ErrMsg & "<li>此订单并未付款，不能进行退款操作！</li>"
        rsOrder.Close
        Set rsOrder = Nothing
        Exit Sub
    End If
   
    Response.Write "<script language = 'JavaScript'>" & vbCrLf
    Response.Write "  function getRefundmoney(HandlingCharge){" & vbCrLf
    Response.Write "    if(HandlingCharge==''|| isNaN(HandlingCharge)){HandlingCharge=0;}" & vbCrLf
    Response.Write "    document.form4.RefundMoney.value=document.form4.MoneyReceipt.value-HandlingCharge;" & vbCrLf
    Response.Write "}" & vbCrLf
    Response.Write "</script>" & vbCrLf
    Response.Write "<form name='form4' method='post' action='Admin_Order.asp' onsubmit=""return confirm('确定所输入的信息都完全正确吗？一旦输入就不可更改哦！')"">"
    Response.Write "  <table width='100%' border='0' cellpadding='2' cellspacing='1' class='border'>"
    Response.Write "    <tr align='center' class='title'>"
    Response.Write "      <td height='22' colspan='2'><b>添 加 订 单 退 款 信 息</b></td>"
    Response.Write "    </tr>"
    Response.Write "    <tr class='tdbg'>"
    Response.Write "      <td width='15%' class='tdbg5' align='right'>客户名称：</td>"
    Response.Write "      <td>" & PE_HTMLEncode(rsOrder("ClientName")) & "</td>"
    Response.Write "    </tr>"
    Response.Write "    <tr class='tdbg'>"
    Response.Write "      <td width='15%' class='tdbg5' align='right'>用户名：</td>"
    Response.Write "      <td>" & rsOrder("UserName") & "</td>"
    Response.Write "    </tr>"
    Response.Write "    <tr class='tdbg'>"
    Response.Write "      <td width='15%' class='tdbg5' align='right'>支付内容：</td>"
    Response.Write "      <td><table  border='0' cellspacing='2' cellpadding='0'>"
    Response.Write "        <tr class='tdbg'>"
    Response.Write "          <td width='15%' class='tdbg5' align='right'>订单编号：</td>"
    Response.Write "          <td>" & rsOrder("OrderFormNum") & "</td>"
    Response.Write "          <td>&nbsp;</td>"
    Response.Write "        </tr>"
    Response.Write "        <tr class='tdbg'>"
    Response.Write "          <td width='15%' class='tdbg5' align='right'>订单金额：</td>"
    Response.Write "          <td>" & rsOrder("MoneyTotal") & "元</td>"
    Response.Write "        </tr>"
    Response.Write "        <tr class='tdbg'>"
    Response.Write "          <td width='15%' class='tdbg5' align='right'>已 付 款：</td>"
    Response.Write "          <td><input type='hidden' name='MoneyReceipt' id='MoneyReceipt' value=" & rsOrder("MoneyReceipt") & " >" & rsOrder("MoneyReceipt") & "元</td>"
    Response.Write "          <td>&nbsp;</td>"
    Response.Write "        </tr>"
    Response.Write "      </table>"
    Response.Write "      </td>"
    Response.Write "    </tr>"
    Response.Write "    <tr class='tdbg'>"
    Response.Write "      <td width='15%' class='tdbg5' align='right'>退款日期：</td>"
    Response.Write "      <td><input name='RefundDate' type='text' id='RefundDate' value='" & Date & "' size='15' maxlength='30'></td>"
    Response.Write "    </tr>"
    Response.Write "    <tr class='tdbg'>"
    Response.Write "      <td width='15%' class='tdbg5' align='right'>手 续 费：</td>"
    Response.Write "      <td><input name='HandlingCharge' type='text' id='HandlingCharge' value='0' size='10' maxlength='10' onchange='getRefundmoney(this.value)'> 元&nbsp;&nbsp;<font color='#0000FF'>手续费将从已付款中扣除。</font></td>"
    Response.Write "    </tr>"
    Response.Write "    <tr class='tdbg'>"
    Response.Write "      <td width='15%' class='tdbg5' align='right'>退款金额：</td>"
    Response.Write "      <td><input name='RefundMoney' type='text' id='RefundMoney' value='" & rsOrder("MoneyReceipt") & "' size='10' maxlength='10'> 元&nbsp;&nbsp;<font color='#0000FF'>退款金额将从已付款中扣除。</font></td>"
    Response.Write "    </tr>"
    Response.Write "    <tr class='tdbg'>"
    Response.Write "      <td width='15%' class='tdbg5' align='right'>退款方式：</td>"
    Response.Write "      <td><input type='radio' name='RefundType' value='1' onClick=""Remark.value='订单退款金额，订单号：" & rsOrder("OrderFormNum") & "'"" checked>扣除的金额添加到会员资金余额中<br><input type='radio' name='RefundType' value='2' onClick=""Remark.value='订单退款金额，退款方式采用其它方式，订单号：" & rsOrder("OrderFormNum") & "'"">采用其它方式：如银行转帐，现金交付等等</td>"
    Response.Write "    </tr>"
    Response.Write "    <tr class='tdbg'>"
    Response.Write "      <td width='15%' class='tdbg5' align='right'>备注：</td>"
    Response.Write "      <td><input name='Remark' type='text' id='Remark' value='订单退款金额，订单号：" & rsOrder("OrderFormNum") & "' size='50' maxlength='200'></td>"
    Response.Write "    </tr>"
    Response.Write "    <tr class='tdbg'>"
    Response.Write "      <td width='15%' class='tdbg5' align='right'>通知会员：</td><td>"
    If EnableSMS = True Then
        Response.Write "      <input type='checkbox' name='SendSMSToUser' value='Yes'" & GetPrevChoiceValue("SendSMSToUser_Refund") & ">同时发送手机短信通知会员已经退款<br>"
        Response.Write "      <input type='checkbox' name='SendSMSToContacter' value='Yes'" & GetPrevChoiceValue("SendSMSToUser_Refund") & ">同时发送手机短信通知收货人已经退款<br>"
    End If
    Response.Write "      <input type='checkbox' name='SendMessageToUser' value='Yes' checked>同时使用站内短信通知会员已经退款<br><input type='checkbox' name='SendEmailToUser' value='Yes'>同时使用Email通知会员已经退款<br><input type='checkbox' name='SendEmailToContacter' value='Yes'>同时使用Email通知收货人已经退款</td>"
    Response.Write "    </tr>"
    Response.Write "    <tr class='tdbg'>"
    Response.Write "      <td height='30' colspan='2'><b><font color='#FF0000'>注意：退款信息一旦录入，就不能再修改或删除！所以在保存之前确认输入无误！<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp退款方式采用其它方式时，为方便查找退款记录，在会员资金明细中也会有对应记录，但收入金额为0</b></td>"
    Response.Write "    </tr>"
    Response.Write "    <tr align='center' class='tdbg'>"
    Response.Write "      <td height='30' colspan='2'><input name='Action' type='hidden' id='Action' value='DoRefund'>"
    Response.Write "      <input name='OrderFormID' type='hidden' id='OrderFormID' value='" & OrderFormID & "'>"
    Response.Write "      <input type='submit' name='Submit' value=' 保存退款款信息 '></td>"
    Response.Write "    </tr>"
    Response.Write "  </table>"
    Response.Write "</form>"
    rsOrder.Close
    Set rsOrder = Nothing
End Sub

Sub DoRefund()
   If AdminPurview > 1 And arrPurview(13) = False Then
        Response.Write "<br><p align='center'><font color='red' style='font-size:9pt'>对不起，你没有此项操作的权限。</font></p>"
        Call WriteEntry(6, AdminName, "越权操作")
        Exit Sub
    End If
    
    Dim OrderFormID, RefundMoney, RefundDate, RefundType, Remark, HandlingCharge, TotalRefund
    Dim rsOrder, rsBankroll, ItemID, trs
    OrderFormID = Trim(Request("OrderFormID"))
    HandlingCharge = PE_CDbl(Trim(Request("HandlingCharge")))
    RefundMoney = PE_CDbl(Trim(Request("RefundMoney")))
    RefundDate = Trim(Request("RefundDate"))
    RefundType = Trim(Request("RefundType"))
    Remark = Trim(Request("Remark"))
    If OrderFormID = "" Then
        FoundErr = True
        ErrMsg = ErrMsg & "<li>请指定订单ID！</li>"
    Else
        OrderFormID = PE_CLng(OrderFormID)
    End If
    If RefundMoney <= 0 Then
        FoundErr = True
        ErrMsg = ErrMsg & "<li>请输入退款金额！</li>"
    End If
    If HandlingCharge < 0 Then
        HandlingCharge = 0
    End If
    If RefundDate = "" Then
        FoundErr = True
        ErrMsg = ErrMsg & "<li>请输入退款日期！</li>"
    Else
        RefundDate = PE_CDate(RefundDate)
    End If
    If RefundType = "" Then
        FoundErr = True
        ErrMsg = ErrMsg & "<li>请选择退款方式！</li>"
    Else
        RefundType = PE_CLng(RefundType)
    End If
    If FoundErr = True Then Exit Sub
    
    TotalRefund = RefundMoney + HandlingCharge
    Set rsOrder = Server.CreateObject("adodb.recordset")
    rsOrder.Open "select * from PE_OrderForm where OrderFormID=" & OrderFormID & "", Conn, 1, 3
    If Not (rsOrder.BOF And rsOrder.EOF) Then
        If rsOrder("MoneyReceipt") >= TotalRefund Then
            rsOrder("MoneyReceipt") = rsOrder("MoneyReceipt") - TotalRefund
            If rsOrder("Status") >= 3 Then
                rsOrder("Status") = 2
            End If
            rsOrder.Update
            If RefundType = 1 Then
                If rsOrder("UserName") <> "" Then
                    Conn.Execute ("update PE_User set Balance=Balance+" & RefundMoney & " where UserName='" & rsOrder("UserName") & "'")
                Else
                    If rsOrder("ClientID") > 0 Then
                        Conn.Execute ("update PE_Client set Balance=Balance+" & RefundMoney & " where ClientID=" & rsOrder("ClientID") & "")
                    End If
                End If
                ' 向会员资金明细表中添加订单金额扣除记录
                Call AddBankrollItem(AdminName, rsOrder("UserName"), rsOrder("ClientID"), RefundMoney, 4, "", 0, 1, OrderFormID, 0, Remark, Now())
            End If
        Else
            FoundErr = True
            ErrMsg = ErrMsg & "<li>退款金额跟手续费的总和不能大于订单已付款！</li>"
        End If
    End If
    If FoundErr = True Then
        rsOrder.Close
        Set rsOrder = Nothing
        Exit Sub
    End If
    Dim strMsg
    strMsg = "保存退款信息成功！"
    strMsg = strMsg & SendMessageOfOrder(MessageOfRefund, "已经退款", rsOrder)
    strMsg = strMsg & SendEmailOfOrder("退款通知", EmailOfRefund, "已经退款", rsOrder)
    rsOrder.Close
    Set rsOrder = Nothing

    Response.Cookies(Site_Sn)("SendSMSToUser_Refund") = Trim(Request("SendSMSToUser"))
    Response.Cookies(Site_Sn)("SendSMSToContacter_Refund") = Trim(Request("SendSMSToContacter"))

    Call WriteSuccessMsg(strMsg, "Admin_Order.asp?Action=ShowOrder&OrderFormID=" & OrderFormID & "")
    If ErrMsg <> "" Then
        FoundErr = True
    End If
End Sub

Sub EndOrder()
    If AdminPurview > 1 And arrPurview(9) = False Then
        Response.Write "<br><p align='center'><font color='red' style='font-size:9pt'>对不起，你没有此项操作的权限。</font></p>"
        Call WriteEntry(6, AdminName, "越权操作")
        Exit Sub
    End If
    
    Dim OrderFormID, rsOrder
    OrderFormID = Trim(Request("OrderFormID"))
    If OrderFormID = "" Then
        FoundErr = True
        ErrMsg = ErrMsg & "<li>请指定OrderFormID！</li>"
    Else
        OrderFormID = PE_CLng(OrderFormID)
    End If
    If FoundErr = True Then Exit Sub
    
    Set rsOrder = Server.CreateObject("adodb.recordset")
    rsOrder.Open "select ClientID,Status,UserName,DeliverStatus,MoneyReceipt,MoneyTotal,PresentMoney,PresentExp,PresentPoint,OrderFormID from PE_OrderForm where OrderFormID=" & OrderFormID & "", Conn, 1, 3
    If rsOrder.BOF And rsOrder.EOF Then
        FoundErr = True
        ErrMsg = ErrMsg & "<li>找不到指定的订单！</li>"
        rsOrder.Close
        Set rsOrder = Nothing
        Exit Sub
    End If
    If rsOrder("Status") <= 1 Then
        FoundErr = True
        ErrMsg = ErrMsg & "<li>此订单还没有确认！不能结清！</li>"
    End If
    If rsOrder("MoneyReceipt") < rsOrder("MoneyTotal") Then
        FoundErr = True
        ErrMsg = ErrMsg & "<li>此订单还没有付清款项！不能结清！</li>"
    End If
    If rsOrder("DeliverStatus") < 2 Then
        FoundErr = True
        ErrMsg = ErrMsg & "<li>此订单还没有送货！不能结清！</li>"
    End If
    If FoundErr = True Then
        rsOrder.Close
        Set rsOrder = Nothing
        Exit Sub
    End If
    rsOrder("Status") = 4
    rsOrder.Update
           
    Dim rsOrderItem, TotalPresentExp, TotalPresentMoney, TotalPresentPoint
    Set rsOrderItem = Conn.Execute("select PresentExp,PresentMoney,PresentPoint,Amount from PE_OrderFormItem where OrderFormID=" & OrderFormID & "")
    Do While Not rsOrderItem.EOF
        '赠送积分
        If rsOrderItem("PresentExp") > 0 Then
            TotalPresentExp = TotalPresentExp + rsOrderItem("PresentExp") * rsOrderItem("Amount")
        End If
        '赠送点卷
        If rsOrderItem("PresentPoint") > 0 Then
            TotalPresentPoint = TotalPresentPoint + rsOrderItem("PresentPoint") * rsOrderItem("Amount")
        End If
        '返还现金卷
        If rsOrderItem("PresentMoney") > 0 Then
            TotalPresentMoney = TotalPresentMoney + rsOrderItem("PresentMoney") * rsOrderItem("Amount")
        End If
        rsOrderItem.MoveNext
    Loop
    Set rsOrderItem = Nothing

    '返还现金
    If rsOrder("PresentMoney") > 0 Or TotalPresentMoney > 0 Then
        Conn.Execute ("update PE_User set Balance=Balance+" & rsOrder("PresentMoney") + TotalPresentMoney & " where UserName='" & rsOrder("UserName") & "'")
        Call AddBankrollItem(AdminName, rsOrder("UserName"), rsOrder("ClientID"), rsOrder("PresentMoney") + TotalPresentMoney, 4, "", 0, 1, rsOrder("OrderFormID"), 0, "购物返还现金券", Now())
    End If
    '赠送积分
    If rsOrder("PresentExp") > 0 Or TotalPresentExp > 0 Then
        Conn.Execute ("update PE_User set UserExp=UserExp+" & rsOrder("PresentExp") + TotalPresentExp & " where UserName='" & rsOrder("UserName") & "'")
    End If
    '赠送点卷
    If rsOrder("PresentPoint") > 0 Or TotalPresentPoint > 0 Then
        Conn.Execute ("update PE_User set UserPoint=UserPoint+" & rsOrder("PresentPoint") + TotalPresentPoint & " where UserName='" & rsOrder("UserName") & "'")
        Call AddConsumeLog(AdminName, 0, rsOrder("UserName"), 0, rsOrder("PresentPoint") + TotalPresentPoint, 1, "购物赠送" & PointName)
    End If
   
    rsOrder.Close
    Set rsOrder = Nothing
    
    Call CloseConn
    Response.Redirect "Admin_Order.asp?Action=ShowOrder&OrderFormID=" & OrderFormID
End Sub

Sub SaveModifyOrder()
    If AdminPurview > 1 And arrPurview(2) = False Then
        Response.Write "<br><p align='center'><font color='red' style='font-size:9pt'>对不起，你没有此项操作的权限。</font></p>"
        Call WriteEntry(6, AdminName, "越权操作")
        Exit Sub
    End If
    
    Dim ContacterName, Address, ZipCode, Phone, Email, Mobile, NeedInvoice, InvoiceContent, Remark, AgentName, BeginDate, Status
    Dim PaymentType, Discount_Payment, rsPaymentType
    Dim DeliverType, Charge_Deliver, rsDeliverType, ChargeType
    Dim ReleaseType, MinMoney1, ReleaseCharge, MinMoney2, MaxCharge, MinMoney3
    Dim Charge_Min, Weight_Min, ChargePerUnit, WeightPerUnit, Charge_Max, Charge_Percent
    Dim TotalWeight

    Dim ClientID, trs, OrderFormID
    OrderFormID = Trim(Request("OrderFormID"))
    ContacterName = Trim(Request("ContacterName"))
    Address = Trim(Request("Address"))
    ZipCode = Trim(Request("ZipCode"))
    Phone = Trim(Request("Phone"))
    Email = Trim(Request("Email"))
    Mobile = Trim(Request("Mobile"))
    Status = PE_CLng(Trim(Request("Status")))
    PaymentType = PE_CLng(Trim(Request("PaymentType")))
    DeliverType = PE_CLng(Trim(Request("DeliverType")))
    NeedInvoice = Trim(Request("NeedInvoice"))
    InvoiceContent = Trim(Request("InvoiceContent"))
    Remark = Trim(Request("Remark"))
    AgentName = Trim(Request("AgentName"))
    BeginDate = Trim(Request("BeginDate"))
    If OrderFormID = "" Then
        FoundErr = True
        ErrMsg = ErrMsg & "<li>请指定OrderFormID！</li>"
    Else
        OrderFormID = PE_CLng(OrderFormID)
    End If
    If ContacterName = "" Then
        FoundErr = True
        ErrMsg = ErrMsg & "<li>请输入收货人姓名！</li>"
    End If
    If Address = "" Then
        FoundErr = True
        ErrMsg = ErrMsg & "<li>请输入收货人地址！</li>"
    End If
    If ZipCode = "" Then
        FoundErr = True
        ErrMsg = ErrMsg & "<li>请输入收货人邮编！</li>"
    End If
    If Phone = "" Then
        FoundErr = True
        ErrMsg = ErrMsg & "<li>请输入收货人电话！</li>"
    End If
    If Email = "" Then
        FoundErr = True
        ErrMsg = ErrMsg & "<li>请输入收货人邮箱！</li>"
    End If
    If Status <= 1 Then
        If PaymentType = "" Then
            FoundErr = True
            ErrMsg = ErrMsg & "<li>请指定付款方式！</li>"
        Else
            PaymentType = CLng(PaymentType)
            Set rsPaymentType = Conn.Execute("select * from PE_PaymentType where TypeID=" & PaymentType & "")
            If rsPaymentType.BOF And rsPaymentType.EOF Then
                FoundErr = True
                ErrMsg = ErrMsg & "<li>找不到指定的付款方式！</li>"
            Else
                Discount_Payment = rsPaymentType("Discount")
            End If
            Set rsPaymentType = Nothing
        End If
        If DeliverType = "" Then
            FoundErr = True
            ErrMsg = ErrMsg & "<li>请指定送货方式！</li>"
        Else
            DeliverType = CLng(DeliverType)
            Set rsDeliverType = Conn.Execute("select * from PE_DeliverType where TypeID=" & DeliverType & "")
            If rsDeliverType.BOF And rsDeliverType.EOF Then
                FoundErr = True
                ErrMsg = ErrMsg & "<li>找不到指定的送货方式！</li>"
            Else
                ChargeType = rsDeliverType("ChargeType")
                ReleaseType = PE_CLng(rsDeliverType("ReleaseType"))
                MinMoney1 = PE_CDbl(rsDeliverType("MinMoney1"))
                ReleaseCharge = PE_CDbl(rsDeliverType("ReleaseCharge"))
                MinMoney2 = PE_CDbl(rsDeliverType("MinMoney2"))
                MaxCharge = PE_CDbl(rsDeliverType("MaxCharge"))
                MinMoney3 = PE_CDbl(rsDeliverType("MinMoney3"))
                Charge_Min = PE_CDbl(rsDeliverType("Charge_Min"))
                Charge_Max = PE_CDbl(rsDeliverType("Charge_Max"))
                Charge_Percent = PE_CDbl(rsDeliverType("Charge_Percent"))
            End If
            Set rsDeliverType = Nothing
        End If
    End If

    If ChargeType = 1 Then
        Dim rsCity, AreaType, strProvince, strPostCode
        Set rsCity = Conn.Execute("select * from PE_City where left(PostCode,4)='" & Left(ZipCode, 4) & "'")
        If rsCity.BOF And rsCity.EOF Then
            strProvince = ""
            strPostCode = ""
        Else
            strProvince = rsCity("Province")
            strPostCode = rsCity("PostCode")
        End If
        rsCity.Close
        Set rsCity = Nothing
        
        If Left(MyPostcode, 4) = Left(ZipCode, 4) Then  '同城
            AreaType = 1
            Set rsDeliverType = Conn.Execute("select * from PE_DeliverCharge where AreaType=1 and DeliverTypeID=" & DeliverType & "")
            If Not (rsDeliverType.BOF And rsDeliverType.EOF) Then
                Charge_Min = PE_CDbl(rsDeliverType("Charge_Min"))
                Weight_Min = PE_CDbl(rsDeliverType("Weight_Min"))
                ChargePerUnit = PE_CDbl(rsDeliverType("ChargePerUnit"))
                WeightPerUnit = PE_CDbl(rsDeliverType("WeightPerUnit"))
                Charge_Max = PE_CDbl(rsDeliverType("Charge_Max"))
            End If
            Set rsDeliverType = Nothing
        Else '不同城
            If strProvince = MyProvince Then '同省
                Set rsDeliverType = Conn.Execute("select * from PE_DeliverCharge where AreaType=2 and DeliverTypeID=" & DeliverType & "")
                If Not (rsDeliverType.BOF And rsDeliverType.EOF) Then
                    If FoundInArr(rsDeliverType("arrArea"), Left(strPostCode, 4), ",") = True Then '如果同区域
                        Charge_Min = PE_CDbl(rsDeliverType("Charge_Min"))
                        Weight_Min = PE_CDbl(rsDeliverType("Weight_Min"))
                        ChargePerUnit = PE_CDbl(rsDeliverType("ChargePerUnit"))
                        WeightPerUnit = PE_CDbl(rsDeliverType("WeightPerUnit"))
                        Charge_Max = PE_CDbl(rsDeliverType("Charge_Max"))
                        AreaType = 2
                    Else  '同省但不同区域
                        AreaType = 3
                    End If
                Else
                    AreaType = 3
                End If
                Set rsDeliverType = Nothing
                If AreaType = 3 Then
                    Set rsDeliverType = Conn.Execute("select * from PE_DeliverCharge where AreaType=3 and DeliverTypeID=" & DeliverType & "")
                    If Not (rsDeliverType.BOF And rsDeliverType.EOF) Then
                        Charge_Min = PE_CDbl(rsDeliverType("Charge_Min"))
                        Weight_Min = PE_CDbl(rsDeliverType("Weight_Min"))
                        ChargePerUnit = PE_CDbl(rsDeliverType("ChargePerUnit"))
                        WeightPerUnit = PE_CDbl(rsDeliverType("WeightPerUnit"))
                        Charge_Max = PE_CDbl(rsDeliverType("Charge_Max"))
                    End If
                    Set rsDeliverType = Nothing
                End If
            Else '不同省
                AreaType = 5
                Set rsDeliverType = Conn.Execute("select * from PE_DeliverCharge where AreaType=4 and DeliverTypeID=" & DeliverType & "")
                If Not (rsDeliverType.BOF And rsDeliverType.EOF) Then
                    Do While Not rsDeliverType.EOF
                        If FoundInArr(rsDeliverType("arrArea"), strProvince, ",") = True Then  '如果在指定省份列表中
                            Charge_Min = PE_CDbl(rsDeliverType("Charge_Min"))
                            Weight_Min = PE_CDbl(rsDeliverType("Weight_Min"))
                            ChargePerUnit = PE_CDbl(rsDeliverType("ChargePerUnit"))
                            WeightPerUnit = PE_CDbl(rsDeliverType("WeightPerUnit"))
                            Charge_Max = PE_CDbl(rsDeliverType("Charge_Max"))
                            AreaType = 4
                            Exit Do
                        End If
                        rsDeliverType.MoveNext
                    Loop
                End If
                Set rsDeliverType = Nothing
                If AreaType = 5 Then
                    Set rsCity = Conn.Execute("select Top 1 * from PE_City where left(PostCode,2)='" & Left(ZipCode, 2) & "'")
                    If Not (rsCity.BOF And rsCity.EOF) Then
                        Set rsDeliverType = Conn.Execute("select Top 1 * from PE_DeliverCharge where AreaType=4 and DeliverTypeID=" & DeliverType & "")
                        If Not (rsDeliverType.BOF And rsDeliverType.EOF) Then
                            Charge_Min = PE_CDbl(rsDeliverType("Charge_Min"))
                            Weight_Min = PE_CDbl(rsDeliverType("Weight_Min"))
                            ChargePerUnit = PE_CDbl(rsDeliverType("ChargePerUnit"))
                            WeightPerUnit = PE_CDbl(rsDeliverType("WeightPerUnit"))
                            Charge_Max = PE_CDbl(rsDeliverType("Charge_Max"))
                            AreaType = 4
                        End If
                        rsDeliverType.Close
                        Set rsDeliverType = Nothing
                    End If
                    rsCity.Close
                    Set rsCity = Nothing
                End If
                If AreaType = 5 Then
                    Set rsDeliverType = Conn.Execute("select * from PE_DeliverCharge where AreaType=5 and DeliverTypeID=" & DeliverType & "")
                    If Not (rsDeliverType.BOF And rsDeliverType.EOF) Then
                        Charge_Min = PE_CDbl(rsDeliverType("Charge_Min"))
                        Weight_Min = PE_CDbl(rsDeliverType("Weight_Min"))
                        ChargePerUnit = PE_CDbl(rsDeliverType("ChargePerUnit"))
                        WeightPerUnit = PE_CDbl(rsDeliverType("WeightPerUnit"))
                        Charge_Max = PE_CDbl(rsDeliverType("Charge_Max"))
                    End If
                    Set rsDeliverType = Nothing
                End If
            End If
        End If
        If WeightPerUnit <= 0 Then
            WeightPerUnit = 1
        End If
    End If
    
    If NeedInvoice = "Yes" Then
        NeedInvoice = True
    Else
        NeedInvoice = False
    End If
    If BeginDate = "" Then
        FoundErr = True
        ErrMsg = ErrMsg & "<li>请输入购买日期！</li>"
    ElseIf IsDate(BeginDate) = False Then
        FoundErr = True
        ErrMsg = ErrMsg & "<li>购买日期格式不正确！</li>"
    Else
        BeginDate = CDate(BeginDate)
    End If
    
    If FoundErr = True Then Exit Sub

    
    Dim dblPrice, dblTruePrice, dblAmount, dblSubtotal, dblTotal, dblTotal2, Charge_Deliver_Original
    Dim OrderFormNum, i
    Dim rsItem, ItemID
    
    dblSubtotal = 0
    dblTotal = 0
    TotalWeight = 0

    Dim rsOrder, sqlOrder
    sqlOrder = "select * from PE_OrderForm where OrderFormID=" & OrderFormID
    Set rsOrder = Server.CreateObject("adodb.recordset")
    rsOrder.Open sqlOrder, Conn, 1, 3
    If rsOrder.BOF And rsOrder.EOF Then
        FoundErr = True
        ErrMsg = ErrMsg & "<li>找不到指定的订单！</li>"
        rsOrder.Close
        Set rsOrder = Nothing
        Exit Sub
    End If
    ClientID = rsOrder("ClientID")
    If rsOrder("Status") <= 1 Then
        '更改订单详细表的数据
        Set rsItem = Server.CreateObject("adodb.recordset")
        rsItem.Open "select I.*,P.Weight from PE_OrderFormItem I inner join PE_Product P on I.ProductID=P.ProductID where OrderFormID=" & OrderFormID & " order by ItemID", Conn, 1, 3
        Do While Not rsItem.EOF
            dblAmount = rsItem("Amount")
            dblTruePrice = PE_CDbl(Trim(Request("TruePrice_" & rsItem("ItemID") & "")))
            dblSubtotal = dblTruePrice * rsItem("Amount")
            dblTotal = dblTotal + dblSubtotal
            TotalWeight = TotalWeight + PE_CDbl(rsItem("Weight")) * dblAmount
            
            rsItem("TruePrice") = dblTruePrice
            rsItem("Subtotal") = dblSubtotal
            rsItem("ServiceTerm") = PE_CLng(Trim(Request("ServiceTerm_" & rsItem("ItemID") & "")))
            rsItem("Remark") = Trim(Request("Remark_" & rsItem("ItemID") & ""))
            rsItem("BeginDate") = BeginDate
            rsItem.Update
            rsItem.MoveNext
        Loop
        rsItem.Close
        Set rsItem = Nothing
        
        rsOrder("MoneyGoods") = dblTotal

        dblTotal2 = dblTotal
        If Discount_Payment > 0 And Discount_Payment < 100 Then
            dblTotal = dblTotal * Discount_Payment / 100
        End If

        Select Case ChargeType
        Case 0
            Charge_Deliver = 0
        Case 1
            If TotalWeight > 0 Then
                If TotalWeight > Weight_Min Then
                    Dim iTemp
                    iTemp = (TotalWeight - Weight_Min) / WeightPerUnit
                    If iTemp > Fix(iTemp) Then
                        iTemp = Fix(iTemp) + 1
                    End If
                    Charge_Deliver = Charge_Min + iTemp * ChargePerUnit
                    If Charge_Deliver > Charge_Max Then
                        Charge_Deliver = Charge_Max
                    End If
                Else
                    Charge_Deliver = Charge_Min
                End If
            Else
                Charge_Deliver = 0
            End If
        Case 2
            Charge_Deliver = dblTotal2 * Charge_Percent / 100 + Charge_Min
            If Charge_Deliver > Charge_Max Then
                Charge_Deliver = Charge_Max
            End If
        End Select
        If Charge_Deliver > 0 And ReleaseType > 0 And dblTotal2 >= MinMoney1 Then
            Charge_Deliver_Original = Charge_Deliver
            If Charge_Deliver <= ReleaseCharge Then
                Charge_Deliver = 0
            Else
                Charge_Deliver = Charge_Deliver - ReleaseCharge
            End If
            If dblTotal2 >= MinMoney2 Then
                If dblTotal2 >= MinMoney3 Then
                    Charge_Deliver = 0
                Else
                    If Charge_Deliver_Original <= MaxCharge Then
                        Charge_Deliver = 0
                    End If
                End If
            End If
        End If

        dblTotal = dblTotal + Charge_Deliver

        If IncludeTax = True Then
            If NeedInvoice = False Then
                dblTotal = dblTotal * (100 - TaxRate) / 100
            End If
        Else
            If NeedInvoice = True Then
                dblTotal = dblTotal * (100 + TaxRate) / 100
            End If
        End If
        rsOrder("PaymentType") = PaymentType
        rsOrder("DeliverType") = DeliverType
        rsOrder("MoneyTotal") = Round(dblTotal, 2)
        rsOrder("Discount_Payment") = Discount_Payment
        rsOrder("Charge_Deliver") = Charge_Deliver
    End If
    rsOrder("AgentName") = AgentName
    rsOrder("ContacterName") = ContacterName
    rsOrder("Address") = Address
    rsOrder("ZipCode") = ZipCode
    rsOrder("Phone") = Phone
    rsOrder("Email") = Email
    rsOrder("Mobile") = Mobile
    rsOrder("NeedInvoice") = NeedInvoice
    rsOrder("InvoiceContent") = InvoiceContent
    rsOrder("Remark") = Remark
    rsOrder("BeginDate") = BeginDate
    rsOrder.Update
    rsOrder.Close
    Set rsOrder = Nothing
    
    Call CloseConn
    Response.Redirect "Admin_Order.asp?Action=ShowOrder&OrderFormID=" & OrderFormID
End Sub


Sub ConfirmOrder()
    If AdminPurview > 1 And arrPurview(1) = False Then
        Response.Write "<br><p align='center'><font color='red' style='font-size:9pt'>对不起，你没有此项操作的权限。</font></p>"
        Call WriteEntry(6, AdminName, "越权操作")
        Exit Sub
    End If
    
    Dim OrderFormID
    Dim rsOrder, sqlOrder
    OrderFormID = Trim(Request("OrderFormID"))
    If OrderFormID = "" Then
        FoundErr = True
        ErrMsg = ErrMsg & "<li>请指定订单ID！</li>"
        Exit Sub
    Else
        OrderFormID = PE_CLng(OrderFormID)
    End If
    
    sqlOrder = "select * from PE_OrderForm where OrderFormID=" & OrderFormID & ""
    Set rsOrder = Server.CreateObject("Adodb.RecordSet")
    rsOrder.Open sqlOrder, Conn, 1, 3
    If rsOrder.BOF And rsOrder.EOF Then
        FoundErr = True
        ErrMsg = ErrMsg & "<li>找不到指定的订单！</li>"
        rsOrder.Close
        Set rsOrder = Nothing
        Exit Sub
    End If
    If rsOrder("Status") > 1 Then
        FoundErr = True
        ErrMsg = ErrMsg & "<li>此订单已经确认！</li>"
        rsOrder.Close
        Set rsOrder = Nothing
        Exit Sub
    End If
    If rsOrder("MoneyReceipt") > 0 Then
        rsOrder("Status") = 3
    Else
        rsOrder("Status") = 2
    End If
    rsOrder.Update
    
    Dim strMsg
    strMsg = "订单确认成功！"
    strMsg = strMsg & SendMessageOfOrder(MessageOfOrderConfirm, "订单已经确认", rsOrder)
    strMsg = strMsg & SendEmailOfOrder("订单确认通知", EmailOfOrderConfirm, "订单已经确认", rsOrder)
    rsOrder.Close
    Set rsOrder = Nothing

    Response.Cookies(Site_Sn)("SendSMSToUser_OrderConfirm") = Trim(Request("SendSMSToUser"))
    Response.Cookies(Site_Sn)("SendSMSToContacter_OrderConfirm") = Trim(Request("SendSMSToContacter"))

    Call WriteSuccessMsg(strMsg, "Admin_Order.asp?Action=ShowOrder&OrderFormID=" & OrderFormID & "")
    If ErrMsg <> "" Then
        FoundErr = True
    End If
End Sub

Sub CancelConfirm()
    If AdminPurview > 1 And arrPurview(1) = False Then
        Response.Write "<br><p align='center'><font color='red' style='font-size:9pt'>对不起，你没有此项操作的权限。</font></p>"
        Call WriteEntry(6, AdminName, "越权操作")
        Exit Sub
    End If
    
    Dim OrderFormID
    Dim rsOrder, sqlOrder
    OrderFormID = Trim(Request("OrderFormID"))
    If OrderFormID = "" Then
        FoundErr = True
        ErrMsg = ErrMsg & "<li>请指定订单ID！</li>"
        Exit Sub
    Else
        OrderFormID = PE_CLng(OrderFormID)
    End If
    
    sqlOrder = "select * from PE_OrderForm where OrderFormID=" & OrderFormID & ""
    Set rsOrder = Server.CreateObject("Adodb.RecordSet")
    rsOrder.Open sqlOrder, Conn, 1, 3
    If rsOrder.BOF And rsOrder.EOF Then
        FoundErr = True
        ErrMsg = ErrMsg & "<li>找不到指定的订单！</li>"
        rsOrder.Close
        Set rsOrder = Nothing
        Exit Sub
    End If
    If rsOrder("Status") = 4 Or rsOrder("MoneyReceipt") >= rsOrder("MoneyTotal") Then
        FoundErr = True
        ErrMsg = ErrMsg & "<li>此订单已经付清，不能再取消确认！</li>"
        rsOrder.Close
        Set rsOrder = Nothing
        Exit Sub
    End If
    rsOrder("Status") = 1
    rsOrder.Update
    rsOrder.Close
    Set rsOrder = Nothing
    
    Dim strMsg
    strMsg = "已经取消确认指定的订单！"

    Call WriteSuccessMsg(strMsg, "Admin_Order.asp?Action=ShowOrder&OrderFormID=" & OrderFormID & "")
    If ErrMsg <> "" Then
        FoundErr = True
    End If
End Sub

Sub DelOrder()
    If AdminPurview > 1 And arrPurview(3) = False Then
        Response.Write "<br><p align='center'><font color='red' style='font-size:9pt'>对不起，你没有此项操作的权限。</font></p>"
        Call WriteEntry(6, AdminName, "越权操作")
        Exit Sub
    End If

    Dim OrderFormID, ClientID, UserName
    Dim rsOrder, sqlOrder, rsOrderItem
    OrderFormID = Trim(Request("OrderFormID"))
    If IsValidID(OrderFormID) = False Then
        OrderFormID = ""
    End If

    If OrderFormID = "" Then
        FoundErr = True
        ErrMsg = ErrMsg & "<li>请指定订单ID！</li>"
        Exit Sub
    End If
    
    sqlOrder = "select * from PE_OrderForm where OrderFormID in (" & OrderFormID & ")"
    Set rsOrder = Server.CreateObject("Adodb.RecordSet")
    rsOrder.Open sqlOrder, Conn, 1, 3
    Do While Not rsOrder.EOF
        If UserName = "" Then
            UserName = rsOrder("UserName")
        End If
        If ClientID = 0 Then
            ClientID = rsOrder("ClientID")
        End If

        If rsOrder("MoneyReceipt") > 0 Or rsOrder("Status") > 3 Then
            FoundErr = True
            ErrMsg = ErrMsg & "<li>订单：" & rsOrder("OrderFormNum") & "已经付款，不能再删除！</li>"
        Else
            Set rsOrderItem = Conn.Execute("select ProductID,Amount from PE_OrderFormItem where OrderFormID=" & rsOrder("OrderFormID") & "")
            Do While Not rsOrderItem.EOF
                Conn.Execute ("update PE_Product set OrderNum=OrderNum-" & rsOrderItem("Amount") & " where ProductID=" & rsOrderItem("ProductID") & "")
                rsOrderItem.MoveNext
            Loop
            rsOrderItem.Close
            Set rsOrderItem = Nothing
            
            Conn.Execute ("delete from PE_BankrollItem where OrderFormID=" & rsOrder("OrderFormID") & "")
            Conn.Execute ("delete from PE_DeliverItem where OrderFormID=" & rsOrder("OrderFormID") & "")
            Conn.Execute ("delete from PE_OrderFormItem where OrderFormID=" & rsOrder("OrderFormID") & "")
            '不能删除在线支付记录，因为有时会员对订单进行在线支付但不是即时成功，此时删除了这个订单，就会造成找不到实际应该成功的在线支付记录
            'Conn.Execute ("delete from PE_Payment where OrderFormID=" & rsOrder("OrderFormID") & "")
            Conn.Execute ("delete from PE_TransferItem where OrderFormID=" & rsOrder("OrderFormID") & "")
            
            rsOrder.Delete
            rsOrder.Update
        End If
        rsOrder.MoveNext
    Loop
    rsOrder.Close
    Set rsOrder = Nothing
    Call CloseConn
    If UserName <> "" Then
        Response.Redirect "Admin_User.asp?Action=Show&UserName=" & UserName
    Else
        If ClientID > 0 Then
            Response.Redirect "Admin_Client.asp?Action=Show&InType=2&ClientID=" & ClientID
        Else
            Response.Redirect "Admin_Order.asp"
        End If
    End If
End Sub

Sub SaveTransfer()
    If AdminPurview > 1 And arrPurview(10) = False Then
        Response.Write "<br><p align='center'><font color='red' style='font-size:9pt'>对不起，你没有此项操作的权限。</font></p>"
        Call WriteEntry(6, AdminName, "越权操作")
        Exit Sub
    End If
    
    Dim OrderFormID, TargetUser, Poundage, Payer, PayerClientID, PayerUserName, Remark, Balance
    OrderFormID = Trim(Request("OrderFormID"))
    Poundage = Trim(Request("Poundage"))
    Payer = Trim(Request("Payer"))
    Remark = Trim(Request("Remark"))
    If OrderFormID = "" Then
        FoundErr = True
        ErrMsg = ErrMsg & "<li>请指定OrderFormID！</li>"
    Else
        OrderFormID = PE_CLng(OrderFormID)
    End If
    TargetUser = Trim(Request("TargetUser"))
    If TargetUser = "" Then
        FoundErr = True
        ErrMsg = ErrMsg & "<li>请指定接收人的用户名！</li>"
    Else
        TargetUser = ReplaceBadChar(TargetUser)
    End If
    If Poundage = "" Then
        Poundage = 0
    Else
        Poundage = PE_CDbl(Poundage)
    End If
    If Payer = "" Then
        Payer = 1
    Else
        Payer = PE_CLng(Payer)
    End If
    If FoundErr = True Then Exit Sub
    
    Dim rsOrder, sqlOrder, strMsg
    sqlOrder = "select * from PE_OrderForm where OrderFormID=" & OrderFormID & ""
    Set rsOrder = Server.CreateObject("adodb.recordset")
    rsOrder.Open sqlOrder, Conn, 1, 3
    If rsOrder.BOF And rsOrder.EOF Then
        FoundErr = True
        ErrMsg = ErrMsg & "<li>找不到指定的订单！</li>"
        rsOrder.Close
        Set rsOrder = Nothing
        Exit Sub
    End If

    If rsOrder("UserName") = TargetUser Then
        FoundErr = True
        ErrMsg = ErrMsg & "<li>接收人与订单当前所有者为同一人，无需过户！</li>"
    End If
    
    Dim rsTarget
    Set rsTarget = Conn.Execute("select ClientID,UserName,Balance from PE_User where UserName='" & TargetUser & "'")
    If rsTarget.BOF And rsTarget.EOF Then
        FoundErr = True
        ErrMsg = ErrMsg & "<li>找不到指定的接收人！</li>"
        rsOrder.Close
        Set rsOrder = Nothing
        Exit Sub
    End If

    If rsTarget("Balance") < Poundage And Payer = 2 Then
        FoundErr = True
        ErrMsg = ErrMsg & "<li>过户对象的资金余额不足支付手续费！</li>"
    End If

    If FoundErr = True Then
        rsTarget.Close
        Set rsTarget = Nothing
        rsOrder.Close
        Set rsOrder = Nothing
        Exit Sub
    End If

    If Payer = 1 And rsOrder("UserName") <> "" Then
        Dim rsUser
        Set rsUser = Conn.Execute("select Balance from PE_User where UserName='" & rsOrder("UserName") & "'")
            If rsUser("Balance") < Poundage Then
                FoundErr = True
                ErrMsg = ErrMsg & "<li>订单当前所有者，资金余额不足支付手续费！</li>"
            End If
    End If

    If FoundErr = True Then
        rsUser.Close
        Set rsUser = Nothing
        rsOrder.Close
        Set rsOrder = Nothing
        Exit Sub
    End If
          
    If Payer = 1 Then
        PayerClientID = PE_CLng(rsOrder("ClientID"))
        PayerUserName = rsOrder("UserName") & ""
    Else
        PayerClientID = PE_CLng(rsTarget("ClientID"))
        PayerUserName = rsTarget("UserName")
    End If
    
            
    '添加进订单过户记录明细表
    Dim rsTransfer
    Set rsTransfer = Server.CreateObject("adodb.recordset")
    rsTransfer.Open "select top 1 * from PE_TransferItem", Conn, 1, 3
    rsTransfer.AddNew
    rsTransfer("OrderFormID") = OrderFormID
    rsTransfer("OwnerUserName") = rsOrder("UserName")
    rsTransfer("TargetUserName") = rsTarget("UserName")
    rsTransfer("Poundage") = Poundage
    rsTransfer("PayerUserName") = PayerUserName
    rsTransfer("Remark") = Remark
    rsTransfer("DateAndTime") = Now()
    rsTransfer("Inputer") = AdminName
    rsTransfer.Update
    rsTransfer.Close
    Set rsTransfer = Nothing
            
    If Poundage > 0 Then
        Conn.Execute ("update PE_User set Balance=Balance-" & Poundage & " where UserName='" & PayerUserName & "'")
        Call AddBankrollItem(AdminName, PayerUserName, PayerClientID, Poundage, 4, "", 0, 2, OrderFormID, 0, "支付订单过户费用，订单号：" & rsOrder("OrderFormNum") & "。由" & rsOrder("UserName") & "过户给" & rsTarget("Username"), Now())
    End If
    
    '更改订单的所属者
    strMsg = "已经成功将编号为：<font color='red'>" & rsOrder("OrderFormNum") & "</font> 的订单（原所有者：<font color='red'>" & rsOrder("UserName") & "</font>）过户给：<font color='red'>" & rsTarget("UserName") & "</font>！"
    strMsg = strMsg & "<br><p align='center'><a href='Admin_Order.asp?Action=ShowOrder&OrderFormID=" & OrderFormID & "'>点此查看订单信息</a></p>"
    
    rsOrder("ClientID") = PE_CLng(rsTarget("ClientID"))
    rsOrder("UserName") = rsTarget("UserName")
    rsOrder.Update
    rsOrder.Close
    Set rsOrder = Nothing
    rsTarget.Close
    Set rsTarget = Nothing
    Call WriteSuccessMsg(strMsg, ComeUrl)
End Sub

Sub outExcel()
    If AdminPurview > 1 And arrPurview(12) = False Then
        Response.Write "<br><p align='center'><font color='red' style='font-size:9pt'>对不起，你没有此项操作的权限。</font></p>"
        Call WriteEntry(6, AdminName, "越权操作")
        Exit Sub
    End If
    
    Dim Rsout
    Set Rsout = Conn.Execute(sqlOrder)
    If Rsout.BOF And Rsout.EOF Then
        Response.Write "无指定的订单！"
    Else
        Response.Write "<table border=""0"" cellspacing=""1"" style=""border-collapse: collapse;table-layout:fixed"" id=""AutoNumber1"" height=""32"">" & vbCrLf
        Response.Write "<tr>" & vbCrLf
        Response.Write "<td align=""center""><span lang=""zh-cn""><b>订单编号</b></span></td>" & vbCrLf
        Response.Write "<td align=""center""><span lang=""zh-cn""><b>客户名称</b></span></td>" & vbCrLf
        Response.Write "<td align=""center""><span lang=""zh-cn""><b>用户名</b></span></td>" & vbCrLf
        Response.Write "<td align=""center""><span lang=""zh-cn""><b>下单时间</b></span></td>" & vbCrLf
        Response.Write "<td align=""center""><span lang=""zh-cn""><b>订单金额</b></span></td>" & vbCrLf
        Response.Write "<td align=""center""><span lang=""zh-cn""><b>收款金额</b></span></td>" & vbCrLf
        Response.Write "<td align=""center""><span lang=""zh-cn""><b>需要发票</b></span></td>" & vbCrLf
        Response.Write "<td align=""center""><span lang=""zh-cn""><b>已开发票</b></span></td>" & vbCrLf
        Response.Write "<td align=""center""><span lang=""zh-cn""><b>发票信息</b></span></td>" & vbCrLf
        Response.Write "<td align=""center""><span lang=""zh-cn""><b>订单状态</b></span></td>" & vbCrLf
        Response.Write "<td align=""center""><span lang=""zh-cn""><b>付款状态</b></span></td>" & vbCrLf
        Response.Write "<td align=""center""><span lang=""zh-cn""><b>物流状态</b></span></td>" & vbCrLf
        Response.Write "<td align=""center""><span lang=""zh-cn""><b>收货人姓名</b></span></td>" & vbCrLf
        Response.Write "<td align=""center""><span lang=""zh-cn""><b>联系电话</b></span></td>" & vbCrLf
        Response.Write "<td align=""center""><span lang=""zh-cn""><b>收货人地址</b></span></td>" & vbCrLf
        Response.Write "<td align=""center""><span lang=""zh-cn""><b>邮政编码</b></span></td>" & vbCrLf
        Response.Write "<td align=""center""><span lang=""zh-cn""><b>收货人邮箱</b></span></td>" & vbCrLf
        Response.Write "<td align=""center""><span lang=""zh-cn""><b>收货人手机</b></span></td>" & vbCrLf
        Response.Write "<td align=""center""><span lang=""zh-cn""><b>代 理 商</b></span></td>" & vbCrLf
        Response.Write "<td align=""center""><span lang=""zh-cn""><b>购买日期</b></span></td>" & vbCrLf
        Response.Write "<td align=""center""><span lang=""zh-cn""><b>购买商品</b></span></td>" & vbCrLf
        Response.Write "<td align=""center""><span lang=""zh-cn""><b>付款方式</b></span></td>" & vbCrLf
        Response.Write "<td align=""center""><span lang=""zh-cn""><b>送货方式</b></span></td>" & vbCrLf
        Response.Write "<td align=""center""><span lang=""zh-cn""><b>备注/留言</b></span></td>" & vbCrLf
        Response.Write "</tr>" & vbCrLf
        Do While Not Rsout.EOF
            Response.Write "<tr>" & vbCrLf
            Response.Write "<td align=""center""><span lang=""zh-cn"">" & Rsout("OrderFormNum") & "</span></td>" & vbCrLf
            Response.Write "<td align=""center""><span lang=""zh-cn"">" & Rsout("ClientName") & "</span></td>" & vbCrLf
            Response.Write "<td align=""center""><span lang=""zh-cn"">" & Rsout("UserName") & "</span></td>" & vbCrLf
            Response.Write "<td align=""center""><span lang=""zh-cn"">" & FormatDateTime(Rsout("InputTime"), 2) & "</span></td>" & vbCrLf
            Response.Write "<td align=""center""><span lang=""zh-cn"">" & FormatNumber(Rsout("MoneyTotal"), 2, vbTrue, vbFalse, vbTrue) & "</span></td>" & vbCrLf
            Response.Write "<td align=""center""><span lang=""zh-cn"">" & FormatNumber(Rsout("MoneyReceipt"), 2, vbTrue, vbFalse, vbTrue) & "</span></td>" & vbCrLf
            Response.Write "<td align=""center""><span lang=""zh-cn"">"
            If Rsout("NeedInvoice") = True Then
                Response.Write "是"
            Else
                Response.Write "否"
            End If
            Response.Write "</span></td>" & vbCrLf
            Response.Write "<td align=""center""><span lang=""zh-cn"">"
            If Rsout("NeedInvoice") = True Then
                If Rsout("Invoiced") = True Then
                    Response.Write "是"
                Else
                    Response.Write "否"
                End If
            Else
                Response.Write "否"
            End If
            Response.Write "</span></td>" & vbCrLf
            Response.Write "<td align=""center""><span lang=""zh-cn"">"
            If Rsout("NeedInvoice") = True Then
                Response.Write Rsout("InvoiceContent")
            End If
            Response.Write "</span></td>" & vbCrLf
            Response.Write "<td align=""center""><span lang=""zh-cn"">"
            Select Case Rsout("Status")
            Case 0, 1
                Response.Write "等待确认"
            Case 2, 3
                Response.Write "已经确认"
            Case 4
                Response.Write "已结清"
            End Select
            Response.Write "</span></td>" & vbCrLf
            Response.Write "<td align=""center""><span lang=""zh-cn"">"
            If Rsout("MoneyTotal") > Rsout("MoneyReceipt") Then
                If Rsout("MoneyReceipt") > 0 Then
                    Response.Write "已收定金"
                Else
                    Response.Write "等待汇款"
                End If
            Else
                Response.Write "已经付清"
            End If
            Response.Write "</span></td>" & vbCrLf
            Response.Write "<td align=""center""><span lang=""zh-cn"">"
            Select Case Rsout("DeliverStatus")
            Case 0, 1
                Response.Write "配送中"
            Case 2
                Response.Write "已发货"
            Case 3
                Response.Write "已签收"
            End Select
            Response.Write "</span></td>" & vbCrLf
            Response.Write "<td align=""center""><span lang=""zh-cn"">" & Rsout("ContacterName") & "</span></td>" & vbCrLf
            Response.Write "<td align=""center""><span lang=""zh-cn"">" & Rsout("Phone") & "</span></td>" & vbCrLf
            Response.Write "<td align=""center""><span lang=""zh-cn"">" & Rsout("Address") & "</span></td>" & vbCrLf
            Response.Write "<td align=""center""><span lang=""zh-cn"">" & Rsout("ZipCode") & "</span></td>" & vbCrLf
            Response.Write "<td align=""center""><span lang=""zh-cn"">" & Rsout("Email") & "</span></td>" & vbCrLf
            Response.Write "<td align=""center""><span lang=""zh-cn"">" & Rsout("Mobile") & "</span></td>" & vbCrLf
            Response.Write "<td align=""center""><span lang=""zh-cn"">" & Rsout("AgentName") & "</span></td>" & vbCrLf
            Response.Write "<td align=""center""><span lang=""zh-cn"">" & FormatDateTime(Rsout("BeginDate"), 2) & "</span></td>" & vbCrLf
            Response.Write "<td align=""center""><span lang=""zh-cn"">" & GetProducts(Rsout("OrderFormID")) & "</span></td>" & vbCrLf
            Response.Write "<td align=""center""><span lang=""zh-cn"">" & GetPaymentType(Rsout("PaymentType")) & "</span></td>" & vbCrLf
            Response.Write "<td align=""center""><span lang=""zh-cn"">" & GetDeliverType(Rsout("DeliverType")) & "</span></td>" & vbCrLf
            Response.Write "<td align=""center""><span lang=""zh-cn"">" & Rsout("Remark") & "</span></td>" & vbCrLf
            Response.Write "</tr>" & vbCrLf
            Rsout.MoveNext
        Loop
    End If
    Rsout.Close
    Set Rsout = Nothing
End Sub

Function GetProducts(intOrderFormID)
    Dim rsProducts, ProductList
    ProductList = ""
    Set rsProducts = Conn.Execute("select I.ItemID,P.ProductID,P.ProductName,P.ProductKind,I.SaleType,I.PresentExp,I.PresentMoney,I.PresentPoint,I.Price_Original,I.Price,I.TruePrice,I.Amount,P.Unit,I.BeginDate,I.ServiceTerm,I.Remark from PE_OrderFormItem I inner join PE_Product P on I.ProductID=P.ProductID where I.OrderFormID=" & intOrderFormID & " order by I.ItemID")
    Do While Not rsProducts.EOF
        ProductList = ProductList & rsProducts("ProductName") & " " & rsProducts("Amount") & rsProducts("Unit") & "&nbsp;&nbsp;&nbsp;&nbsp;"
        rsProducts.MoveNext
    Loop
    GetProducts = ProductList
End Function

Function SendMessageOfOrder(Content, Msg, rsOrder)
    If Content = "" Then
        Exit Function
    End If
    Dim strContent, strMsg
    Dim rsUser

    strContent = ReplaceOrderInfo(Content, rsOrder, 1)
    
    Dim SendSMSToUser, SendSMSToContacter
    Dim strResult
    SendSMSToUser = Trim(Request("SendSMSToUser"))
    SendSMSToContacter = Trim(Request("SendSMSToContacter"))
    If SendSMSToUser = "Yes" And rsOrder("UserName") <> "" Then
        Set rsUser = Conn.Execute("select U.UserID,C.Mobile,C.PHS from PE_User U inner join PE_Contacter C on U.ContacterID=C.ContacterID where U.UserName='" & rsOrder("UserName") & "'")
        If rsUser.BOF And rsUser.EOF Then
            FoundErr = True
            ErrMsg = ErrMsg & "<li>订单对应的会员没有填写联系方式，所以没有发送手机短信！</li>"
        Else
            Dim SendNum
            SendNum = rsUser("Mobile") & ""
            If SendNum = "" Then
                SendNum = rsUser("PHS") & ""
            End If
            If SendNum = "" Then
                FoundErr = True
                ErrMsg = ErrMsg & "<li>订单对应的会员没有填写手机号，所以没有发送手机短信！</li>"
            Else
                strResult = PostSMS(SendNum, strContent, "管理员ID：" & AdminID)
                If strResult = "短信已经提交到发送队列" Then
                    strMsg = strMsg & "<br><br>已经向会员发送了一条手机短信，通知他" & Msg & "！"
                Else
                    strMsg = strMsg & "<br><br>向会员发送了手机短信失败，失败原因：" & strResult & ""
                End If
            End If
        End If
        rsUser.Close
        Set rsUser = Nothing
    End If
    If SendSMSToContacter = "Yes" And rsOrder("Mobile") <> "" Then
        strResult = PostSMS(rsOrder("Mobile"), strContent, "管理员ID：" & AdminID)
        If strResult = "短信已经提交到发送队列" Then
            strMsg = strMsg & "<br><br>已经向收货人发送了一条手机短信，通知他" & Msg & "！"
        Else
            strMsg = strMsg & "<br><br>向收货人发送了手机短信失败，失败原因：" & strResult & ""
        End If
    End If

    SendMessageOfOrder = strMsg
End Function

Function SendEmailOfOrder(Title, Content, Msg, rsOrder)
    If Content = "" Then
        Exit Function
    End If
    Dim strContent, strMsg
    Dim rsUser

    Dim SendMessageToUser, SendEmailToUser, SendEmailToContacter
    SendMessageToUser = Trim(Request("SendMessageToUser"))
    SendEmailToUser = Trim(Request("SendEmailToUser"))
    SendEmailToContacter = Trim(Request("SendEmailToContacter"))
    strContent = ReplaceOrderInfo(Content, rsOrder, 0)

    If SendMessageToUser = "Yes" And rsOrder("UserName") <> "" Then
        Call SendMessage(rsOrder("UserName"), Title, strContent, UserName)
        strMsg = strMsg & "<br><br>已经向会员发送了一条站内短信，通知他" & Msg & "！"
    End If
    If SendEmailToUser = "Yes" Or SendEmailToContacter = "Yes" Then
        Dim PE_Mail
        Set PE_Mail = New SendMail
        If ErrMsg = "" Then
            If SendEmailToUser = "Yes" And rsOrder("UserName") <> "" Then
                Set rsUser = Conn.Execute("select UserName,Email from PE_User where UserName='" & rsOrder("UserName") & "'")
                If rsUser.BOF And rsUser.EOF Then
                    FoundErr = True
                    ErrMsg = ErrMsg & "<li>找不到订单对应的会员，所以没有发送邮件！</li>"
                Else
                    ErrMsg = PE_Mail.Send(rsUser("Email"), rsUser("UserName"), Title, strContent, WebmasterName, WebmasterEmail, 3)
                    If ErrMsg = "" Then
                        strMsg = strMsg & "<br><br>已经向会员发送了一封Email，通知他" & Msg & "！"
                    End If
                End If
                rsUser.Close
                Set rsUser = Nothing
            End If
            If SendEmailToContacter = "Yes" Then
                ErrMsg = PE_Mail.Send(rsOrder("Email"), rsOrder("ContacterName"), Title, strContent, WebmasterName, WebmasterEmail, 3)
                If ErrMsg = "" Then
                    strMsg = strMsg & "<br><br>已经向收货人发送了一封Email，通知他" & Msg & "！"
                End If
            End If
        End If
    End If
    Set PE_Mail = Nothing
    SendEmailOfOrder = strMsg
End Function

Function ReplaceOrderInfo(strContent, rsOrder, iType)
    Dim strTemp
    strTemp = Replace(strContent, "{$OrderFormID}", rsOrder("OrderFormID"))
    strTemp = Replace(strTemp, "{$OrderFormNum}", rsOrder("OrderFormNum"))
    strTemp = Replace(strTemp, "{$MoneyTotal}", rsOrder("MoneyTotal"))
    strTemp = Replace(strTemp, "{$MoneyReceipt}", rsOrder("MoneyReceipt"))
    strTemp = Replace(strTemp, "{$MoneyNeedPay}", rsOrder("MoneyTotal") - rsOrder("MoneyReceipt"))
    strTemp = Replace(strTemp, "{$InputTime}", rsOrder("InputTime"))
    strTemp = Replace(strTemp, "{$UserName}", rsOrder("UserName") & "")
    strTemp = Replace(strTemp, "{$ContacterName}", PE_HTMLEncode(rsOrder("ContacterName")) & "")
    strTemp = Replace(strTemp, "{$Address}", PE_HTMLEncode(rsOrder("Address")) & "")
    strTemp = Replace(strTemp, "{$ZipCode}", rsOrder("ZipCode") & "")
    strTemp = Replace(strTemp, "{$Mobile}", PE_HTMLEncode(rsOrder("Mobile")) & "")
    strTemp = Replace(strTemp, "{$Phone}", PE_HTMLEncode(rsOrder("Phone")) & "")
    strTemp = Replace(strTemp, "{$Email}", rsOrder("Email") & "")
    strTemp = Replace(strTemp, "{$PaymentType}", GetPaymentType(rsOrder("PaymentType")))
    strTemp = Replace(strTemp, "{$DeliverType}", GetDeliverType(rsOrder("DeliverType")))
    strTemp = Replace(strTemp, "{$OrderStatus}", arrOrderStatus(rsOrder("Status")))
    strTemp = Replace(strTemp, "{$PayStatus}", GetPayStatus(rsOrder("MoneyTotal"), rsOrder("MoneyReceipt")))
    strTemp = Replace(strTemp, "{$DeliverStatus}", arrDeliverStatus(rsOrder("DeliverStatus")))
    strTemp = Replace(strTemp, "{$Charge_Deliver}", rsOrder("Charge_Deliver"))
    strTemp = Replace(strTemp, "{$PresentMoney}", rsOrder("PresentMoney"))
    strTemp = Replace(strTemp, "{$PresentExp}", rsOrder("PresentExp"))
    strTemp = Replace(strTemp, "{$PresentPoint}", rsOrder("PresentPoint"))
    strTemp = Replace(strTemp, "{$Discount_Payment}", rsOrder("Discount_Payment"))
    strTemp = Replace(strTemp, "{$SiteName}", SiteName)
    strTemp = Replace(strTemp, "{$ExpressCompany}", GetExpressCompany(rsOrder("OrderFormID")))
    strTemp = Replace(strTemp, "{$ExpressNumber}", GetExpressNumber(rsOrder("OrderFormID")))
    If iType = 0 Then
        strTemp = Replace(strTemp, "{$OrderInfo}", GetOrderInfo(rsOrder("OrderFormID"), rsOrder("UserName"), False, 0))
    End If
    ReplaceOrderInfo = strTemp
End Function

Function GetPrevChoiceValue(ChoiceName)
    Dim oCookieValue
    oCookieValue = ReplaceBadChar(Trim(Request.Cookies(Site_Sn)(ChoiceName)))

    If oCookieValue = "" Then
        GetPrevChoiceValue = ""
    Else
        GetPrevChoiceValue = " checked"
    End If
End Function

Function GetAllExpressCompany()
    Dim rsCompany, strCompany
    strCompany = "<option value=''>请选择</option>"
    Set rsCompany = Conn.Execute("select DISTINCT ExpressCompany from PE_DeliverItem")
    Do While Not rsCompany.EOF
        strCompany = strCompany & "<option value='" & rsCompany(0) & "'>" & rsCompany(0) & "</option>"
        rsCompany.MoveNext
    Loop
    Set rsCompany = Nothing
    GetAllExpressCompany = strCompany
End Function

Function GetExpressCompany(OrderFormID)
    Dim rsExpress, strExpressCompany
    Set rsExpress = Conn.Execute("select ExpressCompany from PE_DeliverItem where OrderFormID=" & OrderFormID & " and DeliverDirection = 1 order by DeliverID desc")
    If Not (rsExpress.EOF And rsExpress.BOF) Then
        strExpressCompany = rsExpress("ExpressCompany")
    End If
    Set rsExpress = Nothing
    GetExpressCompany = strExpressCompany
End Function

Function GetExpressNumber(OrderFormID)
    Dim rsExpress, strExpressNumber
    Set rsExpress = Conn.Execute("select ExpressNumber from PE_DeliverItem where OrderFormID=" & OrderFormID & " and DeliverDirection = 1 order by DeliverID desc")
    If Not (rsExpress.EOF And rsExpress.BOF) Then
        strExpressNumber = rsExpress("ExpressNumber")
    End If
    Set rsExpress = Nothing
    GetExpressNumber = strExpressNumber
End Function

Function GetPayStatus(MoneyTotal, MoneyReceipt)
    If MoneyTotal > MoneyReceipt Then
        If MoneyReceipt > 0 Then
            GetPayStatus = "<font color='green'>已收定金</font>"
        Else
            GetPayStatus = "<font color='red'>等待汇款</font>"
        End If
    Else
        GetPayStatus = "<font color='blue'>已经付清</font>"
    End If
End Function

Function GetValidNum(intValidNum, intValidUnit)
    If intValidUnit = 5 Then
        Dim rsGroupList
        Set rsGroupList = Conn.Execute("Select GroupName from PE_UserGroup where GroupID = " & intValidNum)
        If Not (rsGroupList.EOF And rsGroupList.BOF) Then
            GetValidNum = rsGroupList("GroupName")
        Else
            GetValidNum = intValidNum
        End If
        rsGroupList.Close
        Set rsGroupList = Nothing
    Else
        GetValidNum = intValidNum
    End If
End Function
%>
