<%@ 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 sqlParam = string.Empty;
	protected void Page_Load(object sender, EventArgs e)
	{
		sqlParam = "KS_SJ Where realtest=0 and verify=1 and inputer='" + new TemporaryVar().UserName + "'";
		sqlParam += " and id in(select sjid from KS_SJScore)";
	
		string DoMethod = KSCMS.S("do");
		if (string.IsNullOrEmpty(DoMethod))
		{
			DoMethod = KSCMS.S("action");
		}
		switch (DoMethod)
		{
			case "cancel":
		
				break;
		}
	}
	public static string GetEnterExamRS(int sjid)
	{
		using (DataTable dt = DataFactory.GetDataTable("select distinct(username) from KS_SJScore Where SJID=" + sjid))
		{
			return dt.Rows.Count.ToString();
		}
	}
	public static string GetAgvScore(int sjid, int flag)
	{
		int num = 0;
		decimal totalScore = 0;
		if (flag == 1) //按人数取平均值，每个用户的最高分数
		{
			num = Utils.StrToInt(GetEnterExamRS(sjid));
			totalScore = Utils.StrToDecimal(DataFactory.GetOnlyValue("select sum(t) from (select max(score) t  from ks_sjscore where sjid=" + sjid + " group by username) a"));
		}
		else
		{
			num = Utils.StrToInt(GetExamPGNum(sjid));
			totalScore = Utils.StrToDecimal(DataFactory.GetOnlyValue("select sum(score) From KS_SJScore Where SJID=" + sjid));

		}
		decimal score = 0;
		if (num > 0)
		{
			score = totalScore / num;
		}

		return score.ToString("F2");
	}
	public static string GetExamPGNum(int sjid)
	{
		return DataFactory.GetOnlyValue("select count(1) From KS_SJScore Where SJID=" + sjid);
	}
	public static string GetEnterExamNum(int sjid)
	{
		return DataFactory.GetOnlyValue("select count(1) From KS_SJScore Where SJID=" + sjid);
	}

</script>
<script>
	function dosearch() {
		var url = "<%=BasicField.GetUserUrl("sj/TcSjTotal")%>";
		var value = $("#TextBox1").val();
		location.href = url + ",TextBox1-" + value;
	}
</script>
<%
    if (!isLoadPage) return;
%>
	<div class="t_tybox">
  <div class="tytitle clearfix"><h4 class="fl lf">成绩统计</h4>
     <div class="top_c_sc mt10">
         <span>试卷名称：</span>
        <input name="TextBox1" type="text" id="TextBox1" class="textbox" /> 
         <input type="button" onclick="dosearch()" name="Button1" value="搜索" id="Button1" class="button" />
     </div> 
    </div>
    
     
    <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="48%" align="center">试卷名称</td>            
                <td width="13%" align="center">参加人数/次数</td>          
                <td width="13%">平均得分/总分</td>   
                <td  width="10%" align="center">按用户排名统计    </td>
               <td  width="10%" align="center">卷面分析</td>
              </tr>

		 <%
	   	 int recordcount, pagecount;
					 int CurrPage = new BasicField().GetCurrPage;
					 int PageSize = 10;
					 if (!string.IsNullOrEmpty(KSCMS.S("TextBox1")))
					 {
						 sqlParam += " and title like '%" + KSCMS.S("TextBox1") + "%'";
					 }
					 using (DataTable dt = DataFactory.GetPage("*", sqlParam, "id", "order by ID desc", CurrPage, PageSize, out recordcount, out pagecount))
					 {
						 if (dt.Rows.Count > 0)
						 {
							 foreach (DataRow dr in dt.Rows)
							 {
								 KSCMS.W("<TR class=\"tdbg sort bar\"><td align=\"center\" height=\"30px\" nowrap><input type=\"checkbox\" class=\"checkbtn\"  name=\"ids\" id=\"ids\" value=\"" + dr["id"] + "\" /></td>" +
				"<td align=\"center\" class=\"tag_left lefticon\"> <a href=\"" + BasicField.GetRewriteUrl("examview", Utils.StrToInt(dr["id"].ToString())) + "\" target=\"_blank\"> <i class=\"icon iconfont icon-IE\"></i></a>" +
				   " <span class=\"fonths\">" + Utils.CutStr(Convert.ToString(dr["title"]), 40) + "</span>" +
					"<div class=\"tips\" style=\"padding-left:30px; margin-top:5px;\">分类：" + MyCache.GetCacheSJCategory(Convert.ToInt32(dr["classid"]), 1) + "&nbsp;&nbsp;&nbsp;总分：" + dr["score"] + "分&nbsp;&nbsp;&nbsp;时间：" + dr["KSSJ"] + "分钟</div></td>" +
				"<td><span style='color:#2ac0c6; font-size:22px'>" + GetEnterExamRS(Convert.ToInt16(dr["id"])) + "</span> 人/ <span class=\"fontqs\">" + GetEnterExamNum(Convert.ToInt16(dr["id"])) + "次</span></td>" +
				"<td align=\"center\"> <font style='color:#56b648; font-size:22px'>" + GetAgvScore(Convert.ToInt16(dr["id"]), 1) + "</font> 分/ <span class=\"fontqs\">" + GetAgvScore(Convert.ToInt16(dr["id"]), 2) + "分</span></td>" +
				"<td align=\"center\"><a href=\"" + BasicField.GetUserUrl("sj/TcSjTotalitem", "sjid-" + dr["id"].ToString() + "") + "\" class=\"ty_button2\">查看</a></td>" +
				   "<td>" + (dr["Dtfs"].ToString() == "2" ? "<span class='tips'>---</span>" : "<a href='" + BasicField.GetUserUrl("sj/TcSJPaperAnalysis", "sjid-" + dr["id"].ToString()) + "' class='ty_button2'>查看</a>") + " </td></TR>");
							 }
						 }
						 else
						 {
							 KSCMS.W(" <TR class=\"tdbg sort bar\"><td colspan=\"7\"><div class=\"empty\">暂无成绩统计！</div> </td></TR> ");
						 }
					 }
	    %>

           </table>
           <div class="fy_box fy_center" >
	 <%
            #region 分页
            string PageStr = "[KS:PageStr1]";
            BasicField.ReplaceFilterPage(ref PageStr, CurrPage, PageSize, pagecount, recordcount);
            KSCMS.W(PageStr);
            #endregion
         %>
 	</div>

	    <div class="clearfix"></div>
 	
    
  </div>