private static FieldControl CreateDefaultChoiceControl(ChoiceFieldSetting choiceSetting) { Type controlType = null; ChoiceControl control = null; if (choiceSetting != null) { switch (choiceSetting.DisplayChoice) { case DisplayChoice.CheckBoxes: controlType = typeof(CheckBoxGroup); break; case DisplayChoice.DropDown: controlType = typeof(DropDown); break; case DisplayChoice.RadioButtons: controlType = typeof(RadioButtonGroup); break; default: controlType = choiceSetting.AllowMultiple == true ? typeof(CheckBoxGroup) : typeof(DropDown); break; } control = (ChoiceControl)Activator.CreateInstance(controlType); } return(control); }
public override void SetData(object data) { if (this.ControlStateLoaded) { return; } var optString = data as string; if (string.IsNullOrEmpty(optString)) { return; } try { var optDoc = new XmlDocument(); optDoc.LoadXml(optString); var et = string.Empty; if (optDoc.DocumentElement != null) { ChoiceFieldSetting.ParseOptions(optDoc.DocumentElement.CreateNavigator(), this.DataList, null, out et); } } catch (Exception ex) { Logger.WriteException(ex); } }
public EnumOption(string name, string value, string originalName, ChoiceOption option, ChoiceFieldSetting choiceFielSetting, Class @class) { _class = @class; _choiceFielSetting = choiceFielSetting; Name = name; OriginalName = originalName; Value = value; }
void WizardNextButtonClick(object sender, WizardNavigationEventArgs e) { this.ContentView.UpdateContent(); var sb = new StringBuilder(); foreach (var item in _wizard.ActiveStep.Controls) { var fieldControl = item as FieldControl; if (fieldControl != null && !fieldControl.Field.IsValid) { sb.Clear(); foreach (var param in fieldControl.Field.ValidationResult.GetParameterNames()) { sb.Append(param); sb.Append(": "); sb.AppendLine(fieldControl.Field.ValidationResult.GetParameter(param).ToString()); } fieldControl.SetErrorMessage(sb.ToString()); e.Cancel = true; } } history.Push(e.CurrentStepIndex); PageBreakFieldSetting currentPageBreak; try { currentPageBreak = (from pbf in this.Content.Fields where pbf.Value.FieldSetting.FieldClassName == "ContentRepository.Fields.PageBreakField" orderby pbf.Value.FieldSetting.FieldIndex select pbf).ElementAt(e.CurrentStepIndex).Value.FieldSetting as PageBreakFieldSetting; } catch { currentPageBreak = null; } if (currentPageBreak != null) { var ruleXml = HttpUtility.HtmlDecode(currentPageBreak.Rule); var doc = new XmlDocument(); try { doc.LoadXml(ruleXml); } catch { return; } var selectedQuestion = doc.DocumentElement.GetAttribute("Question"); var rules = new Dictionary <string, int>(); foreach (XPathNavigator node in doc.DocumentElement.CreateNavigator().SelectChildren(XPathNodeType.Element)) { var answerId = node.GetAttribute("AnswerId", ""); int jumpToPage; int.TryParse(node.Value, out jumpToPage); if (jumpToPage != -1) { rules.Add(answerId, jumpToPage); } else { rules.Add(answerId, _wizard.WizardSteps.Count - 1); } } var answerControlEnum = (from fc in this.ContentView.FieldControls where fc.FieldName == selectedQuestion select fc); var answerControl = answerControlEnum.FirstOrDefault() as FieldControl; List <string> answer = null; ChoiceFieldSetting cfs = null; var foundOption = false; if (answerControl != null) { answer = answerControl.GetData() as List <string>; cfs = answerControl.Field.FieldSetting as ChoiceFieldSetting; } if (answer != null && answer.Count != 0) { var answerValue = answer.FirstOrDefault() ?? string.Empty; if (rules.ContainsKey(answerValue)) { //this is a regular option _wizard.ActiveStepIndex = rules[answerValue]; foundOption = true; } else if (cfs != null && //this should be a choice field cfs.AllowExtraValue.HasValue && //if it allows extra value cfs.AllowExtraValue.Value && !cfs.Options.Any(opt => opt.Value == answerValue) && //if the given value is none of the predefined (means extra) !(string.IsNullOrEmpty(answerValue) && cfs.Compulsory.HasValue && cfs.Compulsory.Value) && //the given value must not be empty if the field is compulsory rules.ContainsKey(SurveyRule.EXTRAVALUEID)) //if there is a rule for the extra value { //this is an extra value _wizard.ActiveStepIndex = rules[SurveyRule.EXTRAVALUEID]; foundOption = true; } } if (!foundOption && selectedQuestion != "-100") { _wizard.ActiveStepIndex = _wizard.ActiveStepIndex + 1; _wizard.ActiveStepIndex = _wizard.ActiveStepIndex - 1; this.ContentView.ContentException = new Exception("Compulsory: " + answerControl.FieldName.TrimStart('#')); } } else { _wizard.ActiveStepIndex = _wizard.WizardSteps.Count - 1; } }
private Enumeration(ChoiceFieldSetting choiceFieldSetting, Class @class, EnumOption[] options) : base(choiceFieldSetting, @class) { _choiceFieldSetting = choiceFieldSetting; Options = options; }
public Enumeration(ChoiceFieldSetting choiceFieldSetting, Class @class) : base(choiceFieldSetting, @class) { _choiceFieldSetting = choiceFieldSetting; Options = new MetaEnumOptionEnumerable(_choiceFieldSetting, @class).ToArray(); Key = $"{choiceFieldSetting.Name}:{string.Join(",", Options.Select(o => o.Name).ToArray())}"; }
public MetaEnumOptionEnumerable(ChoiceFieldSetting choiceFieldSetting, Class @class) { _class = @class; _choiceFielSetting = choiceFieldSetting; }