<%@ 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;  //定义页面是否加载
	private string param = string.Empty;
	protected void Page_Load(object sender, EventArgs e)
	{
		param = "KS_SJReviews A Left Join KS_SJ B on a.sjid=b.id where b.inputer='" + new TemporaryVar().UserName + "'";

		if (Utils.StrToInt(KSCMS.S("showType")) > 0)
		{
			param += " and a.status=" + (Utils.StrToInt(KSCMS.S("showType")) - 1);
		}
		string DoMethod = KSCMS.S("do");

		switch (DoMethod)
		{
			case "verify":
				verify(KSCMS.S("id"));
				break;
			case "cancelv":
				BtnUnVerify_Click();
				break;
			case "allverify":
				BtnVerify_Click();
				break;
			case "del":
				deleteReviews(KSCMS.S("id"));
				break;
		}
		
	}
	private void deleteReviews(string classid)
	{

		if (classid == null || classid == "0") return;

		string[] arrid = Utils.SplitString(classid, ",");
		foreach (string id in arrid)
		{
			Hashtable ht = new Hashtable();
			ht.Add("id", id);
			CommonData.Delete("[KS_SJReviews]", ht);
			ht.Clear();
			ht.Add("cmtid", id);
			CommonData.Delete("[KS_SJReviewsCmt]", ht);
		}
		Msg.Alert("恭喜考后心得删除成功!", BasicField.GetUserUrl("sj/TcSjReviews"));
		isLoadPage = false;
		return;
	}
	private void verify(string ids)
	{
		KSSecurity.CheckSubPower(1);
		ids = Utils.FilterIDs(ids);
		if (string.IsNullOrEmpty(ids)) return;
		string[] idsArr = ids.Split(',');
		foreach (string id in idsArr)
		{
			if (DataFactory.GetOnlyValue("select top 1 status from KS_SJReviews Where ID=" + id) == "0")
			{
				DataFactory.ExecuteNonQuery("Update KS_SJReviews Set Status=1 Where ID=" + id);
				Msg.Alert("恭喜，审核成功!", BasicField.GetUserUrl("sj/TcSjReviews"));
				isLoadPage = false;
				return;
			}
			else
			{
				DataFactory.ExecuteNonQuery("Update KS_SJReviews Set Status=0 Where ID=" + id);
				Msg.Alert("恭喜，取消审核成功!", BasicField.GetUserUrl("sj/TcSjReviews"));
				isLoadPage = false;
				return;
			}
		}
	}
	protected void BtnVerify_Click()
	{
		string id = Utils.FilterIDs(KSCMS.S("ids"));
		if (id != "")
		{
			DataFactory.ExecuteNonQuery("Update KS_SJReviews Set Status=1 Where ID in(" + id + ")");
			Msg.Alert("恭喜，批量审核成功!", BasicField.GetUserUrl("sj/TcSjReviews") );
			isLoadPage = false;
				return;
		}
	}

	protected void BtnUnVerify_Click()
	{
		string id = Utils.FilterIDs(KSCMS.S("ids"));
		if (id != "")
		{
			DataFactory.ExecuteNonQuery("Update KS_SJReviews Set Status=0 Where ID in(" + id + ")");
			Msg.Alert("恭喜，批量取消审核成功!", BasicField.GetUserUrl("sj/TcSjReviews"));
			isLoadPage = false;
			return;
		}
	}
</script>

<%
    if (!isLoadPage) return;
