コード例 #1
0
ファイル: AddQuestions.cs プロジェクト: duhowise/ExamSystem
        public void Save()
        {
            if (QuestionText.Text == "" | OpAText.Text == "" | OpBText.Text == "" | Answer.Text == "" |
                TestName.SelectedItem == null)
            {
                MessageBox.Show("The fields with asterisks are Required", "Fill all Required Fields",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else if (OpBText.Text == OpAText.Text | OpBText.Text == OpCText.Text | OpBText.Text == OpDText.Text)
            {
                MessageBox.Show("Provided Options Cannot be the same", "Check Provided Options", MessageBoxButtons.OK,
                                MessageBoxIcon.Information);
            }
            else if (OpAText.Text == OpBText.Text | OpAText.Text == OpCText.Text | OpAText.Text == OpDText.Text)
            {
                MessageBox.Show("Provided Options Cannot be the same", "Check Provided Options", MessageBoxButtons.OK,
                                MessageBoxIcon.Information);
            }

            else if (OpCText.Text == OpAText.Text | OpCText.Text == OpBText.Text | OpCText.Text == OpDText.Text)
            {
                MessageBox.Show("Provided Options Cannot be the same", "Check Provided Options", MessageBoxButtons.OK,
                                MessageBoxIcon.Information);
            }
            else if (OpDText.Text == OpAText.Text | OpDText.Text == OpBText.Text | OpDText.Text == OpCText.Text)
            {
                MessageBox.Show("Provided Options Cannot be the same", "Check Provided Options", MessageBoxButtons.OK,
                                MessageBoxIcon.Information);
            }
            else
            {
                try
                {
                    _testService.AddNewQuestion(new Question
                    {
                        Testid = (int)TestName.SelectedValue,
                        Mark   = 5,
                        Text   = QuestionText.Text,
                        OpA    = OpAText.Text,
                        OpB    = OpBText.Text,
                        OpC    = OpCText.Text,
                        Opd    = OpDText.Text,
                        Answer = Answer.SelectedItem.ToString()
                    });


                    MessageBox.Show("Successfully Added Question", "information!", MessageBoxButtons.OK,
                                    MessageBoxIcon.Information);
                    QuestionText.Text     = "";
                    OpAText.Text          = "";
                    OpBText.Text          = "";
                    OpCText.Text          = "";
                    OpDText.Text          = "";
                    Answer.SelectedItem   = "";
                    TestName.SelectedItem = "";
                    _queno = _queno + 1;
                }
                catch (SqlException exception)
                {
                    MessageBox.Show(exception.Message, "information!", MessageBoxButtons.OK,
                                    MessageBoxIcon.Exclamation);
                }
            }
        }