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

Dim arrProductKind
Dim ClassID, tClass, ClassName, ReadMe, RootID, ParentID, Depth, ParentPath, Child, arrChildID, ChildID

Sub Main()
    ChannelID = 1000
    Call GetChannel(ChannelID)
    If PE_CLng(UserSetting(30)) = 0 Then
        Response.Write "对不起，您没有批发商品的权限！如果您需要批发商品，请与我们联系。"
        Exit Sub
    End If

    ClassID = PE_CLng(Trim(Request("ClassID")))
    SearchType = PE_CLng(Trim(Request("SearchType")))

    FileName = "User_Wholesale.asp?SearchType=" & SearchType
    strFileName = FileName
    
    arrProductKind = Array("", "实物", "软件", "点卡", "服务")

    If ClassID > 0 Then
        Set tClass = Conn.Execute("select ClassName,RootID,ParentID,Depth,ParentPath,Child,arrChildID from PE_Class where ClassID=" & ClassID)
        If tClass.BOF And tClass.EOF Then
            FoundErr = True
            ErrMsg = ErrMsg & "<li>找不到指定的栏目</li>"
        Else
            ClassName = tClass(0)
            RootID = tClass(1)
            ParentID = tClass(2)
            Depth = tClass(3)
            ParentPath = tClass(4)
            Child = tClass(5)
            arrChildID = tClass(6)
        End If
    End If
    
    Response.Write "<table width='100%' border='0' align='center' cellpadding='2' cellspacing='1' Class='border'>"
    Response.Write "  <tr class='topbg'> "
    Response.Write "    <td height='22' colspan='3' align='center'><b>批 发 商 品</b></td>"
    Response.Write "  </tr>"
    Response.Write "  <tr class='tdbg'>"
    Response.Write "<form name='form3' method='Post' action='User_Wholesale.asp'>"
    Response.Write "<td width='70' height='30' ><strong>快速查找：</strong></td><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 ">所有" & ChannelShortName & "</option>"
    Response.Write "          <option value='3'"
    If SearchType = 3 Then Response.Write " selected"
    Response.Write ">正常销售的" & ChannelShortName & "</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='8'"
    If SearchType = 8 Then Response.Write " selected"
    Response.Write ">有促销活动的" & ChannelShortName & "</option>"
    Response.Write "          <option value='12'"
    If SearchType = 12 Then Response.Write " selected"
    Response.Write ">所有固顶" & ChannelShortName & "</option>"
    Response.Write "          <option value='13'"
    If SearchType = 13 Then Response.Write " selected"
    Response.Write ">所有热卖" & ChannelShortName & "</option>"
    Response.Write "          <option value='14'"
    If SearchType = 14 Then Response.Write " selected"
    Response.Write ">所有推荐" & ChannelShortName & "</option>"
    Response.Write "        </select>"
    Response.Write "</td>"
    Response.Write "</form>" & vbCrLf
    Response.Write "<form method='Get' name='SearchForm' action='User_Wholesale.asp'>"
    Response.Write "<td><b>高级查询：</b>"
    Response.Write "<select name='Field' size='1'>"
    Response.Write "<option value='ProductName' selected>" & ChannelShortName & "名称</option>"
    Response.Write "<option value='ProductIntro'>" & ChannelShortName & "简介</option>"
    Response.Write "<option value='ProductExplain'>" & ChannelShortName & "介绍</option>"
    Response.Write "<option value='ProducerName'>厂商</option>"
    Response.Write "<option value='TrademarkName'>品牌/商标</option>"
    Response.Write "</select>"
    Response.Write "<select name='ClassID'><option value=''>所有栏目</option>" & User_GetClass_Option(1, 0) & "</select>"
    Response.Write "<input type='text' name='keyword'  size='15' value='关键字' maxlength='50' onFocus='this.select();'>"
    Response.Write "<input type='submit' name='Submit'  value='搜索'>"
    Response.Write "<input name='SearchType' type='hidden' id='SearchType' value='-1'>"
    Response.Write "</td></form>"
    Response.Write "</tr>"
    Response.Write "</table><br>"

    Dim rsProductList, sql, Querysql
    
    Call ShowJS_Manage(ChannelShortName)
    Response.Write "<table width='100%' border='0' align='center' cellpadding='2' cellspacing='1' class='border'>"
    Response.Write "  <tr class='title'>"
    Response.Write "    <td height='22'>" & GetRootClass() & "</td>"
    Response.Write "  </tr>" & GetChild_Root() & ""
    Response.Write "</table><br>"
    Response.Write "<table width='100%' border='0' align='center' cellpadding='0' cellspacing='0'>"
    Response.Write "  <tr>"
    Response.Write "    <td height='22'>"
    Call ShowPath(ChannelShortName & "批发")
    Response.Write "    </td></tr>"
    Response.Write "</table>"
    
    Response.Write "<table width='100%' border='0' cellpadding='0' cellspacing='0'><tr>"
    Response.Write "    <form name='myform' method='Post' action='../Shop/ShoppingCart.asp' target='ShoppingCart'>"
    Response.Write "     <td><table class='border' border='0' cellspacing='1' width='100%' cellpadding='0'>"
    Response.Write "          <tr class='title' height='22'> "
    Response.Write "            <td align='center' ><strong>" & ChannelShortName & "名称</strong></td>"
    Response.Write "            <td width='40' align='center' ><strong>类型</strong></td>"
    Response.Write "            <td width='40' align='center' ><strong>单位</strong></td>"
    Response.Write "            <td width='40' align='center' ><strong>库存量</strong></td>"
    Response.Write "            <td width='60' align='center' ><strong>原始价</strong></td>"
    Response.Write "            <td width='80' align='center' ><strong>数量/价格</strong></td>"
    Response.Write "            <td width='80' align='center' ><strong>数量/价格</strong></td>"
    Response.Write "            <td width='80' align='center' ><strong>数量/价格</strong></td>"
    Response.Write "            <td width='30' align='center' ><strong>购买</strong></td>"
    Response.Write "            <td width='60' align='center' ><strong>购买量</strong></td>"
    Response.Write "          </tr>"
    sql = sql & "select top " & MaxPerPage & " P.ProductID,P.ClassID,C.ClassName,P.ProductKind,P.ProductNum,P.ProductName,P.ProductModel,P.ProductStandard,P.ProductType,P.Price_Original,P.Number_Wholesale1,P.Price_Wholesale1,P.Number_Wholesale2,P.Price_Wholesale2,P.Number_Wholesale3,P.Price_Wholesale3,P.Unit,P.Stars,P.Stocks,P.Discount,P.BeginDate,P.EndDate,P.UpdateTime from PE_Product P"
    sql = sql & " left join PE_Class C on P.ClassID=C.ClassID "
    
    Querysql = Querysql & " where P.Deleted=" & PE_False & " and P.EnableWholesale=" & PE_True
    
    Select Case SearchType
    Case 1
        Querysql = Querysql & " and P.EnableSale=" & PE_True
    Case 2
        Querysql = Querysql & " and P.EnableSale=" & PE_False
    Case 3
        Querysql = Querysql & " and P.ProductType=1"
    Case 4
        Querysql = Querysql & " and P.ProductType=2"
    Case 5
        Querysql = Querysql & " and P.ProductType=3"
    Case 6
        Querysql = Querysql & " and P.ProductType=5"
    Case 7
        Querysql = Querysql & " and P.ProductType=4"
    Case 8
        Querysql = Querysql & " and P.SalePromotionType>0"
    Case 9
        Querysql = Querysql & " and P.Stocks<=AlarmNum"
    Case 10
        Querysql = Querysql & " and P.Stocks<=AlarmNum+OrderNum"
    Case 11
        Querysql = Querysql & " and P.Stocks<=0"
    Case 12
        Querysql = Querysql & " and P.OnTop=" & PE_True
    Case 13
        Querysql = Querysql & " and P.Hits>=" & HitsOfHot
    Case 14
        Querysql = Querysql & " and P.IsElite=" & PE_True
    Case 15
        Querysql = Querysql & " and P.EnableWholesale=" & PE_True
    End Select
    If ClassID > 0 Then
        If Child > 0 Then
            Querysql = Querysql & " and P.ClassID in (" & arrChildID & ")"
        Else
            Querysql = Querysql & " and P.ClassID=" & ClassID
        End If
    End If

    If Keyword <> "" Then
        Select Case strField
        Case "ProductName"
            Querysql = Querysql & " and P.ProductName like '%" & Keyword & "%' "
        Case "ProductIntro"
            Querysql = Querysql & " and P.ProductIntro like '%" & Keyword & "%' "
        Case "ProductExplain"
            Querysql = Querysql & " and P.ProductExplain like '%" & Keyword & "%' "
        Case "ProducerName"
            Querysql = Querysql & " and P.ProducerName like '%" & Keyword & "%' "
        Case "TrademarkName"
            Querysql = Querysql & " and P.TrademarkName like '%" & Keyword & "%' "
        Case Else
            Querysql = Querysql & " and P.ProductName like '%" & Keyword & "%' "
        End Select
    End If
    
    totalPut = PE_CLng(Conn.Execute("select Count(*) from PE_Product P " & Querysql)(0))
    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
        Querysql = Querysql & " and P.ProductID < (select min(ProductID) from (select top " & ((CurrentPage - 1) * MaxPerPage) & " P.ProductID from PE_Product P " & Querysql & " order by P.ProductID desc) as QueryProduct) "
    End If
    sql = sql & Querysql & " order by P.ProductID desc"

    Set rsProductList = Server.CreateObject("ADODB.Recordset")
    rsProductList.Open sql, Conn, 1, 1
    
    If rsProductList.BOF And rsProductList.EOF Then
        totalPut = 0
        If Child = 0 Then
            Response.Write "<tr class='tdbg' height='50'><td colspan='20' align='center'>没有任何" & ChannelShortName & "！<br><br></td></tr>"
        Else
            Response.Write "<tr class='tdbg' height='50'><td colspan='20' align='center'>此栏目及其子栏目中没有任何" & ChannelShortName & "！</td></tr>"
        End If
    Else
        Dim ProductNum, ProductPath
        ProductNum = 0
        Do While Not rsProductList.EOF
            Response.Write "      <tr class='tdbg' onmouseout=""this.className='tdbg'"" onmouseover=""this.className='tdbgmouseover'"">"
            Response.Write "        <td>"
            If rsProductList("ClassID") <> ClassID Then
                Response.Write "<a href='User_Wholesale.asp?ClassID=" & rsProductList("ClassID") & "'>[" & rsProductList("ClassName") & "]</a>&nbsp;"
            End If
            Response.Write "<a href='../Shop/ShowProduct.asp?ProductID=" & rsProductList("ProductID") & "' target='_blank'"
            Response.Write " title='" & ChannelShortName & "名称：" & rsProductList("ProductName") & vbCrLf
            Response.Write ChannelShortName & "类别：" & arrProductKind(rsProductList("ProductKind")) & "商品" & vbCrLf
            Response.Write ChannelShortName & "型号：" & rsProductList("ProductModel") & vbCrLf
            Response.Write ChannelShortName & "规格：" & rsProductList("ProductStandard") & vbCrLf
            Response.Write "上市时间：" & rsProductList("UpdateTime") & vbCrLf
            Response.Write "推荐等级："
            If rsProductList("Stars") = 0 Then
                Response.Write "无"
            Else
                Response.Write String(rsProductList("Stars"), "★")
            End If
            Response.Write "'>"
            Select Case rsProductList("ProductKind")
            Case 1
                Response.Write "<font color='#000000'>"
            Case 2
                Response.Write "<font color='green'>"
            Case 3
                Response.Write "<font color='blue'>"
            End Select
            Response.Write rsProductList("ProductName") & "</font></a>"
            Response.Write "</td>"
            Response.Write "            <td width='40' align='center'>"
            Select Case rsProductList("ProductType")
            Case 1
                Response.Write "<font color='#000000'>正常</font>"
            Case 2
                Response.Write "<font color='green'>涨价</font> "
            Case 5
                Response.Write "<font color='red'>降价</font> "
            Case 3
                If rsProductList("Begindate") > Date Or rsProductList("EndDate") < Date Then
                    Response.Write "<font color='#000000'>正常</font>"
                Else
                    Response.Write "<font color='#FFCC00'>特价</font>"
                End If
            Case 4
                Response.Write "<font color='blue'>礼品</font> "
            End Select
            Response.Write "    </td>"
            Response.Write "            <td width='40' align='center' >" & rsProductList("Unit") & "</td>"
            Response.Write "            <td width='40' align='center' >" & rsProductList("Stocks") & "</td>"
            Response.Write "            <td width='60' align='center' >" & FormatNumber(rsProductList("Price_Original"), 2, vbTrue, vbFalse, vbFalse) & "</td>"
            Response.Write "            <td width='80' align='center' >" & rsProductList("Number_Wholesale1") & " / " & FormatNumber(rsProductList("Price_Wholesale1"), 2, vbTrue, vbFalse, vbFalse) & "</td>"
            Response.Write "            <td width='80' align='center' >" & rsProductList("Number_Wholesale2") & " / " & FormatNumber(rsProductList("Price_Wholesale2"), 2, vbTrue, vbFalse, vbFalse) & "</td>"
            Response.Write "            <td width='80' align='center' >" & rsProductList("Number_Wholesale3") & " / " & FormatNumber(rsProductList("Price_Wholesale3"), 2, vbTrue, vbFalse, vbFalse) & "</td>"
            Response.Write "            <td width='30' align='center' ><input type='checkbox' name='ProductID' value='" & rsProductList("ProductID") & "'></td>"
            Response.Write "            <td width='60' align='center' ><input type='text' name='Amount_" & rsProductList("ProductID") & "' size='5' value='" & rsProductList("Number_Wholesale1") & "' style='text-align:center'></td>"
            Response.Write "</tr>"

            ProductNum = ProductNum + 1
            If ProductNum >= MaxPerPage Then Exit Do
            rsProductList.MoveNext
        Loop
    End If
    rsProductList.Close
    Set rsProductList = Nothing
    Response.Write "</table>"
    Response.Write "<table width='100%' border='0' cellpadding='0' cellspacing='0'>"
    Response.Write "  <tr height='30'>"
    Response.Write "    <td width='200'><input name='chkAll' type='checkbox' id='chkAll' onclick='CheckAll(this.form)' value='checkbox'>选中本页显示的所有" & ChannelShortName & "</td>"
    Response.Write "    <td align='center'><input type='submit' name='submit1' value='确定批量购买选中的" & ChannelShortName & "'><input name='Action' type='hidden' id='Action' value='Modify'><input name='IsWholesale' type='hidden' id='IsWholesale' value='1'></td>"
    Response.Write "  </tr>"
    Response.Write "</table>"
    Response.Write "</td>"
    Response.Write "</form></tr></table>"
    If Keyword <> "" Then
        strFileName = strFileName & "&Keyword=" & Keyword
    End If
    If ClassID > 0 Then
        strFileName = strFileName & "&ClassID=" & ClassID
    End If
    If totalPut > 0 Then
        Response.Write ShowPage(strFileName, totalPut, MaxPerPage, CurrentPage, True, True, ChannelItemUnit & ChannelShortName & "", True)
    End If

