private void btnDelete_Click(object sender, EventArgs e) { this.Cursor = Cursors.WaitCursor; if (this.dgExam.CurrentRow != null) { if (this.dgExam[0, this.dgExam.CurrentRow.Index].Value != null) { String examSeq = this.dgExam[0, this.dgExam.CurrentRow.Index].Value.ToString(); ExamQuestionDao examQuestionDao = new ExamQuestionDao(); examQuestionDao.Delete(examSeq); ExamDao examDao = new ExamDao(); examDao.Delete(examSeq); prepareGrid(this.txtSearchCondition.Text.Trim()); } } }
private void btnSave_Click(object sender, EventArgs e) { if (String.IsNullOrEmpty(this.txtExamName.Text.Trim())) { MessageBox.Show("名称不能为空"); txtExamName.Focus(); return; } if (this.dtEndDate.Value.CompareTo(this.dtStartDate.Value) <= 0) { MessageBox.Show("有效期结束时间必须大于开始时间"); return; } this.Cursor = Cursors.WaitCursor; Exam exam = new Exam(); if (rdoExam.Checked) { exam.type = "Exam"; } if (rdoSurvey.Checked) { exam.type = "Survey"; } if (String.IsNullOrEmpty(exam.type)) { MessageBox.Show("请选择试题类型"); return; } exam.subject = this.txtExamName.Text; //exam.type = "Exam"; exam.validateStartTime = this.dtStartDate.Value.ToString("yyyy-MM-dd"); exam.validateEndTime = this.dtEndDate.Value.ToString("yyyy-MM-dd"); exam.creatTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); exam.isValidate = "Y"; exam.agentType = this.cboAgentType.Text; ExamDao examDao = new ExamDao(); examDao.Add(exam); exam = examDao.GetByName(exam.subject); if (exam != null) { ExamQuestionDao examQuestionDao = new ExamQuestionDao(); for (int i = 0; i < this.dgExamSingleChoice.RowCount; i++) { ExamQuestion examQuestion = new ExamQuestion(); examQuestion.question = dgExamSingleChoice[0, i].Value.ToString(); examQuestion.answer = dgExamSingleChoice[1, i].Value.ToString(); examQuestion.option1 = dgExamSingleChoice[2, i].Value.ToString(); examQuestion.option2 = dgExamSingleChoice[3, i].Value.ToString(); examQuestion.option3 = dgExamSingleChoice[4, i].Value.ToString(); examQuestion.option4 = dgExamSingleChoice[5, i].Value.ToString(); examQuestion.option5 = dgExamSingleChoice[6, i].Value.ToString(); examQuestion.option6 = dgExamSingleChoice[7, i].Value.ToString(); examQuestion.option7 = dgExamSingleChoice[8, i].Value.ToString(); // examQuestion.option8 = dgExamSingleChoice[9, i].Value.ToString(); examQuestion.questionType = "Single"; examQuestion.exam_sequence = exam.sequence; examQuestionDao.Add(examQuestion); } for (int i = 0; i < this.dgExamMultiChoice.RowCount; i++) { ExamQuestion examQuestion = new ExamQuestion(); examQuestion.question = dgExamMultiChoice[0, i].Value.ToString(); examQuestion.answer = dgExamMultiChoice[1, i].Value.ToString(); examQuestion.option1 = dgExamMultiChoice[2, i].Value.ToString(); examQuestion.option2 = dgExamMultiChoice[3, i].Value.ToString(); examQuestion.option3 = dgExamMultiChoice[4, i].Value.ToString(); examQuestion.option4 = dgExamMultiChoice[5, i].Value.ToString(); examQuestion.option5 = dgExamMultiChoice[6, i].Value.ToString(); examQuestion.option6 = dgExamMultiChoice[7, i].Value.ToString(); examQuestion.option7 = dgExamMultiChoice[8, i].Value.ToString(); // examQuestion.option8 = dgExamMultiChoice[9, i].Value.ToString(); examQuestion.questionType = "Multi"; examQuestion.exam_sequence = exam.sequence; examQuestionDao.Add(examQuestion); } for (int i = 0; i < this.dgExamJugement.RowCount; i++) { ExamQuestion examQuestion = new ExamQuestion(); examQuestion.question = dgExamJugement[0, i].Value.ToString(); examQuestion.answer = dgExamJugement[1, i].Value.ToString(); examQuestion.exam_sequence = exam.sequence; examQuestion.questionType = "Jugement"; examQuestionDao.Add(examQuestion); } ExamReceiverDao examReceiverDao = new ChinaUnion_DataAccess.ExamReceiverDao(); examReceiverDao.Delete(exam.sequence); for (int i = 0; i < lstAgentType.Items.Count; i++) { if (lstAgentType.GetItemChecked(i)) { ExamReceiver examReceiver = new ExamReceiver(); examReceiver.examSequence = exam.sequence; examReceiver.receiver = lstAgentType.Items[i].ToString(); examReceiver.type = "渠道类型"; examReceiverDao.Add(examReceiver); } } for (int i = 0; i < lstGroup.Items.Count; i++) { if (lstGroup.GetItemChecked(i)) { ExamReceiver examReceiver = new ExamReceiver(); examReceiver.examSequence = exam.sequence; examReceiver.receiver = lstGroup.Items[i].ToString(); examReceiver.type = "自定义组"; examReceiverDao.Add(examReceiver); } } } MessageBox.Show("操作完毕"); this.Cursor = Cursors.Default; }
private void dgExam_SelectionChanged(object sender, EventArgs e) { this.Cursor = Cursors.WaitCursor; if (this.dgExam.CurrentRow != null) { if (this.dgExam[0, this.dgExam.CurrentRow.Index].Value != null) { String examSeq = this.dgExam[0, this.dgExam.CurrentRow.Index].Value.ToString(); ExamQuestionDao examQuestionDao = new ExamQuestionDao(); IList<ExamQuestion> questionList = examQuestionDao.GetList(examSeq); this.dgExamSingleChoice.Rows.Clear(); dgExamSingleChoice.Columns.Clear(); dgExamSingleChoice.Columns.Add("序列号", "序列号"); dgExamSingleChoice.Columns.Add("题目", "题目"); dgExamSingleChoice.Columns.Add("答案", "答案"); dgExamSingleChoice.Columns.Add("选项1", "选项1"); dgExamSingleChoice.Columns.Add("选项2", "选项2"); dgExamSingleChoice.Columns.Add("选项3", "选项3"); dgExamSingleChoice.Columns.Add("选项4", "选项4"); dgExamSingleChoice.Columns.Add("选项5", "选项5"); dgExamSingleChoice.Columns.Add("选项6", "选项6"); dgExamSingleChoice.Columns.Add("选项7", "选项7"); dgExamSingleChoice.Columns[0].Visible = false; this.dgExamMultiChoice.Rows.Clear(); dgExamMultiChoice.Columns.Clear(); dgExamMultiChoice.Columns.Add("序列号", "序列号"); dgExamMultiChoice.Columns.Add("题目", "题目"); dgExamMultiChoice.Columns.Add("答案", "答案"); dgExamMultiChoice.Columns.Add("选项1", "选项1"); dgExamMultiChoice.Columns.Add("选项2", "选项2"); dgExamMultiChoice.Columns.Add("选项3", "选项3"); dgExamMultiChoice.Columns.Add("选项4", "选项4"); dgExamMultiChoice.Columns.Add("选项5", "选项5"); dgExamMultiChoice.Columns.Add("选项6", "选项6"); dgExamMultiChoice.Columns.Add("选项7", "选项7"); dgExamMultiChoice.Columns[0].Visible = false; this.dgExamJugement.Rows.Clear(); dgExamJugement.Columns.Clear(); dgExamJugement.Columns.Add("序列号", "序列号"); dgExamJugement.Columns.Add("题目", "题目"); dgExamJugement.Columns.Add("答案", "答案"); dgExamJugement.Columns[0].Visible = false; if (questionList != null && questionList.Count > 0) { for (int i = 0; i < questionList.Count; i++) { ExamQuestion examQuestion = questionList[i]; DataGridViewRow row = null; switch (examQuestion.questionType) { case "Single": dgExamSingleChoice.Rows.Add(); row = dgExamSingleChoice.Rows[dgExamSingleChoice.RowCount - 1]; row.Cells["序列号"].Value = examQuestion.sequence; row.Cells["题目"].Value = examQuestion.question; row.Cells["答案"].Value = examQuestion.answer; row.Cells["选项1"].Value = examQuestion.option1; row.Cells["选项2"].Value = examQuestion.option2; row.Cells["选项3"].Value = examQuestion.option3; row.Cells["选项4"].Value = examQuestion.option4; row.Cells["选项5"].Value = examQuestion.option5; row.Cells["选项6"].Value = examQuestion.option6; row.Cells["选项7"].Value = examQuestion.option7; break; case "Multi": dgExamMultiChoice.Rows.Add(); row = dgExamMultiChoice.Rows[dgExamMultiChoice.RowCount - 1]; row.Cells["序列号"].Value = examQuestion.sequence; row.Cells["题目"].Value = examQuestion.question; row.Cells["答案"].Value = examQuestion.answer; row.Cells["选项1"].Value = examQuestion.option1; row.Cells["选项2"].Value = examQuestion.option2; row.Cells["选项3"].Value = examQuestion.option3; row.Cells["选项4"].Value = examQuestion.option4; row.Cells["选项5"].Value = examQuestion.option5; row.Cells["选项6"].Value = examQuestion.option6; row.Cells["选项7"].Value = examQuestion.option7; break; case "Jugement": this.dgExamJugement.Rows.Add(); row = dgExamJugement.Rows[dgExamJugement.RowCount - 1]; row.Cells["序列号"].Value = examQuestion.sequence; row.Cells["题目"].Value = examQuestion.question; row.Cells["答案"].Value = examQuestion.answer; break; } } } } } this.Cursor = Cursors.Default; }