<%@ Control Language="C#" %>
<%@ Import Namespace="Kesion.Publics" %>
<%@ Import Namespace="Kesion.BLL" %>
<%@ Import Namespace="Kesion.Cache" %>
<%@ Import Namespace="Kesion.HtmlTags" %>
<%@ Import Namespace="Kesion.APPCode" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="Kesion.Course" %>
<script runat="server" type="text/C#">
    dynamic __user = HttpContext.Current.Items["user"];                //初始化用户信息，
    private static dynamic __info = new System.Dynamic.ExpandoObject();   //初始化当前页信息
    bool isLoadPage = true;  //定义页面是否加载
    public string title = string.Empty;
    public string days = "0";
    public string showdata = string.Empty;
    public string AgreeMent = string.Empty;
    public DataRow drs = null;
    protected void Page_Load(object sender, EventArgs e)
    {
        string DoMethod = BasicField.GetParam("do");
        if (string.IsNullOrEmpty(DoMethod))
        {
            DoMethod = KSCMS.S("action");
        }
        showdata= getuse();
    }
    public static string GetInfo(string RangeType, string LimitType, string LimitClassIDs)
    {

        #region 使用条件
        string str = string.Empty;
        string sql = string.Empty;
        if (RangeType == "0")//内容
        {
            switch (LimitType)
            {
                case "2":
                    StringBuilder sb = new StringBuilder();
                    if (!string.IsNullOrEmpty(LimitClassIDs))
                    {
                        sb.Append("<span>");
                        string[] ids = LimitClassIDs.Split(',');
                        foreach (string s in ids)
                        {
                            sb.Append(MyCache.GetCacheClass(Utils.StrToInt(s), 1) + "&nbsp;");
                        }
                        sb.Append("</span>");
                    }
                    str = sb.ToString();
                    break;
            }

        }
        if (RangeType == "1")//考试
        {
            switch (LimitType)
            {
                case "2":
                    if (!string.IsNullOrEmpty(LimitClassIDs))
                    {
                        using (DataTable dt = DataFactory.GetDataTable("select top 600 classid,classname from KS_SjClass Where classId in(" + Utils.FilterIDs(LimitClassIDs) + ")"))
                        {
                            if (dt.Rows.Count > 0)
                            {
                                foreach (DataRow dr in dt.Rows)
                                {
                                    str += string.Format("<span><a href='{0}' target='_blank'>", "javascript:void(0)") + dr[1].ToString() + "</a></span>";
                                }
                            }
                        }
                    }

                    break;
                case "3":
                    if (!string.IsNullOrEmpty(LimitClassIDs))
                    {
                        using (DataTable dt = DataFactory.GetDataTable("select top 600 title,id from KS_SJ where verify=1 and id in(" + Utils.FilterIDs(LimitClassIDs) + ")"))
                        {
                            if (dt.Rows.Count > 0)
                            {
                                foreach (DataRow dr in dt.Rows)
                                {
                                    str += string.Format("<span><a href=\"{0}\" target=\"_blank\">", BaseFun.GetRewriteUrl("examview", Utils.StrToInt(dr["id"].ToString()))) + dr["title"].ToString() + " </a></span>";
                                }
                            }
                        }
                    }

                    break;
            }
        }
        if (RangeType == "2")//课程
        {
            switch (LimitType)
            {
                case "2":
                    if (!string.IsNullOrEmpty(LimitClassIDs))
                    {
                        using (DataTable dt = DataFactory.GetDataTable("select top 600 classid,classname from KS_CosClass Where Type=0 and classId in(" + Utils.FilterIDs(LimitClassIDs) + ")"))
                        {
                            if (dt.Rows.Count > 0)
                            {
                                foreach (DataRow dr in dt.Rows)
                                {

                                    str += string.Format("<span><a href='{0}' target='_blank'>",BaseFun.GetRewriteUrl("courselist",Utils.StrToInt(dr["classid"].ToString())) ) + dr[1].ToString() + "</a></span>";
                                }
                            }
                        }
                    }

                    break;
                case "3":
                    if (!string.IsNullOrEmpty(LimitClassIDs))
                    {
                        int cosType = 0;
                        #region 新增支持面授课，点播课
                        //0|467,1|137,1|138
                        string[] limitArr = LimitClassIDs.Split(',');
                        foreach (string limitId in limitArr)
                        {
                            string newLimitId = limitId;
                            if (newLimitId.IndexOf("|") == -1) newLimitId = "0|" + limitId;
                            var idArr = newLimitId.Split('|');
                            cosType = Utils.StrToInt(idArr[0]);//0在线，1面授
                            string sqlStr = string.Empty;
                            if (cosType == 1)
                            {
                                sqlStr = "SELECT TOP 1 Name,courseid,TeachWay From KS_CourseFace Where CourseId=" + idArr[1]+ " AND verify=1 and IsOff=1";
                            }
                            else
                            {
                                sqlStr = "SELECT TOP 1 Name,courseid,TeachWay From KS_Course Where CourseId=" + idArr[1]+ " AND verify=1 and IsOff=1";
                            }

                            using (DataTable dtCourse = DataFactory.GetDataTable(sqlStr))
                            {

                                if (dtCourse.Rows.Count > 0)
                                {
                                    DataRow drCourse = dtCourse.Rows[0];
                                    int  teachWay=Utils.StrToInt(drCourse["TeachWay"].ToString());
                                    str += string.Format("<span><a href=\"{0}\" target=\"_blank\">",BaseFun.GetRewriteUrl(teachWay==5?"liveview":teachWay==0?"faceview":"courseview",Utils.StrToInt(drCourse["courseid"].ToString()))) + drCourse["name"].ToString() + " </a></span>";

                                }
                            }


                        }

                        #endregion
                    }


                    break;


            }

        }


        return str;


        #endregion
    }
    public static string GetShiYong(string limit, int contenttf, int examtf, int coursetf, string examclassids, string contentclassids, string cosclassids, string examids, string cosids)
    {
        #region 使用条件
        string str = "<div class=\"noAuth\">无任何权限</div>";
        string sql = string.Empty;

        if (Utils.StrToInt(limit) == 0)
        {
            switch (contenttf)
            {
                case 1:
                    str += "<div class=\"f-l w-80 lh-30\">文章模块拥有所有免费查看权限</div><div class=\"clear\"></div>";
                    break;
                case 2:
                    str += "<div class=\"f-l w-80 lh-30\">部分文章栏目下拥有免费查看权限</div><div class=\"f-l lac\">" + GetInfo("0", contenttf.ToString(), contentclassids) + "</div><div class=\"clear\"></div>";
                    break;
            }
            switch (examtf)
            {
                case 1:
                    str += "<div class=\"f-l w-80 lh-30\">考试模块拥有所有免费做题权限</div><div class=\"clear\"></div>";

                    break;
                case 2:
                    str += "<div class=\"f-l w-80 lh-30\">部分考试栏目下拥有免费做题权限</div><div class=\"f-l lac\">" + GetInfo("1", examtf.ToString(), examclassids) + "</div><div class=\"clear\"></div>";

                    break;
                case 3:
                    str += "<div class=\"f-l w-80 lh-30\">指定试卷免费</div><div class=\"f-l lac\">" + GetInfo("1", examtf.ToString(), examids) + "</div><div class=\"clear\"></div>";

                    break;
            }
            switch (coursetf)
            {
                case 1:
                    str += "<div class=\"f-l w-80 lh-30\">课程模块拥有所有免费观看权限</div><div class=\"clear\"></div>";

                    break;
                case 2:
                    str += "<div class=\"f-l w-80 lh-30\">部分课程栏目下拥有免费观看权限</div><div class=\"f-l lac\">" + GetInfo("2", coursetf.ToString(), cosclassids) + "</div><div class=\"clear\"></div>";

                    break;
                case 3:
                    str += "<div class=\"f-l w-80 lh-30\">指定课程免费</div><div class=\"f-l lac\">" + GetInfo("2", coursetf.ToString(), cosids) + "</div><div class=\"clear\"></div>";

                    break;
            }

        }
        else if (limit == "1")
        {
            str = @" <p><span class=""used_info_tj"">可以查看本站的所有收费项目</span></p>";
        }

        return str;
        #endregion
    }
    public string getuse()
    {
        string result = string.Empty;
        int packid = Utils.StrToInt(KSCMS.S("packid"));
        using (DataTable dt = DataFactory.GetDataTable("select top 1 * from KS_UserFeePackages where id=" + packid + ""))
        {
            if (dt.Rows.Count > 0)
            {
                drs = dt.Rows[0];
                days = drs["days"].ToString();
                title = drs["title"].ToString();
                if (Utils.StrToInt(drs["limit"].ToString()) == 0)
                {
                    result = GetShiYong(drs["limit"].ToString(), Utils.StrToInt(drs["contenttf"].ToString()), Utils.StrToInt(drs["examtf"].ToString()), Utils.StrToInt(drs["coursetf"].ToString()), drs["examclassids"].ToString(), drs["contentclassids"].ToString(), drs["cosclassids"].ToString(), drs["examids"].ToString(), drs["cosids"].ToString());
                }
                else
                {
                    result = "在有效期内可以查看所有需要收费的内容";
                }

            }
        }
        return result;
    }
    public string GetUserInfo(int feeid)
    {
        string userinfo = DataFactory.GetOnlyValue("select top 1 userinfo from KS_UserFeeSell where id=" + feeid);
        if (userinfo == "0")
        {
            userinfo = string.Empty;
        }
        else
        {
            userinfo="<div style=\"padding:5px;border:1px solid #ccc;height:300px;overflow:auto;width:700px;\">" + userinfo + "</div>";
        }
        return userinfo.ToString();
    }
    public string getVal(string t)
    {
        string s = "";
        if (drs != null)
        {
            s = drs[t].ToString();
        }
        return s;
    }
    public string getroupname(int groupid)
    {
        string result=DataFactory.GetOnlyValue("select top 1 groupname from KS_UserGroup where groupid=" + groupid + "");
        if (result == "0")
        {
            result = "级别不变";
        }
        return result;
    }
