<!--#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 = "PaymentType"   '其他权限
    
Response.Write "<html>" & vbCrLf
Response.Write "<head>" & vbCrLf
Response.Write "<meta http-equiv='Content-Type' content='text/html; charset=gb2312'>" & vbCrLf
Response.Write "<title>付款方式管理</title>" & vbCrLf
Response.Write "<link href='Admin_STYLE.CSS' rel='stylesheet' type='text/css'>" & vbCrLf
Response.Write "</head>" & vbCrLf
Response.Write "" & vbCrLf
Response.Write "<body>" & vbCrLf
Response.Write "<table width='100%'  border='0' cellpadding='2' cellspacing='1' class='border'>" & vbCrLf
Call ShowPageTitle("付 款 方 式 管 理", 10210)
Response.Write "  <tr>" & vbCrLf
Response.Write "    <td width='70' height='30' class='tdbg'>管理导航：</td>" & vbCrLf
Response.Write "    <td class='tdbg'><a href='Admin_PaymentType.asp'>付款方式管理首页</a> | <a href='Admin_PaymentType.asp?Action=Add'>添加付款方式</a></td>" & vbCrLf
Response.Write "  </tr>" & vbCrLf
Response.Write "</table>" & vbCrLf
Select Case Action
Case "Add"
    Call Add
Case "Modify"
    Call Modify
Case "SaveAdd", "SaveModify"
    Call SaveType
Case "Disable", "Enable"
    Call DisableType
Case "SetDefault"
    Call SetDefault
Case "Del"
    Call Del
Case "Order"
    Call Order
Case Else
    Call main
End Select
If FoundErr = True Then
    Call WriteErrMsg(ErrMsg, ComeUrl)
End If
Response.Write "</body></html>"
Call CloseConn

Sub main()
    Response.Write "<br>" & vbCrLf
    Response.Write "<table width='100%'  border='0' cellpadding='2' cellspacing='1' class='border'>" & vbCrLf
    Response.Write "  <tr align='center' class='title'>" & vbCrLf
    Response.Write "    <td width='30'>ID</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='50'>已启用</td>" & vbCrLf
    Response.Write "    <td width='150'>常规操作</td>" & vbCrLf
    Response.Write "    <td width='100'>排序操作</td>" & vbCrLf
    Response.Write "  </tr>" & vbCrLf
    Dim rsType
    Set rsType = Conn.Execute("select * from PE_PaymentType order by OrderID asc,Discount asc")
    If rsType.BOF And rsType.EOF Then
        Response.Write "<tr><td colspan='10' height='50' align='center'>没有任何付款方式</td></tr>"
    Else
        Do While Not rsType.EOF
            Response.Write "  <tr class='tdbg' onmouseout=""this.className='tdbg'"" onmouseover=""this.className='tdbg2'"">" & vbCrLf
            Response.Write "    <td width='30' align='center'>" & rsType("TypeID") & "</td>" & vbCrLf
            Response.Write "    <td width='80' align='center'>" & rsType("TypeName") & "</td>" & vbCrLf
            Response.Write "    <td align='center'>" & rsType("Intro") & "</td>" & vbCrLf
            Response.Write "    <td width='60' align='center'>" & rsType("Discount") & "%</td>" & vbCrLf
            Response.Write "    <td width='60' align='center'>" & vbCrLf
            If rsType("IsDefault") = True Then
                Response.Write "√"
            End If
            Response.Write "      </td>" & vbCrLf
            Response.Write "    <td width='50' align='center'>" & vbCrLf
            If rsType("IsDisabled") = False Then
                Response.Write "√"
            Else
                Response.Write "<font color='red'>×</font>"
            End If
            Response.Write "</td>" & vbCrLf
            Response.Write "    <td width='150' align='center'>" & vbCrLf
            If rsType("IsDefault") = True Then
                Response.Write "<font color='gray'>设为默认 禁用</font> "
            Else
                Response.Write "<a href='Admin_PaymentType.asp?Action=SetDefault&TypeID=" & rsType("TypeID") & "'>设为默认</a> "
                If rsType("IsDisabled") = True Then
                    Response.Write "<a href='Admin_PaymentType.asp?Action=Enable&TypeID=" & rsType("TypeID") & "'>启用</a> "
                Else
                    Response.Write "<a href='Admin_PaymentType.asp?Action=Disable&TypeID=" & rsType("TypeID") & "'>禁用</a> "
                End If
            End If
            Response.Write "<a href='Admin_PaymentType.asp?Action=Modify&TypeID=" & rsType("TypeID") & "'>修改</a> "
            If rsType("IsDefault") = True Then
                Response.Write "<font color='gray'>删除</font> "
            Else
                Response.Write "<a href='Admin_PaymentType.asp?Action=Del&TypeID=" & rsType("TypeID") & "'>删除</a>"
            End If
            Response.Write "</td>"
            Response.Write "<form name='orderform' method='post' action='Admin_PaymentType.asp'>"
            Response.Write "    <td width='100' align='center'>      <input name='OrderID' type='text' id='OrderID' value='" & rsType("OrderID") & "' size='4' maxlength='4' style='text-align:center '>"
            Response.Write "      <input name='TypeID' type='hidden' id='TypeID' value='" & rsType("TypeID") & "'>"
            Response.Write "    <input type='submit' name='Submit' value='修改'>"
            Response.Write "    <input name='Action' type='hidden' id='Action' value='Order'></td></form>"
            Response.Write "  </tr>"
            rsType.MoveNext
        Loop
    End If
    Set rsType = Nothing
    Response.Write "</table>"
    Response.Write "<br>" & vbCrLf
    Response.Write "说明：“禁用”某付款方式后，前台订购时将不再显示此付款方式，但已有订单中仍然显示。<br>" & vbCrLf
