Exemple #1
0
        private void frmQuestion_Load(object sender, EventArgs e)
        {
            if (currentSubject != null && currentSubject.IdSchoolSubject != null && currentSubject.IdSchoolSubject != "")
            {
                //string dummyId = currentSubject.IdSchoolSubject;
                //currentSubject = db.GetSchoolSubject(dummyId);
                cmbSchoolSubject.SelectedValue = currentSubject.IdSchoolSubject;
            }

            switch (formType)
            {
            case QuestionFormType.CreateSeveralQuestions:
            {
                btnNewQuestion.Visible = true;
                btnSaveQuestion.Text   = "Salva";
                break;
            }

            case QuestionFormType.EditOneQuestion:
            {
                btnNewQuestion.Visible = false;
                btnSaveQuestion.Text   = "Salva e Esci";
                break;
            }
            }

            cmbQuestionType.SelectedValue = currentQuestion.IdQuestionType;

            if (currentQuestion != null)
            {
                if (currentQuestion.IdQuestion != 0)
                {
                    currentQuestion = db.GetQuestionById(currentQuestion.IdQuestion);
                }
                txtIdQuestion.Text    = currentQuestion.IdQuestion.ToString();
                txtQuestionText.Text  = currentQuestion.Text;
                txtQuestionImage.Text = currentQuestion.QuestionImage;
                txtDuration.Text      = currentQuestion.Duration.ToString();
                txtWeight.Text        = currentQuestion.Weight.ToString();
                txtDifficulty.Text    = currentQuestion.Difficulty.ToString();
                tagsList               = db.TagsOfAQuestion(currentQuestion.IdQuestion);
                lstTags.DataSource     = tagsList;
                Commons.LastTagsChosen = tagsList;

                // show the path of the topic of the question
                if (currentTopic != null)
                {
                    txtTopic.Text = dbMptt.GetTopicPath(currentTopic.Id);
                }

                answersList           = db.GetAnswersOfAQuestion(currentQuestion.IdQuestion);
                dgwAnswers.DataSource = answersList;
            }
            else
            {
                currentQuestion = new Question();
            }

            txtImagesPath.Text = Commons.PathImages;
        }
        private void dgwQuestions_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex > -1)
            {
                dgwQuestions.Rows[e.RowIndex].Selected = true;

                List <Question> listQuestions = (List <Question>)(dgwQuestions.DataSource);
                currentQuestion = listQuestions[e.RowIndex];

                txtQuestion.Text = currentQuestion.Text;

                List <Answer> listAnswers = db.GetAnswersOfAQuestion(currentQuestion.IdQuestion);
                dgwAnswers.DataSource = listAnswers;
                // erase all previous radio buttons in grpStudentsAnswers
                grpStudentsAnswers.Visible = false;
                while (grpStudentsAnswers.Controls.Count > 0)
                {
                    grpStudentsAnswers.Controls[0].Dispose();
                }
                grpStudentsAnswers.Visible = true;

                // the next database field must be managed, today it ISN'T!!!
                currentQuestion.IsMutex = false; // !!!!!!!!!!!!!!!!!!!!!!!!!! remove before publishing anything

                Control cntrl;
                for (int i = 0; i < listAnswers.Count; i++)
                {
                    if ((bool)currentQuestion.IsMutex)
                    {
                        cntrl = new RadioButton();
                    }
                    else
                    {
                        cntrl = new CheckBox();
                    }
                    cntrl.Location = new Point(7, i * 30 + 40);
                    cntrl.Size     = new Size(grpStudentsAnswers.Size.Width - 14, cntrl.Size.Height);
                    //rb.TextAlign = ContentAlignment.MiddleLeft;
                    cntrl.Text = listAnswers[i].Text;
                    grpStudentsAnswers.Controls.Add(cntrl);

                    fillCheckBoxes();
                }
            }
        }