End Sub

Sub ShowPath(RootName)
    Response.Write "您现在的位置：&nbsp;" & ChannelName & "管理&nbsp;&gt;&gt;&nbsp;<a href='User_Wholesale.asp'>" & RootName & "</a>&nbsp;&gt;&gt;&nbsp;"
    If ClassID > 0 Then
        If ParentID > 0 Then
            Dim sqlPath, rsPath
            sqlPath = "select ClassID,ClassName from PE_Class where ClassID in (" & ParentPath & ") order by Depth"
            Set rsPath = Conn.Execute(sqlPath)
            Do While Not rsPath.EOF
                Response.Write "<a href='User_Wholesale.asp?ClassID=" & rsPath(0) & "'>" & rsPath(1) & "</a>&nbsp;&gt;&gt;&nbsp;"
                rsPath.MoveNext
            Loop
            rsPath.Close
            Set rsPath = Nothing
        End If
        Response.Write "<a href='User_Wholesale.asp?ClassID=" & ClassID & "'>" & ClassName & "</a>&nbsp;&gt;&gt;&nbsp;"
    End If
    Select Case SearchType
    Case 0
        Response.Write "所有" & ChannelShortName & ""
    Case 3
        Response.Write "正常销售的" & ChannelShortName & ""
    Case 4
        Response.Write "涨价商品"
    Case 5
        Response.Write "降价/打折商品"
    Case 7
        Response.Write strPath & "有促销活动的" & ChannelShortName & ""
    Case 11
        Response.Write "所有固顶的" & ChannelShortName & ""
    Case 12
        Response.Write "所有热卖" & ChannelShortName & ""
    Case 13
        Response.Write "所有推荐" & ChannelShortName & ""
    Case Else
        Select Case strField
            Case "ProductName"
                Response.Write ChannelShortName & "名称中含有 <font color=red>" & Keyword & "</font> "
            Case "ProductIntro"
                Response.Write ChannelShortName & "简介中含有 <font color=red>" & Keyword & "</font> "
            Case "ProductExplain"
                Response.Write ChannelShortName & "介绍中含有 <font color=red>" & Keyword & "</font> "
            Case "Inputer"
                Response.Write "<font color=red>" & Keyword & "</font> 添加"
            Case "ProducerName"
                Response.Write "厂商为 <font color=red>" & Keyword & "</font> "
            Case "TrademarkName"
                Response.Write "品牌为 <font color=red>" & Keyword & "</font> "
            Case Else
                Response.Write ChannelShortName & "名称中含有 <font color=red>" & Keyword & "</font> "
        End Select
        Response.Write "的" & ChannelShortName
    End Select
End Sub

%>
