QAQuestion.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. [NullEditor]
  15. [Obsolete("Replaced with Form")]
  16. public QAFormLink QAForm { get; set; }
  17. public DigitalFormLink Form { get; set; }
  18. [NullEditor]
  19. public string Section { get; set; }
  20. [TextBoxEditor]
  21. public string Code { get; set; }
  22. [TextBoxEditor]
  23. public string Question { get; set; }
  24. [MemoEditor]
  25. public string Description { get; set; }
  26. [EnumLookupEditor(typeof(QAAnswer))]
  27. public QAAnswer Answer { get; set; }
  28. [MemoEditor]
  29. public string Parameters { get; set; }
  30. //[NullEditor]
  31. //public String Value { get; set; }
  32. //[MemoEditor]
  33. //public String Notes { get; set; }
  34. [NullEditor]
  35. public long Sequence { get; set; }
  36. protected override void DoPropertyChanged(string name, object? before, object? after)
  37. {
  38. base.DoPropertyChanged(name, before, after);
  39. if (name.Equals("Answer"))
  40. {
  41. var answer = (QAAnswer)after;
  42. if (answer == QAAnswer.Choice)
  43. Parameters =
  44. "Options: Value 1, Value 2, Value 3\n" +
  45. "Colors: Green, Yellow, Red\n" +
  46. "Default: Value 1\n";
  47. else if (answer == QAAnswer.Number)
  48. Parameters =
  49. "Minimum: 0.0\n" +
  50. "Maximum: 100.0\n" +
  51. "Default: 0.0\n";
  52. else if (answer == QAAnswer.Text)
  53. Parameters =
  54. "Default: \n";
  55. else if (answer == QAAnswer.Combo)
  56. Parameters =
  57. "Options: Value 1, Value 2, Value 3\n" +
  58. "Default: Value 1\n";
  59. else
  60. Parameters = "";
  61. }
  62. }
  63. public Dictionary<string, string> ParseParameters()
  64. {
  65. var result = new Dictionary<string, string>();
  66. var lines = Parameters == null ? new string[] { } : Parameters.Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);
  67. foreach (var line in lines)
  68. {
  69. var comps = line.Split(':');
  70. if (comps.Length > 1)
  71. result[comps[0]] = string.Join(":", comps.Skip(1));
  72. else if (comps.Length == 1)
  73. result[comps[0]] = "";
  74. }
  75. if (Answer == QAAnswer.Choice)
  76. CheckParams(result, "Options", "Colors", "Default");
  77. else if (Answer == QAAnswer.Number)
  78. CheckParams(result, "Minimum", "Maximum", "Default");
  79. else if (Answer == QAAnswer.Text)
  80. CheckParams(result, "Default");
  81. if (Answer == QAAnswer.Combo)
  82. CheckParams(result, "Options", "Default");
  83. return result;
  84. }
  85. private void CheckParams(Dictionary<string, string> result, params string[] keys)
  86. {
  87. foreach (var key in keys)
  88. if (!result.ContainsKey(key))
  89. result[key] = "";
  90. }
  91. }
  92. }