<%@ 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="System.IO" %>
<script runat="server" type="text/C#">
    dynamic __user = HttpContext.Current.Items["user"];                //初始化用户信息，
    private static dynamic __info = new System.Dynamic.ExpandoObject();   //初始化当前页信息
    bool isLoadPage = true;  //定义页面是否加载
    private string param = string.Empty;
    public string PageData = string.Empty;
    public int sjid = 0;
    public int recordcount, pagecount;
    public int CurrPage = new BasicField().GetCurrPage;
    public int PageSize = 20;
    protected void Page_Load(object sender, EventArgs e)
    {
        CheckUserLogin.Run();
  
        //  param = "KS_SJScore A Left Join KS_SJ B on a.sjid=b.id Where A.istj=0 and a.realtest=0";
        sjid=Utils.StrToInt(KSCMS.S("sjid"));
        param = "KS_SJScore A Left Join KS_SJ B on a.sjid=b.id Where b.realtest=0 and b.id=" + sjid;
        if (!string.IsNullOrEmpty(KSCMS.S("showType")))
        {
            param += " and a.istj=" + Utils.StrToInt(KSCMS.S("showtype"));
        }
        string DoMethod = KSCMS.S("do");
        switch (DoMethod)
        {
            case "out":
                BtnSubmit_Click();
                break;
        }
    }
    public string pagedata(bool isExport=false)
    {
        if (!string.IsNullOrEmpty(KSCMS.S("TxtKeyWord")))
        {
            param += " and a.username like '%" + Utils.ChkSQL(KSCMS.S("TxtKeyWord")) + "%'";
        }
        #region 日期限制
        if (!string.IsNullOrEmpty(KSCMS.S("adddate")))
        {
            if (Utils.IsDateTime(KSCMS.S("adddate")))
            {
                param += " and [adddate]>='" + KSCMS.S("adddate") + "'";
            }
        }
        #endregion

        using (DataTable dt = DataFactory.GetPage("a.*,b.dtfs,b.title,b.id,b.kssj as totaltime", param, "scoreid", "order by scoreID desc", CurrPage, PageSize, out recordcount, out pagecount))
        {
            if (dt.Rows.Count > 0)
            {
                int i = (CurrPage - 1) * PageSize + 1;
                foreach (DataRow dr in dt.Rows)
                {
                    string url = BasicField.GetRewriteUrl("examexplained", Utils.StrToInt(dr["ScoreID"].ToString()));
                    //if (url.IndexOf('&') == -1)//开启了伪静态
                    //{
                    //	url += "?member=tc";
                    //}
                    //else
                    //{
                    //	url += "&member=tc";
                    //}

                    PageData += "  <TR class=\"tdbg sort bar\"><td align=\"center\" height=\"30px\" nowrap><input type=\"checkbox\" class=\"checkbtn\"  name=\"ids\" id=\"ids\" value=\"" + dr["id"] + "\" style=\" display:none\" /> " + i + ".</td>" +
   "<td align=\"center\" class=\"tag_left lefticon\"><a href=\"" + BasicField.GetRewriteUrl("examview", Utils.StrToInt(dr["id"].ToString())) + "\" target=\"_blank\"><i class=\"iconfont\">&#xe637;</i></a>" +
   "<span class=\"fonths\">" + Utils.CutStr(Convert.ToString(dr["title"]), 40) + "</span> " + (Convert.ToString(dr["istj"]) == "1" ? "<span style='color:red'>未完成</span><div style='color: #909090;padding-left: 30px;font-size: 12px;margin-top: 5px;'>总时间：" + dr["totaltime"] + " 分钟&nbsp;&nbsp;&nbsp;已用时间：" + Convert.ToString(dr["hasusetime"]).Replace(":", "分钟") + "秒</div>" : "") + "</td>" +
   "<td align=\"center\">" + dr["UserName"] + " </td>" +
   "<td align=\"center\"> <font color=red>" + Convert.ToString(Utils.StrToFloat(dr["score"].ToString()).ToString("f1")) + "</font> 分</td>" +
   "<td>" + dr["AddDate"].ToString() + "</td>";
                    if (isExport == false)
                    {
                        PageData +="<td><div class=\"gl_btn\">" +
                               //	"<span class=\"span1\" style=\"width:100%\"><a  href='" + BasicField.GetUserUrl("teacher/TcSjComment", "scoreid-" + Utils.StrToInt(dr["ScoreID"].ToString())) + "'><i class=\"iconfont\">&#xe63f;</i>评语</a></span>" +
                               "<span class=\"span1\" style=\"width:100%\"><a  href='" + BasicField.GetUserUrl("teacher/TcClassSjPY", "scoreid-" + dr["scoreid"].ToString() + ",sjid-" + dr["id"].ToString() + "") + "'><i class=\"iconfont\">&#xe62d;</i>批阅</a></span>" +
                               "</div></td>";
                    }
                    PageData += "</TR>";
                    i++;
                }	
                return PageData;
            }
            else
            {
                return "<TR class=\"tdbg sort bar\"><td colspan=\"6\"><div class=\"empty\">没有找到任何试卷记录</div></td></TR> ";
            }
        }
    }
    protected void BtnSubmit_Click()
    {
        PageData = @"<table cellpadding=""0"" cellspacing=""0"" border=""1""> <th><td>序号</td><td>试卷名称</td><td>测试者</td><td>得分</td><td>考试时间</td></th>";
        PageData += pagedata(true);
        PageData += "</table>";
        Utils.ExportToExcel("" + DateTime.Now.ToShortDateString() + "成绩单.xls", PageData);
        isLoadPage = false;

    }
