<%@ 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" %>
<%@ Import Namespace="Kesion.NET.WebSite.Admin.Exam" %>
<script runat="server" type="text/C#">
	dynamic __user = HttpContext.Current.Items["user"];                //初始化用户信息，
	private static dynamic __info = new System.Dynamic.ExpandoObject();   //初始化当前页信息
	bool isLoadPage = true;  //定义页面是否加载
	public int SJID = 0;
	public static int CurrPage = 1;
	public static int pagesize = 100;
	public static DataRow dr = null;
	public string param = string.Empty;
	public static string TJQK = string.Empty;
	public static string tabStr = string.Empty;
	private static DataTable cjdTable = null;
	protected void Page_Load(object sender, EventArgs e)
	{
		SJID = Utils.StrToInt(KSCMS.S("SJID"));
		tabStr = string.Empty;
		if (SJID == 0)
		{
			Msg.Alert("参数传递出错啦！");
			isLoadPage = false;
			return;
		}
		using (DataTable dt = DataFactory.GetDataTable("select top 1 * From KS_SJ Where inputer='" + new TemporaryVar().UserName + "' and ID=" + SJID))
		{
			if (dt.Rows.Count > 0)
			{
				dr = dt.Rows[0];
				param = " Where SJID=" + SJID + "";

				#region 成绩段
				int cjdId = Utils.StrToInt(dr["CJDID"].ToString());  //成绩段ID
				if (cjdId != 0)
				{
					cjdTable = DataFactory.GetDataTable("select * From KS_SJCJDItem Where ItemID=" + cjdId + " order by orderid,id");
					using (DataTable dtd = cjdTable)
					{
						if (dtd.Rows.Count > 0)
						{
							StringBuilder sb = new StringBuilder();
							StringBuilder ssb = new StringBuilder();
							ssb.AppendLine(@"<div class=""tabs"">
                                     <ul>");
							//ssb.AppendFormat(@"<li{0}><a href=""?sjid={2}""><span>所有记录({1}人)</span></a></li>", KSCMS.S("cjdId") == "" ? " class='puton'" : string.Empty, Admin_ZGSJTotal.GetEnterExamNum(SJID), SJID);
							ssb.AppendFormat(@"<li{0}><a href=""{2}""><span>所有记录({1}人)</span></a></li>", KSCMS.S("cjdId") == "" ? " class='puton'" : string.Empty, Admin_ZGSJTotal.GetEnterExamNum(SJID), BasicField.GetUserUrl("sj/TcSjTotalitem", "sjid-" + SJID));
							foreach (DataRow drr in dtd.Rows)
							{
								if (KSCMS.S("cjdId").ToString() == drr["id"].ToString())
								{
									param += " and a.Score>=" + drr["minscore"].ToString() + " and a.score<=" + drr["maxscore"].ToString();
								}
								int num = Utils.StrToInt(DataFactory.GetOnlyValue("select count(1) From KS_SJScore Where SJID=" + SJID + " and Score>=" + drr["minscore"].ToString() + " and score<=" + drr["maxscore"].ToString()));
								sb.AppendFormat("{0}：{1}人&nbsp;&nbsp;", drr["title"].ToString(), num);
							//	ssb.AppendFormat(@"<li{0}><a href=""?sjid={4}&cjdId={3}""><span>{1}({2}人)</span></a></li>", KSCMS.S("cjdId") == drr["id"].ToString() ? " class='puton'" : string.Empty, drr["title"].ToString(), num, drr["id"].ToString(), SJID.ToString());
								ssb.AppendFormat(@"<li{0}><a href=""{3}""><span>{1}({2}人)</span></a></li>", KSCMS.S("cjdId") == drr["id"].ToString() ? " class='puton'" : string.Empty, drr["title"].ToString(), num, BasicField.GetUserUrl("sj/TcSjTotalitem", "sjid-" + SJID.ToString() + ",cjdId-" + drr["id"].ToString()));
							}
							ssb.AppendLine(@"</ul></div>");
							tabStr = ssb.ToString();
							TJQK = sb.ToString();
						}
					}
				}
				#endregion
			}
			else
			{
				Msg.AlertDoFun("出错啦！", "history.back()");
				isLoadPage = false;
				return;
			}
		}
		
		
	}
	
	public static string GetScoreRank(float score)
	{
		string rank = string.Empty;
		if (cjdTable == null)
		{
			rank = "---";
		}
		else
		{
			using (DataTable dt = cjdTable)
			{
				if (dt.Rows.Count > 0)
				{
					DataView dv = dt.DefaultView;
					dv.RowFilter = "minscore<=" + score + " and maxscore>=" + score;
					using (DataTable dtt = dv.ToTable())
					{
						if (dtt.Rows.Count > 0)
						{
							rank = dtt.Rows[0]["title"].ToString();
						}
						else
						{
							rank = "---";
						}
					}
				}
				else
				{
					rank = "---";
				}
			}
		}
		return rank;
	}


</script>
<%
    if (!isLoadPage) return;
%>
  <form name="myform" action="<%=BasicField.GetUserUrl("sj/TcSjTotalitem") %>" method="post" id="myform" >
 		<div class="t_tybox">
          	<div class="tytitle clearfix">
               <h4 class="fl lf">考试记录</h4>
               <a href="<%=BasicField.GetUserUrl("sj/tcSJTotal") %>" class="ty_button2 lf" style="margin-top: 10px;margin-left: 20px;margin-right: 10px;"><strong>返 回</strong></a>
               <p style="line-height: 50px; color:#999;">试卷[<span style="color:Red"><%=dr!=null?dr["title"].ToString():String.Empty %></span>]成绩排行   
               &nbsp;限制时间：<%=dr!=null?dr["kssj"].ToString():string.Empty %>分钟 </p>
          	</div>     
        	<div class="clear blank10"></div>
			<div class="top_c_sc" style="top:75px;">
            <span>搜索考生：</span>
          	<select name="DrpTJ" id="DrpTJ">
                <option value="a.username">用户名 </option>
                <option value="realname">姓名</option>
            </select>
	 		<input name="sjid" type="hidden"  value="<%=KSCMS.S("sjid") %>" /> 
	    	<input name="TxtKeyWord" type="text" id="TxtKeyWord" class="textbox" /> 
            <input type="submit" name="BtnSearch" value="搜索" id="BtnSearch" class="button" />        
        </div>    
        <div class="tips" style="padding: 10px 20px ; line-height:30px">
            <strong>整体统计情况：</strong> 
            试卷总分：<%=dr != null ? dr["score"].ToString() : string.Empty%>分&nbsp;
            参加人数：<%=Kesion.NET.WebSite.Admin.Exam.Admin_SJTotal.GetEnterExamRS(SJID)%>人 参加次数：<%=Kesion.NET.WebSite.Admin.Exam.Admin_SJTotal.GetEnterExamNum(SJID)%>次 已批改：<%=Kesion.NET.WebSite.Admin.Exam.Admin_ZGSJTotal.GetExamPGNum(SJID)%>份 平均得分：<%=Kesion.NET.WebSite.Admin.Exam.Admin_ZGSJTotal.GetAgvScore(SJID)%>分
        <%=TJQK%>
        </div>  
    <%=tabStr%>
         <div class="clear blank10"></div>
           <table id="tablist" width="100%"  border="0" align="center" cellpadding="0" cellspacing="0" class="border">
            <tr align="center" class="title">
                <td width="6%" align="center">排名</td>
                <td width="5%" align="center">头像</td>            
                <td width="6%" align="center">用户名</td>          
                <td width="15%">姓名</td>   
                <td  width="7%" align="center">性别</td>
               <td  width="7%" align="center">用时</td>
                <td  width="7%" align="center">总题目数</td>
                 <td  width="7%" align="center">没做完题数</td>
                   <td  width="7%" align="center">成绩</td>
                <td  width="7%" align="center">成绩等级</td>
              </tr>
         <%
			 int recordcount, pagecount;
					 int CurrPage = new BasicField().GetCurrPage;
					 int PageSize = 10;
					 string sqlStr = string.Empty;
					 if (!string.IsNullOrEmpty(KSCMS.S("TxtKeyWord")))
					 {
						 param += " and " + KSCMS.S("DrpTJ") + " like '%" + KSCMS.S("TxtKeyWord") + "%'";
					 }
					 if (dr["AuthorizationType"].ToString() == "1" && dr["RealTest"].ToString() == "1")  //准考证
					 {
						 sqlStr = " KS_SJScore A inner Join KS_SJCardItem B on a.cardnum=b.cardnum";
					 }
					 else  //按会员权限的
					 {
						 sqlStr = " KS_SJScore A inner Join KS_User b on a.username=b.username";
					 }

                     using (DataTable dt = DataFactory.GetPage("a.*,b.userface,b.realname,b.sex,b.idcard , dense_rank() over(order by a.score desc) tt", sqlStr + param, "a.scoreid", "order by a.score desc,a.scoreid", CurrPage, pagesize, out recordcount, out pagecount))
					 {
						 if (dt.Rows.Count > 0)
						 {
                             int i = (CurrPage - 1) * PageSize + 1;
                             foreach (DataRow drs in dt.Rows)
                             {


                                 KSCMS.W("  <TR class=\"tdbg sort bar\"><td align=\"center\" height=\"30px\" nowrap>第" + drs["tt"].ToString() + "名</td>" +
                "<td align=\"center\"> <img onerror=\"this.src='" + MyCache.GetCacheConfig(5) + MyCache.GetCacheConfig(0) + "SysImg/face/" + (Convert.ToString(drs["Sex"]) == "男" ? "boy.jpg" : "girl.jpg") + "';\" src=\"" + (Convert.ToString(drs["userface"]).ToLower().IndexOf("http") == -1 ? MyCache.GetCacheConfig(5) : "") + "" + drs["userface"] + "\" width=\"30\" height=\"32\" /></td>" +
                "<td>" + drs["username"].ToString() + "</td>  <td align=\"center\">" + drs["realname"].ToString() + "</td><td align=\"center\">" + drs["sex"].ToString() + "</td>" +
                   "<td> " + drs["KSSJ"].ToString() + "</td><td> <span style=\"color:#609c58;font-size:15px\">" + Utils.StrToInt(drs["totaltms"]) + "</span> 题</td>" +
                  "<td><span style=\"color:#f14e29;font-size:15px\">" + Utils.StrToInt(drs["nofinishtms"]) + "</span> 题</td>" +
                    "<td> <a  href='" + BasicField.GetRewriteUrl("examexplained", Utils.StrToInt(drs["ScoreID"].ToString())) + "' title=\"查看作答详情\" target=\"_blank\">" + ((Convert.ToInt16(drs["ispg"]) == 0 && Convert.ToInt16(drs["realtest"]) == 1) ? "---" : "<font style='color:#56b64d;font-size:22px'>" + drs["score"] + "</font>分") + "</a></td>" +
                     "<td> " + GetScoreRank(Utils.StrToFloat(drs["score"])) + "</td> </TR>");
                                 i++;
                             }
						 }
						 else
						 {
							 KSCMS.W(" <TR class=\"tdbg sort bar\"><td colspan=\"7\"><div class=\"empty\">没有添加任何试卷！</div> </td></TR> ");
						 }
					 }
			  %>
           </table>

       <div class="fy_box" style="border-top:0px;margin-top:0px;">
	    <%
            #region 分页
            string PageStr = "[KS:PageStr3]";
            BasicField.ReplaceFilterPage(ref PageStr, CurrPage, PageSize, pagecount, recordcount);
            KSCMS.W(PageStr);
            #endregion
         %>
       </div>
		   <div class="clear"></div>
	</div>

	</form>