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

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

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

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("数 据 字 典 管 理", 10225)
Response.Write "  <tr>" & vbCrLf
Response.Write "    <td width='70' height='30' class='tdbg'>管理说明：</td>" & vbCrLf
Response.Write "    <td class='tdbg'>" & vbCrLf
Response.Write "<li><font color='red'>请勿删除选项内容；请勿对现有选项内容重新排序。因为数据库中存放的是项目的序号，重新排序会导致数据信息的错位！</font></li>"
Response.Write "<li>对于不再使用的项目，不要勾选“启用”栏的复选框即可。 </li>"
Response.Write "<li>您可以使某一条选项内容作为该字段的缺省内容。清除缺省项的方法是：点击下方空数据的缺省即可。 </li>"
Response.Write "<li>系统每次会在已有项目自动增加 3 个空白条目待填，如果您使用的项目数量较多，超过了系统提供的项目格数，请提交后再编辑。</li>"
Response.Write "  </td></tr>" & vbCrLf
Response.Write "</table>" & vbCrLf
Select Case Action
Case "SaveValue"
    Call SaveValue
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 "<form action='Admin_Dictionary.asp' method='post' name='myform' id='myform'>"
    Response.Write "<table width='100%' border='0' align='center' cellpadding='2' cellspacing='1'>"
    Response.Write "<tr><td width='20%' valign='top'><table width='100%' border='0' align='center' cellpadding='1' cellspacing='0' class='border'>"
    Dim rsField, PrevTable
    Dim TableName, FieldName, FieldValue
    TableName = ReplaceBadChar(Trim(Request("TableName")))
    FieldName = ReplaceBadChar(Trim(Request("FieldName")))
    If TableName = "" Then TableName = "PE_Client"
    If FieldName = "" Then FieldName = "Area"

    PrevTable = ""
    Set rsField = Conn.Execute("select * from PE_Dictionary order by TableName,FieldID")
    Do While Not rsField.EOF
        If rsField("TableName") <> PrevTable Then
            Select Case rsField("TableName")
            Case "PE_Client"
                Response.Write "<tr class='title'><td>客户信息表：</td></tr>"
            Case "PE_Company"
                Response.Write "<tr class='title'><td>公司信息表：</td></tr>"
            Case "PE_Contacter"
                Response.Write "<tr class='title'><td>联系人信息表：</td></tr>"
            Case "PE_ServiceItem"
                Response.Write "<tr class='title'><td>服务记录表：</td></tr>"
            Case "PE_ComplainItem"
                Response.Write "<tr class='title'><td>投诉记录表：</td></tr>"
            Case "PE_Supply"
                Response.Write "<tr class='title'><td>供求信息表：</td></tr>"
            End Select
        End If
        If rsField("TableName") = TableName And rsField("FieldName") = FieldName Then
            Response.Write "<tr class='tdbg'><td>&nbsp;&nbsp;<font color='red'>" & rsField("Title") & "</font></td></tr>"
            FieldValue = rsField("FieldValue")
        Else
            Response.Write "<tr class='tdbg'><td>&nbsp;&nbsp;<a href='Admin_Dictionary.asp?TableName=" & rsField("TableName") & "&FieldName=" & rsField("FieldName") & "'>" & rsField("Title") & "</a></td></tr>"
        End If
        PrevTable = rsField("TableName")
        rsField.movenext
    Loop
    rsField.Close
    Set rsField = Nothing
    Response.Write "</table></td><td width='80%' valign='top'>"
    Response.Write "<table width='100%' border='0' align='center' cellpadding='2' cellspacing='1' class='border'>"
    Response.Write "<tr class='title' align='center'><td>序号</td><td>默认</td><td>启用</td><td>选项值</td></tr>"
    Dim arrOption, i, j, arrSetting
    If FieldValue <> "" Then
        arrOption = Split(FieldValue, "$$$")
        For i = 0 To UBound(arrOption)
            arrSetting = Split(arrOption(i), "|")
            Response.Write "<tr class='tdbg'><td align='center'>" & i & "</td><td align='center'><input type='radio' name='DefaultID' value='" & i & "'"
            If CLng(arrSetting(2)) = 1 Then
                Response.Write " checked"
            End If
            Response.Write "></td><td align='center'><input type='checkbox' name='Enabled" & i & "' value='1'"
            If CLng(arrSetting(1)) = 1 Then
                Response.Write " checked"
            End If
            Response.Write "></td><td><input type='text' name='FieldValue' size='30' value='" & arrSetting(0) & "'></td></tr>"
        Next
    End If
    For j = 0 To 2 '这是因为i经过前面的循环后，值变成ubount(arrOption)+1
        Response.Write "<tr class='tdbg'><td align='center'>" & i + j & "</td><td align='center'><input type='radio' name='DefaultID' value='" & i + j & "'></td><td align='center'><input type='checkbox' name='Enabled" & i + j & "' value='1'></td><td><input type='text' name='FieldValue' size='30' value=''></td></tr>"
    Next
    Response.Write "</table>"
    Response.Write "<p align='center'><input type='submit' value=' 保存设置 '><input type='hidden' name='OptionCount' value='" & i & "'><input type='hidden' name='TableName' value='" & TableName & "'><input type='hidden' name='FieldName' value='" & FieldName & "'><input type='hidden' name='Action' value='SaveValue'></p>"

    Response.Write "</td></tr></table></form>"
