QAQuestion.cs 3.6 KB

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