<%@ 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 static int CourseId = 0;
    public static string CourseName = string.Empty;
    public static int totalPeriod = 0;//总课时
    public static int studentNum = 0;//购买人数
    public static int totalView = 0;//观看人数
    public static int totalFinish = 0;//完成课时学习数
    protected void Page_Load(object sender, EventArgs e)
    {
        CourseId = Utils.StrToInt(KSCMS.S("CourseId"));

        if (CourseId != 0)
        {
            #region 初始化课程信息
            using (DataTable dt = DataFactory.GetDataTable( "select top 1 * from KS_Course where CourseId = " + CourseId))
            {
                if (dt.Rows.Count > 0)
                {
                    DataRow dr = dt.Rows[0];
                    CourseName = dr["name"].ToString();
                    if (dr["Isperiod"].ToString() == "0")
                    {
                        totalPeriod= 1;
                    }
                    else
                    {
                        totalPeriod = Utils.StrToInt(dr["CountPid"].ToString());
                    }
                    studentNum= Utils.StrToInt(dr["Studentnum"].ToString());
                    totalView= Utils.StrToInt(DataFactory.GetOnlyValue("select count(userid) from KS_CosLearnRecord where courseid=" + CourseId + " group by userid"));
                    totalFinish= Utils.StrToInt(DataFactory.GetOnlyValue("select count(id) from KS_CosLearnRecord where courseid=" + CourseId + " and status=1 "));
                }
            }
            #endregion
        }
        if (KSCMS.S("do").Equals("del"))
        {
            #region 清空进度
            CleanLearnRecord(KSCMS.S("ids"));
            #endregion
        }

    }
        private string GetSqlParam()
    {
        string sqlParam = string.Empty;
        if (!string.IsNullOrEmpty(KSCMS.S("TxtKey")))
        {
            sqlParam += " and username like '%" + KSCMS.S("TxtKey").Replace("'", "''") + "%'";
        }
        if (KSCMS.S("showtype") == "1")//已学完
        {
            sqlParam += " and status=1";
        }
        if (KSCMS.S("showtype") == "2")//未学完
        {
            sqlParam += " and status=0";
        }
        return sqlParam;
    }
    public string GetFinishTime(int UserID,int CourseId)
    {
        string s = Kesion.Course.CourseLearnRecordCache.GetUserLearnJsonNodeValue(UserID, "finishlearntime", CourseId);
        return s;
    }

    private void CleanLearnRecord(string pjid)
    {
        #region 删除学员进度
        if (pjid == null || pjid == "0"||string.IsNullOrEmpty(pjid))
        {
            Msg.Alert("对不起,请选择要清空的学员!", BasicField.GetUserUrl("teacher/CosLearnRecord","courseid-"+CourseId));
            isLoadPage = false;
            return;
        }else
        {
            //清空对应的课程学习进度信息
             int courseId = Utils.StrToInt(KSCMS.S("courseid"));
            using (DataTable dt = DataFactory.GetDataTable("select userId from KS_User where userid in (" + pjid + ")"))
            {
                if (dt.Rows.Count > 0)
                {
                    foreach (DataRow dr in dt.Rows)
                    {
                        Kesion.Course.CourseLearnRecordCache.CleanUserLearnRecordFromDB(Utils.StrToInt(dr["userId"].ToString()), courseId);
                    }
                }
            }
            Msg.Alert("恭喜,清空成功!", BasicField.GetUserUrl("teacher/CosLearnRecord", "courseid-" + CourseId));
            isLoadPage = false;
            return;
        }
        #endregion
    }

</script>
<%
    if (!isLoadPage) return;
