protected void btnSave_Click1(object sender, EventArgs e) { if (string.IsNullOrEmpty(txtbQuestionNo.Text)) { MessageBox.ShowAndRedirect(this, "请添加题号信息", "QuestionList.aspx?dimID=" + ddlDeminsion.SelectedValue); return; } QuestionBLL questionBll = new QuestionBLL(); Question temp = new Question(); temp.Question_no = int.Parse(txtbQuestionNo.Text.Trim()); temp.Question_typeid = 1;//单选题 temp.Question_status = 1;//0:禁用状态 1:启用状态 temp.Question_title = fckEtitle.Value.Replace("<p>", "").Replace("</p>", ""); temp.Question_dimensionid = int.Parse(ddlDeminsion.SelectedValue); temp.Question_answer_A = fckEA.Value.Replace("<p>", "").Replace("</p>", ""); temp.Question_answer_A_score = txtbAscore.Text.Trim().Equals(string.Empty) ? 0 : int.Parse(txtbAscore.Text.Trim()); temp.Question_answer_B = fckEB.Value.Replace("<p>", "").Replace("</p>", ""); temp.Question_answer_B_score = txtbBscore.Text.Trim().Equals(string.Empty) ? 0 : int.Parse(txtbBscore.Text.Trim()); temp.Question_answer_C = fckEC.Value.Replace("<p>", "").Replace("</p>", ""); temp.Question_answer_C_score = txtbCscore.Text.Trim().Equals(string.Empty) ? 0 : int.Parse(txtbCscore.Text.Trim()); temp.Question_answer_D = fckED.Value.Replace("<p>", "").Replace("</p>", ""); temp.Question_answer_D_score = txtbDscore.Text.Trim().Equals(string.Empty) ? 0 : int.Parse(txtbDscore.Text.Trim()); temp.Question_answer_E = fckEE.Value.Replace("<p>", "").Replace("</p>", ""); temp.Question_answer_E_score = txtbEscore.Text.Trim().Equals(string.Empty) ? 0 : int.Parse(txtbEscore.Text.Trim()); if (Request.QueryString["question_id"] == null) { int nRows = questionBll.Add(temp); if (nRows > 0) { MessageBox.ShowAndRedirect(this, "条目添加成功", "QuestionList.aspx?dimID=" + ddlDeminsion.SelectedValue); } else { MessageBox.ShowAndRedirect(this, ADD_QUESTION_ERROR, "QuestionList.aspx?dimID=" + ddlDeminsion.SelectedValue); return; } } else { temp.Question_id = int.Parse(Request.QueryString["question_id"].ToString()); int resultTemp = questionBll.Update(temp); if (resultTemp > 0) { MessageBox.ShowAndRedirect(this, "条目修改成功", "QuestionList.aspx?dimID=" + ddlDeminsion.SelectedValue); } else { MessageBox.ShowAndRedirect(this, ADD_QUESTION_ERROR, "QuestionList.aspx?dimID=" + ddlDeminsion.SelectedValue); return; } } }
protected void Page_Load(object sender, EventArgs e) { if (Session["isTesting"] == null)//如果没有输入序列号,则禁止访问此页面 { Response.Redirect("Tlogin.aspx"); } btnNext.Enabled = false; if (!IsPostBack) { if (Request.QueryString["logopath"] != null) { if (string.IsNullOrEmpty(Request.QueryString["logopath"])) { usrLogo.ImageUrl = "~/images/5050.jpg"; usrLogo.Visible = false; } else { usrLogo.ImageUrl = Request.QueryString["logopath"].ToString().Replace("\\", "/"); } } string companyName = string.Empty; int totalMinutes = 50; int xiaxian = 0; int shangxian = 0; if (!string.IsNullOrEmpty(Request.QueryString["guid"])) { GuidBLL gbll = new GuidBLL(); QuestionBLL qbll = new QuestionBLL(); ActivityBLL abll = new ActivityBLL(); int aID = gbll.GetActivityId(Request.QueryString["guid"]); totalMinutes = qbll.GetQuestionTimeByGUID(Request.QueryString["guid"],1) / 60; xiaxian = qbll.GetQuestionTimeByGUID(Request.QueryString["guid"], 2) / 60; shangxian = qbll.GetQuestionTimeByGUID(Request.QueryString["guid"], 3) / 60; DataSet ds = abll.GetEUsrInfoByActivityId(aID); if (ds != null) { companyName = ds.Tables[0].Rows[0]["users_incname"].ToString(); } } txtWelcome.Text = @" 欢迎您参加" + companyName + "组织的题目测试,本次测试需要" + xiaxian.ToString() + "-" + shangxian.ToString() + "分钟左右的时间。"; } }
private void bind() { QuestionBLL qbl = new QuestionBLL(); DataSet dsQuestion = qbl.GetQuestionByActivityIDRand(m_actid); if (dsQuestion != null && dsQuestion.Tables[0].Rows.Count > 0) { rpCust.DataSource = GenerateGuid.SelectTop(20, dsQuestion.Tables[0]); rpCust.DataBind(); } else { Response.Write("<script language='javascript'>alert('没有相应的题目,请检查该测评项目的维度设置!');</script>"); Response.Write("<script language='javascript'>window.close()</script>"); } }
protected void btnDelete_Click(object sender, EventArgs e) { QuestionBLL temp = new QuestionBLL(); int selectCount = 0; int question_id = 0; foreach (GridViewRow gr in grVQuestionManage.Rows) { CheckBox chk = (CheckBox)gr.Cells[0].FindControl("CB_Select"); if (chk.Checked) { question_id = int.Parse(grVQuestionManage.DataKeys[gr.RowIndex].Values[0].ToString()); temp.Delete(question_id); selectCount++; } } if (0 == selectCount) { //MessageBox.Show("对不起,你没有选择记录!"); } temp = null; Response.Redirect(Request.Url.ToString()); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (Session["isTesting"] == null)//如果没有输入序列号,则禁止访问此页面 { Response.Redirect("Tlogin.aspx"); } if (Request.QueryString["logopath"] != null) { if (string.IsNullOrEmpty(Request.QueryString["logopath"])) { usrLogo.ImageUrl = "~/images/5050.jpg"; usrLogo.Visible = false; } else { usrLogo.ImageUrl = Request.QueryString["logopath"].ToString().Replace("\\","/"); } } if (Request["guid"] != null) { if (CacheManager.Get("guid_" + Request["guid"].ToString()) == null) { CacheManager.Add("guid_" + Request["guid"].ToString(), 1, null); } if (CacheManager.Get("currentQNumber_" + Request["guid"].ToString()) == null) { CacheManager.Add("currentQNumber_" + Request["guid"].ToString(), 0, "guid"); } //计算总时间 if (CacheManager.Get("QuestionTotalMinutes_" + Request["guid"].ToString()) == null) { CacheManager.Add("QuestionTotalMinutes_" + Request["guid"].ToString(), m_QuestionBll.GetQuestionTimeByGUID(Request["guid"].ToString(),1), ""); } if (CacheManager.Get("question_dt_" + Request["guid"].ToString()) == null) { QuestionBLL qbl = new QuestionBLL(); DataSet dsQuestion = qbl.GetQuestionByGUIDRand(Request["guid"].ToString(), out m_QuestionNum); if (dsQuestion == null || dsQuestion.Tables[0].Rows.Count < 1) { MessageBox.ShowAndRedirect(this, "找不到相应的题目,请检查测评项目的维度设置!!", "Tlogin.aspx"); return; } DataTable dtQuestion = dsQuestion.Tables[0]; CacheManager.Add("question_dt_" + Request["guid"].ToString(), dtQuestion, "guid"); //增加2个特殊题目 DataRow dataRow = dtQuestion.NewRow(); dataRow[0] = -1; dataRow[1] = 0; dataRow[2] = "现实很难讲清楚什么是对的,什么是错的"; dataRow[3] = "是"; dataRow[4] = "不是"; dataRow[8] = 0; dataRow[9] = 0; dataRow[13] = 0; dataRow[14] = 0; dataRow[15] = 0; DataRow dataRow2 = dtQuestion.NewRow(); dataRow2[0] = -2; dataRow2[1] = 0; dataRow2[2] = "现实很难讲清楚什么是对的,什么是错的"; dataRow2[3] = "是"; dataRow2[4] = "不是"; dataRow2[8] = 0; dataRow2[9] = 0; dataRow2[13] = 0; dataRow2[14] = 0; dataRow2[15] = 0; ((DataTable)CacheManager.Get("question_dt_" + Request["guid"].ToString())).Rows.InsertAt(dataRow, 0); CacheManager.Add("questionNum_" + Request["guid"].ToString(), m_QuestionNum, "guid"); ((DataTable)CacheManager.Get("question_dt_" + Request["guid"].ToString())).Rows.InsertAt(dataRow2, m_QuestionNum + 1); //智力类题目的标志位 if (CacheManager.Get("zhiliFlag_" + Request["guid"].ToString()) == null) { CacheManager.Add("zhiliFlag_" + Request["guid"].ToString(), m_QuestionNum.ToString(), ""); } //智力类题目的标志位 } int nCur = (int)CacheManager.Get("currentQNumber_" + Request["guid"].ToString()); bind(nCur); lblPosition.Text= m_TesterInfoBll.GetPositionByGUID(Request["guid"].ToString()); lblName.Text = m_TesterInfoBll.GetUserNameByGUID(Request["guid"].ToString()); //记录答题者开始考试时间 m_TesterInfoBll.UpdateTesterInfo(Request["guid"].ToString(), "tester_teststarttime", DateTime.Now.ToString()); //记录开始答题时间 if (CacheManager.Get("QuestionUsedMinutes_" + Request["guid"].ToString()) == null) { DataSet ds = m_TesterInfoBll.GetListByGuid(Request["guid"].ToString()); if (ds != null) { DateTime dtStart = DateTime.Parse(ds.Tables[0].Rows[0]["tester_teststarttime"].ToString()); CacheManager.Add("QuestionUsedMinutes_" + Request["guid"].ToString(), dtStart, ""); } } //测试中 m_GuidBll.UpdateStatus(Request["guid"].ToString(), 1); } } updateQuestionProgress(); updateTimeProgress(); }
protected void BtnLogin_Click(object sender, ImageClickEventArgs e) { if (!txtValidate.Text.ToUpper().Equals(Session["CheckCode"].ToString())) { MessageBox.ShowAndRedirect(this, "您输入的验证码有误,请重新输入!", "Tlogin.aspx"); return; } GuidBLL guidBll = new GuidBLL(); QuestionBLL qBll = new QuestionBLL(); ActivityBLL aBll = new ActivityBLL(); string userGUID = txtPart1.Text.Trim().ToUpper(); int status = guidBll.GetStatus(userGUID); int nActID = guidBll.GetActivityId(userGUID); Activity activity = aBll.GetModel(nActID); if (-1 == status)//无效序列号 { MessageBox.ShowAndRedirect(this, "您好,序列号无效,请输入正确的8位序列号", "Tlogin.aspx"); } else if (2 == status)//测试完成过的序列号,如果测评项目允许查看报告,则跳转至相关界面。 { if (activity != null && activity.Activity_viewreport.ToString().Substring(0,1).Equals("1")) { MessageBox.ShowAndRedirect(this, "您好,该序列号已经测试完成,将转入报告查看页面", "../Report/GenPdfReport.aspx?sn=" + userGUID); } else { MessageBox.ShowAndRedirect(this, "您好,该序列号已经测试完成", "Tlogin.aspx"); } } else if (0 == status || 1 == status)//正常,未使用过的序列号,或者正在测试的。 { if (activity != null) { //是否为禁用的活动状态 if (activity.Activity_status == 0) { MessageBox.ShowAndRedirect(this, "您好,您参加的测评项目未开启,请联系发放序列号的相关人员", "Tlogin.aspx"); } else { Session["isTesting"] = "true";//开始考试 if (status == 1 && CacheManager.Get("guid_" + userGUID) != null) { MessageBox.ShowAndRedirect(this, "将继续上次答题", "QuestionRepeat.aspx?guid=" + userGUID + "&logopath=" + activity.Activity_logo); } else { Response.Redirect("Introduce.aspx?guid=" + userGUID + "&logopath=" + activity.Activity_logo + "&weltext=" + activity.Activity_welcometext.Replace("\n", "") + "&atext=" + activity.Activity_content.Replace("\n", "") + "&ctext=" + activity.Activity_companyintrotext.Replace("\n", "")); } } } } else { MessageBox.ShowAndRedirect(this, "您好,该序列号无效", "Tlogin.aspx"); } }
protected void btnExport_Click(object sender, EventArgs e) { //导出到Excel QuestionBLL quesitionBll = new QuestionBLL(); DataSet ds = quesitionBll.GetQuestionByDimension(ddlDimension.SelectedValue); ds.Tables[0].Columns[0].ColumnName = "库内题号"; DataColumn dc = new DataColumn(); dc.DataType = Type.GetType("System.String"); dc.ColumnName = "维度名称"; dc.DefaultValue = ddlDimension.SelectedItem.ToString(); ds.Tables[0].Columns.Add(dc); ds.Tables[0].Columns["维度名称"].SetOrdinal(1); ds.Tables[0].Columns[1].DefaultValue = ddlDimension.SelectedItem.ToString(); ds.Tables[0].Columns.Add("鉴别度", Type.GetType("System.String")); ds.Tables[0].Columns["鉴别度"].SetOrdinal(2); ds.Tables[0].Columns.Add("难度", Type.GetType("System.String")); ds.Tables[0].Columns["难度"].SetOrdinal(3); ds.Tables[0].Columns[4].ColumnName = "维度库内编号"; ds.Tables[0].Columns[5].ColumnName = "题干内容"; ds.Tables[0].Columns.Add("最后修改时间", Type.GetType("System.DateTime")); ds.Tables[0].Columns["最后修改时间"].SetOrdinal(6); ds.Tables[0].Columns[7].ColumnName = "选项A内容"; ds.Tables[0].Columns[8].ColumnName = "选项B内容"; ds.Tables[0].Columns[9].ColumnName = "选项C内容"; ds.Tables[0].Columns[10].ColumnName = "选项D内容"; ds.Tables[0].Columns[11].ColumnName = "选项E内容"; ds.Tables[0].Columns[12].ColumnName = "选项A分值"; ds.Tables[0].Columns[13].ColumnName = "选项B分值"; ds.Tables[0].Columns[14].ColumnName = "选项C分值"; ds.Tables[0].Columns[15].ColumnName = "选项D分值"; ds.Tables[0].Columns[16].ColumnName = "选项E分值"; ds.Tables[0].Columns.Remove("question_dimensionid"); ds.Tables[0].Columns.Remove("question_status"); ds.Tables[0].Columns.Remove("question_typeid"); string filePath = Server.MapPath("../userfiles") + @"\question_" + DateTime.Now.ToString("yyyyMMdd_HH_mm_ss") + ".xls"; string fileName = Path.GetFileName(filePath); ExcelLibrary.DataSetHelper.CreateWorkbook(filePath, ds); Stream stream = null; stream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read); long bytesToRead = stream.Length; Response.Clear(); Response.ContentType = "application/ms-excel"; Response.AddHeader("Content-Disposition", "attachment; filename=" + fileName); while (bytesToRead > 0) { if (Response.IsClientConnected) { byte[] buffer = new Byte[10000]; int length = stream.Read(buffer, 0, 10000); Response.OutputStream.Write(buffer, 0, length); Response.Flush(); bytesToRead = bytesToRead - length; } else { bytesToRead = -1; } } }
private void bind() { DimensionBLL dimensionBll = new DimensionBLL(); DataSet dsPosition = dimensionBll.GetDimensionAll(); ddlDimension.DataSource = dsPosition.Tables[0].DefaultView; ddlDimension.DataValueField = "dimension_id"; ddlDimension.DataTextField = "dimension_name"; ddlDimension.DataBind(); if (Request.QueryString["dimID"] != null) { ddlDimension.SelectedValue = Request.QueryString["dimID"]; } QuestionBLL quesitionBll = new QuestionBLL(); DataSet ds = quesitionBll.GetQuestionByDimension(ddlDimension.SelectedValue); grVQuestionManage.DataSource = ds.Tables[0].DefaultView; grVQuestionManage.DataSourceID = null; grVQuestionManage.DataBind(); quesitionBll = null; dimensionBll = null; }
protected void GrVQuestionList_RowCommand(object sender, GridViewCommandEventArgs e) { int rowIndex = Int32.Parse(e.CommandArgument.ToString());//获取点击了第几行 if (e.CommandName == "DisableQuestion") { string strStatus = ((Button)grVQuestionManage.Rows[rowIndex].Cells[6].Controls[0]).Text; string questionid = grVQuestionManage.DataKeys[rowIndex].Values[0].ToString(); QuestionBLL temp = new QuestionBLL(); switch (strStatus) { case "启用": if (temp.UpdateQuestionStatus(questionid, false) != -1) { MessageBox.ShowAndRedirect(this, "已成功开启", "QuestionList.aspx?dimID=" + ddlDimension.SelectedValue); } break; case "禁用": if (temp.UpdateQuestionStatus(questionid, true) != -1) { MessageBox.ShowAndRedirect(this, "已成功禁用", "QuestionList.aspx?dimID=" + ddlDimension.SelectedValue); } break; default: break; } } }
protected void GridView1_IndexChanging(object sender, GridViewPageEventArgs e) { this.grVQuestionManage.PageIndex = e.NewPageIndex; QuestionBLL quesitionBll = new QuestionBLL(); DataSet ds = quesitionBll.GetQuestionAll(); grVQuestionManage.DataSource = ds.Tables[0].DefaultView; grVQuestionManage.DataSourceID = null; grVQuestionManage.DataBind(); quesitionBll = null; }
protected void ddlDimension_SelectedIndexChanged(object sender, EventArgs e) { QuestionBLL quesitionBll = new QuestionBLL(); DataSet ds = quesitionBll.GetQuestionByDimension(ddlDimension.SelectedValue); grVQuestionManage.DataSource = ds.Tables[0].DefaultView; grVQuestionManage.DataSourceID = null; grVQuestionManage.DataBind(); }
private bool ImportQuestion(string xlsFileNm) { try { xlsFileNm = @"E:\Project\svn_all\exam-report\需求文档\功能调试版题库(维度仍旧在增加).xls"; if (!File.Exists(xlsFileNm)) return false; Workbook book = Workbook.Load(xlsFileNm); //Worksheet sheet = book.Worksheets[0]; DimensionBLL dimBLL = new DimensionBLL(); QuestionBLL qesBLL = new QuestionBLL(); Question question = new Question(); DataSet dimDS = dimBLL.GetDimensionAll(); foreach (Worksheet sheet in book.Worksheets) { if (sheet.Name.Trim().Equals("说明")) { continue; } string sheetNm = sheet.Name.Trim(); int dimID = -1;//在这里加断点可以监视单个维度的导入情况 foreach (DataRow row in dimDS.Tables[0].Rows) { if (row["dimension_name"].ToString().Equals(sheetNm)) { dimID = Int32.Parse(row["dimension_id"].ToString().Trim()); break; } } for (int rowIndex = sheet.Cells.FirstRowIndex + 2;//忽略第一行(标题行) rowIndex <= sheet.Cells.LastRowIndex; rowIndex++) { Row row = sheet.Cells.GetRow(rowIndex); question.Question_no = Int32.Parse(row.GetCell(0).StringValue.Trim()); question.Question_title = row.GetCell(5).StringValue.Trim(); question.Question_answer_A = row.GetCell(6).StringValue.Trim(); question.Question_answer_B = row.GetCell(7).StringValue.Trim(); question.Question_answer_C = row.GetCell(8).StringValue.Trim(); question.Question_answer_D = row.GetCell(9).StringValue.Trim(); question.Question_answer_E = row.GetCell(10).StringValue.Trim(); question.Question_answer_A_score = row.GetCell(11).StringValue.Trim().Equals(string.Empty) ? 0 : Int32.Parse(row.GetCell(11).StringValue.Trim()); question.Question_answer_B_score = row.GetCell(12).StringValue.Trim().Equals(string.Empty) ? 0 : Int32.Parse(row.GetCell(12).StringValue.Trim()); question.Question_answer_C_score = row.GetCell(13).StringValue.Trim().Equals(string.Empty) ? 0 : Int32.Parse(row.GetCell(13).StringValue.Trim()); question.Question_answer_D_score = row.GetCell(14).StringValue.Trim().Equals(string.Empty) ? 0 : Int32.Parse(row.GetCell(14).StringValue.Trim()); question.Question_answer_E_score = row.GetCell(15).StringValue.Trim().Equals(string.Empty) ? 0 : Int32.Parse(row.GetCell(15).StringValue.Trim()); question.Question_typeid = 1;//1 单选 question.Question_status = 1;//1 有效 if (dimID > 0) { question.Question_dimensionid = dimID; } else { MessageBox.Show("Error"); return false; } qesBLL.Add(question); } } MessageBox.Show("题目导入成功"); return true; } catch (Exception ex) { MessageBox.Show(ex.Message); return false; } }
private bool ImportQuestion(string xlsFileNm,ArrayList arDimID) { try { if (!File.Exists(xlsFileNm)) return false; Workbook book = Workbook.Load(xlsFileNm); DimensionBLL dimBLL = new DimensionBLL(); QuestionBLL qesBLL = new QuestionBLL(); Question question = new Question(); DataSet dimDS = dimBLL.GetDimensionAll(); //qesBLL.DeleteAllQuestion(); for (int k = 0; k < arDimID.Count; k++) { qesBLL.DeleteQuestionByDim(Int32.Parse(arDimID[k].ToString())); } string dName = string.Empty; for (int i = 0; i < arDimID.Count; i++) { dName = dimBLL.GetDimension(arDimID[i].ToString()).Dimnm; foreach (Worksheet sheet in book.Worksheets) { string sheetNm = sheet.Name.Trim(); if (sheetNm.Equals("说明")) { continue; } if (false == sheetNm.Equals(dName)) { continue; } int dimID = -1;//在这里加断点可以监视单个维度的导入情况 foreach (DataRow row in dimDS.Tables[0].Rows) { if (row["dimension_name"].ToString().Equals(sheetNm)) { dimID = Int32.Parse(row["dimension_id"].ToString().Trim()); break; } } if (dimID < 1) { string msg = "Excel工作表中存在的[" + sheet.Name + "]维度在系统维度表中不存在!" + Environment.NewLine + "请先确保Excel工作表中的维度名称在系统中存在,然后再执行导入操作"; //Response.Write("<script>...alert('" + msg + "')</script>"); MessageBox.ShowMessage(msg); continue; } for (int rowIndex = sheet.Cells.FirstRowIndex + 2;//忽略第一行(标题行) rowIndex <= sheet.Cells.LastRowIndex; rowIndex++) { Row row = sheet.Cells.GetRow(rowIndex); question.Question_no = Int32.Parse(row.GetCell(0).StringValue.Trim()); question.Question_title = row.GetCell(5).StringValue.Trim(); question.Question_answer_A = row.GetCell(6).StringValue.Trim(); question.Question_answer_B = row.GetCell(7).StringValue.Trim(); question.Question_answer_C = row.GetCell(8).StringValue.Trim(); question.Question_answer_D = row.GetCell(9).StringValue.Trim(); question.Question_answer_E = row.GetCell(10).StringValue.Trim(); question.Question_answer_A_score = row.GetCell(11).StringValue.Trim().Equals(string.Empty) ? 0 : Int32.Parse(row.GetCell(11).StringValue.Trim()); question.Question_answer_B_score = row.GetCell(12).StringValue.Trim().Equals(string.Empty) ? 0 : Int32.Parse(row.GetCell(12).StringValue.Trim()); question.Question_answer_C_score = row.GetCell(13).StringValue.Trim().Equals(string.Empty) ? 0 : Int32.Parse(row.GetCell(13).StringValue.Trim()); question.Question_answer_D_score = row.GetCell(14).StringValue.Trim().Equals(string.Empty) ? 0 : Int32.Parse(row.GetCell(14).StringValue.Trim()); question.Question_answer_E_score = row.GetCell(15).StringValue.Trim().Equals(string.Empty) ? 0 : Int32.Parse(row.GetCell(15).StringValue.Trim()); question.Question_typeid = 1;//1 单选 question.Question_status = 1;//1 有效 if (dimID > 0) { question.Question_dimensionid = dimID; } else { break; } qesBLL.Add(question); } } } return true; } catch (Exception ex) { string errMsg = ex.Message; return false; } }