<%@ Control Language="C#" %>
<%@ Import Namespace="Kesion.Cache" %>
<%@ Import Namespace="Kesion.Publics" %>
<%@ Import Namespace="Kesion.BLL" %>
<%@ Import Namespace="Kesion.Config" %>
<%@ Import Namespace="Kesion.Components" %>
<%@ Import Namespace="Kesion.HtmlTags" %>
<%@ Import Namespace="Kesion.UCenter" %>
<%@ Import Namespace="Kesion.XML" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Xml" %>
<script runat="server" type="text/C#">

    dynamic __user = HttpContext.Current.Items["user"];                //初始化用户信息
    bool isLoadPage = true;  //定义页面是否加载

    public static ConfigInfo __configinfo = null;
    public static int PointScore = 0;

    protected void Page_Load(object sender, EventArgs e)
    {
        CheckUserLogin.Run();
        if (KSCMS.S("action") == "dosave")
        {
            isLoadPage = false;
            DoSave();
            return;
        }
        else if (KSCMS.S("action") == "dosavescore")
        {
            isLoadPage = false;
            DoSaveScore();
            return;
        }

        __configinfo = ConfigManage.GetConfig();

        if (__configinfo == null)
        {
            Msg.Alert("出错啦！", KSCMS.GetComeUrl());
        }
        if (KSCMS.S("flag") == "score" && Utils.StrToInt(__configinfo.ScoreToPointRate, 0) > 0)
        {
            PointScore = Utils.StrToInt(__user.AvailableScore / Utils.StrToInt(__configinfo.ScoreToPointRate, 1));
        }

    }
    //兑换科汛币
    private void DoSave()
    {
        #region 保存
        int point = Utils.StrToInt(KSCMS.S("point"));
        if (point <= 0)
        {
            Msg.Alert("兑换" + MyCache.GetCacheConfig(49) + "必须大于0!", KSCMS.GetComeUrl());
        }
        double allowMoney = __user.Money;
        if (point > allowMoney)
        {
            Msg.Alert("您当前可用预付款" + __user.Money + "元，最多只能兑换" + allowMoney.ToString("0") + MyCache.GetCacheConfig(50) + MyCache.GetCacheConfig(49) + "!", KSCMS.GetComeUrl());
            return;
        }
        string realname = __user.RealName;
        if (string.IsNullOrEmpty(realname)) realname = __user.UserName;
     
        if (Charge.MoneyInOrOut(__user.UserID, realname, Utils.StrToFloat(point), 1, 2, "0", "system", "用于兑换" + point + MyCache.GetCacheConfig(50) + MyCache.GetCacheConfig(49) + "。", 0, 0, 1))
        {
           
        }
        if (Charge.PointInOrOut(0, 0, __user.UserID, 1, Utils.StrToFloat(point), "system", "使用预付款" + point + "兑换所得!"))
        {

        }
        Msg.Alert("恭喜，兑换成功!", KSCMS.GetComeUrl());
        return;

        #endregion
    }

    //积分兑换科汛币
    private void DoSaveScore()
    {
        #region 积分兑换
        int point = Utils.StrToInt(KSCMS.S("ScorePoint"));
        if (point <= 0)
        {
            Msg.Alert("兑换" + MyCache.GetCacheConfig(49) + "必须大于0!", KSCMS.GetComeUrl());
            return;
        }
        if (PointScore <= 0)
        {
            Msg.Alert("对不起,您的可兑换"+MyCache.GetCacheConfig(90)+"不足!", KSCMS.GetComeUrl());
            //Msg.Alert("对不起，本站没有开启" + MyCache.GetCacheConfig(90) + "兑换" + MyCache.GetCacheConfig(49) + "功能!", KSCMS.GetComeUrl());
            return;
        }
        if (point > PointScore)
        {
            Msg.Alert("您当前可用" + MyCache.GetCacheConfig(90) + __user.AvailableScore + "分，最多只能兑换" + PointScore + MyCache.GetCacheConfig(50) + MyCache.GetCacheConfig(49) + "!", KSCMS.GetComeUrl());
            return;
        }

        string realname = __user.RealName;
        if (string.IsNullOrEmpty(realname)) realname = __user.UserName;

        int xhScore = point * Utils.StrToInt(__configinfo.ScoreToPointRate);
        if (xhScore > 0) {
            Charge.ScoreInOrOut(0, 0, __user.UserID, 2, xhScore, "system", string.Format(@"使用{3}兑换了{0}{1}{2}消费!", point, MyCache.GetCacheConfig(50), MyCache.GetCacheConfig(49), MyCache.GetCacheConfig(90)), 1);
            Charge.PointInOrOut(0, 0, __user.UserID, 1, point, "system", string.Format(@"使用{0}个{1}兑换所得!", xhScore,MyCache.GetCacheConfig(90)));
        }

        Msg.Alert("恭喜，兑换成功!", KSCMS.GetComeUrl());
        return;
        #endregion
    }
</script>
<%
    if (!isLoadPage) return;
%>


