Пример #1
0
 public Question()
 {
     Id              = Guid.NewGuid().ToString();
     Children        = new List <Question>();
     LogicalChildren = new List <string>();
     UserResponse    = new ResponseChoice();
     ChildSetCount   = 0;
 }
Пример #2
0
        public void SetResponseDataCaptureType(enumDataCaptureType type, IEnumerable <ResponseChoice> possibleResponses, ResponseChoice userResponse)
        {
            this.AutoSize = true;
            switch (type)
            {
            case enumDataCaptureType.DateTimePicker:
                DateTimePicker picker = new DateTimePicker();
                picker.Format       = DateTimePickerFormat.Custom;
                picker.CustomFormat = "yyyy-MM-dd";
                if (userResponse != null && userResponse.Display != null)
                {
                    picker.Value = DateTime.Parse(userResponse.Display);
                }
                picker.ValueChanged += Picker_ValueChanged;
                if (userResponse == null)
                {
                    picker.Value = DateTime.Today;
                }

                this.flowLayoutPanel1.Controls.Add(picker);
                break;

            case enumDataCaptureType.TextBox:
                var textBox = new TextBox();
                //textBox.Multiline = true;
                textBox.Width = 350;
                if (userResponse != null)
                {
                    textBox.Text = userResponse.Display;
                }
                textBox.TextChanged += TextBox_TextChanged;
                if (userResponse == null)
                {
                    textBox.Text = "";
                }
                this.flowLayoutPanel1.Controls.Add(textBox);
                break;

            case enumDataCaptureType.DropDown:
                var combo = new ComboBox();
                combo.DropDownStyle = ComboBoxStyle.DropDownList;
                //combo.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
                combo.Width         = 350;
                combo.DataSource    = possibleResponses;
                combo.DisplayMember = "Display";
                if (userResponse != null)
                {
                    combo.SelectedValue = possibleResponses.FirstOrDefault(s => s.Value == userResponse.Value);
                }
                else
                {
                    combo.SelectedValue = possibleResponses.FirstOrDefault();
                }
                combo.SelectedValueChanged += Combo_SelectedValueChanged;
                this.flowLayoutPanel1.Controls.Add(combo);
                break;

            case enumDataCaptureType.RadioButton:
                //FlowLayoutPanel panel = new FlowLayoutPanel();
                //panel.Dock = DockStyle.Fill;
                //panel.AutoSize = true;
                //this.flowLayoutPanel1.Controls.Add(panel);
                bool        rbOneInvoked = false;
                RadioButton rbOne        = null;
                possibleResponses.ToList().ForEach(s =>
                {
                    RadioButton rb = new RadioButton();
                    rb.AutoSize    = true;
                    rb.Margin      = new Padding(2);
                    rb.Text        = s.Display;
                    rb.Tag         = s;
                    if (userResponse != null && rb.Text == userResponse.Display)
                    {
                        rb.Checked = true;
                    }
                    rb.CheckedChanged += Rb_CheckedChanged;
                    if (userResponse == null)
                    {
                        if (rbOneInvoked == false)
                        {
                            rbOne        = rb;
                            rbOneInvoked = true;
                        }
                    }
                    this.flowLayoutPanel1.Controls.Add(rb);
                });
                if (rbOne != null)
                {
                    rbOne.Checked = true;
                }
                break;

            case enumDataCaptureType.CheckBox:
                CheckBox checkBoxChoice = new CheckBox();
                checkBoxChoice.Text = possibleResponses.FirstOrDefault().Display;
                bool state = false;

                if (userResponse != null)
                {
                    bool.TryParse(userResponse.Display, out state);
                    checkBoxChoice.Checked = state;
                }
                checkBoxChoice.CheckedChanged += CheckBoxChoice_CheckedChanged;
                if (userResponse == null)
                {
                    checkBoxChoice.Checked = true;
                    checkBoxChoice.Checked = false;
                }
                this.flowLayoutPanel1.Controls.Add(checkBoxChoice);
                break;

            case enumDataCaptureType.TextBoxAndNotSureCheckBox:
                var textBox2 = new TextBox();
                textBox2.Name = "TextBoxAndNotSureCheckBox_TextBox";
                //textBox2.Multiline = true;
                CheckBox checkBox = new CheckBox();
                checkBox.Text = "Not sure";
                checkBox.Name = "TextBoxAndNotSureCheckBox_CheckBox";
                if (userResponse != null)
                {
                    if (userResponse.Display == checkBox.Text)
                    {
                        checkBox.Checked = true;
                    }
                    else
                    {
                        textBox2.Text = userResponse.Display;
                    }
                }
                textBox2.TextChanged += TextBoxAndNotSureCheckBo_Changed;
                this.flowLayoutPanel1.Controls.Add(textBox2);
                checkBox.CheckedChanged += TextBoxAndNotSureCheckBo_Changed;
                this.flowLayoutPanel1.Controls.Add(checkBox);

                break;

            case enumDataCaptureType.NoDataCapture:
                break;
            }
        }
Пример #3
0
        public void ResponseChanged(ResponseChoice value)
        {
            if (Changed != null)
            {
                Changed.Invoke(value);
            }
            _Question.UserResponse = value;

            _Question.Children.ForEach(s =>
            {
                bool invoke = s.InvokeThisQuestion();
                if (s.ShowHide != null)
                {
                    s.ShowHide.Invoke(invoke);
                }
                s.Children.ForEach(c =>
                {
                    if (c.ShowHide != null)
                    {
                        c.ShowHide.Invoke(invoke && c.InvokeThisQuestion());
                    }
                });
                s.LogicalChildren.ForEach(c =>
                {
                    Question q = Questions.Utility.Questions.GetQuestion(c);
                    if (q != null && q.ShowHide != null)
                    {
                        q.ShowHide.Invoke(q.InvokeThisQuestion());
                    }
                });
            });
            _Question.LogicalChildren.ForEach(s =>
            {
                Question q  = Questions.Utility.Questions.GetQuestion(s);
                bool invoke = q.InvokeThisQuestion();
                if (q.ShowHide != null)
                {
                    q.ShowHide.Invoke(invoke);
                }
                q.LogicalChildren.ForEach(c =>
                {
                    Question r = Questions.Utility.Questions.GetQuestion(c);

                    if (r.ShowHide != null)
                    {
                        r.ShowHide.Invoke(invoke && r.InvokeThisQuestion());
                    }
                });
            });

            this.SetHeight();
            // If this control is the parent of a logical child, then the child may physically belong to
            // a common parent. Therefore the parent needs to recalculate the height too to cover this scenario.
            if (this.Parent != null &&
                this.Parent.Parent != null &&
                this.Parent.Parent.Parent != null &&
                this.Parent.Parent.Parent.Parent != null &&
                this.Parent.Parent.Parent.Parent is QuestionControl)
            {
                (this.Parent.Parent.Parent.Parent as QuestionControl).SetHeight();
            }

            this.Invalidate();
            this.Update();
            this.Refresh();
            this.Parent?.Refresh();
        }