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

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

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

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

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 "<table width='100%' border='0' align='center' cellpadding='2' cellspacing='1' Class='border'>"
Call ShowPageTitle("发 退 货 记 录 查 询", 10207)
Response.Write "    <tr class='tdbg' height='30'> "
Response.Write "  <form name='form1' action='Admin_Deliver.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 ">最近10天内的新记录</option>"
Response.Write "          <option value='2'"
If SearchType = 2 Then Response.Write " selected"
Response.Write ">最近一月内的新记录</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 "        </select>&nbsp;&nbsp;&nbsp;&nbsp;<a href='Admin_Deliver.asp'>发退货记录首页</a></td>"
Response.Write "  </form>"
Response.Write "<form name='form2' method='post' action='Admin_Deliver.asp'>"
Response.Write "    <td>高级查询："
Response.Write "      <select name='Field' id='Field'>"
Response.Write "      <option value='ClientName' selected>客户姓名</option>"
Response.Write "      <option value='ContacterName'>收货人姓名</option>"
Response.Write "      <option value='UserName'>用户名</option>"
Response.Write "      <option value='ExpressCompany'>快递公司名</option>"
Response.Write "      <option value='ExpressNumber'>快递单号</option>"
Response.Write "      <option value='HandlerName'>经手人</option>"
Response.Write "      <option value='DeliverDate'>发退货日期</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'>"
Response.Write " </td>"
Response.Write "</form>"
Response.Write "</table>"
Response.Write "<br>"
If Action = "ShowDetail" Then
    Call ShowDetail
Else
    Call main
End If
If FoundErr = True Then
    Call WriteErrMsg(ErrMsg, ComeUrl)
End If
Response.Write "</body></html>"