<div class="r_tybox t_tybox nomar">
    <div class="r_title tytitle pd0"><h4 class="float-none disting_show"><%=MyCache.GetCacheConfig(49) %>兑换</h4>
  </div>
               
    <div class="top-sort clearfix">

        <div class="top-sort-tab lf">
            <ul>

                <li<%=KSCMS.S("flag")==""?" class='puton'":"" %>><a href="<%=BasicField.GetUserUrl("basic/ExchangePoint") %>">余额兑换<%=MyCache.GetCacheConfig(49) %></a></li>
                 <%if (Utils.StrToInt(__configinfo.ScoreToPointRate.ToString()) > 0)
            { %>
                <li<%=KSCMS.S("flag")=="score"?" class='puton'":"" %> ><a href="<%=BasicField.GetUserUrl("basic/ExchangePoint","flag-score") %>"><%=MyCache.GetCacheConfig(90) %>兑换<%=MyCache.GetCacheConfig(49)%></a></li>
                <%} %>
    
            </ul>
        </div>
        
 
      
    </div>


    <%if (string.IsNullOrEmpty(KSCMS.S("flag")))
                { %>

        	<form name="myform" action="{$GetCurrUrl}" method="post" id="myform">
              <input type="hidden" name="action" id="action" value="dosave"/>
             <table  cellspacing="0" cellpadding="0" class="border" width="100%" align="center" border="0">
                 <tr class="tdbg">
                     <td style="height:50px; text-align:left; line-height:34px;" class="splittd">
                        可用余额 <%=MyCache.GetCurrencySymbol %><font color=red><%=Kesion.APPCode.Public.ReturnShopPrice(__user.Money) %></font> <%=MyCache.GetCurrencyUnit %> <a href="<%=BasicField.GetUserUrl("basic/logmoney") %>"><span class=blue-color>明细</span></a> ，
                         <br />可用<%=MyCache.GetCacheConfig(49)%><%=__user.Point %><%=MyCache.GetCacheConfig(50) %> <a href="<%=BasicField.GetUserUrl("basic/consumer") %>"><span class=blue-color>明细</span></a>
                         </td>
                 </tr>
                 <tr class="tdbg">
                     <td class="splittd" style="border-bottom:0">
                       兑换比率：1<%=MyCache.GetCurrencyUnit %>兑换1<%=MyCache.GetCacheConfig(50) %><%=MyCache.GetCacheConfig(49) %>，您当前可用预付款为<font class=red-color><%=Kesion.APPCode.Public.ReturnShopPrice(__user.Money) %>元</font>，您最多可以兑换<font class=green-color><%=__user.Money.ToString("0") %><%=MyCache.GetCacheConfig(50) %></font><%=MyCache.GetCacheConfig(49) %>。
                        <Br />&nbsp;兑换： <input type="text" name="Point" id="Pont" class="textbox" style="text-align:center; padding-left:0px;width:50px" value="100"> &nbsp;<%=MyCache.GetCacheConfig(50)%><%=MyCache.GetCacheConfig(49)%>
                       &nbsp; <input ID="BtnNext" type="submit" class="green-bt d-inline button" value="确定兑换" style="margin-top:15px;" onclick="return(confirm('此操作不可逆，确定执行兑换吗？'));"  />
                     <br />
                     
                     </td>
                 </tr>
                </table>
              </form>
            <%} else { %>

            <form name="myform" action="{$GetCurrUrl}" method="post" id="myform">
              <input type="hidden" name="action" id="action" value="dosavescore"/>
             <table  class="border" width="100%" align="center" border="0">
                 <tr class="tdbg">
                     <td style="height:50px; font-size:14px; line-height:30px; text-align:left" class="splittd">
                         累计<%=MyCache.GetCacheConfig(90)  %><font color=#888><%=__user.Score %></font> 分 可用<%=MyCache.GetCacheConfig(90)  %><font color=green><%=__user.AvailableScore %></font>分 <a href="<%=BasicField.GetUserUrl("basic/logscore") %>"><span class=blue-color>明细</span></a>。
                         <br />可用<%=MyCache.GetCacheConfig(49)%><%=__user.Point %><%=MyCache.GetCacheConfig(50) %> <a href="<%=BasicField.GetUserUrl("basic/consumer") %>"><span class=blue-color>明细</span></a>
                         </td>
                 </tr>
                 <tr class="tdbg">
                     <td class="splittd" style="height:50px; text-align:left;border-bottom:0px; font-size:12px">
                        <span class="tips" style="padding-left:0px">兑换比率：<%=__configinfo.ScoreToPointRate %>个<%=MyCache.GetCacheConfig(90)  %>兑换1<%=MyCache.GetCacheConfig(50) %><%=MyCache.GetCacheConfig(49) %>，您当前可用<%=MyCache.GetCacheConfig(90)  %>为<%=__user.Score.ToString() %>元，您最多可以兑换<%=PointScore %><%=MyCache.GetCacheConfig(50) %><%=MyCache.GetCacheConfig(49) %>。
                        </span><Br />&nbsp;
                        兑换： <input type="text" name="ScorePoint" class="textbox" style="text-align:center; padding-left:0px;width:50px" value="<%=PointScore %>"> &nbsp;<%=MyCache.GetCacheConfig(50)%><%=MyCache.GetCacheConfig(49)%>
                       &nbsp; <input type="submit" ID="Button1" class="green-bt d-inline button mt20" value="确定兑换" onclick="return(confirm('此操作不可逆，确定执行兑换吗？'));"/>
                     </td>
                 </tr>
            </table>
            </form>


            <%} %>

   	</div>
  