<%@ 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 StringBuilder stk = 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();
        if (KSCMS.S("action").Equals("save"))
        {
            SaveChange();
        }
        string DoMethod =KSCMS.S("do");

        switch (DoMethod)
        {
            case "del":
                if (!string.IsNullOrEmpty(KSCMS.S("sjid")))
                {
                    deleteSj(KSCMS.S("sjid"));
                }
                break;
            case "modify":
                initialEdit(SjId);
                break;
            case "add":
                break;
        }
    }
    private void infoInitial()
    {
        if (__user.GroupID == 3)
        {
            __info.ClassID  = DataFactory.GetOnlyValue("select top 1 ExamClass from KS_EnterPrise where   userid=" + new TemporaryVar().UserID );
        }
        else {
            __info.ClassID = KSCMS.S("DrpClassID");
        }

        if (KSCMS.S("dtfs") == "3")
        {


            if (HttpContext.Current.Items["exam_totalfs"] != null)
            {
                //this.TxtScore.Text = HttpContext.Current.Items["exam_totalfs"].ToString();
            }

            StringBuilder sb = new StringBuilder();
            if (!string.IsNullOrEmpty(KSCMS.GetCookie("sjrnd", "righttmtype")))
            {
                //   sb.AppendFormat(@"<input type='hidden' name='dtfs' value='{0}'/>", KSCMS.S("dtfs"));
                sb.AppendFormat(@"<input type='hidden' name='righttmtype' value='{0}'/>", KSCMS.GetCookie("sjrnd", "righttmtype"));
                string[] righttmtypearr = Utils.SplitString(KSCMS.GetCookie("sjrnd", "righttmtype"), ",");
                foreach (string s in righttmtypearr)
                {
                    string tmType = s;
                    sb.AppendFormat(@"<input type='hidden' name='tmIds{0}' value='{1}'/>", tmType, KSCMS.GetCookie("sjrnd", "exam_tmids" + tmType).ToString());
                    sb.AppendFormat(@"<input type='hidden' name='num{0}' value='{1}'/>", tmType, KSCMS.GetCookie("sjrnd", "exam_num" + tmType).ToString());
                    sb.AppendFormat(@"<input type='hidden' name='title{0}' value='{1}'/>", tmType, KSCMS.GetCookie("sjrnd", "exam_title" + tmType).ToString());
                    sb.AppendFormat(@"<input type='hidden' name='fs{0}' value='{1}'/>", tmType, KSCMS.GetCookie("sjrnd", "exam_fs" + tmType).ToString());
                    sb.AppendFormat(@"<input type='hidden' name='koufs{0}' value='{1}'/>", tmType, KSCMS.GetCookie("sjrnd", "exam_koufs" + tmType).ToString());
                    sb.AppendFormat(@"<input type='hidden' name='iskoufs{0}' value='{1}'/>", tmType, KSCMS.GetCookie("sjrnd", "exam_iskoufs" + tmType).ToString());
                    sb.AppendFormat(@"<input type='hidden' name='orderid{0}' value='{1}'/>", tmType, KSCMS.GetCookie("sjrnd", "exam_orderid" + tmType).ToString());
                    sb.AppendFormat(@"<input type='hidden' name='tmtype{0}' value='{1}'/>", tmType, KSCMS.GetCookie("sjrnd", "exam_tmtype" + tmType).ToString());

                }
            }
            stk.Append(sb.ToString());
            HttpCookie userck = new HttpCookie("sjrnd" + KSCMS.SiteSN);
            if (Kesion.Config.BaseConfigManage.AllowSubDomain.ToLower().Equals("true")) //启用二级域名
            {
                userck.Domain = Kesion.Config.BaseConfigManage.RootDomain;
            }
            userck.Values["righttmtype"] = string.Empty;
            HttpContext.Current.Response.AppendCookie(userck);
        }

    }
    protected void SaveChange()
    {
        Utils.TipsDisabled();  //检查是否演示状态

        if (KSCMS.S("TxtTitle").Trim() == "")
        {
            Msg.Alert("试卷名称不能为空!");
            return;
        }
        if (Utils.StrToInt(KSCMS.S("DrpClassID")) == 0)
        {
            Msg.Alert("请选择试卷分类!");
            return;

        }
        object syncLocker = new object();
        lock (syncLocker)
        {
            classId = Utils.StrToInt(KSCMS.S("DrpClassID"));
            Hashtable ht = new Hashtable();
            ht.Add("title", KSCMS.S("TxtTitle"));
            ht.Add("classid", classId);
            ht.Add("typeid", Utils.StrToInt(KSCMS.S("DrpSJTypeID")));
            ht.Add("provinceid", Utils.StrToInt(KSCMS.S("DrpProvince")));
            ht.Add("kssj", Utils.StrToInt(KSCMS.S("TxtKSSJ")));
            ht.Add("score", Utils.StrToFloat(KSCMS.S("TxtScore")));
            ht.Add("money", Utils.StrToInt(KSCMS.S("TxtMoney")));
            ht.Add("times", Utils.StrToInt(KSCMS.S("TxtTimes")));
            ht.Add("groupids", KSCMS.S("ArrGroupID"));
            ht.Add("cjdid", Utils.StrToInt(KSCMS.S("DrpCjdID")));
            ht.Add("comment", 1);
            ht.Add("IsSaveAnswer", 1);
            ht.Add("IsDelRecord", 1);

            ht.Add("intro", KSCMS.S("TxtIntro"));
            ht.Add("seotitle", "");
            ht.Add("seokeywords", "");
            ht.Add("seodescription", "");
            ht.Add("keytags", KSCMS.S("TxtKeyTags"));
            ht.Add("FrontSize", 0);
            ht.Add("DoExamWay", Utils.StrToInt(KSCMS.S("DrpDoExamWay")));
            ht.Add("MustLogin", 1);
            ht.Add("ShowOn3g", 1);
            ht.Add("OpenTimeLimit", Utils.StrToInt(KSCMS.S("RdbLimitDate")));
            if (Utils.StrToInt(KSCMS.S("RdbLimitDate")) == 1)
            {
                if (Utils.IsDateTime(KSCMS.S("TxtBeginTime").Trim()))
                {
                    ht.Add("TimeLimitBegin", Convert.ToDateTime(KSCMS.S("TxtBeginTime")));
                }
                else
                {
                    Msg.AlertDoFun("考试开放时间的开始日期格式不正确！", "history.back()");
                    isLoadPage = false;
                    return;
                }
                if (Utils.IsDateTime(KSCMS.S("TxtEndTime").Trim()))
                {
                    ht.Add("TimeLimitEnd", Convert.ToDateTime(KSCMS.S("TxtEndTime")));
                }
                else
                {
                    Msg.AlertDoFun("考试开放时间的结束日期格式不正确！", "history.back()");
                    isLoadPage = false;
                    return;

                }
            }
            ht.Add("departIds", "");
            if (KSCMS.S("do").Equals("add"))
            {
                if (MyCache.GetCourseCacheConfig(9) == "1")  //需要审核
                {
                    ht.Add("verify", 0);//未审状态
                }
                else
                {
                    ht.Add("verify", 1);//已审状态
                }

                ht.Add("realtest", 0);
                if (KSCMS.S("dtfs") == "3")
                {
                    ht.Add("dtfs", 3);
                }
                else
                {
                    ht.Add("dtfs", KSCMS.S("dtfs"));
                }
                ht.Add("inputer", new TemporaryVar().UserName);
                ht.Add("adddate", DateTime.Now);

                Kesion.Controls.CustomFields.DoSchoolFieldSave(ref ht);

                CommonData.Insert("KS_SJ", ht);

                EnterPrise.AddInorOutScore("exam", "sjadd", __user.UserName, __user.UserID);

                int sjId = CommonData.GetMaxId("KS_SJ", "ID");
                string righttmtype = KSCMS.S("righttmtype");
                if (!string.IsNullOrEmpty(righttmtype) && KSCMS.S("dtfs") == "3")
                {
                    string[] rightTmTypeArr = Utils.SplitString(righttmtype, ",");
                    foreach (string tmType in rightTmTypeArr)
                    {
                        ht.Clear();
                        ht.Add("sjid", sjId);
                        ht.Add("tmtype", Utils.StrToInt(KSCMS.S("tmtype" + tmType)));
                        ht.Add("tmids", Utils.FilterIDs(KSCMS.S("tmids" + tmType)));
                        ht.Add("orderid", Utils.StrToInt(KSCMS.S("orderid" + tmType)));
                        ht.Add("title", KSCMS.S("title" + tmType));
                        ht.Add("fs", Utils.StrToFloat(KSCMS.S("fs" + tmType)));
                        ht.Add("num", Utils.StrToInt(KSCMS.S("num" + tmType)));
                        CommonData.Insert("KS_SJRndZJ", ht);
                    }
                }
                else if (!string.IsNullOrEmpty(KSCMS.S("TxtContent")))  //word导入试卷
                {
                    InsertTkFromText(KSCMS.S("TxtContent"), sjId);
                }

                #region 关联上传文件
                string tempContent = UtilsQueryParam.Get("__VIEWSTATE,__EVENTVALIDATION", 0);
                Kesion.APPCode.Public.FileAssociation(100006, sjId, tempContent, 0);
                #endregion
                Msg.Alert("恭喜,添加成功!",BasicField.GetUserUrl("SJ/TcSjList"));
                isLoadPage = false;
                return;
            }
            else
            {
                CommonData.Update("[KS_SJ]", ht, "where id=" + SjId);
                #region 关联上传文件
                string tempContent = UtilsQueryParam.Get("__VIEWSTATE,__EVENTVALIDATION", 0);
                Kesion.APPCode.Public.FileAssociation(100006, SjId, tempContent, 1);
                #endregion

                Msg.Alert("恭喜,修改成功!", BasicField.GetUserUrl("SJ/TcSjList"));
                isLoadPage = false;
                return;
            }
        }
    }
    private void initialEdit(int sjid)
    {

        #region 构造sql参数
        SqlParam[] param = new SqlParam[1];
        param[0] = new SqlParam("id", sjid);
        #endregion

        DataTable dt = CommonData.GetDataTable("[KS_SJ]", "*", 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_SJ Where id in(" + classid + ")"))
        {
            if (dt.Rows.Count > 0)
            {
                foreach (DataRow dr in dt.Rows)
                {
                    int id = Utils.StrToInt(dr["id"].ToString());
                    Hashtable ht = new Hashtable();
                    ht.Add("id", id);
                    CommonData.Delete("[KS_SJ]", ht);
                    ht.Clear();
                    DataFactory.ExecuteNonQuery("DELETE FROM KS_SJTK Where isrnd=0 and TypeID in(SELECT TypeID From KS_SJTMType Where SJID=" + id + ")");
                    ht.Add("sjid", id);
                    CommonData.Delete("[KS_SJTMType]", ht);
                    CommonData.Delete("[KS_SJRndZJ]", ht);
                    ht = new Hashtable();
                    ht.Add("channelid", "100006");
                    ht.Add("infoid", id);
                    CommonData.Delete("[KS_UploadFiles]", ht);
                }
            }
        }
        Msg.Alert("恭喜,试卷删除成功!",BasicField.GetUserUrl("SJ/TcSjList") );
        isLoadPage = false;
        return;
    }


    public string GetSJDtfs(int dtfs)
    {
        string str = string.Empty;
        switch (dtfs)
        {
            case 1: str = "<span style='color:#999'>整份添加</span>";
                break;
            case 2:
                str = "<span style='color:red'>前台随机</span>";
                break;
            case 3: str = "<span style='color:blue'>后台组卷</span>";
                break;
            default: str = "整份添加";
                break;
        }
        return str;
    }
    public string GetParam(string Fields)
    {
        string result = string.Empty;
        if (drp != null)
        {
            result = drp[Fields].ToString();
        }
        return result;
    }
    public void InsertTkFromText(string str, int sjId)
    {
        #region word导入试卷

        str = Regex.Replace(str, "</p><p>", "<br/>", RegexOptions.IgnoreCase);

        string[] tmTypeArr = Regex.Split(str, @"\[TypeEnd\]", RegexOptions.IgnoreCase);
        int n = 0;
        int TypeID = 0;
        float tmfs = 0;
        int succNum = 0;
        string[] xtArr;

        StringBuilder sb = new StringBuilder();

        string tplt = @"<tr class=""CtrMouseOut"" onmouseover=""this.className='CtrMouseOver'"" onmouseout=""this.className='CtrMouseOut'"" style='height:20px;'>
				<td class='Ctd' align='left' nowrap>[{0}]</td>
				<td class='Ctd' align='left' style='width:150px'>{1}</td>
				<td class='Ctd' align='left'>{2}</td>
				<td class='Ctd' align='left'>参考答案：{3}</td>
				<td class='Ctd' align='left'>答案解释：{4}</td>
				<td class='Ctd' align='left' nowrap>{5}</td>
            </tr>";


        foreach (string tm in tmTypeArr)
        {
            if (!string.IsNullOrEmpty(tm))
            {
                xtArr = Regex.Split(tm, @"\[TypeNameEnd\]", RegexOptions.IgnoreCase);
                if (xtArr.Length == 2)
                {
                    n++;

                    #region 大题
                    string title = Utils.RemoveHtml(xtArr[0]);
                    string typeName = Utils.CutHttpString(title, "、", "（", false);

                    if (string.IsNullOrEmpty(typeName)) typeName = Utils.CutHttpString(title, "、", "(", false);
                    if (string.IsNullOrEmpty(typeName)) typeName = Utils.CutHttpString(title, ".", "（", false);
                    if (string.IsNullOrEmpty(typeName)) typeName = Utils.CutHttpString(title, ".", "(", false);

                    tmfs = Utils.StrToFloat(Utils.CutHttpString(tm, "每小题", "分", false), 1);
                    if (string.IsNullOrEmpty(typeName))
                    {
                        typeName = UtilsAutoID.CapitalFigures(n - 1);
                    }
                    else if (typeName.Length > 30)
                    {
                        typeName = typeName.Substring(0, 30);
                    }
                    if (!string.IsNullOrEmpty(title))
                    {
                        if (title.IndexOf("、") != -1)
                        {
                            title = title.Split('、')[1];
                        }
                        else if (title.IndexOf(".") != -1)
                        {
                            title = title.Split('.')[1];
                        }
                    }

                    TMTypeInfo __info = new TMTypeInfo();
                    __info.TmType = 1;
                    __info.TypeName = typeName;
                    __info.SJID = sjId;
                    __info.Intro = title;
                    __info.OrderID = n;
                    TypeID = SJManage.InsertSJTMType(__info);
                    #endregion

                    //小题


                    #region 小题
                    InportFromExamClass.TmpExamsModels em = InportFromExamClass.GetExamFromWord(xtArr[1]);
                    if (em.examList != null)
                    {
                        for (int i = 0; i < em.examList.Count; i++)
                        {
                            InportFromExamClass.TmpExamsModels _em = em.examList[i];
                            Hashtable ht = new Hashtable();
                            ht.Add("TypeId", TypeID);
                            ht.Add("ClassID", classId);
                            ht.Add("Tmtype", _em.type);
                            _em.Tm = InportFromExamClass.LosePreBr(string.IsNullOrEmpty(_em.Tm) ? "" : _em.Tm.Trim());

                            string Tmnr = "";
                            if (_em.Tm.Length >= 255)
                            {
                                Tmnr = _em.Tm + "<br/>";
                                ht.Add("Title", string.Empty);
                            }
                            else
                            {
                                ht.Add("Title", _em.Tm);
                            }
                            for (int j = 0; j < _em.Options.Count; j++)
                            {
                                Tmnr += _em.Options[j];
                            }

                            Tmnr = InportFromExamClass.LosePreBr(Tmnr.Trim());
                            ht.Add("Tmnr", Tmnr);
                            ht.Add("DAJS", _em.Dajs);
                            ht.Add("tmfs", tmfs);
                            string Answer = "";
                            /*      foreach (var a in _em.answer)
								  {
									  if (_em.type == InportFromExamClass.TmType.multiple)
									  {
										  Answer += Answer == "" ? a.Value : "," + a.Value;
									  }
									  else
									  {
										  Answer += Answer == "" ? a.Value : "※" + a.Value;
									  }
								  }
							 */
                            Answer = InportFromExamClass.LosePreBr(Answer);
                            if (_em.type == InportFromExamClass.TmType.trueorfalse)
                            {
                                if (Answer.ToLower().Equals("a"))
                                {
                                    Answer = "1";
                                }
                                else
                                {
                                    Answer = "0";
                                }
                            }
                            ht.Add("Answer", Answer);
                            ht.Add("OptionNum", _em.Options.Count);
                            ht.Add("OrderID", i + 1);
                            ht.Add("IsRnd", 1);
                            ht.Add("IsMedia", 0);
                            ht.Add("MediaUrl", "");
                            ht.Add("MediaTxt", "");
                            ht.Add("DAJSMedia", "");
                            ht.Add("Difficulty", 0);
                            ht.Add("KnowledgeId", 0);
                            ht.Add("KeyWords", "");

                            string tmtype = "";
                            switch (_em.type)
                            {
                                case InportFromExamClass.TmType.single:
                                    tmtype = "单选题";
                                    break;
                                case InportFromExamClass.TmType.multiple:
                                    tmtype = "多选题";
                                    break;
                                case InportFromExamClass.TmType.trueorfalse:
                                    tmtype = "判断题";
                                    break;
                                case InportFromExamClass.TmType.fillblank:
                                    tmtype = "填空题";
                                    break;
                                case InportFromExamClass.TmType.subject:
                                    tmtype = "主观题";
                                    break;
                            }

                            if (CommonData.Insert("KS_SJTK", ht))
                            {
                                succNum++;
                                sb.AppendFormat(tplt, tmtype, _em.Tm, Tmnr, Answer, _em.type, "<font color=blue>导入成功！</font>");
                            }
                            else
                            {
                                sb.AppendFormat(tplt, tmtype, _em.Tm, Tmnr, Answer, _em.type, "<font color=red>导入失败！</font>");
                            }

                        }
                    }

                    #endregion
                }
            }
        }
        #endregion
    }

    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 = "　   ├ ";
                }
                if (depth == 4)
                {
                    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;
%>
	<script src="/ks_inc/DatePicker/WdatePicker.js"></script>

   <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="lf">试卷列表</h4><a  href="<%=BasicField.GetUserUrl("SJ/TcSjList","do-add") %>" class="addbtn mt10">+添加试卷</a>
         <div class="top_c_sc mt10">
            <span>试卷名称：</span> 
            <input name="TextBox1" type="text" id="TextBox1" class="textbox" />
            <input type="submit" name="Button4" value=" 搜索 "  id="Button4" class="button" />
         </div>
     </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="6%" align="center">选择</td>
                <td width="6%" align="center">状态</td>            
                <td>试卷名称</td>      
                <td width="15%">更新时间</td>                
                <td  width="100" align="center">编辑</td>
                <td  width="100" align="center">删除</td>
              </tr>
    <%
	  string sqlParam = "KS_SJ Where realtest=0 and inputer='"+new TemporaryVar().UserName+"'";
	  int pagesize = 12;
	  int CurrPage = new BasicField().GetCurrPage;
            int recordcount, pagecount;

            if (!string.IsNullOrEmpty(KSCMS.S("TextBox1")))
            {
				sqlParam += " and title like '%" + KSCMS.S("TextBox1") + "%'";               
            }
             int showType = Utils.StrToInt(KSCMS.S("showType"));
            if (showType > 0)
            {
                if (showType == 100)
                    sqlParam += " and OpenTimeLimit=1";
                else
                    sqlParam += " and dtfs=" + showType;
            }
			using (DataTable dt = DataFactory.GetPage("*", sqlParam, "id", "order by 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=\"sjid\" id=\"sjid\" value=\"" + dr["id"].ToString() + "\" /></span></td>" +
				"<td align=\"center\"><img src=\"/sysimg/user/show" + Utils.StrToInt(dr["verify"].ToString()) + ".gif\" align=\"absbottom\" /></td>" +
				"<td class=\"tag_left lefticon\"><div onmouseover=\"jQuery('#a" + dr["id"].ToString() + "').show();\" onmouseout=\"jQuery('#a" + dr["id"].ToString() + "').hide();\">" +
				 "<a href=\"" + BasicField.GetRewriteUrl("examview",Utils.StrToInt(dr["id"].ToString())) +"\" " + (dr["OpenTimeLimit"].ToString() == "1" ? " title='开考时间限制:" + dr["TimeLimitBegin"].ToString() + "至" + dr["TimeLimitEnd"].ToString() + "'" : "") + "  target=\"_blank\"> <i class=\"icon iconfont icon-IE\"></i></a>[" + MyCache.GetCacheSJCategory(Convert.ToInt32(dr["classid"].ToString()), 1) + "]" +
				Utils.CutStr(Convert.ToString(dr["title"]), 30) +
				  "<span id='a" + dr["id"] + "' style=\"display:none;padding-left:20px;\" class=\"fonths\">" +
				   " <span style=\"display:" + (dr["dtfs"].ToString() == "2" ? "none" : "inline") + ";\">" +
				   "<a href=" + BasicField.GetUserUrl("sj/TcSjAddST", "do-stmanage,sjid-" + dr["id"].ToString() + ",dtfs-" + dr["dtfs"].ToString() + "") + " style=\"color:Gray;\">试题管理</a>" +
				   "<a href=" + BasicField.GetUserUrl("sj/TcSjAddST", "do-add,sjid-" + dr["id"].ToString() + ",dtfs-" + dr["dtfs"].ToString() + "") + " style=\"color:Gray;\"><img src=\"SysImg/teacher/icon08.png\" width=\"12\" align=\"absmiddle\" border=\"0\" style=\"margin:0px 5px 0px 10px\" />添加</a>" +
				  "</span></span></div></td>" +
				"<td align=\"center\" class=\"time-color\">" + dr["adddate"].ToString() + " </td> <td style='text-align:center'><div class=\"gl_btn\">" +
				   "<span class=\"span4\" style=\"width:100%\">" +
						"<a href=\"" + BasicField.GetUserUrl("SJ/TcSjList", "do-modify,sjid-" + dr["id"].ToString() + "") + " \"><i class=\"icon iconfont icon-xiazai48\"></i>编辑</a></span>" +
						"</td><td  style='text-align:center'><div class=\"gl_btn\"><span class=\"span5\" style=\"width:100%\"><a onclick=\"return(confirm(确定删除试卷吗?));\" title=\"删除\" href=\"" + BasicField.GetUserUrl("SJ/TcSjList", "do-del,sjid-" + dr["id"].ToString() + "") + "\"><i class=\"icon iconfont icon-lajitong-copy\"></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">
		  <input type="hidden" name="do" value="del" />
              <input type="checkbox" class="checkbtn" name="chkall" id="chkall" onclick="CheckAll(this.form);" /><label for="chkall">全选</label>
             <input type="button" value="删除记录" class="button" onclick="if (confirm('您确定删除选中试卷吗？')) { this.form.action ='<%=BasicField.GetUserUrl("sj/tcsjlist","do-del")%>'; this.form.submit() }" />
          </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>
		 </form>
	 <%}else{ %>

	  <form name="myform" action="<%=BasicField.GetUserUrl("SJ/TcSjList") %>" method="post" id="Form1" >
	  <input type="hidden" name="action" value="save" />
	   <input type="hidden" name="do" value="<%=KSCMS.S("do") %>" />
	  <input type="hidden" name="sjid" value="<%=KSCMS.S("sjid") %>" />
    <div class="ty_title">添加模拟试卷</div>

    <table width="100%"border="0" cellpadding="0" cellspacing="0" class="border"> 

      <tbody class="fromWordFile" id="inprotClass"<%=KSCMS.S("fromword")=="1"?"":" style='display:none'" %>>
       <tr class="CTitle">
           <td colspan="2" style="text-align:left;"><strong>第一步：上传Word试题</strong></td>
       </tr>
       <tr>
            <td align="right" class="lefttd" height="30" width="140">从Word文件导入：</td>
            <td class="righttd"><table border="0" cellpadding="0" cellspacing="0">
                 <tr>
                  <td width="150" style="padding-left:2px;border-bottom:0px"><iframe src="../../../<%=MyCache.GetCacheConfig(4)%>/include/UpLoad.aspx?FieldID=doc&ChannelID=1"  marginheight="0" marginwidth="0"  width="100%" height="32" frameborder="0" scrolling="no"></iframe></td>
                  <td style="border-bottom:0px"><a href="/admin/exam/word试卷示例.doc" style="color:#54a049">下载Word试卷示例</a></td>
                 </tr>
                </table>
                <input type="text" style="display:inline;position:absolute; left:-9999px;" id="doc" value="0"  />
            </td>
        </tr>
        
        <tr id="sjtm">
            <td align="right" class="lefttd" height="30" >
                试卷的试题内容：
                <div class="clear" style="height:10px"></div>
               <input type="button" class="ty_button" style="margin-left:35px" value="存Word图片" onclick="KesionJS.saveWordPic('admin', '1');" />
                </td>
            <td class="righttd" style="padding-right:2px">
         <textarea name="TxtContent" rows="2" cols="20" id="TxtContent" style="width:100%;height:400px;"></textarea>
                 <%Kesion.APPCode.EditorAPI.EchoHead(); %>
                <% Kesion.APPCode.EditorAPI.EchoEditor("editor", "TxtContent", "Basic");%>
              	<div style="text-align:center;height:40px; line-height:40px;color:#f02e1f;">内容复制到文本框中时，清除复制内容的格式，删除该试卷的标题</div>
            </td>
        </tr>

        <script>
        	function removeHTMLTag(str) {
        		str = str.replace(/<\/?[^>]*>/g, ''); //去除HTML tag
        		str = str.replace(/[ | ]*\n/g, '\n'); //去除行尾空白
        		str = str.replace(/&nbsp;/ig, '');//去掉&nbsp;
        		return str;
        	}
        	jQuery(function(){
        		var ie = !-[1,];  
        		var evs="focus";
        		if (ie) evs="propertychange";

        		jQuery('#inprotClass,#doc').bind(evs, function(){
        			var path = jQuery("#doc").val();
        			if(path == 0)
        			{
        				return;
        			}
        			jQuery.ajax({
        				type: "POST",
        				url: "InportFromWord.ashx",
        				data: "path="+path,
        				success: function(s){
        					if(s.substring(0,3) == "err" && s.indexOf("找不到此文件")==-1)
        					{
        						jQuery.dialog.alert(s);
        						return;
        					}else{
        						var arr=s.split('[PaperNameEnd]');
        						jQuery("#sjtm").show();
        						jQuery("#sjdetail").show();
        						jQuery("#TxtTitle").val(removeHTMLTag(arr[0]));
        						editor1.setContent(arr[1]);
        					}
        				}
        			});
        		});

        	});

        </script>
      <tr class="CTitle">
           <td colspan="2" style="text-align:left"><strong>第二步：录入试卷基本信息</strong></td>
       </tr>
        </tbody>

        <tbody id="sjdetail"<%=KSCMS.S("fromword")=="1"?" style='display:nones'":"" %>>
          <tr>
            <td class="lefttd" height="30" align="right">模拟试卷名称：</td>
            <td class="tag_left">
                 <input name="TxtTitle" type="text" id="TxtTitle" class="textbox" value="<%=GetParam("title") %>" style="width:325px;" />
                <span id="RequiredFieldValidator1" style="color:Red;display:none;">请填写试卷名称!</span><span class="tips">必填：如（2017年仿真高考数学卷）等</span>         
				    </td>
        </tr>
        <tr>

             <td align="right" class="lefttd" height="30">试卷分类：</td>
            <td class="tag_left">
               
                <select name="DrpClassID" id="DrpClassID">
				<%
        string selceted = "," + __info.ClassID + ",";
        string str = GetBusiness(selceted);

       KSCMS.W(str);
				 %>
				</select>

            </td>

        </tr><% if (MyCache.GetSJCacheConfig(4) == "1")
                             { %>
                <%}else{ %><span style="display:none"><tr><%} %>
            	
             <td align="right" class="lefttd" height="30">试卷类别：</td>
             <td class="tag_left">
            <select name="DrpSJTypeID" id="DrpSJTypeID">
		<%
		sb.Clear();
		   string sqlStr = "select * from KS_SJType Order By OrderID,Typeid";
		   using (DataTable dt = DataFactory.GetDataTable(sqlStr))
		   {
			   if (dt.Rows.Count > 0)
			   {
				   string selectItem = "0";
				   foreach (DataRow dr in dt.Rows)
				   {
					   string selected = "";
					   if (Utils.StrToInt(dr["isdefault"].ToString()) == 1)
					   {
						   selected = "selected";
					   }
					   sb.AppendFormat("<option value=\"{0}\" {2}>{1}</option>", dr["typeid"].ToString(), dr["typename"].ToString(), selected);
	
				   }
			   }
			   KSCMS.W(sb.ToString());
		   }
		
		 %>
	</select>
              <font class="tips">可不选</font>
              </td>
              </tr>
              </span>
              <% if (MyCache.GetSJCacheConfig(3) == "1")
                             { %>
                <%}else{ %><span style="display:none"><tr><%} %>
              	<td align="right" class="lefttd" height="30">试卷地区：</td>
                <td class="tag_left">
          <select name="DrpProvince" id="DrpProvince">

		  <%
		  sb.Clear();
		   sqlStr = "select id,city from ks_area where parentid=0 order by orderid,id";
            using (DataTable dt = DataFactory.GetDataTable(sqlStr))
            {
                if (dt.Rows.Count > 0)
                {
                    foreach (DataRow dr in dt.Rows)
                    {
						string selected = "";
						if (GetParam("provinceid").Equals(dr["id"].ToString()))
						{
							selected = "selected";
						}
						sb.AppendFormat("<option value=\"{0}\" {2}>{1}</option>", dr["id"].ToString(), dr["city"].ToString(), selected);
                    
                    }
                }
				KSCMS.W(sb.ToString());
            }
		   %>

		  </select>
               <font class="tips">可不选</font>
               </td>
               </tr>
               </span>

           
		 <tr>
            <td align="right" class="lefttd" height="30" style="width: 102px">开考时间限制：</td>
            <td class="tag_left">
                <span id="ctl00_KSContent_RdbLimitDate" onclick="showvaliddate();">
				<input id="ctl00_KSContent_RdbLimitDate_0" type="radio" name="RdbLimitDate" value="1" <%=GetParam("OpenTimeLimit")=="1"?"checked":"" %> />
				<label for="ctl00_KSContent_RdbLimitDate_0">启用</label>
				<input id="ctl00_KSContent_RdbLimitDate_1" type="radio" name="RdbLimitDate" value="0" <%=GetParam("OpenTimeLimit")=="0" ?"checked":string.IsNullOrEmpty(GetParam("OpenTimeLimit"))?"checked":"" %> />
				<label for="ctl00_KSContent_RdbLimitDate_1">不启用</label></span>
            </td>
        </tr>

        <tr style="display:none" id="datearea">    
        	 <td align="right" class="lefttd" height="30" style="width: 102px">&nbsp;</td>
             <td class="tag_left">
               
                <script>  isHour = 1;</script>
                有效期： &nbsp; 从 &nbsp; 
				<input name="TxtBeginTime" type="text" value="<%=GetParam("TimeLimitBegin")%>" id="TxtBeginTime" class="textbox" onclick="WdatePicker({dateFmt:&#39;yyyy-MM-dd HH:mm:ss&#39;});" style="width:160px; padding-left:0px; text-align:center" /> &nbsp; 
				至 &nbsp;
				<input name="TxtEndTime" type="text" value="<%=GetParam("TimeLimitEnd") %>" id="TxtEndTime" class="textbox" onclick="WdatePicker({dateFmt:&#39;yyyy-MM-dd HH:mm:ss&#39;});" style="width:160px; padding-left:0px; text-align:center" />
               <script>
               	jQuery(document).ready(function () {
               		showvaliddate();
               	});
               	function showvaliddate() {
               		var checkrad = jQuery("#ctl00_KSContent_RdbLimitDate :radio[checked]").val();
                   	if (checkrad == "1") {
                   		jQuery("#datearea").show();
                   	} else {
                   		jQuery("#datearea").hide();
                   	}
                   }
               </script>

           </td>
        </tr>       

        <tr>
            <td align="right" class="lefttd" height="30">考试时间：
              </td>
            <td class="tag_left"><input name="TxtKSSJ" type="text" value="<%=Utils.StrToInt(GetParam("kssj"))<=0?"60":GetParam("kssj") %>" id="TxtKSSJ" class="textbox nopleft" style="width:50px;text-align:center" /> 分钟 &nbsp;  &nbsp; 
			试卷总分：<input name="TxtScore" type="text" value="<%=string.IsNullOrEmpty(GetParam("score"))?"100":GetParam("score") %>" id="TxtScore" class="textbox nopleft" style="width:50px;text-align:center" /> 分 &nbsp;  &nbsp; 
			答卷次数：<input name="TxtTimes" type="text" value="<%=string.IsNullOrEmpty(GetParam("times"))?"0":GetParam("times") %>" id="TxtTimes" class="textbox nopleft" style="width:50px;text-align:center" />
              <span class="tips">如果每份考卷只允许每位会员答1次请输入“<font>1</font>”，不限制请输入“<font>0</font>”。</span></td>
        </tr>
       
        
        <tr>
            <td align="right" class="lefttd" height="30">应用成绩等级：</td>
            <td class="tag_left">
             <select name="DrpCjdID" id="DrpCjdID">
		 <%
		  sb.Clear();
		     sqlStr = "select id,itemname From KS_SJCJD order by orderid,id desc";
            using (DataTable dt = DataFactory.GetDataTable(sqlStr))
            {
                if (dt.Rows.Count > 0)
                {
                    foreach (DataRow dr in dt.Rows)
                    {
						string selected = "";
						if (GetParam("cjdid").Equals(dr["id"].ToString()))
						{
							selected = "selected";
						}
						sb.AppendFormat("<option value=\"{0}\" {2}>{1}</option>", dr["id"].ToString(), dr["itemname"].ToString(), selected);
                    }
                }
				KSCMS.W(sb.ToString());
            }
		   %>
	</select>         
             </td>
        </tr>       
     
      <tr >
            <td align="right" class="lefttd" height="30">试题添加方式：</td>
            <td class="tag_left">
             <select name="dtfs" id="Drpdtfs" onclick="showrnd();" >
		<option value="1" <%=GetParam("dtfs")=="1"?"selected":"" %>>整份添加</option>
    	<option value="3" <%=(GetParam("dtfs")=="3" || KSCMS.S("dtfs")=="3") ?"selected":"" %>>手工组卷</option>

	
	</select>
            </td>
       </tr>


       <tr style="display:none">      
       	 	<td align="right" class="lefttd" height="30">作答方式：</td>
            <td class="tag_left">
            <select name="DrpDoExamWay" id="DrpDoExamWay">
		<option selected="selected" value="2">仅整卷方式(试题按题型显示)</option>

	</select>
            </td>
        </tr>

        <tr>
            <td align="right" class="lefttd" height="30">试卷介绍：</td>
            <td class="tag_left">
             <textarea name="TxtIntro" rows="2" id="TxtIntro" class="textbox" style="width:800px;height:150px;"><%=GetParam("intro") %></textarea> 
               <% Kesion.APPCode.EditorAPI.EchoEditor("editor", "TxtIntro", "Basic",0,false,true,true,false);%>

             </td>
        </tr>
         
         <tr>
            <td align="right" class="lefttd" height="30">关键字Tags：</td>
            <td class="tag_left">
             <input name="TxtKeyTags" type="text" value="<%=GetParam("keytags") %>" id="TxtKeyTags" class="textbox" style="width:300px;" /> 

            【<a href='javascript:;' onclick='GetKeyTags()' style='color:#54a049'>根据试卷名称自动获取Tags</a>】&nbsp;&nbsp;<font class='tips'>多个tags请用空格隔开</font>
             </td>
        </tr> 
            
            <tr style="display:none">
             <td align="right" class="lefttd" height="30">所需<%=MyCache.GetCacheConfig(49) %>：</td>
             <td class="tag_left">
			 <input name="TxtMoney" type="text" value="<%=GetParam("money") %>" id="TxtMoney" class="textbox nopleft" style="width:50px;text-align:center" />

			 <span class="tips" style="padding-left:5px"><%=MyCache.GetCacheConfig(50) %>，免费请输入“<font>0</font>”</span>
             </td>
        </tr>
        </tbody>

        

        </table>

     <div id="labsjinfo" style="display:none"><%=stk.ToString() %> </div>

      <div class="cz_btn nofloat" style="padding:10px 0px 0px 192px">
      		<span><input type="submit" name="Button2" value="确定保存" onclick="return(CheckForm());" id="Button2" class="button" /></span>
            <span><input type="button" class="button" onclick="window.history.go(-1);"value=" 返 回 "></span>
      </div>	   
      <div class="clear blank20"></div>



	  </form>


		<%} %>
      </div>
	  

	   <script>
	       jQuery(document).ready(function () {
	           showrnd();
	       });
	       function showrnd() {
	           var checkrad = jQuery("#Drpdtfs").val();
	           if (checkrad == "3") {
	               jQuery("#rnd_st").show();
	           } else {
	               jQuery("#rnd_st").hide();
	           }
	       }


	   	function CheckForm() {
	   		if (jQuery('#TxtTitle').val() == '') {
	   			KesionJS.Alert('试卷名称必须输入!', "jQuery('#TxtTitle').focus()");
	   			return false;
	   		}
	   		if (jQuery('#DrpClassID').val() == '0') {
	   			KesionJS.Alert('请选择试卷分类!', "jQuery('#DrpClassID').focus()");
	   			return false;
	   		}
	   		return true;
	   	}
	   	function GetKeyTags() {
	   		var text = escape(jQuery('#TxtTitle').val());
	   		if (text != '') {
	   			jQuery('#TxtKeyTags').val('请稍等,系统正在自动获取tags...').attr("disabled", true);
	   			jQuery.get("../../plus/ajaxs.ashx", { a: "GetTags", text: text },
				  function (data) { jQuery('#TxtKeyTags').val(unescape(data)).attr("disabled", false); });
	   		} else { KesionJS.Alert('对不起,请先输入试卷名称!', "jQuery('#TxtTitle').focus();"); }
	   	}


    </script>