%>
  <script>
      var box = '';
      function openWin(title, url, isreload, width, height) {
          if (width == null) width = 760;
          if (height == null) height = 450;
          box = $.dialog.open(url, {
              id: 'topbox', lock: true, title: title, width: width, height: height, close: function () {
                  if (isreload) {
                      frames['main'].location.reload();
                  }
              }
          });
      }
      function dosearch() {
          var url = "<%=BasicField.GetUserUrl("sj/TcSjReviews")%>";
          var value = $("#TextBox1").val();
          var value2 = $("#TextBox2").val();
          location.href = url + ",TextBox2-" + value2 + " ,TextBox1-" + value;
      }

      // 获取全选的id值
      function GetMyIds() {
          var sid = null;
          for (var i = 0; i < document.getElementsByName("ids").length; i++) {
              var KS = document.getElementsByName("ids")[i];
              if (KS.checked == true) {
                  if (sid == null)
                      sid = KS.value;
                  else
                      sid += "," + KS.value;
              }
          }
          return sid;
      }
      function submitsh(i) {
          var sid = GetMyIds();
          if (sid == null) {
              KesionJS.Alert("您未选择记录信息！");
              return false;
          }
          if (i == 1) {
              $("#myforms").submit();
          }
          else {
              $("#tablesub").val("cancelv");
              $("#myforms").submit();
          }
      }
      function openwindow(id) {
          var url = "<%=BasicField.GetUserUrl("sj/tcSJShowReviews")%>";
            url += ",frame-no,id-" + id;
            parent.openWin("查看考后心得详情", url, false, 900, 530)
        }
  </script>
    <form name="myform" action="<%=BasicField.GetUserUrl("sj/TcSjReviews") %>" method="post" id="myforms" >
	<input type="hidden" name="do" value="allverify" id="tablesub" />
	
  <div class="r_tybox t_tybox s_tybox">
    <div class="r_title tytitle"><h4>考后心得</h4></div>
    <div class="tabs">
        <ul class="clearfix">
            <li <%=KSCMS.S("showType")==""?" class='puton'":string.Empty %>><a href="<%=BasicField.GetUserUrl("sj/TcSjReviews") %>"><span>所有心得</span></a></li>
            <li <%=KSCMS.S("showType")=="1"?" class='puton'":string.Empty %>><a href="<%=BasicField.GetUserUrl("sj/TcSjReviews","showType-1") %>"><span>未审核的心得</span></a></li>
            <li <%=KSCMS.S("showType")=="2"?" class='puton'":string.Empty %>><a href="<%=BasicField.GetUserUrl("sj/TcSjReviews","showType-2") %>"><span>已审核的心得</span></a></li>
        </ul>
    </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="6%" align="center">状态</td>
                <td width="31%" align="center">试卷名称</td>            
                <td width="42%" align="center">心得内容</td>          
                <td width="15%">管理操作</td> 
              </tr>
             <%
				  int recordcount, pagecount;
					 int CurrPage = new BasicField().GetCurrPage;
					 int PageSize = 10;
					 if (!string.IsNullOrEmpty(KSCMS.S("TextBox2")))
					 {
						 param += " and title like '%" + KSCMS.S("TextBox2") + "%'";
					 }
					 if (!string.IsNullOrEmpty(KSCMS.S("TextBox1")))
					 {
						 param += " and username like '%" + KSCMS.S("TextBox1") + "%'";
					 }
					 using (DataTable dt = DataFactory.GetPage("a.*,b.title,b.id as sjid", param, "a.id", "order by a.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>" + (Utils.StrToInt(dr["status"].ToString()) == 0 ? "<font color='#f13229'>未审</font>" : "<font color='#41ab32'>已审</font>") + "  </td>" +
				"<td class=\"tag_left lefticon\"> <a title=\"浏览试卷\" href=\"" + BasicField.GetRewriteUrl("examview", Utils.StrToInt(dr["sjid"])) + "\" target=\"_blank\"> <i class=\"icon iconfont icon-IE\"></i></a>" +
				"<font class=\"fonths\">" + Utils.CutStr(Convert.ToString(dr["title"]), 40) + "</font>	<span style=\"display:none\">" + (Convert.ToString(dr["status"]) == "1" ? "<font color=green>已审核</font>" : "<font color=red>未审核</font>") + "</span>" +
				"<div class=\"tips\" style=\"padding:10px 0px 0px 10px\">发表者：" + dr["UserName"] + " 时间：" + dr["adddate"] + "回复：" + dr["CmtNum"] + " 条</div></td>" +
				"<td class=\"tag_left1\" style=\"font-size:12px; line-height:22px; padding-right:10px\">" +
					 " <span style=\"cursor:pointer\" onmousedown='openwindow(" + dr["id"].ToString() + ")'>" + Utils.CutStr(Convert.ToString(dr["content"]), 160) + "</span></td>" +
			   " <td align=\"center\"><div class=\"gl_btn\">" +
						"<span class=\"span1\" style=\"cursor:pointer;width:33.3%\" onmousedown='openwindow(" + dr["id"].ToString() + ")'><i class=\"icon iconfont icon-xiangqing\"></i>详情</span>" +
						" <span style=\"width:33.3%\"><a  href=\"" + BasicField.GetUserUrl("sj/TcSjReviews", "do-del,id-" + dr["id"].ToString() + "") + "\"><i class=\"icon iconfont icon-lajitong-copy\"></i>删除</a></span>" +
						" <span class=\"span5\" style=\"width:33.3%\"><a href=\"" + BasicField.GetUserUrl("sj/TcSjReviews", "do-verify,id-" + dr["id"].ToString() + "") + "\"><i class=\"icon iconfont icon-shenhe\"></i>审核</a></span></div> </td> </TR>");
							 }
						 }
						 else
						 {
							 KSCMS.W(" <TR class=\"tdbg sort bar\"><td colspan=\"7\"><div class=\"empty\">没找到任何记录！</div></td></TR> ");
						 }
					 }
				  %>
           </table>
  <div class="clear" style="height:10px"></div>
    
          <div class="cz_btn" >
             <span style="margin-right:0px"><input type="checkbox" class="checkbtn" name="chkall" id="chkall" onclick="CheckAll(this.form);"/><label for="chkall">全选</label></span>
          	<span><input type="button" value="删除记录" class="green-bt button" onclick="if (GetIDS('del')) { this.form.action = ',do-del'; this.form.submit() }" /></span>
            <span><input type="button" name="BtnVerify" value="批量审核" id="BtnVerify" class="green-bt button" onclick="submitsh(1)" /></span>
           	<span style="margin-right:0px"><input type="button" name="BtnUnVerify" value="批量取消审核" onclick="submitsh(2)" id="BtnUnVerify" class="green-bt button"/></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=" clearfix"></div>
    </div>       
	</form>