Esempio n. 1
0
        public List<FillBlankQuestionModel> GetAllFillBlankQuestionsByQuizMakerID(long quizMakerID)
        {
            List<FillBlankQuestionModel> fillBlankQuestionModels = new List<FillBlankQuestionModel>();
            DataTable dataTable = new DataTable();
            try
            {
                SqlConnection conn = new SqlConnection(DbHelper.ConnectionString);

                SqlCommand command = new SqlCommand(@"dbo.uspGetAllFillBlankQuestionsByQuizMakerID", conn);
                command.CommandType = CommandType.StoredProcedure;
                command.Parameters.AddWithValue("@QuizMakerID", quizMakerID);

                SqlDataAdapter dataAdapter = new SqlDataAdapter(command);
                dataAdapter.Fill(dataTable);

                foreach (DataRow row in dataTable.Rows)
                {
                    FillBlankQuestionModel fillBlankQuestionModel = new FillBlankQuestionModel();
                    fillBlankQuestionModel.QuestionID = row["QuestionID"] != DBNull.Value ? Convert.ToInt64(row["QuestionID"].ToString()) : 0;
                    fillBlankQuestionModel.QuizMakerID = row["QuizMakerID"] != DBNull.Value ? Convert.ToInt64(row["QuizMakerID"].ToString()) : 0;
                    fillBlankQuestionModel.QuestionText = row["QuestionText"] != DBNull.Value ? Convert.ToString(row["QuestionText"]) : string.Empty;
                    fillBlankQuestionModel.AnswerText = row["AnswerText"] != DBNull.Value ? Convert.ToString(row["AnswerText"]) : string.Empty;

                    fillBlankQuestionModels.Add(fillBlankQuestionModel);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {

                dataTable.Clear();
                dataTable = null;
            }

            return fillBlankQuestionModels;
        }
        private void btnAddFillBlankQuestion_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtQuestion.Text))
            {
                MessageBox.Show("Question can't be blank!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (string.IsNullOrEmpty(txtAnswer.Text))
            {
                MessageBox.Show("Answer can't be blank!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (_quizMakeID == 0)
            {
                FillBlankQuestionModel fillBlankQuestionModel = new FillBlankQuestionModel();

                fillBlankQuestionModel.QuestionText = txtQuestion.Text;
                fillBlankQuestionModel.QuizMakerID  = 0;
                fillBlankQuestionModel.MainTopicID  = 0;
                fillBlankQuestionModel.SubTopicID   = 0;

                fillBlankQuestionModel.AnswerText = txtAnswer.Text;

                fillBlankQuestionModel.CreatedOn  = DateTime.Now;
                fillBlankQuestionModel.CreatedBy  = 1;
                fillBlankQuestionModel.ModifiedOn = DateTime.Now;
                fillBlankQuestionModel.ModifiedBy = 1;

                if (QuizMaker.fillBlankQuestionModelsGlobal != null && QuizMaker.fillBlankQuestionModelsGlobal.Count > 0)
                {
                    fillBlankQuestionModel.QuestionCounter = QuizMaker.fillBlankQuestionModelsGlobal.Max(x => x.QuestionCounter) + 1;
                }
                else
                {
                    fillBlankQuestionModel.QuestionCounter = 1;
                }

                QuizMaker.fillBlankQuestionModelsGlobal.Add(fillBlankQuestionModel);
                if (QuizMaker.multipleQuestionModelsGlobal != null)
                {
                    QuizMaker quiz = (QuizMaker)Application.OpenForms["QuizMaker"];
                    if (quiz != null)
                    {
                        int totalQuestions = QuizMaker.multipleQuestionModelsGlobal.Count() + QuizMaker.trueFalseQuestionModelsGlobal.Count() + QuizMaker.fillBlankQuestionModelsGlobal.Count();
                        quiz.txtTotalQuestions.Text = totalQuestions.ToString();
                    }
                }
            }
            else
            {
                FillBlankQuestionModel fillBlankQuestionModel = new FillBlankQuestionModel();

                fillBlankQuestionModel.QuestionText = txtQuestion.Text;
                fillBlankQuestionModel.QuizMakerID  = _quizMakeID;
                fillBlankQuestionModel.MainTopicID  = 0;
                fillBlankQuestionModel.SubTopicID   = 0;

                fillBlankQuestionModel.AnswerText = txtAnswer.Text;

                fillBlankQuestionModel.CreatedOn  = DateTime.Now;
                fillBlankQuestionModel.CreatedBy  = 1;
                fillBlankQuestionModel.ModifiedOn = DateTime.Now;
                fillBlankQuestionModel.ModifiedBy = 1;

                if (AddMoreQuestions.addMoreFillBlankQuestionModelsGlobal != null && AddMoreQuestions.addMoreFillBlankQuestionModelsGlobal.Count > 0)
                {
                    fillBlankQuestionModel.QuestionCounter = AddMoreQuestions.addMoreFillBlankQuestionModelsGlobal.Max(x => x.QuestionCounter) + 1;
                }
                else
                {
                    fillBlankQuestionModel.QuestionCounter = 1;
                }

                AddMoreQuestions.addMoreFillBlankQuestionModelsGlobal.Add(fillBlankQuestionModel);
            }
            this.Close();
        }