End Sub

Sub Add()
    Response.Write "<form name='myform' method='post' action='Admin_PaymentType.asp'>" & vbCrLf
    Response.Write "  <table width='100%'  border='0' cellpadding='2' cellspacing='1' class='border'>" & vbCrLf
    Response.Write "    <tr align='center'>" & vbCrLf
    Response.Write "      <td colspan='2' class='title'><b>添 加 付 款 方 式</b></td>" & vbCrLf
    Response.Write "    </tr>" & vbCrLf
    Response.Write "    <tr class='tdbg'>" & vbCrLf
    Response.Write "      <td width='40%' align='right'>付款方式名称：</td>" & vbCrLf
    Response.Write "      <td><input name='TypeName' type='text' id='TypeName' size='20' maxlength='20'> <font color='#FF0000'>*</font></td>" & vbCrLf
    Response.Write "    </tr>" & vbCrLf
    Response.Write "    <tr class='tdbg'>" & vbCrLf
    Response.Write "      <td width='40%' align='right'>付款方式简介：</td>" & vbCrLf
    Response.Write "      <td><input name='Intro' type='text' id='Intro' size='40' maxlength='50'></td>" & vbCrLf
    Response.Write "    </tr>" & vbCrLf
    Response.Write "    <tr class='tdbg'>" & vbCrLf
    Response.Write "      <td width='40%' align='right'>折扣率：</td>" & vbCrLf
    Response.Write "      <td><input name='Discount' type='text' id='Discount' value='100' size='6' maxlength='6' style='text-align:center '>%</td>" & vbCrLf
    Response.Write "    </tr>" & vbCrLf
    Response.Write "    <tr class='tdbg'>" & vbCrLf
    Response.Write "      <td align='right'>&nbsp;</td>" & vbCrLf
    Response.Write "      <td><input name='IsDefault' type='checkbox' id='IsDefault' value='Yes'> 设为默认付款方式</td>" & vbCrLf
    Response.Write "    </tr>" & vbCrLf
    Response.Write "    <tr align='center' class='tdbg'>" & vbCrLf
    Response.Write "      <td height='50' colspan='2'><input name='Action' type='hidden' id='Action' value='SaveAdd'><input type='submit' name='Submit' value='保存付款方式'></td>" & vbCrLf
    Response.Write "    </tr>" & vbCrLf
    Response.Write "  </table>" & vbCrLf
    Response.Write "</form>" & vbCrLf
End Sub

