Beispiel #1
0
        public void ImportFromModel(object model, params object[] context)
        {
            TValue input = default(TValue);

            if (model != null)
            {
                input = (TValue)model;
            }


            ChoiceList <TChoiceItem, TValue, TDisplay> choiceList = context[0] as ChoiceList <TChoiceItem, TValue, TDisplay>;

            List <MutualExclusionListItem <TValue> > items = new List <MutualExclusionListItem <TValue> >();


            foreach (TChoiceItem item in choiceList.Items)
            {
                MutualExclusionListItem <TValue> mutualExclusionListItem = new MutualExclusionListItem <TValue>();

                mutualExclusionListItem.Value = choiceList.ValueSelector(item);
                mutualExclusionListItem.Label = choiceList.DisplaySelector(item).ToString();

                if (choiceList.LabelAttributesSelector != null)
                {
                    mutualExclusionListItem.LabelAttributes = choiceList.LabelAttributesSelector(item);
                }
                else
                {
                    mutualExclusionListItem.LabelAttributes = new { }
                };
                if (choiceList.DisplayAttributesSelector != null)
                {
                    mutualExclusionListItem.DisplayAttributes = choiceList.DisplayAttributesSelector(item);
                }
                else
                {
                    mutualExclusionListItem.DisplayAttributes = new { }
                };
                items.Add(mutualExclusionListItem);

                if (((IComparable)input).CompareTo(mutualExclusionListItem.Value) == 0)
                {
                    mutualExclusionListItem.Selected = true;
                }
            }
            Items = items.ToArray();
        }
    }
Beispiel #2
0
        public void ImportFromModel(object model, params object[] context)
        {
            IEnumerable   input = model as IEnumerable;
            List <TValue> inputList;

            if (input == null)
            {
                inputList = new List <TValue>();
            }
            else
            {
                inputList = EnumerableHelper.CreateFrom <TValue>(typeof(List <TValue>), input, 0) as List <TValue>;

                inputList.Sort();

                ChoiceList <TChoiceItem, TValue, TDisplay> choiceList = context[0] as ChoiceList <TChoiceItem, TValue, TDisplay>;

                List <CheckBoxListItem <TValue> > items   = new List <CheckBoxListItem <TValue> >();
                List <OrderItem <TValue> >        orderer = new List <OrderItem <TValue> >();

                int index = 0;

                foreach (TChoiceItem item in choiceList.Items)
                {
                    CheckBoxListItem <TValue> checkBoxListItem = new CheckBoxListItem <TValue>();
                    OrderItem <TValue>        orderItem        = new OrderItem <TValue>();
                    checkBoxListItem.Code  = choiceList.ValueSelector(item);
                    checkBoxListItem.Label = choiceList.DisplaySelector(item).ToString();

                    if (choiceList.LabelAttributesSelector != null)
                    {
                        checkBoxListItem.LabelAttributes = choiceList.LabelAttributesSelector(item);
                    }
                    else
                    {
                        checkBoxListItem.LabelAttributes = new { }
                    };
                    if (choiceList.DisplayAttributesSelector != null)
                    {
                        checkBoxListItem.DisplayAttributes = choiceList.DisplayAttributesSelector(item);
                    }
                    else
                    {
                        checkBoxListItem.DisplayAttributes = new { }
                    };
                    items.Add(checkBoxListItem);

                    orderItem.Value = checkBoxListItem.Code;
                    orderItem.Place = index;
                    orderer.Add(orderItem);
                    index++;
                }
                Items = items.ToArray();
                orderer.Sort();
                IEnumerator <OrderItem <TValue> > ordererIterator = (orderer as IEnumerable <OrderItem <TValue> >).GetEnumerator();
                ordererIterator.Reset();
                ordererIterator.MoveNext();
                foreach (TValue selectedValue in inputList)
                {
                    while (((IComparable)selectedValue).CompareTo(ordererIterator.Current.Value) > 0)
                    {
                        ordererIterator.MoveNext();
                    }
                    if (((IComparable)selectedValue).CompareTo(ordererIterator.Current.Value) == 0)
                    {
                        Items[ordererIterator.Current.Place].Selected = true;
                    }
                }
            }
        }
    }