Exemple #1
0
        private void AddChildQuestions(Question question, bool additional)
        {
            //Add this to the question's children collection if needed:
            if (question.HasArrayOfChildren && additional /*question.Children.Count() == this.flowLayoutPanel2.Controls.Count * distinctChildren.Count()*/)
            {
                var distinctChildren = question.Children.GroupBy(s => s.Ref).Select(s => s.First()).ToList();
                if (question.Children.Count() == question.ChildSetCount * distinctChildren.Count)
                {
                    // We now have to add a new set of child questions
                    var questionsToRender = distinctChildren.CloneList <Question>();
                    questionsToRender.ForEach(q => q.ChildSetCount = 0);
                    question.Children.AddRange(questionsToRender);
                }
                question.ChildSetCount++;
            }

            if (!question.HasArrayOfChildren || question.ChildSetCount > 0)
            {
                this.flowLayoutPanel2.Controls.Clear();
                //question.Children.ForEach(s =>
                int setCount      = question.Children.GroupBy(s => s.Text).Count();
                int questionCount = question.Children.Count();
                for (int i = 0; i < questionCount; i += setCount)
                {
                    FlowLayoutPanel childQuestionsPanel = new FlowLayoutPanel();
                    childQuestionsPanel.AutoScroll    = true;
                    childQuestionsPanel.AutoSize      = true;
                    childQuestionsPanel.AutoSizeMode  = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
                    childQuestionsPanel.BackColor     = System.Drawing.SystemColors.ControlLight;
                    childQuestionsPanel.Dock          = System.Windows.Forms.DockStyle.Fill;
                    childQuestionsPanel.FlowDirection = System.Windows.Forms.FlowDirection.TopDown;
                    //childQuestionsPanel.Location = new System.Drawing.Point(27, 49);
                    childQuestionsPanel.Margin = new System.Windows.Forms.Padding(0, 3, 0, 3);
                    //childQuestionsPanel.Name = "flowLayoutPanel3";
                    childQuestionsPanel.Size = new System.Drawing.Size(42, 0);
                    //childQuestionsPanel.TabIndex = 5;
                    childQuestionsPanel.WrapContents = false;

                    question.Children.Skip(i).Take(setCount).ToList().ForEach(s =>
                    {
                        QuestionControl control = new QuestionControl(550, 500);
                        control.SetQuestion(s);
                        //this.flowLayoutPanel2.Controls.Add(control);
                        childQuestionsPanel.Controls.Add(control);
                        s.ShowHide(s.InvokeThisQuestion());
                    });

                    this.flowLayoutPanel2.Controls.Add(childQuestionsPanel);
                }
                ;
            }
        }
Exemple #2
0
        private void LoadQuestions(string group)
        {
            this.SuspendLayout();
            tableLayoutPanel2.Show();
            splitContainer1.Show();
            this.flowLayoutPanel1.Hide();
            this.flowLayoutPanel1.Controls.Clear();

            var questions = Questions.Utility.Questions.GetQuestions(group)
                            .ToList();

            if (questions.FirstOrDefault() != null)
            {
                label1.Text = questions.FirstOrDefault().Category;
            }
            else
            {
                label1.Text = string.Empty;
            }
            questions.ForEach(s =>
            {
                QuestionControl control = new QuestionControl();
                control.SetQuestion(s);
                this.flowLayoutPanel1.Controls.Add(control);
            });
            questions.ForEach(s =>
            {
                s.Children.ForEach(q =>
                {
                    if (q.ShowHide != null)
                    {
                        q.ShowHide.Invoke(q.InvokeThisQuestion());
                    }
                    q.LogicalChildren.ForEach(r =>
                    {
                        Question t = Questions.Utility.Questions.GetQuestion(r);
                        if (t != null && t.ShowHide != null)
                        {
                            t.ShowHide.Invoke(t.InvokeThisQuestion());
                        }
                    });
                });
                s.LogicalChildren.ForEach(q =>
                {
                    Question p = Questions.Utility.Questions.GetQuestion(q);
                    if (p != null && p.ShowHide != null)
                    {
                        p.ShowHide.Invoke(p.InvokeThisQuestion());
                    }
                    if (p.ShowHide != null)
                    {
                        p.ShowHide.Invoke(p.InvokeThisQuestion());
                    }
                });
                //if (s.ShowHide != null)
                //{
                //    s.ShowHide.Invoke(s.InvokeThisQuestion());
                //}
            });

            /*
             * foreach(var control in this.flowLayoutPanel1.Controls)
             * {
             *  if (control is QuestionControl) (control as QuestionControl).SetHeight();
             *  if (control is QuestionControl) (control as QuestionControl).Refresh();
             * }
             *
             * questions.ForEach(s =>
             * {
             *  if (s.ShowHide != null)
             *  {
             *      s.ShowHide.Invoke(s.InvokeThisQuestion());
             *  }
             * });*/
            flowLayoutPanel1.Show();
            this.ResumeLayout();
            this.Refresh();
        }