<%@ 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="System.Data" %>
<%@ Import Namespace="Kesion.Controllers" %>
<script runat="server" type="text/C#">
    dynamic __user = HttpContext.Current.Items["user"];
    private static dynamic __info = new System.Dynamic.ExpandoObject();   //初始化当前页信息
    bool isLoadPage = true;  //定义页面是否加载
    string sql = string.Empty;
    string m = string.Empty;
    int CurrPage = new BasicField().GetCurrPage;
    int recordcount, pagecount;
    int PageSize = 10;
    protected void Page_Load(object sender, EventArgs e)
    {
        CheckUserLogin.Run();
        m = KSCMS.S("m").ToLower();

        switch (KSCMS.S("action").ToLower())
        {
            case "delete"://移除错题本
                deleteSj(KSCMS.S("ids"));
                break;
        }
    }

    /// <summary>
    /// 删除错题信息   
    /// </summary>
    /// <param name="ids">需要删除的错题题目id信息</param>
    private void deleteSj(string ids)
    {
        #region     删除错题本
        if (!string.IsNullOrEmpty(ids))
        {
            DataFactory.ExecuteNonQuery("DELETE FROM KS_SJCTB WHERE　UserID＝" + new TemporaryVar().UserID + " AND Flag=1 AND  tmid IN (" + Utils.FilterIDs(ids) + ")");
        }
        Msg.Alert("删除操作成功！");
        return;
        #endregion
    }

    private void ExamRecord()
    {
        #region 考试记录
        if (!string.IsNullOrEmpty(BasicField.GetParam("real")))
        {
            sql += " and a.realtest=" + Utils.StrToInt(BasicField.GetParam("real"));
        }
        sql += " and  a.UserID=" + (new TemporaryVar()).UserID;
        string sqlstr = "  KS_SJScore A Left Join KS_SJ B on a.sjid=b.id Where 1=1 " + sql;
        string orderstr = "order by a.adddate desc";

        using (DataTable dt = DataFactory.GetPage("a.*,b.RealTest,b.dtfs,b.title,b.id,B.CmtNum,b.ScorePubType,b.ScorePubDate,b.classid", sqlstr, "ScoreID", orderstr, CurrPage, PageSize, out recordcount, out pagecount))
        {
            int i = 1;
            if (dt.Rows.Count > 0)
            {
                foreach (DataRow dr in dt.Rows)
                {

                    string cosname = dr["title"].ToString();
                    string PeriodID = dr["id"].ToString();
                    DateTime adddate = Utils.StrToDateTime(dr["adddate"].ToString());

                    KSCMS.W("<li data-year=\"" + adddate.Year.ToString() + "\">");
                    KSCMS.W("<div class=\"cos-learn-date\"><i></i>" + adddate.ToString("M-d H:m") + "</div>");
                    KSCMS.W("<div class=\"cos-learn-info\">");
                    KSCMS.W("<div class=\"name\"><a href=\"" + BaseFun.GetRewriteUrl("examview", Utils.StrToInt(PeriodID)) + "\" target=\"_blank\">" + cosname + "</a></div>");
                    KSCMS.W("<div class=\"other\">");
                    if (dr["istj"].ToString() == "0")
                    {
                        KSCMS.W("<a href=\"" + BaseFun.GetRewriteUrl("exam", "do-explained/scoreid-" + Utils.StrToInt(dr["scoreid"].ToString())) + "\"target=\"_blank\" class=\"grey-bt\">查看详情</a>");
                    }
                    else
                    {
                        KSCMS.W("<a href=\"" + BaseFun.GetRewriteUrl("exam", "do-ex/id-" + Utils.StrToInt(PeriodID)) + "\" target=\"_blank\" class=\"green-bt\">继续考试</a> ");
                    }
                    KSCMS.W("<span>练习时间：" + dr["KSSJ"].ToString() + "</span><span>练习类型：" + (dr["RealTest"].ToString() == "1" ? "正规" : "模拟") + "</span><span>考试得分：" + dr["score"].ToString() + "分" + "</span></div>");
                    KSCMS.W("</div></li>");
                    i++;
                }
            }
            else
            {
                KSCMS.W("<div class=\"empty\">还没有考试记录</div><style>.cz_btn{display:none;}</style>");
            }
        }
        #endregion
    }

    private void MyExamTrang()
    {
        #region 练习记录
        string sql = " KS_SJMyTrainPaper Where 1=1  and username='" + (new TemporaryVar()).UserName + "'";
        string orderstr = "order by adddate desc";
        using (DataTable dt = DataFactory.GetPage("*", sql, "id", orderstr, CurrPage, PageSize, out recordcount, out pagecount))
        {
            int i = 1;
            if (dt.Rows.Count > 0)
            {
                foreach (DataRow dr in dt.Rows)
                {

                    string cosname = dr["title"].ToString();
                    string PeriodID = dr["id"].ToString();
                    DateTime adddate = Utils.StrToDateTime(dr["adddate"].ToString());

                    KSCMS.W("<li data-year=\"" + adddate.Year.ToString() + "\">");
                    KSCMS.W("<div class=\"cos-learn-date\"><i></i>" + adddate.ToString("M-d H:m") + "</div>");
                    KSCMS.W("<div class=\"cos-learn-info\">");
                    KSCMS.W("<div class=\"name\">" + cosname + "</div>");
                    KSCMS.W("<div class=\"other\">");
                    if (dr["istj"].ToString() == "0")
                    {
                        KSCMS.W("<a href=\"" + BaseFun.GetRewriteUrl("exam", "do-trang/id-" + Utils.StrToInt(dr["ID"].ToString())) + "\" target=\"_blank\" class=\"green-bt\">继续考试</a> ");
                    }
                    else
                    {

                        KSCMS.W("<a href=\"" + BaseFun.GetRewriteUrl("exam", "do-trainingplained/id-" + Utils.StrToInt(dr["id"].ToString())) + "\"target=\"_blank\" class=\"grey-bt\">查看详情</a>");
                    }
                    KSCMS.W("<span>练习用时：" + dr["HasUseTime"].ToString() + "</span><span>练习类型：" + (dr["type"].ToString() == "0" ? "每日一练" : (dr["type"].ToString()) == "1" ? "随机练习" : "章节练习") + "</span></div>");

                    KSCMS.W("</div></li>");

                    i++;
                }
            }
            else
            {
                KSCMS.W("<div class=\"empty\">还没有练习记录</div><style>.cz_btn{display:none;}</style>");
            }
        }
        #endregion

    }

    private void MyExamCTB()
    {
        #region 错题本
        KSCMS.W(@"<table id=""tablist"" width=""100%"" border=""0"" align=""center"" cellpadding=""0"" cellspacing=""0"" class=""border border1"">
        <tr class=""title"">
            <td width=""40px"" align=""center"">序号</td>
		    <td align=""center"">题目内容</td>
	        <td width=""10%"" align=""center"">操作 </td>
        </tr>");
        string sql = "  KS_SJCTB a INNER JOIN KS_SJTK B ON a.tmid=b.tmid WHERE flag=1 AND a.userid=" + (new TemporaryVar()).UserID;
        #region     题目类型分类
        if (Utils.StrToInt(KSCMS.S("showtype"))>0)
        {
            sql += " AND B.TmType="+Utils.StrToInt(KSCMS.S("showtype"));
        }
        #endregion
        string orderstr = "ORDER BY a.adddate desc";
        using (DataTable dt = DataFactory.GetPage("a.id,a.adddate,b.*", sql, "a.id", orderstr, CurrPage, PageSize, out recordcount, out pagecount))
        {
            int i = 1;
            if (dt.Rows.Count > 0)
            {
                foreach (DataRow dr in dt.Rows)
                {
                    int tmType = Utils.StrToInt(dr["TmType"].ToString());

                    string cosname = dr["title"].ToString();
                    string PeriodID = dr["id"].ToString();

                    KSCMS.W("<tr class=\"tdbg\">");
                    KSCMS.W("<td class=\"splittd t-a-center\">" + i.ToString() + "</td>");
                    KSCMS.W("<td class=\"splittd tag_left\">");
                    if (tmType == 6 || tmType == 7)
                    {
                        string tmTypeName = Kesion.Exam.Function.TMTypeArr[tmType - 1];
                        StringBuilder sb = new StringBuilder();
                        sb.AppendFormat(@"<textarea  name='ans{0}' id='ans{0}' typeid='{0}' class='hidans' style='display:none'></textarea>", dr["tmid"].ToString());
                        sb.AppendFormat(@"<input hassubtm='true' name='num{0}' id='num{0}' class='hidnum' type='hidden' value='{1}' tmtype='{2}' index='0'/>", dr["tmid"].ToString(), DataFactory.GetOnlyValue("select count(1) from ks_sjtksub where parentTmId=" + dr["tmid"].ToString()), dr["tmtype"].ToString());
                        sb.AppendFormat(@"<input type='hidden' name='pid' id='pid' value='{0}'/>", dr["tmid"].ToString());
                        sb.AppendFormat(@"<div class=""xttitleclass""><strong> {0}：</strong></div><div>{1}</div>", tmTypeName, dr["tmnr"].ToString());
                        KSCMS.S(sb.ToString());
                    }
                    KSCMS.W(Kesion.Exam.Function.GetTMList(dr, 0, 0, 0, 1, 0, string.Empty, string.Empty, 1, 2));
                    KSCMS.W("</td>");

                    KSCMS.W(" <td class=\"splittd\" nowrap=\"nowrap\" style=\"text-align:center\"><a onClick=\"return(confirm('确定移除吗？'));\" href=\"{=GetUserUrl(exam/myexamrecord,m-MyExamCtb|action-delete|ids-" + dr["tmid"].ToString() + ")}\"><i class=\"userfont uf-delete\"></div></a></td> ");

                    KSCMS.W("</tr>");
                    i++;
                }
            }
            else
            {
                KSCMS.W(" <tr class=\"tdbg\"> <td class=\"splittd\" style=\"text-align:center\" colspan=\"10\" ><div class=\"empty\">还没有错题记录</div> </td></tr> ");
            }
        }
        KSCMS.W("</table>");
        #endregion
    }

    private void MyExamFavorite()
    {
        #region 收藏题
        KSCMS.W(@"  <table id=""tablist"" width=""100%"" border=""0"" align=""center"" cellpadding=""0"" cellspacing=""0"" class=""border border_left sjlist"">
      <tr class=""title"">
        	<td width=""120px"" align=""center"">序号</td>
			 <td  align=""center"">题目内容</td>
	       <td width=""10%"" align=""center"">操作 </td>
     </tr>");
        string sql = "  KS_SJCTB a inner join KS_SJTK B ON a.tmid=b.tmid Where flag=0 And a.userid=" + (new TemporaryVar()).UserID;
        string orderstr = "order by a.adddate desc";
        using (DataTable dt = DataFactory.GetPage("a.id,a.adddate,b.*", sql, "a.id", orderstr, CurrPage, PageSize, out recordcount, out pagecount))
        {
            int i = 1;
            if (dt.Rows.Count > 0)
            {
                foreach (DataRow dr in dt.Rows)
                {


                    int tmType = Utils.StrToInt(dr["TmType"].ToString());

                    string cosname = dr["title"].ToString();
                    string PeriodID = dr["id"].ToString();

                    KSCMS.W("<tr class=\"tdbg\">");
                    KSCMS.W("<td class=\"splittd\" style=\"text-align:center\">" + i.ToString() + "</td>");
                    KSCMS.W("<td class=\"splittd tag_left\">");
                    if (tmType == 6 || tmType == 7)
                    {
                        string tmTypeName = Kesion.Exam.Function.TMTypeArr[tmType - 1];
                        StringBuilder sb = new StringBuilder();
                        sb.AppendFormat(@"<textarea  name='ans{0}' id='ans{0}' typeid='{0}' class='hidans' style='display:none'></textarea>", dr["tmid"].ToString());
                        sb.AppendFormat(@"<input hassubtm='true' name='num{0}' id='num{0}' class='hidnum' type='hidden' value='{1}' tmtype='{2}' index='0'/>", dr["tmid"].ToString(), DataFactory.GetOnlyValue("select count(1) from ks_sjtksub where parentTmId=" + dr["tmid"].ToString()), dr["tmtype"].ToString());
                        sb.AppendFormat(@"<input type='hidden' name='pid' id='pid' value='{0}'/>", dr["tmid"].ToString());
                        sb.AppendFormat(@"<div class=""xttitleclass""><strong> {0}：</strong></div><div>{1}</div>", tmTypeName, dr["tmnr"].ToString());
                        KSCMS.S(sb.ToString());
                    }
                    KSCMS.W(Kesion.Exam.Function.GetTMList(dr, 0, 0, 0, 1, 0, string.Empty, string.Empty, 1, 2));
                    KSCMS.W("</td>");


                    KSCMS.W(" <td class=\"splittd\" nowrap=\"nowrap\" style=\"text-align:center\"><a onClick=\"return(confirm('确定移除吗？'));\" href=\"{=GetUserUrl(exam/myexamfavorite,do-myfavorite|action-delete|ids-" + dr["tmid"].ToString() + ")}\">删除</a></td> ");

                    KSCMS.W("</tr>");
                    i++;
                }
            }
            else
            {
                KSCMS.W(" <tr class=\"tdbg\"> <td class=\"splittd\" style=\"text-align:center\" colspan=\"10\" ><div class=\"empty\">还没有收藏试题记录</div> </td></tr> ");
            }
        }
        KSCMS.W("</table>");
        #endregion
    }


</script>
<%
    if (!isLoadPage) return;
%>
<script src="/ks_inc/exam/exam.js"></script>
<div class="r_tybox t_tybox nomar disting">

    <div class="r_title">
        <h4 class="disting-title disting_show">我的考试</h4>
    </div>

    <div class="top-sort clearfix">
        <div class="top-sort-tab lf">
            <ul>
                <li <%=string.IsNullOrEmpty(m)?"  class='puton'":"" %>><a href="<%=BasicField.GetUserUrl("exam/MyExamRecord") %>">考试记录</a></li>
                <li <%=m=="myexamtrang"?"  class='puton'":"" %>><a href="<%=BasicField.GetUserUrl("exam/MyExamRecord","m-MyExamTrang") %>">练习记录</a></li>
                <li <%=m=="myexamctb"?"  class='puton'":"" %>><a href="<%=BasicField.GetUserUrl("exam/MyExamRecord","m-MyExamCtb") %>">错题本</a></li>
            </ul>
        </div>
    </div>

    <% if (m == "myexamctb") {%>
    <div class="top-sort clearfix">
        <div class="top-sort-tab lf">
            <ul>
                <li <%= string.IsNullOrEmpty(KSCMS.S("showtype"))?"  class='puton'":"" %>><a href="<%=BasicField.GetUserUrl("exam/MyExamRecord","m-MyExamCtb") %>">全部题型</a></li>
                <li <%= KSCMS.S("showtype")=="1"?"  class='puton'":"" %>><a href="<%=BasicField.GetUserUrl("exam/MyExamRecord","m-MyExamCtb,showtype-1") %>">主观题</a></li>
                <li <%= KSCMS.S("showtype")=="2"?"  class='puton'":"" %>><a href="<%=BasicField.GetUserUrl("exam/MyExamRecord","m-MyExamCtb,showtype-2") %>">单选题</a></li>
                <li <%= KSCMS.S("showtype")=="3"?"  class='puton'":"" %>><a href="<%=BasicField.GetUserUrl("exam/MyExamRecord","m-MyExamCtb,showtype-3") %>">多选题</a></li>
                <li <%= KSCMS.S("showtype")=="4"?"  class='puton'":"" %>><a href="<%=BasicField.GetUserUrl("exam/MyExamRecord","m-MyExamCtb,showtype-4") %>">判断题</a></li>
                <li <%= KSCMS.S("showtype")=="5"?"  class='puton'":"" %>><a href="<%=BasicField.GetUserUrl("exam/MyExamRecord","m-MyExamCtb,showtype-5") %>">填空题</a></li>
            </ul>
        </div>
    </div>
    <% }%>

    <div id="myRecord">
        <%
            switch (m)
            {
                case "myexamtrang":       //练习记录
                    MyExamTrang();
                    break;
                case "myexamctb":         //错题本
                    MyExamCTB();
                    break;
                case "myexamfavorite":     //收藏题
                    MyExamFavorite();
                    break;
                default:                   //考试记录
                    ExamRecord();
                    break;
            }
        %>
    </div>

    <div class="cz_btn">
        <%
            #region 分页
            string PageStr = __user.GroupID == 3 || __user.GroupID == 4 ? "[KS:PageStr1]" : "[KS:PageStr2]";
            BasicField.ReplaceFilterPage(ref PageStr, CurrPage, PageSize, pagecount, recordcount);
            KSCMS.W(PageStr);
            #endregion
        %>
    </div>
</div>
