QAQuestion.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. namespace InABox.Core
  5. {
  6. [Caption("QA Checks")]
  7. [UserTracking(typeof(DigitalForm))]
  8. public class QAQuestion : Entity, IRemotable, IPersistent, ISequenceable, IOneToMany<DigitalForm>, ILicense<DigitalFormsLicense>
  9. {
  10. public QAQuestion()
  11. {
  12. Answer = QAAnswer.Comment;
  13. }
  14. public DigitalFormLink Form => InitializeField(ref _form, nameof(Form));
  15. private DigitalFormLink? _form;
  16. [NullEditor]
  17. public string Section { get; set; }
  18. [TextBoxEditor]
  19. public string Code { get; set; }
  20. [TextBoxEditor]
  21. public string Question { get; set; }
  22. [MemoEditor]
  23. public string Description { get; set; }
  24. [EnumLookupEditor(typeof(QAAnswer))]
  25. public QAAnswer Answer { get; set; }
  26. [MemoEditor]
  27. public string Parameters { get; set; }
  28. //[NullEditor]
  29. //public String Value { get; set; }
  30. //[MemoEditor]
  31. //public String Notes { get; set; }
  32. [NullEditor]
  33. public long Sequence { get; set; }
  34. protected override void DoPropertyChanged(string name, object? before, object? after)
  35. {
  36. base.DoPropertyChanged(name, before, after);
  37. if (name.Equals("Answer"))
  38. {
  39. var answer = (QAAnswer)after;
  40. if (answer == QAAnswer.Choice)
  41. Parameters =
  42. "Options: Value 1, Value 2, Value 3\n" +
  43. "Colors: Green, Yellow, Red\n" +
  44. "Default: Value 1\n";
  45. else if (answer == QAAnswer.Number)
  46. Parameters =
  47. "Minimum: 0.0\n" +
  48. "Maximum: 100.0\n" +
  49. "Default: 0.0\n";
  50. else if (answer == QAAnswer.Text)
  51. Parameters =
  52. "Default: \n";
  53. else if (answer == QAAnswer.Combo)
  54. Parameters =
  55. "Options: Value 1, Value 2, Value 3\n" +
  56. "Default: Value 1\n";
  57. else
  58. Parameters = "";
  59. }
  60. }
  61. public Dictionary<string, string> ParseParameters()
  62. {
  63. var result = new Dictionary<string, string>();
  64. var lines = Parameters == null ? new string[] { } : Parameters.Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);
  65. foreach (var line in lines)
  66. {
  67. var comps = line.Split(':');
  68. if (comps.Length > 1)
  69. result[comps[0]] = string.Join(":", comps.Skip(1));
  70. else if (comps.Length == 1)
  71. result[comps[0]] = "";
  72. }
  73. if (Answer == QAAnswer.Choice)
  74. CheckParams(result, "Options", "Colors", "Default");
  75. else if (Answer == QAAnswer.Number)
  76. CheckParams(result, "Minimum", "Maximum", "Default");
  77. else if (Answer == QAAnswer.Text)
  78. CheckParams(result, "Default");
  79. if (Answer == QAAnswer.Combo)
  80. CheckParams(result, "Options", "Default");
  81. return result;
  82. }
  83. private void CheckParams(Dictionary<string, string> result, params string[] keys)
  84. {
  85. foreach (var key in keys)
  86. if (!result.ContainsKey(key))
  87. result[key] = "";
  88. }
  89. }
  90. }