123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace InABox.Core
- {
- [Caption("QA Checks")]
- [UserTracking(typeof(DigitalForm))]
- public class QAQuestion : Entity, IRemotable, IPersistent, ISequenceable, IOneToMany<DigitalForm>, ILicense<DigitalFormsLicense>
- {
- public QAQuestion()
- {
- Answer = QAAnswer.Comment;
- QAForm = new QAFormLink();
- Form = new DigitalFormLink();
- }
- [NullEditor]
- [Obsolete("Replaced with Form")]
- public QAFormLink QAForm { get; set; }
- public DigitalFormLink Form { get; set; }
- [NullEditor]
- public string Section { get; set; }
- [TextBoxEditor]
- public string Code { get; set; }
- [TextBoxEditor]
- public string Question { get; set; }
- [MemoEditor]
- public string Description { get; set; }
- [EnumLookupEditor(typeof(QAAnswer))]
- public QAAnswer Answer { get; set; }
- [MemoEditor]
- public string Parameters { get; set; }
- //[NullEditor]
- //public String Value { get; set; }
- //[MemoEditor]
- //public String Notes { get; set; }
- [NullEditor]
- public long Sequence { get; set; }
- protected override void DoPropertyChanged(string name, object before, object after)
- {
- base.DoPropertyChanged(name, before, after);
- if (name.Equals("Answer"))
- {
- var answer = (QAAnswer)after;
- if (answer == QAAnswer.Choice)
- Parameters =
- "Options: Value 1, Value 2, Value 3\n" +
- "Colors: Green, Yellow, Red\n" +
- "Default: Value 1\n";
- else if (answer == QAAnswer.Number)
- Parameters =
- "Minimum: 0.0\n" +
- "Maximum: 100.0\n" +
- "Default: 0.0\n";
- else if (answer == QAAnswer.Text)
- Parameters =
- "Default: \n";
- else if (answer == QAAnswer.Combo)
- Parameters =
- "Options: Value 1, Value 2, Value 3\n" +
- "Default: Value 1\n";
- else
- Parameters = "";
- }
- }
- public Dictionary<string, string> ParseParameters()
- {
- var result = new Dictionary<string, string>();
- var lines = Parameters == null ? new string[] { } : Parameters.Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);
- foreach (var line in lines)
- {
- var comps = line.Split(':');
- if (comps.Length > 1)
- result[comps[0]] = string.Join(":", comps.Skip(1));
- else if (comps.Length == 1)
- result[comps[0]] = "";
- }
- if (Answer == QAAnswer.Choice)
- CheckParams(result, "Options", "Colors", "Default");
- else if (Answer == QAAnswer.Number)
- CheckParams(result, "Minimum", "Maximum", "Default");
- else if (Answer == QAAnswer.Text)
- CheckParams(result, "Default");
- if (Answer == QAAnswer.Combo)
- CheckParams(result, "Options", "Default");
- return result;
- }
- private void CheckParams(Dictionary<string, string> result, params string[] keys)
- {
- foreach (var key in keys)
- if (!result.ContainsKey(key))
- result[key] = "";
- }
- }
- }
|