Exemplo n.º 1
0
        private void buttonSubmit_Click(object sender, EventArgs e)
        {
            if (selectQuestionNoSystem == "Online")
            {
                if (radioButtonOptionA.Checked)
                {
                    user_Answer = OptionA.ToLower().Replace(" ", "");
                }
                else if (radioButtonOptionB.Checked)
                {
                    user_Answer = OptionB.ToLower().Replace(" ", "");
                }
                else if (radioButtonOptionC.Checked)
                {
                    user_Answer = OptionC.ToLower().Replace(" ", "");
                }
                else if (radioButtonOptionD.Checked)
                {
                    user_Answer = OptionD.ToLower().Replace(" ", "");
                }
                else
                {
                    user_Answer = "";
                }

                //user_Answer = textBoxAnswer.Text.ToLower().Replace(" ", "");
                right_Answer = right_Answer.ToLower().Replace(" ", "");


                if (user_Answer == right_Answer)
                {
                    point = 5;

                    UserInformation.setQuestionNO(QSN);
                    makeSolve.makeSolveStatus();
                }
                else if (user_Answer == "")
                {
                    point = 0;
                }
                else if (user_Answer != right_Answer)
                {
                    point = -2;
                }

                this.Hide();

                InformationAnalysis ia = new InformationAnalysis();

                ia.removeForm(point);
            }



            else if (selectQuestionNoSystem == "Offline")
            {
                if (radioButtonOptionA.Checked)
                {
                    user_Answer = OptionA.ToLower().Replace(" ", "");
                }
                else if (radioButtonOptionB.Checked)
                {
                    user_Answer = OptionB.ToLower().Replace(" ", "");
                }
                else if (radioButtonOptionC.Checked)
                {
                    user_Answer = OptionC.ToLower().Replace(" ", "");
                }
                else if (radioButtonOptionD.Checked)
                {
                    user_Answer = OptionD.ToLower().Replace(" ", "");
                }
                else
                {
                    user_Answer = "";
                }

                //user_Answer = textBoxAnswer.Text.ToLower().Replace(" ", "");
                right_Answer = right_Answer.ToLower().Replace(" ", "");


                if (user_Answer == right_Answer)
                {
                    UserInformation.setQuestionNO(QSN);
                    makeSolve.makeSolveStatus();

                    MessageBox.Show("Right Answer!");

                    this.Hide();

                    offlineInformationAnalysis oia = new offlineInformationAnalysis();

                    oia.removeForm();
                }
                else if (user_Answer == "")
                {
                    MessageBox.Show("Answer is blank!");
                }
                else if (user_Answer != right_Answer)
                {
                    MessageBox.Show("Wrong Answer!!");
                }
            }
        }
        public void selectQuestionNo()
        {
            try
            {
                // step 1: Create a connection

                var           result        = Path.GetFullPath("InformationDatabase.mdf");
                string        strConnection = "Data Source=.\\sqlexpress;AttachDbFilename=" + result + ";User Instance=true;Integrated Security=True;Pooling=False;MultipleActiveResultSets=true";
                SqlConnection objConnection = new SqlConnection(strConnection);
                objConnection.Open();

                // step 2: fire a command
                string username = UserInformation.getUserName();
                // string quizno = onlineQuizSerialNo;


                AllorUnsolved = UserInformation.getAllorSolved();

                string strCommand = "";
                if (AllorUnsolved == "Unsolved")
                {
                    Unsolved = true;

                    strCommand = "SELECT QSN FROM Question EXCEPT SELECT QSN FROM Solve WHERE userID=@UN";
                }
                else if (AllorUnsolved == "All")
                {
                    All        = true;
                    strCommand = "SELECT QSN FROM Question";
                }
                SqlCommand objCommand = new SqlCommand(strCommand, objConnection);


                objCommand.Parameters.Add(new SqlParameter("@UN", username));


                // step 3: bind the result data with user interface

                SqlDataReader reader = objCommand.ExecuteReader();



                while (reader.Read())
                {
                    for (int i = 0; i < reader.FieldCount; i++)
                    {
                        unsolvedQuestion.Add(reader[i].ToString());
                    }
                }



                reader.Close();
                objConnection.Close();


                if (unsolvedQuestion.Count == 0 && Unsolved == true)
                {
                    MessageBox.Show("You have no unsolved Questions!");
                    Unsolved = false;

                    Question q = new Question();
                    q.ShowDialog();
                }
                else if (unsolvedQuestion.Count == 0 && All == true)
                {
                    MessageBox.Show("Please Update Questions!\nDatabase is empty.");
                    All = false;
                    Question q = new Question();
                    q.ShowDialog();
                }


                makeValue(unsolvedQuestion);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);


                Question q = new Question();
                q.ShowDialog();

                //MessageBox.Show(ex.Message);
            }
        }