<%@ page language="C#" masterpagefile="~/MasterPage/UserMasterPage.master" autoeventwireup="true" inherits="Rest_Gift_Default, 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">

    <script type="text/javascript">
        var gSourceUserInfo = new Object();
        gSourceUserInfo.UserId = 0;
        gSourceUserInfo.Integral = 0;
        var gTargetUserInfo = new Object();
        gTargetUserInfo.UserId = 0;
        gTargetUserInfo.Integral = 0;
         gSourceUserInfo.ExpendIntegral = 0;
          gSourceUserInfo.SpreadIntegral = 0;
        
        $(document).ready( function(){ init() });
        
        function init()
        {
            bindEvents();
        }
        
        function bindEvents()
        {
            $("#btnGetSourceUserInfo").bind("click", function(){ getSourceUserInfo() });
            $("#btnGetTargetUserInfo").bind("click", function(){ getTargetUserInfo() });
            $("#btnMove").bind("click", function(){ move() });
        }
        
        function getSourceUserInfo()
        {
            gSourceUserInfo.UserId = 0;
            gSourceUserInfo.Integral = 0;
            $("#SourceUserInfo").html("");
            var Email = $("#tbSourceUserEmail").val();
            if (Email == "")
            {
                alert("请填写用户Email！");
                return;
            }
            var ret = Rest_Gift_Default.GetUserInfo(Email).value;
            if (ret != null && typeof(ret) == "object")
            {
                gSourceUserInfo.UserId = parseInt(ret.Id);
                gSourceUserInfo.Integral = parseInt(ret.Integral);
                 gSourceUserInfo.ExpendIntegral = parseInt(ret.ExpendIntegral);
                 gSourceUserInfo.SpreadIntegral = parseInt(ret.SpreadIntegral);
                
                var str = "用户邮箱：" + ret.Email
                    + "<br />用户昵称：" + HtmlEncode(ret.NickName)
                     //+ "<br />用户总积分：" + ret.Integral + "分"
                    //+ "<br />用户金豆：" + ret.SpreadIntegral + "个"
                    + "<br />剩余积分：" + ret.ExpendIntegral + "分";
                $("#SourceUserInfo").html(str);
            }
            else
            {
                alert("未找到用户信息！");
            }
        }
        
        function getTargetUserInfo()
        {
            gTargetUserInfo.UserId = 0;
            gTargetUserInfo.Integral = 0;
            $("#TargetUserInfo").html("");
            var Email = $("#tbTargetUserEmail").val();
            if (Email == "")
            {
                alert("请填写用户Email！");
                return;
            }
            var ret = Rest_Gift_Default.GetUserInfo(Email).value;
            if (ret != null && typeof(ret) == "object")
            {
                gTargetUserInfo.UserId = parseInt(ret.Id);
                gTargetUserInfo.Integral = parseInt(ret.Integral);
                gTargetUserInfo.ExpendIntegral = parseInt(ret.ExpendIntegral);
                 gTargetUserInfo.SpreadIntegral = parseInt(ret.SpreadIntegral);
                
                var str = "用户邮箱：" + ret.Email
                    + "<br />用户昵称：" + HtmlEncode(ret.NickName)
                     //+ "<br />用户总积分：" + ret.Integral + "分"
                    //+ "<br />用户金豆：" + ret.SpreadIntegral + "个"
                    + "<br />剩余积分：" + ret.ExpendIntegral + "分";
                $("#TargetUserInfo").html(str);
            }
            else
            {
                alert("未找到用户信息！");
            }
        }
        
        function move()
        {
//          var rdS = document.getElementById("rdSpread");
//             var rdE = document.getElementById("rdExpend");
             var classID  = 0;
            if (gSourceUserInfo.UserId == 0)
            {
                alert("请选择源用户！");
                return;
            }
            if (gTargetUserInfo.UserId == 0)
            {
                alert("请选择目标用户！");
                return;
            }
            if (gSourceUserInfo.UserId == gTargetUserInfo.UserId)
            {
                alert("不可在同一用户中转移积分！");
                return;
            }
            if (gSourceUserInfo.Integral <= 100)
            {
                alert("源用户积分需大于100！");
                return;
            }
//            if (document.getElementById("rdSpread").checked)
//            {
//                var MoveIntegral = $("#tbMoveIntegral").val();
//            }
//            else
//            {
                var MoveIntegral = parseInt($("#tbMoveIntegral").val());
//            }
            if (isNaN(MoveIntegral))
            {
                alert("请填写有效的转移积分值！");
                return;
            }
            if (MoveIntegral < 1)
            {
                alert("转移分值需是大于1的数！");
                return;
            }
            
//             if(rdS.checked)//推广
//             {
//                
//                classID = 2;
//                 if(gSourceUserInfo.SpreadIntegral <= 100)
//                {
//                    alert("用户的金豆大于100才能转移");
//                    return;
//                }
//                var ValidIntegral = gSourceUserInfo.SpreadIntegral - 100;//可转积分值
//                if (MoveIntegral > ValidIntegral)
//                {
//                    alert("可转金豆值不可大于：" + ValidIntegral + "个！");
//                    return;
//                }
//                
//             }else if(rdE.checked)//消费
//             {
                
                classID = 1;
                  if(gSourceUserInfo.ExpendIntegral <= 100)
                {
                    alert(" 用户的剩余积分大于100才能转移");
                    return;
                }
                var ValidIntegral = gSourceUserInfo.ExpendIntegral - 100;//可转积分值
                if (MoveIntegral > ValidIntegral)
                {
                    alert("可转剩余积分值不可大于：" + ValidIntegral + "分！");
                    return;
                }
//             }
//             else if (!(rdS.checked || rdE.checked))
//             {
//                window.alert("请选择要转移积分/金豆的类型！");
//                return;
//             }
             
             if(window.confirm("确实要转移积分吗？"))
             {
                var ret = Rest_Gift_Default.MoveIntegral(gSourceUserInfo.UserId, gTargetUserInfo.UserId, MoveIntegral,classID,"转移积分").value;
                if (ret)
                {
                    alert("转移成功！");
                    getTargetUserInfo();
                    getSourceUserInfo();
                    //window.location.reload();
                }
                else
                {
                    alert("转移失败，请重试！");
                }
            }
        }
    </script>

    <style type="text/css">
        td
        {
            vertical-align:top;
        }
        .UserInfo
        {
            margin:5px;
            padding:5px;
            height:90px;
        }
        .mei{ height:50px; margin-top:20px;}
        .si{ width:48px; height:25px; background-color:green; color:#FFFFFF;
 line-height:24px; text-align:center; margin-right:25px;}
         .cu{ width:48px; height:25px; background-color:green; color:#FFFFFF;
 line-height:24px; text-align:center; margin-right:25px; margin-top:20px;}
 .bi{float:left; width:43px; height:37px; margin-top:82px; margin-left:27px;
      background:url(/images/v6top/jiantou.gif) no-repeat;}
        
    </style>
    <div id="divDemo" runat="server" style="color: red; font-size: 24px; margin: 0px;
        padding: 0px;">
        <strong>如果您需要申请试用或购买本模块请<a href='http://www.doulaiding.com/buy/' target="_blank">联系我们</a>！</strong><br />
    </div>
    <div class="MainContent" id="divContent" runat="server">
        <table class="NewTable" style="width: 281px; float: left;">
            <tr>
                <th>
                    转出用户</th>
            </tr>
            <tr>
                <td>
                    <span style="float:left; margin-left:5px;">用户邮箱：</span>
                    <br /><input id="tbSourceUserEmail" type="text" style="width: 180px" />
                    <input class="si" id="btnGetSourceUserInfo" type="button" value="查询" />
                    <div id="SourceUserInfo" class="UserInfo">
                    </div>
                </td>
            </tr>
        </table>
        <table class="NewTable" style="width: 281px; float: right;">
            <tr>
                <th>
                    转入用户</th>
            </tr>
            <tr>
                <td>
                    <span style="float:left; margin-left:5px;">用户邮箱：</span>
                   <br /> <input id="tbTargetUserEmail" type="text" style="width: 180px" />
                    <input class="si" id="btnGetTargetUserInfo" type="button" value="查询" />
                    <div id="TargetUserInfo" class="UserInfo">
                    </div>
                </td>
            </tr>
        </table>
        <div class="bi">
        </div>
        <div style="width: 281px">
            <div style="display: none;">
                <input id="rdSpread" name="rd" style="width: 14px; display: none;" type="radio" value="1" />金豆
                <input id="rdExpend" name="rd" style="width: 16px; display: none;" type="radio" value="2" />
                消费积分<br />
                <br />
            </div>
            <div>
            转移积分：<input id="tbMoveIntegral" type="text" size="8" maxlength="10" />
            <input class="cu" id="btnMove" type="button" value="转移" /></div>
        </div>
    </div>
</asp:Content>
