コード例 #1
0
        private void btnCreate_Click(object sender, EventArgs e)
        {
            if (cboSubject.SelectedIndex == -1)
            {
                lblStatus.Text = "  Please choose subject";
                cboSubject.Focus();
            }
            else if (cboExamType.SelectedIndex == -1)
            {
                lblStatus.Text = "  Please choose exam type";
                cboExamType.Focus();
            }
            else if (cboSubject.SelectedIndex > -1 && cboExamType.SelectedIndex > -1)
            {
                string subject       = cboSubject.Text;
                string examType      = cboExamType.Text;
                string timeLimit     = lblOutputTimeLimit.Text;
                string items         = numItems.Value.ToString();
                string dialogMessage = string.Format("Are you sure you want to create exam for \nSubject: {0}\nExam Type: {1}\nTime Limit: {2}\nItems: {3} ?",
                                                     subject, examType, timeLimit, items);

                DialogResult result = MessageBox.Show(this, dialogMessage, "Message", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                if (result == DialogResult.Yes)
                {
                    Exam exam = new Exam();
                    exam.UserId          = UserInfo.UserId;
                    exam.SubjectId       = (int)cboSubject.SelectedValue;
                    exam.ExaminationType = (int)cboExamType.SelectedValue;
                    exam.TimeLimit       = (int)numTimeLimit.Value;
                    exam.ItemCount       = (int)numItems.Value;
                    exam.Archived        = false;
                    //exam.DateTimeAdded to DAL

                    for (int i = 1; i <= exam.ItemCount; i++)
                    {
                        exam.QuestionBank.Add(new QuestionBank {
                            QuestionNumber = i
                        });
                    }

                    _examBLL.InsertExam(exam);

                    _selectedExamType         = SetExamType(cboExamType.Text);
                    cboSubject.SelectedIndex  = -1;
                    cboExamType.SelectedIndex = -1;
                    numTimeLimit.Value        = 60;
                    lblStatus.Text            = "  Successfully created new exam";

                    SetExamDatagridViewDataScource();
                    SetExamTotalDataGridViewDataSource();
                    ShowQuestionFrom(exam.ExamId);
                }
            }
        }