<%@ page language="C#" masterpagefile="~/MasterPage/UserMasterPage.master" autoeventwireup="true" inherits="Rest_Gift_AddGiftClass, DoodiiShop" title="Untitled Page" enableEventValidation="false" viewStateEncryptionMode="Never" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder2" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<style type="text/css">
.cui{background-color:#008c00; color:#FFFFFF; width:72px;  height:25px; line-height:25px; text-align:center; margin-right:8px; cursor:pointer;}
</style>
    <script type="text/javascript">
 function AddClass()
    {
       var Name=$("#ClassName").val();
       if($.trim(Name)!="")
       {
         var ret=Rest_Gift_AddGiftClass.addClass(Name,0).value;
         if(ret==0)
         {alert("添加成功！");getClassUl();$("#ClassName").val("")}
         else
         {alert(ret);}
       }
       else
       {alert("请填写类名！");}
    }
    function getClassUl()
    {
       var ret=Rest_Gift_AddGiftClass.GetClass().value;
       var div=document.getElementById("ClassList");
       div.innerHTML="";
       if(ret !=null)
       {
            var str="<table class='NewTable'><tr><th> 类别名称</th><th> 操作</th></tr>";
          for (i=0;i<ret.Rows.length;i++)
          {
             str+="<tr><td>"+ret.Rows[i]["ClassName"]+"</td><td><a href='javascript:delclass("+ret.Rows[i]["id"]+")'>[删除]</a> | "
                                                  +"<a href='javascript:editclass(\"edit"+ret.Rows[i]["id"]+"\","+ret.Rows[i]["id"]+",\""+HTMLDeCode(ret.Rows[i]["ClassName"])+"\")' id='edit"+ret.Rows[i]["id"]+"'>[修改]</a></td></tr>";
          }
          div.innerHTML=str+"</table>";
          
       }
    }
    function delclass(id)
    {
     if(confirm("确定要删除这个类别吗？"))
     {
       var ret=Rest_Gift_AddGiftClass.DelClass(id).value;
       if(ret==0)
       {alert("删除成功！");getClassUl();}
       else
       {alert(ret);}
     }else
     {}
    }
     //浮动提示信息
    function ShowMsg(obj)
    {
        var divPopMessage = document.getElementById("WhyMsg");          
        divPopMessage.style.left = (getPosition(obj).x + 0) + "px";
        divPopMessage.style.top = (getPosition(obj).y + 0) + "px"; 
        divPopMessage.style.display = ""; 
    }
    function CloseMsg()
    {
        var divPopMessage = document.getElementById("WhyMsg");  
        divPopMessage.style.display = "none";
    }
    function editclass(a,id,name)
    {
       ShowMsg(a);
       $("#edName").val(name);
       $("#hdid").val(id)
    }
    function UpClass()
    {
       var id=$("#hdid").val();
       var newname=$("#edName").val();
       var ret=Rest_Gift_AddGiftClass.addClass(newname,id).value;
       if(ret==0)
       {alert("修改成功！");getClassUl();CloseMsg();}
       else
       {alert(ret);}
    }
     $(document).ready( function(){ getClassUl() });
    </script>

    <style type="text/css">
    .PopMessage
{
    position:absolute;
    width:200px;
    height:50px;
    padding:5px 5px 5px 5px;
    right:0px; top:0px;
    background-color:#F7FCF5;
    z-index:9999;
    border:2px solid #61BD33;
}
    </style>
    <input type="hidden" id="hdid" value="0" />
    <div style="background-color: #f5f5f5; height: 22px; padding-top: 6px; padding-bottom: 6px;">
        &nbsp;&nbsp;类别名称：<input type="text" value="" id="ClassName" />
        <input class="cui" type="button" value="添加" onclick="AddClass()" /></div>
    <div style="margin-top: 8px; margin-left: 10px; text-align:center;">
        <div id="ClassList">
        </div>
    </div>
    <div id="WhyMsg" class="PopMessage" style="display: none;">
        <div style="clear: both; text-align: right;">
            <a class="normal" href="javascript:void(0);" onclick="CloseMsg()">[关闭]</a></div>
        <div style="line-height: 16px; margin-top: 10px;">
            <input type="text" value="" id="edName" />
            <input type="button" value="更新" onclick="UpClass()" />
        </div>
    </div>
</asp:Content>