Sub Modify()
    Dim TypeID, rsType
    TypeID = Trim(Request("TypeID"))
    If TypeID = "" Then
        FoundErr = True
        ErrMsg = ErrMsg & "<li>请指定付款方式ID</li>"
        Exit Sub
    Else
        TypeID = PE_CLng(TypeID)
    End If
    Set rsType = Conn.Execute("select * from PE_PaymentType where TypeID=" & TypeID & "")
    If rsType.BOF And rsType.EOF Then
        FoundErr = True
        ErrMsg = ErrMsg & "<li>找不到指定的方案！</li>"
        Set rsType = Nothing
        Exit Sub
    End If
    Response.Write "<form name='myform' method='post' action='Admin_PaymentType.asp'>" & vbCrLf
    Response.Write "  <table width='100%'  border='0' cellpadding='2' cellspacing='1' class='border'>" & vbCrLf
    Response.Write "    <tr align='center'>" & vbCrLf
    Response.Write "      <td colspan='2' class='title'><b>修 改 付 款 方 式</b></td>" & vbCrLf
    Response.Write "    </tr>" & vbCrLf
    Response.Write "    <tr class='tdbg'>" & vbCrLf
    Response.Write "      <td width='40%' align='right'>付款方式名称：</td>" & vbCrLf
    Response.Write "      <td><input name='TypeName' type='text' id='TypeName' value='" & rsType("TypeName") & "' size='20' maxlength='20'> <font color='#FF0000'>*</font></td>" & vbCrLf
    Response.Write "    </tr>" & vbCrLf
    Response.Write "    <tr class='tdbg'>" & vbCrLf
    Response.Write "      <td width='40%' align='right'>付款方式简介：</td>" & vbCrLf
    Response.Write "      <td><input name='Intro' type='text' id='Intro' value='" & rsType("Intro") & "' size='40' maxlength='50'></td>" & vbCrLf
    Response.Write "    </tr>" & vbCrLf
    Response.Write "    <tr class='tdbg'>" & vbCrLf
    Response.Write "      <td width='40%' align='right'>折扣率：</td>" & vbCrLf
    Response.Write "      <td><input name='Discount' type='text' id='Discount' value='" & rsType("Discount") & "' size='6' maxlength='6' style='text-align:center '>%</td>" & vbCrLf
    Response.Write "    </tr>" & vbCrLf
    Response.Write "    <tr class='tdbg'>" & vbCrLf
    Response.Write "      <td align='right'>&nbsp;</td>" & vbCrLf
    Response.Write "      <td><input name='IsDefault' type='checkbox' id='IsDefault' value='Yes'"
    If rsType("IsDefault") = True Then Response.Write " checked"
    Response.Write "> 设为默认付款方式</td>" & vbCrLf
    Response.Write "    </tr>" & vbCrLf
    Response.Write "    <tr align='center' class='tdbg'>" & vbCrLf
    Response.Write "      <td height='50' colspan='2'><input name='TypeID' type='hidden' id='TypeID' value='" & TypeID & "'><input name='Action' type='hidden' id='Action' value='SaveModify'>" & vbCrLf
    Response.Write "          <input type='submit' name='Submit' value='保存付款方式'></td>" & vbCrLf
    Response.Write "    </tr>" & vbCrLf
    Response.Write "  </table>" & vbCrLf
    Response.Write "</form>" & vbCrLf
    Response.Write "" & vbCrLf
    Set rsType = Nothing
End Sub

Sub SaveType()
    Dim TypeID, strTypeName, Intro, Discount, IsDefault, OrderID
    Dim rsType, sqlType
    TypeID = Trim(Request("TypeID"))
    strTypeName = ReplaceBadChar(Trim(Request("TypeName")))
    Intro = Trim(Request("Intro"))
    Discount = Trim(Request("Discount"))
    IsDefault = Trim(Request("IsDefault"))
    If strTypeName = "" Then
        FoundErr = True
        ErrMsg = ErrMsg & "<li>请指定付款方式名称</li>"
    End If
    If Not IsNumeric(Discount) Then
        FoundErr = True
        ErrMsg = ErrMsg & "<li>折扣率只能是数字！</li>"
    End If
    If IsDefault = "Yes" Then
        IsDefault = True
        Conn.Execute ("update PE_PaymentType set IsDefault=" & PE_False & "")
    Else
        IsDefault = False
    End If
    
    If Action = "SaveAdd" Then
        sqlType = "select top 1 * from PE_PaymentType"
        Dim mrs
        Set mrs = Conn.Execute("select max(TypeID) from PE_PaymentType")
        If IsNull(mrs(0)) Then
            TypeID = 1
        Else
            TypeID = mrs(0) + 1
        End If
        Set mrs = Nothing
        Set mrs = Conn.Execute("select max(OrderID) from PE_PaymentType")
        If IsNull(mrs(0)) Then
            OrderID = 1
        Else
            OrderID = mrs(0) + 1
        End If
        Set mrs = Nothing
    Else
        If TypeID = "" Then
            FoundErr = True
            ErrMsg = ErrMsg & "<li>请指定TypeID！</li>"
        Else
            TypeID = PE_CLng(TypeID)
        End If
        sqlType = "select * from PE_PaymentType where TypeID=" & TypeID
    End If
    
    If FoundErr = True Then Exit Sub
    
    Set rsType = Server.CreateObject("adodb.recordset")
    rsType.Open sqlType, Conn, 1, 3
    If Action = "SaveAdd" Then
        rsType.AddNew
        rsType("TypeID") = TypeID
        rsType("OrderID") = OrderID
        rsType("IsDisabled") = False
    End If
    rsType("TypeName") = strTypeName
    rsType("Intro") = Intro
    rsType("Discount") = Discount
    rsType("IsDefault") = IsDefault
    rsType.Update
    rsType.Close
    Set rsType = Nothing
    Call CloseConn
    Response.Redirect "Admin_PaymentType.asp"
