コード例 #1
0
        private object ReadResponse()
        {
            if (ShowTextObs)        // Text
            {
                return(ResponseText);
            }

            if (ShowSingleObs) //"Single";
            {
                var selected = SelectedSingleOption.ItemId;
                if (selected.IsNullOrEmpty())
                {
                    return(null);
                }
                return(selected);
            }

            if (ShowNumericObs) //"Numeric";
            {
                var selected = ResponseNumeric;
                if (selected == 0)
                {
                    return(null);
                }
                return(selected);
            }

            if (ShowMultiObs)       //"Multi";
            {
                var options = MultiOptions.Where(x => x.Selected).ToList();
                return(string.Join(",", options.Select(x => x.ItemId)));
            }
            if (ShowDateObs)       //"Multi";
            {
                return(ResponseDate);
            }
            return(null);
        }
コード例 #2
0
        public void SetResponse(object response)
        {
            if (ShowTextObs)        // Text
            {
                ResponseText = response.ToString();
            }

            if (ShowSingleObs)      //"Single";
            {
                var text = response.ToString();
                if (!string.IsNullOrWhiteSpace(text))
                {
                    var option = SingleOptions.FirstOrDefault(x => x.ItemId == new Guid(text));
                    SelectedSingleOption = option;
                }
            }

            if (ShowNumericObs)     //"Numeric";
            {
                var text = response.ToString();
                if (!string.IsNullOrWhiteSpace(text))
                {
                    decimal numeric;
                    decimal.TryParse(text, out numeric);
                    ResponseNumeric = numeric;
                }
            }

            if (ShowMultiObs)       //"Multi";
            {
                var itemIds = new List <Guid>();
                var ids     = response.ToString().Split(',');
                foreach (var id in ids)
                {
                    itemIds.Add(new Guid(id));
                }
                if (itemIds.Count > 0)
                {
                    var multiOptions = new List <CategoryItem>();
                    var options      = MultiOptions
                                       .Where(
                        x => itemIds.Contains(x.ItemId) &&
                        x.ItemId != Guid.Empty)
                                       .ToList();

                    foreach (var categoryItem in MultiOptions)
                    {
                        if (options.Any(x => x.ItemId == categoryItem.ItemId))
                        {
                            if (!categoryItem.Selected)
                            {
                                categoryItem.Selected = true;
                            }
                        }
                        multiOptions.Add(categoryItem);
                    }

                    MultiOptions = multiOptions;
                }
            }

            if (ShowDateObs)     //"Date";
            {
                var text = response.ToString();
                if (!string.IsNullOrWhiteSpace(text))
                {
                    DateTime dateTime;
                    DateTime.TryParse(text, out dateTime);
                    ResponseDate = dateTime;
                }
            }
        }