</script>
<%
    if (!isLoadPage) return;
%>
  <form name="myform" action="<%=BasicField.GetUserUrl("teacher/TcHWSjScore","sjid-"+sjid+"") %>" method="post" id="myform" >
 <div class="t_tybox">
    	 <div class="tytitle"><h4>试卷成绩</h4>
            <%--  	<a onclick="" href="<%=BasicField.GetUserUrl("teacher/TcHWSjScore","do-out,sjid-"+sjid+"") %>" class="addbtn">导出Excel</a>--%>
               	<a onclick="" href="<%=Utils.GetRootPath() %>/plus/course/ExcelOutput.aspx?page=<%=CurrPage %>&sjid=<%=sjid %>" class="addbtn">导出Excel</a>
		   	<a onclick="" href="<%=BasicField.GetUserUrl("teacher/TcClassRoom") %>" class="addbtn">返回</a>
    	 </div>
		
          <div class="top_c_sc">
             <span>考试者：</span>
			 <input name="TxtKeyWord" type="text" id="TxtKeyWord" class="textbox" style="width:100px;border-radius:3px" />
           
             <input type="submit" onclick="return(submitclick(1))" name="Button1" value=" 搜索 " id="Button1" class="button" style="margin-left:10px;border-left:1px solid #dce2e4;border-radius:3px;" />
         </div>

		 <div class="tabs">
			<ul clear="clearfix" style="height:37px">
				<li <%=KSCMS.S("showType")==""?" class='puton'":string.Empty %>><a href='<%=BasicField.GetUserUrl("teacher/TcHWSjScore","sjid-"+sjid+"") %>' ><span>所有记录</span></a></li>
				<li <%=KSCMS.S("showType")=="0"?" class='puton'":string.Empty %>><a href='<%=BasicField.GetUserUrl("teacher/TcHWSjScore","showType-0,sjid-"+sjid+"") %>'><span>已做完的记录</span></a></li>
				<li <%=KSCMS.S("showType")=="1"?" class='puton'":string.Empty %>><a href='<%=BasicField.GetUserUrl("teacher/TcHWSjScore","showType-1,sjid-"+sjid+"") %>'><span>未做完的记录</span></a></li>
			</ul>
		</div>
	    <div class="clear"></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="40%" align="center">试卷名称</td>            
				<td width="12%" align="center">测试者</td>         
				<td width="14%" align="center">得分</td>
				<td width="14%" align="center">考试时间</td>
				<td width="14%" align="center">↓管理操作</td>
            </tr>
      
	  <% = pagedata()%>
           
           </table>
    
           <div class="cz_btn" style="padding:20px 0px 0px 0px">    
		   <input type="hidden" name="do" value="out" id="doid" />
        <%--     <span><input type="submit" onclick="return(submitclick(2))" name="BtnSubmit" value="导出Excel" class="button" /></span>
         	 <span><input type="button" class="button" value="打印" onclick="window.print()" /></span>--%>
           </div>   

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

      </div>
     </div>
	 </form>
	 <script>
	 	function submitclick(i)
	 	{
	 		if (i == 1) {
	 			$("#doid").val("search");
	 		}
	 		else {
	 			$("#doid").val("out");
	 		}
	 	}

	 </script>