private void prepareGrid(String condition)
        {
            String type = "";
            if (rdoExam.Checked)
            {
                type = "Exam";
            }
            if (rdoSurvey.Checked)
            {
                type = "Survey";
            }
            if (String.IsNullOrEmpty(type))
            {
                MessageBox.Show("请选择试题类型");

                return;
            }

            this.Cursor = Cursors.WaitCursor;
            ExamDao examDao = new ChinaUnion_DataAccess.ExamDao();
            IList<Exam> examList = examDao.GetList(condition, type);
            this.dgExam.Rows.Clear();
            this.dgExamJugement.Rows.Clear();
            this.dgExamMultiChoice.Rows.Clear();
            this.dgExamSingleChoice.Rows.Clear();
            dgExam.Columns.Clear();
            dgExam.Columns.Add("序列号", "序列号");
            dgExam.Columns.Add("名称", "名称");

            dgExam.Columns.Add("生效时间", "生效时间");
            dgExam.Columns.Add("失效时间", "失效时间");

            dgExam.Columns[0].Visible = false;
            if (examList != null && examList.Count > 0)
            {

                for (int i = 0; i < examList.Count; i++)
                {
                    dgExam.Rows.Add();
                    DataGridViewRow row = dgExam.Rows[dgExam.RowCount - 1];
                    row.Cells[0].Value = examList[i].sequence;
                    
                    row.Cells[1].Value = examList[i].subject;
                    
                    row.Cells[2].Value = examList[i].validateStartTime;
                    row.Cells[3].Value = examList[i].validateEndTime;
                   

                }
            }


            this.dgExam.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None;
            this.dgExam.AutoResizeColumns();
            this.Cursor = Cursors.Default;
        }
Beispiel #2
0
        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 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());
                 }
             }
        }