%>
     <div class="t_tybox">
    
            <div class="tytitle clearfix"><h4 class="lf">学员进度</h4>
                <a onclick="window.history.go(-1);" class="addbtn">返回</a>
                <form action="/plus/Course/ImportExcel.aspx" method="post">
                    <input type="hidden" name="export" value="learnrecordexcel" />
                    <input type="hidden" name="courseid" value="<%=CourseId %>" />
                    <input type="submit" id="ExcelBtn" value="本页导出Excel" class="addbtn" />
                    <textarea style="display: none" name="courseName" id="courseName"> <%=CourseName%></textarea>
                    <textarea style="display: none" name="sqlparam" id="sqlparam"> <%=GetSqlParam()%></textarea>
                </form>
            </div>
           
            <div class="part_now">
                当前课程：<%=CourseName %>
                总课时：<%=totalPeriod%>
                购买人数：<%=studentNum %>
                观看人数：<%=totalView%>
                完成课时学习数：<%=totalFinish %>
             
            </div> 
             <form name="myform" action="<%=BasicField.GetUserUrl("teacher/CosLearnRecord") %>" method="post" id="myform" >
             <div class="tabs_header">
            <ul class="tabs clearfix">
               
                <li <%=KSCMS.S("showtype")==""||KSCMS.S("showtype")=="0"?" class='active'":string.Empty %>><a href="<%=BasicField.GetUserUrl("teacher/CosLearnRecord","courseid-"+CourseId) %>"><span>所有列表</span></a></li>
                <li <%=KSCMS.S("showtype")=="1"?" class='active'":string.Empty %>><a href="<%=BasicField.GetUserUrl("teacher/CosLearnRecord","showtype-1,courseid-"+CourseId) %>"><span>已学完</span></a></li>
                <li <%=KSCMS.S("showtype")=="2"?" class='active'":string.Empty %>><a href="<%=BasicField.GetUserUrl("teacher/CosLearnRecord","showtype-2,courseid-"+CourseId) %>"><span>未学完</span></a></li>
            
            </ul>
        </div>
             <div class="top_c_sc" style="margin-right: 10px;">
                <span>学员：</span>
                <input name="TxtKey" type="text" id="TxtKey" class="textbox coursename" />
                <input type="submit" name="Button4" value=" 搜索 " onclick="changedo(0)" id="Button4" class="button" />
              
            </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="8%" align="center">选择</td>
                     <td width="8%" align="center">序号</td>
                     <td width="20%" align="center">学员名称</td>
                     <td width="20%" >学习进度</td>              
                     <td width="10%">完成日期</td>
                     <td width="15%">IP地址</td>
                     <td width="10%">学习设备</td>
                     <td width="15%">查看详情</td>
                     <td align="center" nowrap width="10%">操作</td>
                </tr>
				<%
                    int recordcount, pagecount;
                    int CurrPage = new BasicField().GetCurrPage;
                    int PageSize = 10;
                     string sqlParam = " Ks_CosLearnRecord where courseid=" + CourseId + " ";
                     sqlParam =sqlParam+ GetSqlParam();
                    using (DataTable dt = DataFactory.GetPage("*", sqlParam, "ID", " order by  ID DESC", CurrPage, PageSize, out recordcount, out pagecount))
                    {
                        if (dt.Rows.Count > 0)
                        {
                            int i = (CurrPage - 1) * PageSize + 1;
                            foreach (DataRow dr in dt.Rows)
                            {
                                KSCMS.W("<TR class=\"tdbg sort bar\"><td height=\"38\" align=\"center\" nowrap><input type=\"checkbox\"  name=\"ids\" id=\"ids\" value=\"" + dr["userid"].ToString() + "\" class=\"checkbtn\" /></td><td align=\"center\">" + i + "</td> <td class=\"Ctd\" align=\"center\">" + dr["username"].ToString() + "</td>");
                                KSCMS.W("<td class=\"tag_left lefticon\">" + Kesion.Course.CourseLearnRecordCache.GetLearnProcess(Utils.StrToInt(dr["userid"].ToString()), CourseId) + " </td> <td align=\"center\">" + GetFinishTime(Utils.StrToInt(dr["userid"].ToString()), Utils.StrToInt(dr["courseid"].ToString())) + " </td>");
                                KSCMS.W("<td align =\"center\">" + dr["LastLearnIP"].ToString() + " </td>");
                                KSCMS.W("<td align =\"center\">" + Utils.OrderDeviceName(Utils.StrToInt(dr["LastLearnDevice"].ToString())) + " </td>");
                                KSCMS.W("<td align =\"center\"><a onclick='showDetail("+dr["userid"].ToString()+","+dr["courseid"]+")'>查看</a></td>");
                                KSCMS.W(" <td style=\"text-align:center\" nowrap><div class=\"gl_btn\"> <span class=\"span5\" style=\"width:100%\"><a href=\"" + BasicField.GetUserUrl("teacher/CosLearnRecord", "do-del,ids-" + dr["userid"].ToString() + ",courseid-" + dr["courseid"].ToString() + "") + " \" onclick=\"return confirm('确认清空吗?\n如果要清空,请点确认,否则请取消.')\"><i class=\"icon iconfont icon-lajitong-copy\"></i>清空</a> </span></div></td></TR>");
                                i++;
                            }
                        }
                        else
                        {
                            KSCMS.W("<tr class=\"tdbg\"><td class=\"Ctd\" style=\"text-align:center\" colspan=\"15\"><div class=\"empty\">暂未无学员进度</div></td></tr> ");
                        }
                    }
                %>

            </table>
            <div class="cz_btn mt10">        
                <span><input type="checkbox" class="checkbtn" name="chkall" id="chkall" onclick="CheckAll(this.form);" /><label for="chkall">全部选中</label></span>		   
                <span>
                    <input type="submit"  class="button" value="批量清空" onclick="return (GetIDS());">
                     <input type="hidden" id="actiondel" value="del" name="do">
                     <input type="hidden" id="courseid" value="<%=CourseId %>" name="courseid">
                </span>
            </div> 
            <div class="fy_box" >
                <%
                #region 分页
                string PageStr = "[KS:PageStr1]";
                BasicField.ReplaceFilterPage(ref PageStr, CurrPage, PageSize, pagecount, recordcount);
                KSCMS.W(PageStr);
                #endregion
                %>
            </div>
            <div class="clear"></div>
        </form>
        <div ID="Panel1"  Width="100%">
		   	<div class="scheduleTipsBox" style="padding:10px 0px 0px">
				<script type="text/javascript">
                    showtips(' <span>操作说明：<br /></span><span class="tips_cor" style="display:block;margin-top:5px;">清空进度不是删除进度，只是把学员学过的课程标记清除！</span>');
                </script>
			</div>
       	</div>
        <script>
            $(function () {
                //获取进度百分比
				$(".schedule").each(function () {
					if($(this).find("em").text()!=0){
						var a = $(this).find(".linebg").text() / $(this).find("em").text() * 100;
						$(this).find(".linebg").animate({ width: "" + a + "%" }, 300);
					}else{
						$(this).find(".linebg").animate({ width: 0}, 300);
					}
				});

            });
            function showDetail(uid, cid) {
                var url = "<%=BasicField.GetUserUrl("teacher/CosLearnRecordDetail")%>";
                url += ",userid-" + uid + ",courseid-"+cid+",frame-no";
			openWin('学员课程完成情况', url, 900,1120);
	     	}
	
            function changedo(i) {
                if (i == 0) {
                    $("#actiondel").val("search");
                }
            }

        </script>
	 </div>