End Sub

Sub SaveValue()
    Dim TableName, FieldName
    Dim FieldValue, arrValue, DefaultID, OptionCount, i, strValue
    TableName = ReplaceBadChar(Trim(Request("TableName")))
    FieldName = ReplaceBadChar(Trim(Request("FieldName")))
    FieldValue = Trim(Request("FieldValue"))
    DefaultID = Trim(Request("DefaultID"))
    OptionCount = PE_CLng(Trim(Request("OptionCount")))

    If TableName = "" Then
        FoundErr = True
        ErrMsg = ErrMsg & "<li>请指定表名</li>"
    End If
    If FieldName = "" Then
        FoundErr = True
        ErrMsg = ErrMsg & "<li>请指定字段名</li>"
    End If
    If FieldValue = "" Then
        FoundErr = True
        ErrMsg = ErrMsg & "<li>请指定字段的值</li>"
    End If
    If FoundErr = True Then
        Exit Sub
    End If
    If DefaultID = "" Then
        DefaultID = -1
    Else
        DefaultID = PE_CLng(DefaultID)
    End If

    arrValue = Split(FieldValue, ",")
    If OptionCount > UBound(arrValue) Then
        FoundErr = True
        ErrMsg = ErrMsg & "<li>非法数据</li>"
        Exit Sub
    End If
    FieldValue = ""
    '得到原有项目
    For i = 0 To OptionCount - 1
        strValue = Trim(arrValue(i))
        If strValue = "" Then
            strValue = "***"
        End If
        If FieldValue <> "" Then
            FieldValue = FieldValue & "$$$"
        End If
        FieldValue = FieldValue & strValue & "|" & PE_CLng(Trim(Request("Enabled" & i)))
        If i = DefaultID Then
            FieldValue = FieldValue & "|1"
        Else
            FieldValue = FieldValue & "|0"
        End If
    Next
    '得到扩展的项目，如果没有，则不加
    For i = OptionCount To UBound(arrValue)
        If Trim(arrValue(i)) <> "" Then
            If FieldValue <> "" Then
                FieldValue = FieldValue & "$$$"
            End If
            FieldValue = FieldValue & Trim(arrValue(i)) & "|" & PE_CLng(Trim(Request("Enabled" & i)))
            If i = DefaultID Then
                FieldValue = FieldValue & "|1"
            Else
                FieldValue = FieldValue & "|0"
            End If
        End If
    Next

    Dim rsField, sqlField
    sqlField = "select * from PE_Dictionary where TableName='" & TableName & "' and FieldName='" & FieldName & "'"
    Set rsField = Server.CreateObject("ADODB.Recordset")
    rsField.Open sqlField, Conn, 1, 3
    If rsField.bof And rsField.EOF Then
        FoundErr = True
        ErrMsg = ErrMsg & "<li>找不到指定的字段</li>"
    Else
        rsField("FieldValue") = FieldValue
        rsField.Update
    End If
    rsField.Close
    Set rsField = Nothing
    Call WriteSuccessMsg("保存设置成功！", "Admin_Dictionary.asp?TableName=" & TableName & "&FieldName=" & FieldName & "")
    
End Sub
%>