Sub main()
    Dim rsDeliver, sql
    sql = "select D.*,O.OrderFormNum,O.UserName,O.ContacterName,O.ClientID,C.ShortedForm as ClientName from PE_DeliverItem D left join (PE_OrderForm O left join PE_Client C on O.ClientID=C.ClientID) on D.OrderFormID=O.OrderFormID "
    Response.Write "<table width='100%'><tr><td align='left'><img src='images/img_u.gif' align='absmiddle'>您现在的位置：<a href='Admin_Deliver.asp'>发退货记录管理</a>&nbsp;&gt;&gt;&nbsp;"
    Select Case SearchType
        Case 0
            sql = sql & " order by D.DeliverID desc"
            Response.Write "所有记录"
        Case 1
            sql = sql & " where datediff(" & PE_DatePart_D & ",D.DeliverDate," & PE_Now & ")<10 order by D.DeliverID desc"
            Response.Write "最近10天内的新记录"
        Case 2
            sql = sql & " where datediff(" & PE_DatePart_M & ",D.DeliverDate," & PE_Now & ")<1 order by D.DeliverID desc"
            Response.Write "最近一月内的新记录"
        Case 3
            sql = sql & " where D.DeliverDirection=1 order by D.DeliverID desc"
            Response.Write "所有发货记录"
        Case 4
            sql = sql & " where D.DeliverDirection=2 order by D.DeliverID desc"
            Response.Write "所有退货记录"
        Case 10
            If Keyword = "" Then
                sql = sql & " order by D.DeliverID desc"
                Response.Write "所有记录"
            Else
                Select Case strField
                Case "ClientName"
                    sql = sql & " where C.ClientName like '%" & Keyword & "%' order by D.DeliverID desc"
                    Response.Write "客户姓名中含有“ <font color=red>" & Keyword & "</font> ”的记录"
                Case "ContacterName"
                    sql = sql & " where O.ContacterName like '%" & Keyword & "%' order by D.DeliverID desc"
                    Response.Write "收货人姓名中含有“ <font color=red>" & Keyword & "</font> ”的记录"
                Case "UserName"
                    sql = sql & " where O.UserName like '%" & Keyword & "%' order by D.DeliverID desc"
                    Response.Write "用户名中含有“ <font color=red>" & Keyword & "</font> ”的记录"
                Case "ExpressCompany"
                    sql = sql & " where D.ExpressCompany like '%" & Keyword & "%' order by D.DeliverID desc"
                    Response.Write "快递公司名中含有 <font color=red>" & Keyword & "</font> 的记录"
                Case "ExpressNumber"
                    sql = sql & " where D.ExpressNumber like '%" & Keyword & "%' order by D.DeliverID desc"
                    Response.Write "快递单号中含有 <font color=red>" & Keyword & "</font> 的记录"
                Case "HandlerName"
                    sql = sql & " where D.HandlerName='" & Keyword & "' order by D.DeliverID desc"
                    Response.Write "经手人为 <font color=red>" & Keyword & "</font> 的记录"
                Case "DeliverDate"
                    If IsDate(Keyword) = True Then
                        If SystemDatabaseType = "SQL" Then
                            sql = sql & " where D.DeliverDate='" & Keyword & "'  order by D.DeliverID desc"
                        Else
                            sql = sql & " where D.DeliverDate=#" & Keyword & "#  order by D.DeliverID desc"
                        End If
                        Response.Write "发退货日期为 <font color=red>" & Keyword & "</font> 的记录"
                    Else
                        FoundErr = True
                        ErrMsg = ErrMsg & "<li>查询的发退货日期格式不正确！</li>"
                    End If
                End Select
            End If
        Case Else
            FoundErr = True
            ErrMsg = ErrMsg & "<li>错误的参数！</li>"
    End Select
    Response.Write "</td></tr></table>"
    If FoundErr = True Then Exit Sub
    
    Response.Write "<table width='100%' border='0' cellpadding='2' cellspacing='1' class='border'>"
    Response.Write "  <tr align='center' class='title'>"
    Response.Write "    <td width='80'>日期</td>"
    Response.Write "    <td width='30'>方向</td>"
    Response.Write "    <td width='60'>客户姓名</td>"
    Response.Write "    <td width='60'>用户名</td>"
    Response.Write "    <td width='60'>收货人<br>姓名</td>"
    Response.Write "    <td width='100'>订单编号</td>"
    Response.Write "    <td width='60'>快递公司</td>"
    Response.Write "    <td width='80'>快递单号</td>"
    Response.Write "    <td width='60'>经手人</td>"
    Response.Write "    <td width='40'>已签收</td>"
    Response.Write "    <td>备注</td>"
    Response.Write "    <td>操作</td>"
    Response.Write "  </tr>"
    
    Set rsDeliver = Server.CreateObject("Adodb.RecordSet")
    rsDeliver.Open sql, Conn, 1, 1
    If rsDeliver.BOF And rsDeliver.EOF Then
        totalPut = 0
        Response.Write "<tr class='tdbg' height='50'><td colspan='20' align='center'>没有任何符合条件的记录！</td></tr>"
    Else
        totalPut = rsDeliver.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
                rsDeliver.Move (CurrentPage - 1) * MaxPerPage
            Else
                CurrentPage = 1
            End If
        End If
    
        Dim i
        i = 0
        Do While Not rsDeliver.EOF
            Response.Write "  <tr class='tdbg' onmouseout=""this.className='tdbg'"" onmouseover=""this.className='tdbgmouseover'"">"
            Response.Write "    <td width='80' align='center'>" & rsDeliver("DeliverDate") & "</td>"
            Response.Write "    <td width='30' align='center'>"
            If rsDeliver("DeliverDirection") = 1 Then
                Response.Write "发货"
            Else
                Response.Write "<font color='red'>退货</font>"
            End If
            Response.Write "</td>"
            Response.Write "    <td width='60' align='center'><a href='Admin_Client.asp?Action=Show&ClientID=" & rsDeliver("ClientID") & "'>" & rsDeliver("ClientName") & "</a></td>"
            Response.Write "    <td width='60' align='center'><a href='Admin_User.asp?Action=Show&UserName=" & rsDeliver("UserName") & "'>" & rsDeliver("UserName") & "</a></td>"
            Response.Write "    <td width='60' align='center'><a href='Admin_Order.asp?Action=ShowOrder&OrderFormID=" & rsDeliver("OrderFormID") & "'>" & rsDeliver("ContacterName") & "</a></td>"
            Response.Write "    <td width='100' align='center'><a href='Admin_Order.asp?Action=ShowOrder&OrderFormID=" & rsDeliver("OrderFormID") & "'>" & rsDeliver("OrderFormNum") & "</a></td>"
            Response.Write "    <td width='60' align='center'>" & rsDeliver("ExpressCompany") & "</td>"
            Response.Write "    <td width='80' align='center'>" & rsDeliver("ExpressNumber") & "</td>"
            Response.Write "    <td width='60' align='center'>" & rsDeliver("HandlerName") & "</td>"
            Response.Write "    <td width='40' align='center'>"
            If rsDeliver("Received") = True Then
                Response.Write "<font color='red'><b>√</b></font>"
            End If
            Response.Write "</td>"
            Response.Write "    <td>" & rsDeliver("Remark") & "</td>"
            Response.Write "    <td width='32' align='center'><a href='Admin_Deliver.asp?Action=ShowDetail&DeliverID=" & rsDeliver("DeliverID") & "'>查看</a></td>"
            Response.Write "  </tr>"
    
            i = i + 1
            If i >= MaxPerPage Then Exit Do
            rsDeliver.MoveNext
        Loop
    End If
    rsDeliver.Close
    Set rsDeliver = Nothing

    Response.Write "</table>"
    Response.Write ShowPage(strFileName, totalPut, MaxPerPage, CurrentPage, True, True, "条记录", True)
End Sub

