<%@ 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;  //定义页面是否加载
    bool ispower = false;     //判断用户权限
	public static int RoomID = 0;
	public static int type;
	public static int workID;
	public static string name;
	public static string DefaultFile = string.Empty;
	public static string photourl = string.Empty;
	public static string ClassRoomTitle = string.Empty;
	protected void Page_Load(object sender, EventArgs e)
	{
		string DoMethod = BasicField.GetParam("do");
        
		if (string.IsNullOrEmpty(DoMethod))
		{
			DoMethod = KSCMS.S("action");
		}
        switch (DoMethod)
        {
            case "del":
                deleteSj(KSCMS.S("ids"));
                break;
        }
        CheckUserLogin.Run();

        RoomID = Utils.StrToInt(KSCMS.S("RoomID"));
        int tcid = Utils.StrToInt(DataFactory.GetOnlyValue("select TcID from KS_CosTeacher where UserID =" + __user.UserID));
       /* if (__user.GroupID == 3 || Utils.StrToInt(DataFactory.GetOnlyValue("select count(*) from KS_CosClassroom where BanzhuRenID =" + new TemporaryVar().UserID + " and RoomID =" + RoomID)) > 0)
        {
            ispower = true;
        }
        else if (Utils.StrToInt(DataFactory.GetOnlyValue("select count(*) from KS_CosClassManage where TaskType = 5 and RoomID =" + RoomID + " and TcID=" + tcid)) != 0)
        {
            ispower = true;
        }
        */
        ispower = true;
        string sql1 = "";
        if (RoomID != 0)
        {
            sql1 = "select top 1 Title from KS_CosClassRoom where RoomID=" + RoomID;
            using (DataTable dt = DataFactory.GetDataTable(sql1))
            {
                if (dt.Rows.Count > 0)
                {
                    DataRow dr = dt.Rows[0];
                    ClassRoomTitle = dr["Title"].ToString();
                }
            }
		}
		if (KSCMS.S("action").Equals("del"))
		{
			deleteSj(KSCMS.S("ids"));
		}
	}
	private void deleteSj(string WorkID)
	{
		if (WorkID == null || WorkID == "0") return;

		WorkID = Utils.FilterIDs(WorkID);
		using (DataTable dt = DataFactory.GetDataTable("select PJID,CourseID from KS_CoursePJ Where PJID in(" + WorkID + ")"))
		{
			if (dt.Rows.Count > 0)
			{
				foreach (DataRow dr in dt.Rows)
				{
					int id = Utils.StrToInt(dr["PJID"].ToString());
					int RoomID1 = Utils.StrToInt(dr["CourseID"].ToString());
					Hashtable ht = new Hashtable();
					ht.Add("PJID", id);
					float StarNum = Utils.StrToFloat(DataFactory.GetOnlyValue("select AVG(Cosnumber) from KS_CoursePJ where OrderType=20 and CourseID=" + RoomID1));  //
					int pfnum = Utils.StrToInt(DataFactory.GetOnlyValue("select count(*) from KS_CoursePJ  Where status=1 and OrderType=20 and  CourseID=" + RoomID1 + ""));
					DataFactory.ExecuteNonQuery("Update KS_CosClassRoom   Set Score=" + StarNum + ",pfnum=" + pfnum + "  Where  RoomID=" + RoomID1);
					CommonData.Delete("[KS_CoursePJ]", ht);
				}
			}
		}
		Msg.Alert("删除成功!", BasicField.GetUserUrl("teacher/TcClassRoomPj", "roomid-" + RoomID));
	}
	public string GetUserName(int UserID)
	{
		#region 得到用户名
		string str = string.Empty;
		str = DataFactoryUser.GetOnlyValue("select top 1 username from KS_user where userid=" + UserID).ToString();
		return str;
		#endregion
	}
</script>
<%
    if (!isLoadPage) return;
