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; } } }
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; } }