End Sub

Sub Del()
    Dim TypeID
    TypeID = Trim(Request("TypeID"))
    If TypeID = "" Then
        FoundErr = True
        ErrMsg = ErrMsg & "<li>请指定付款方式ID</li>"
        Exit Sub
    Else
        TypeID = PE_CLng(TypeID)
    End If
    
    Dim trs
    Set trs = Conn.Execute("select IsDefault from PE_PaymentType where TypeID=" & TypeID & "")
    If trs.BOF And trs.EOF Then
        FoundErr = True
        ErrMsg = ErrMsg & "<li>找不到指定的付款方式</li>"
    Else
        If trs(0) = True Then
            FoundErr = True
            ErrMsg = ErrMsg & "<li>不能删除默认的付款方式</li>"
        End If
    End If
    Set trs = Nothing
    If FoundErr = True Then Exit Sub
    
    Set trs = Conn.Execute("select top 1 OrderFormID from PE_OrderForm where PaymentType=" & TypeID & "")
    If Not (trs.BOF And trs.EOF) Then
        FoundErr = True
        ErrMsg = ErrMsg & "<li>已经有订单在使用此付款方式，所以不能删除！但你可以禁用此付款方式，以达到订购时不显示此付款方式的目的。</li>"
    End If
    Set trs = Nothing
    If FoundErr = True Then Exit Sub
    Conn.Execute ("delete from PE_PaymentType where TypeID=" & TypeID & "")
    Call CloseConn
    Response.Redirect "Admin_PaymentType.asp"
End Sub

Sub DisableType()
    Dim TypeID
    TypeID = Trim(Request("TypeID"))
    If TypeID = "" Then
        FoundErr = True
        ErrMsg = ErrMsg & "<li>请指定付款方式ID</li>"
    Else
        TypeID = PE_CLng(TypeID)
    End If
    If FoundErr = True Then Exit Sub
    
    Dim trs
    Set trs = Conn.Execute("select IsDefault from PE_PaymentType where TypeID=" & TypeID & "")
    If trs.BOF And trs.EOF Then
        FoundErr = True
        ErrMsg = ErrMsg & "<li>找不到指定的付款方式</li>"
    Else
        If trs(0) = True Then
            FoundErr = True
            ErrMsg = ErrMsg & "<li>不能禁用默认的付款方式</li>"
        End If
    End If
    Set trs = Nothing
    If FoundErr = True Then Exit Sub
    
    Select Case Action
    Case "Disable"
        Conn.Execute ("update PE_PaymentType set IsDisabled=" & PE_True & " where TypeID=" & TypeID & "")
    Case "Enable"
        Conn.Execute ("update PE_PaymentType set IsDisabled=" & PE_False & " where TypeID=" & TypeID & "")
    End Select
    Call CloseConn
    Response.Redirect "Admin_PaymentType.asp"
End Sub

Sub Order()
    Dim TypeID, OrderID
    TypeID = Trim(Request("TypeID"))
    OrderID = Trim(Request("OrderID"))
    If TypeID = "" Then
        FoundErr = True
        ErrMsg = ErrMsg & "<li>请指定付款方式ID</li>"
    Else
        TypeID = PE_CLng(TypeID)
    End If
    If OrderID = "" Then
        FoundErr = True
        ErrMsg = ErrMsg & "<li>请指定OrderID</li>"
    Else
        OrderID = PE_CLng(OrderID)
    End If
    If FoundErr = True Then Exit Sub
    Conn.Execute ("update PE_PaymentType set OrderID=" & OrderID & " where TypeID=" & TypeID & "")
    Call CloseConn
    Response.Redirect "Admin_PaymentType.asp"
End Sub

Sub SetDefault()
    Dim TypeID
    TypeID = Trim(Request("TypeID"))
    If TypeID = "" Then
        FoundErr = True
        ErrMsg = ErrMsg & "<li>请指定TypeID</li>"
        Exit Sub
    Else
        TypeID = PE_CLng(TypeID)
    End If
    Conn.Execute ("update PE_PaymentType set IsDefault=" & PE_False & "")
    Conn.Execute ("update PE_PaymentType set IsDefault=" & PE_True & " where  TypeID=" & TypeID)
    Call CloseConn
    Response.Redirect "Admin_PaymentType.asp"
End Sub
%>