%>
  <form name="myform" action="<%=BasicField.GetUserUrl("teacher/TcClassRoomPj") %>" method="post" id="Form1" >
	  <div class="t_tybox">
            <div class="tytitle"><h4>班级评价管理</h4>
           	<a onclick="" href="<%=BasicField.GetUserUrl("teacher/tcclassroom") %>" class="addbtn">返回</a>
            </div>
            <div class="clear blank10"></div>
			<div class="part_now">当前班级：<%=ClassRoomTitle %></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="5%">选择</td>         
			
                 <td width="10%">用户ID</td>  
                  <td width="40%">用户名</td> 
                   <td width="6%">等级</td> 
                  <td width="6%">星级</td>
                  <td width="6%">评价内容</td>                
                 <td width="12%">评价时间</td>
                 <td width="20%">操作</td>
              </tr>  
       <%
		   int recordcount, pagecount;
		   int CurrPage = new BasicField().GetCurrPage;
		   int PageSize = 10;
		   using (DataTable dt = DataFactory.GetPage("*", "KS_CoursePJ where  OrderType=6 and  CourseID=" + RoomID + "", "PJID", "order by AddDate 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\">");
                       KSCMS.W(" <td class=\"splittd\" align=\"center\"><input class=\"cleckbtn\" type=\"checkbox\" name=\"ids\" value=\"" + dr["pjid"].ToString() + "\" /></td>" +
                           "<td class=\"Ctd\" align=\"center\">" + dr["userid"].ToString() + "</td>" +
                        "<td class=\"tag_left lefticon text-center\">" + GetUserName(Utils.StrToInt(dr["userid"].ToString())) + " </td>" +
                        "<td class=\"Ctd\" align=\"center\">" + (dr["CmtType"].ToString() == "0" ? "好评" : dr["CmtType"].ToString() == "1" ? "中评" : "差评") + "</td>" +
                          " <td class=\"Ctd\" align=\"center\">" + (dr["Cosnumber"].ToString() == string.Empty ? "" : "<img src=\"../../SysImg/default/star/mood" + dr["Cosnumber"] + ".png\" title=\"" + dr["Cosnumber"] + "颗星\" /> ") + "</td>" +
                          "<td class=\"Ctd\" align=\"center\"> " + dr["CosContent"].ToString() + " </td> <td width=\"135\">" + Convert.ToDateTime(dr["adddate"].ToString()).ToString("yyyy-MM-dd") + " </td>");
                       if (ispower)
                       {
                           KSCMS.W("<td><div class=\"gl_btn\"><span class=\"span5\" style=\"width:50%\">" +
                                   "<a href=\"" + BasicField.GetUserUrl("teacher/tcclassroompj", "roomid-" + RoomID + ",do-del,ids-" + dr["pjid"].ToString()) + "\" Class=\"delete\" id=\"delete\" OnClick=\"return(confirm('确定删除该评价将会影响的您的班级的评分吗?'));\"><i class=\"icon iconfont icon-lajitong-copy\"></i>删除</a></span> </div></td>");
                       }
                        else
                        {
                            KSCMS.W("<td class=\"splittd\" align=\"center\">无操作权限</td>");
                        }
                       KSCMS.W("</tr>");
                       i++;
                   }
			   }
			   else
			   {
				   KSCMS.W("<tr class=\"tdbg\"><td class=\"Ctd\" style=\"text-align:center\" colspan=\"7\"> <div class=\"empty\">暂未添加任何评价信息</div></td></tr> ");
			   }
		   }
		    %>
           </table>
           <%if(ispower){ %>
         <div class="cz_btn">
		  <input type="hidden" value="<%=RoomID %>" name="RoomID" />
		 <input type="hidden" value="del" name="action" />
        <span><input type="checkbox" name="chkall" id="chkall" onclick="CheckAll(this.form);"/>全选</span>
        <span><input type="submit" class="button" value="批量删除" onclick="return (CheckIds('del'));"></span>
        <div class="clear"></div>
     </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>
		</div>
		
     
     <div style="padding:10px 0px 0">
        <script type="text/javascript">
            showtips('<span><strong>操作说明：</strong><br />这里删除是影响您的班级的评分，因为它会重新在统计班级的评分的</span>的。');
		</script>
		</div>
	   </form>