</script>

<style>
.card{width: 85%;margin:60px auto;}
.cardBox {width: 400px;height: 190px;border-radius: 10px;box-sizing: border-box;position: relative;}
.taocan{background: #35a0da;border: 1px solid #35a0da;border-top: 2px solid #4bbdfb;}
.chongzhi{ background:#fb8181;border: 1px solid #fb8181;border-top: 2px solid #f9aaaa;}

.textImg{ float:left; width:45px; height:45px; background:#fff; border-radius:45px; padding:5px; box-sizing:border-box; margin-left:28px;margin-top: 34px;}
.textImg span{font-size: 20px;font-weight: bold;border-radius: 35px;display: block;width: 35px;height: 35px;box-sizing: border-box;line-height: 31px;text-align: center;}
.taocan .textImg span{border: 2px solid #35a0da;color: #35a0da;}
.chongzhi .textImg span{border: 2px solid #fb8181;color: #fb8181;}

.cardBgText{position: absolute;width: 164px;height: 164px;box-sizing: border-box;text-align: center;line-height: 134px;font-size: 90px;font-weight: bold;border-radius: 164px;border: 15px solid #fff;opacity: 0.1;bottom: -32px;right: -8px;}
.cardBgText span{ color:#fff;}
.cardInfo{padding-left: 87px;}
.cardName{ margin-top:30px;font-size: 20px;color: #fff;letter-spacing: 1px;margin-bottom: 13px;height: 26px;line-height: 26px;overflow: hidden;white-space: nowrap;text-overflow: ellipsis;}
.cardTime,.cardAuthority{ color:#fff; font-size:14px;opacity:0.7; letter-spacing:1px; margin-bottom:10px;}
.lac span a{color: #fff;text-decoration: underline;}
.f-l{ float:left;}
.lac{ margin-right:10px; margin-left:10px;width:auto;height: 19px; line-height:19px;overflow: hidden;}
.cardIntroB{ padding:20px; padding-left:430px; min-height:190px; border:1px solid #eee;background: #f8f8f8; border-radius:10px; box-sizing:border-box;}
.cardIntroB .cardIntro{font-size: 18px;margin-top: 10px;color: #666;letter-spacing: 1px;margin-bottom: 13px;}
.cardIntroB .cardSIntro{ font-size:14px; color:#888;}
</style>
<%
    if (!isLoadPage) return;
%>
  	<div class="card clearfix">
		<%if(KSCMS.S("cardtype") != "1") {%>
        <div class="cardBox taocan f-l">
            <div class="cardBgText"><span>套</span></div>
            <div class="textImg"><span>套</span></div>
        <%}else{%>
        <div class="cardBox chongzhi f-l">
            <div class="cardBgText"><span>充</span></div>
            <div class="textImg"><span>充</span></div>
        <%}%>
            <div class="cardInfo">
                <div class="cardName"><%=title %></div>
                <div class="cardAuthority">
                    <%if(KSCMS.S("cardtype") != "1") {%>
                    <!--营销卡权-->
                    <div class="cardAuth">
                        <%=showdata %>
                    </div>
                    <%}else{ %>
                    <!--用户组权限：-->
                    <div class="cardUsed">
                         <p>使用升级：<span><%=getroupname(Utils.StrToInt( getVal("UpGroup"))) %></span></p>
                         <p>到期降级：<span><%=getroupname(Utils.StrToInt(getVal("DownGroup"))) %></span></p>
                    </div>
                    <%} %> 
                </div>
                <div class="cardTime">期限：<%=days %>天<%=KSCMS.S("cardtype")=="0"?Utils.StrToInt(drs["GiveVIPDay"].ToString())==0?"":"(赠送VIP:"+Utils.StrToInt(drs["GiveVIPDay"].ToString())+"天)":"" %></div>
                
            </div>
        </div>
        <div class="cardIntroB">
            <!--介绍-->
            <div class="cardIntro"><%=getVal("Descript") %></div>
            <div class="cardSIntro"><%=Utils.StrToInt(getVal("IsIdentity"))==1?GetUserInfo(Utils.StrToInt(KSCMS.S("feeid"))):"" %></div>
        </div>
    </div>
