Created
April 8, 2020 03:31
-
-
Save hughesjs/9c2a39acdc93f81220d04d97b36224a1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void SaveResults() | |
{ | |
List<AnswerData> answers = new List<AnswerData>(); | |
foreach (GroupBox group in questionGroups) | |
{ | |
JObject question = (JObject) group.Tag; | |
Enum.TryParse((string)question["questiontype"], out QuestionType qType); | |
AnswerData answer; | |
switch (qType) | |
{ | |
case QuestionType.YesNo: | |
case QuestionType.MultipleChoiceExclusive: | |
answer = new AnswerData(question, group.Controls | |
.OfType<TableLayoutPanel>() | |
.First().Controls | |
.Cast<RadioButton>() | |
.Where(c=>c.Checked) | |
.Select(c=>c.Text) | |
.ToArray()); | |
break; | |
case QuestionType.MultipleChoiceNotExclusive: | |
answer = new AnswerData(question, group.Controls | |
.OfType<TableLayoutPanel>() | |
.First() | |
.Controls.OfType<CheckBox>() | |
.Where(c => c.Checked) | |
.Select(c => c.Text) | |
.ToArray()); | |
break; | |
case QuestionType.FreeComment: | |
answer = new AnswerData(question, group.Controls | |
.OfType<TableLayoutPanel>() | |
.First() | |
.Controls.OfType<RichTextBox>() | |
.Select(c=>c.Rtf) | |
.ToArray()); | |
break; | |
default: | |
throw new ArgumentOutOfRangeException(); | |
} | |
answers.Add(answer); | |
} | |
Task.Run(() => _client.Save(answers, _metadata, _client, _site, _fsr, _customer)); | |
Close(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment