<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="memberlevel_edit.aspx.cs" Inherits="VA.Modules.JDingMember.basic.memberlevel_edit" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <!--#include virtual="/include/css/edit.aspx"-->
    <!--#include virtual="/include/js/edit.aspx"-->     
    <script type="text/javascript">
    function save() {

        //调用asp.net验证控件自带的js数据验证脚本对控件进行验证；
        var validationResult = Page_ClientValidate('');
        if (!validationResult) {
            return;
        }

        var flag = "0";
        if ($("#hfKey").val() != "") {
            flag = "1";
        }

        if (flag == 0) {
            add();
        }
        else {
            update();
        }
    }

    function add() {
        var requestType = "POST";
        var url = pageName + "?act=add";  //pageName在BasePage中注册到的客户端；
        var dataType = "html";
        var data = $("form").eq(0).serialize();
        var successFN = function (data, textStatus) {
            if (data == "ok") {
                showActResult("添加成功！", true, doAfterAdd);
            } else if (data.indexOf("01|") != -1) {
                showActResult(data.substring(3), false, doAfterAdd);
            }
            else {
                showActResult("添加失败：" + data, false, doAfterAdd);
            }
        };
        ajaxRequest(requestType,
            url,
            dataType,
            data,
            successFN,
            errorFN
            );
    }

    function update() {
        var requestType = "POST";
        var url = pageName + "?act=update";
        var dataType = "html";
        var data = $("form").eq(0).serialize();
        var successFN = function (data, textStatus) {
            if (data == "ok") {
                showActResult("修改成功！", true, doAfterUpdate);
            } else if (data.indexOf("01|") != -1) {
                showActResult(data.substring(3), false, doAfterUpdate);
            }
            else {
                showActResult("修改失败：" + data, false, doAfterUpdate);
            }
        };
        ajaxRequest(requestType,
            url,
            dataType,
            data,
            successFN,
            errorFN
            );
    }

    function doAfterAdd(actResult) {
        if (actResult) {
            try {
                if (window.parent != window.self) {
                    window.parent.completeReload();
                }
            } catch (e) { }
            resetPage();
        }
    }
    function doAfterUpdate(actResult) {
        if (actResult) {
            try {
                if (window.parent != window.self) {
                    window.parent.closeFrameWindow();
                    window.parent.completeReload();
                }
            } catch (e) { }
        }
    }

    //显示操作结果；
    function showActResult(sMsg, actResult, callback) {
        JTongModalAlert(sMsg);
        if (callback != null && callback != undefined) {
            callback(actResult);
        }
    }

    function resetPage() {

        $("#txtLevelCode").val("");
        $("#txtLevelName").val("");
        $("#txtLevelValue").val("");
        $("#ckbIsDefault")[0].checked = false;
       
        clearInputValidatorError();

        $("#txtLevelCode").focus();
    }

    $(function () {
        $("#txtLevelCode").focus();

        //焦点控制
        $("input").keyup(function (event) {
            if (event.keyCode == 13) {
                var targetID = event.target.id;
                switch (targetID) {
                    case "txtLevelCode":
                        $("#txtLevelName").focus();
                        break;
                    case "txtLevelName":
                        $("#txtLevelValue").focus();
                        break;
                    case "txtLevelValue":
                        if ($("#txtLevelValue").val() != "") {
                            save();
                        }
                        break;               
                    default:
                        break;
                }
                return false;
            }
        });

    });

    </script>

</head>
<body>
<form id="Form1" method="post" runat="server">

<div class="editPageWrapper" style="width:460px;">

<%--<div class="centerFormTitle">
   <h1>会员级别</h1>
</div>
--%>
<table cellspacing="0" cellpadding="3" class="editTable">
<tr>
<td class="th">(<span class="note mustfill">*</span>)级别代码：</td>
<td>              
    <VACTL:TextBox ID="txtLevelCode" Runat="server"
            EnableViewState="False"
            CssClass="input"
            Width="80px"
            CanBeNull="No"
            FieldName="级别代码"
            MaxLength="10" />   
</td>
</tr>
<tr>
<td class="th">(<span class="note mustfill">*</span>)级别名称：</td>
<td>              
    <VACTL:TextBox ID="txtLevelName" Runat="server"
            EnableViewState="False"
            CssClass="input"
            Width="200px"
            CanBeNull="No"
            FieldName="级别名称"
            MaxLength="25" />  
    <asp:CheckBox ID="ckbIsDefault" runat="server"
         Text="默认级别" />     
        
</td>
</tr>
<tr>
<td class="th">(<span class="note mustfill">*</span>)级 别 值：</td>
<td>              
    <VACTL:TextBox ID="txtLevelValue" Runat="server"
            EnableViewState="False"
            CssClass="input"
            Width="80px"
            CanBeNull="No"
            FieldName="级 别 值"
            RequiredFieldType="PositiveInteger"
            MaxLength="5" />   //请填写数字，值代表级别越高。
</td>
</tr>
<tr>
<td colspan="2" class="footer"> 
    <% if (base.flag == 0) { %>
    <input type="button" id="btnSubmit" class="btn" style="width:100px" onclick="save()" value="保存" />
    <input type="button" id="btnClear" class="btn" style="width:100px" onclick="resetPage()" value="重置" />
    <% } else { %>
    <input type="button" id="Button1" class="btn" style="width:100px" onclick="save()" value="保存" />
    <% } %>    
    
    <asp:HiddenField ID="hfKey" runat="server" />
    
    <VACTL:Hint ID="Hint1" runat="server" HintImageUrl="/app_themes/default/images/textbox" />
    <VACTL:ValidationSummary ID="ValidationSummary1" runat="server"
            DisplayMode="List"
            EnableClientScript="true" />
    
    <!--注意：这个文件一定要放到页面底部，以便覆盖asp.net验证脚本中的同名函数-->
    <script type="text/javascript" src="/scripts/utils/aspnet_validator_extend.js"></script> 
</td>
</tr>
</table>

</div><!--editPageWrapper.END-->

</form>
</body>
</html>

