<%@ 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="Kesion.Components" %>
<%@ Import Namespace="Kesion.NET.WebSite.Admin.Exam" %>

<script runat="server" type="text/C#">
	dynamic __user = HttpContext.Current.Items["user"];                //初始化用户信息，
	private static dynamic __info = new System.Dynamic.ExpandoObject();   //初始化当前页信息
	bool isLoadPage = true;  //定义页面是否加载
	public StringBuilder sb = new StringBuilder();
	public int SjId = 0;
	private int CurrPage = 1;
	public int classId = 0;
	public int SJtypeClass = 0; //试郑属性
	public DataRow drp = null;
	public string sqlStr = string.Empty;
    protected void Page_Load(object sender, EventArgs e)
    {
        SjId = Utils.StrToInt(KSCMS.S("sjid"));
        classId = Utils.StrToInt(KSCMS.S("DrpClassID"));
        // infoInitial();

        string DoMethod = KSCMS.S("do");

        switch (DoMethod)
        {
            case "del":
                if (!string.IsNullOrEmpty(KSCMS.S("tmid")))
                {
                    deleteSj(KSCMS.S("tmid"));
                }
                break;

        }
    }
    private void infoInitial()
    {
        __info.ClassID = KSCMS.S("DrpClassID");
        
    }
	
	private void initialEdit(int sjid)
	{
		
		#region 构造sql参数
		SqlParam[] param = new SqlParam[1];
		param[0] = new SqlParam("id", sjid);
		#endregion

		DataTable dt = CommonData.GetDataTable("[KS_SJtk]", "*", param);
		if (dt.Rows.Count > 0)
		{
			 drp = dt.Rows[0];
		}
		dt.Dispose();

	}
	private void deleteSj(string classid)
	{
		if (classid == null || classid == "0") return;

		classid = Utils.FilterIDs(classid);
		using (DataTable dt = DataFactory.GetDataTable("select * from KS_SJtk Where tmid in(" + classid + ")"))
		{
			if (dt.Rows.Count > 0)
			{
				foreach (DataRow dr in dt.Rows)
				{
					int id = Utils.StrToInt(dr["tmid"].ToString());
					Hashtable ht = new Hashtable();
					ht.Add("tmid", id);
					CommonData.Delete("[KS_SJtk]", ht);
			
				}
			}
		}
		Msg.Alert("恭喜,删除成功!",BasicField.GetUserUrl("SJ/TcTkList") );
		isLoadPage = false;
		return;
	}
	


	public string GetParam(string Fields)
	{
		string result = string.Empty;
		if (drp != null)
		{
			result = drp[Fields].ToString();
		}
		return result;
	}
	

    public string GetBusiness(string nametype)
    {
        #region 经营范围
     

        DataTable dt = MyCache.GetCacheSJCategoryTable();       //考试分类         
       
        StringBuilder sb = new StringBuilder();
        if (!string.IsNullOrEmpty(nametype))
        {
            DataView dv = dt.DefaultView;
            nametype = Utils.FilterIDs(nametype);
            dv.RowFilter = " classid in(" + nametype + ")";
            //  dv.Sort = "root,orderid";
            dt = dv.ToTable();
        }
        int depth = 1;
        if (dt.Rows.Count > 0)
        {
            foreach (DataRow dr in dt.Rows)
            {
                string str = string.Empty;
                depth = Utils.StrToInt(dr["depth"].ToString());
                if (depth == 2)
                {
                    str = "　├ ";
                }
                if (depth == 3)
                {
                    str = "　   　├ ";
                }
                nametype = "," + nametype + ",";
                if (nametype.IndexOf("," + dr["classid"].ToString() + ",") != -1)
                {
                    sb.AppendFormat(@"<option value ={0} selected = 'selected' >{1}</option>", dr["classid"].ToString(), str + dr["classname"].ToString());

                }
                else
                {
                    sb.AppendFormat(@"<option value ='{0}' >{1}</option>", dr["classid"].ToString(), str + dr["classname"].ToString());
                }
            }

        }
        dt.Dispose();
        return sb.ToString();
        #endregion
    }
</script>
<%
    if (!isLoadPage) return;
%>
   <form name="myform" action="<%=BasicField.GetUserUrl("SJ/TcSjList") %>" method="post" id="myform" >
   
     

   <div class="t_tybox">