Sub ShowDetail()
    Dim rs, crs, UserName, ClientID, ContacterName
    Response.Write "<table width='100%'><tr><td align='left'><img src='images/img_u.gif' align='absmiddle'>您现在的位置：<a href='Admin_Deliver.asp'>发退货记录管理</a>&nbsp;&gt;&gt;&nbsp;发退货记录详情"
    Response.Write "</td></tr></table>"
    Set rs = Conn.Execute("select * from PE_DeliverItem Where DeliverID=" & PE_CLng(Request("DeliverID")))
    If rs.BOF And rs.EOF Then
        Response.Write "<p align='center'>找不到指定的发退货记录</p>"
    Else

        Response.Write "    <table width='100%' border='0' align='center' cellpadding='2' cellspacing='1' class='border'>"
        Response.Write "        <tr class='title'>"
        Response.Write "          <td align='center' colspan='4'>查看发退货记录详情</td>"
        Response.Write "        </tr>"
        Response.Write "        <tr class='tdbg'>"
        Response.Write "          <td width='15%' class='tdbg5' align='right'>日期：</td>"
        Response.Write "          <td>" & rs("DeliverDate") & "</td>"
        Response.Write "        </tr>"
        Response.Write "        <tr class='tdbg'>"
        Response.Write "          <td width='15%' class='tdbg5' align='right'>方向：</td>"
        Response.Write "    <td>"
        If rs("DeliverDirection") = 1 Then
            Response.Write "发货"
        Else
            Response.Write "<font color='red'>退货</font>"
        End If
        Response.Write "</td>"
        Response.Write "        </tr>"
        Response.Write "        <tr class='tdbg'>"
        Response.Write "          <td width='15%' class='tdbg5' align='right'>订单编号：</td>"
        Response.Write "          <td>"
        Set crs = Conn.Execute("select OrderFormNum,UserName,ClientID,ContacterName from PE_OrderForm where OrderFormID=" & rs("OrderFormID") & "")
        If crs.BOF And crs.EOF Then
            UserName = ""
            ClientID = 0
            ContacterName = ""
        Else
            UserName = crs("UserName")
            ClientID = PE_Clng(crs("ClientID"))
            ContacterName = crs("ContacterName")
            Response.Write "<a href='Admin_Order.asp?Action=ShowOrder&OrderFormID=" & rs("OrderformID") & "'>" & crs("OrderFormNum") & "</a>"
        End If
        crs.Close
        Set crs = Nothing
        Response.Write "</td>"
        Response.Write "        </tr>"
        Response.Write "        <tr class='tdbg'>"
        Response.Write "          <td width='15%' class='tdbg5' align='right'>客户姓名:</td>"
        Response.Write "          <td>"
        Set crs = Conn.Execute("select ClientName from PE_Client C where ClientID=" & ClientID & "")
        If Not (crs.BOF And crs.EOF) Then
            Response.Write "<a href='Admin_Client.asp?Action=Show&ClientID=" & ClientID & "'>" & crs(0) & "</a>"
        End If
        crs.Close
        Set crs = Nothing
        Response.Write "</td>"
        
        Response.Write "        </tr>"
        Response.Write "        <tr class='tdbg'>"
        Response.Write "          <td width='15%' class='tdbg5' align='right'>用户名：</td>"
        Response.Write "          <td>" & UserName & "</td>"
        Response.Write "        </tr>"
        Response.Write "        <tr class='tdbg'>"
        Response.Write "          <td width='15%' class='tdbg5' align='right'>收货人姓名：</td>"
        Response.Write "          <td>" & ContacterName & "</td>"
        Response.Write "        </tr>"
        Response.Write "        <tr class='tdbg'>"
        Response.Write "          <td width='15%' class='tdbg5' align='right'>快递公司：</td>"
        Response.Write "          <td>" & rs("ExpressCompany") & "</td>"
        Response.Write "        </tr>"
        Response.Write "        <tr class='tdbg'>"
        Response.Write "          <td width='15%' class='tdbg5' align='right'>快递单号：</td>"
        Response.Write "          <td>" & rs("ExpressNumber") & "</td>"
        Response.Write "        </tr>"
        Response.Write "        <tr class='tdbg'>"
        Response.Write "          <td width='15%' class='tdbg5' align='right'>已签收：</td>"
        Response.Write "    <td>"
        If rs("Received") = True Then
            Response.Write "<font color='red'><b>√</b></font>"
        End If
        Response.Write "</td>"
        Response.Write "        </tr>"
        Response.Write "        <tr class='tdbg'>"
        Response.Write "          <td width='15%' class='tdbg5' align='right'>经手人：</td>"
        Response.Write "          <td>" & rs("HandlerName") & "</td>"
        Response.Write "        </tr>"
        Response.Write "        <tr class='tdbg'>"
        Response.Write "          <td width='15%' class='tdbg5' align='right'>备注/退货原因：</td>"
        Response.Write "          <td>" & rs("Remark") & "</td>"
        Response.Write "        </tr>"
        Response.Write "        <tr class='tdbg'>"
        Response.Write "          <td width='15%' class='tdbg5' align='right'>录入者：</td>"
        Response.Write "          <td>" & rs("Inputer") & "</td>"
        Response.Write "        </tr>"
        Response.Write "    </table>"
    End If
    Response.Write "<br><div align='center'><input type='button' name='button' value=' 返 回 ' onclick='javascript:history.go(-1)'></div>"
End Sub
%>