<%if (!KSCMS.S("do").Equals("modify") && !KSCMS.S("do").Equals("add"))
  { %>
 <div class="tytitle clearfix"><h4 class="fl lf">题目列表</h4><a onclick="addSt(0)" class="addbtn mt10">+添加题目</a>

     </div>
     
 	 <div class="clear blank10"></div>
          
       <div class="top_c_sc mt10 clearfix">
            <span>试题名称：</span> 
            <input name="TextBox1" type="text" id="TextBox1" class="textbox" />
            <input type="submit" name="Button4" value=" 搜索 "  id="Button4" class="button green-bt bt-auto" style="display:inline-block" />
        </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 style="text-align:left">题目内容</td>      
                    
                <td  width="100" align="center">编辑</td>
                <td  width="100" align="center">删除</td>
              </tr>
    <%
	  string sqlParam = "KS_SJtk Where  inputer='"+new TemporaryVar().UserName+"'";
	  int pagesize = 12;
	  int CurrPage = new BasicField().GetCurrPage;
            int recordcount, pagecount;

            if (!string.IsNullOrEmpty(KSCMS.S("TextBox1")))
            {
				sqlParam += " and tmnr like '%" + KSCMS.S("TextBox1") + "%'";               
            }
             int showType = Utils.StrToInt(KSCMS.S("showType"));
      
			using (DataTable dt = DataFactory.GetPage("*", sqlParam, "tmid", "order by tmID 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\">");
                        KSCMS.W("<td align=\"center\" height=\"30px\" nowrap> <input type=\"checkbox\" class=\"checkbtn\"  name=\"tmid\" id=\"sjid\" value=\"" + dr["tmid"].ToString() + "\" /></span><br/>	 <span class='tips'>( "+dr["tmfs"].ToString()+"分)</span></td>");
                        KSCMS.W("<td class='Ctd' style='word-break:break-all;text-align:left'>");
                        KSCMS.W(" <strong " + dr["title"].ToString() + "</strong>");
                        KSCMS.W("<div style='line-height:36px'>"+dr["tmnr"].ToString()+"</div>" + "<div class='tips'style='background:#F9F9F9'>");

                        KSCMS.W((Convert.ToString(dr["tmtype"].ToString()) != "6" && Convert.ToString(dr["tmtype"].ToString()) != "7") ? "<div>参考答案：" + Kesion.Exam.Function.GetCKDA(Utils.StrToInt(dr["tmtype"].ToString()), Convert.ToString(dr["answer"].ToString())) + "</div>" : "");
                        KSCMS.W(string.IsNullOrEmpty(Convert.ToString(dr["dajs"].ToString())) ? "" : "答案解释：" + Utils.replaceBR(Convert.ToString(dr["dajs"].ToString())));
                        KSCMS.W(" </div></div></td>");

                        KSCMS.W(" <td style='text-align:center'><div class=\"gl_btn\"><span class=\"span4\" style=\"width:100%\">");

                        KSCMS.W("<a onclick=\"editSt(" +dr["tmid"].ToString() + ")\"><i class=\"icon iconfont icon-xiazai48\"></i>编辑</a></span></td>");
                        
                         KSCMS.W("<td  style='text-align:center'><div class=\"gl_btn\"><span class=\"span5\" style=\"width:100%\"><a onclick=\"return(confirm('确定删除试题吗?'));\" title=\"删除\" href=\"" + BasicField.GetUserUrl("SJ/TctkList", "do-del,tmid-" + dr["tmid"].ToString() + "") + "\"><i class=\"icon iconfont icon-lajitong-copy\"></i>删除</a></span> </div></td>");
	
                        KSCMS.W("</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">
             <div class="f-right">
		      <input type="hidden" name="do" value="del" />
             <span class="check-all"> <input type="checkbox" class="checkbtn" name="chkall" id="chkall" onclick="CheckAll(this.form);" /><label for="chkall">全选</label></span>
             <span><input type="button" value="删除记录" class="button green-bt bt-auto" onclick="if (confirm('您确定删除选中试题吗？')) { this.form.action ='<%=BasicField.GetUserUrl("sj/tctklist","do-del")%> '; this.form.submit() }" /><span>
             </div>  
          </div>         
    
     <div class="fy_box"> 
          <%
            #region 分页
           string PageStr=__user.GroupID==3||__user.GroupID==4?"[KS:PageStr1]": "[KS:PageStr2]";
            BasicField.ReplaceFilterPage(ref PageStr, CurrPage, pagesize, pagecount, recordcount);
            KSCMS.W(PageStr);
            #endregion
         %>

     </div>
          <div class="clear"></div>
</div>
		 </form>
<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();
                }
            }
        });
    }

    var purl="<%=BasicField.GetUserUrl("SJ/TcSjEditeSt")%>";
    function editSt(id) {
        purl+=",frame-no,do-modify,tmid-"+id;
        openWin('修改试题', purl, false, 980, 600);
    }
    function addSt(typeid) {
       
        purl+=",frame-no,do-add,typeid-"+typeid;
        openWin('添加试题', purl, false, 900,520);
    }


</script>


	 <%}else{
  
  
  }%>
