Пример #1
0
        private List <CheckBoxListTree> createCheckBoxListFrom(List <CheckBoxItem> checkedboxes)
        {
            List <CheckBoxListTree> chkboxList = new List <CheckBoxListTree>();

            if (!checkedboxes.IsNullOrEmpty())
            {
                //we expect that the list to be sorted.
                foreach (CheckBoxItem chkBoxItem in checkedboxes)
                {
                    CheckBoxListTree mp1InTree;
                    chkBoxItem.Label = chkBoxItem.Mp3Name;

                    //check here if the main list contains MP1
                    if (checkBoxListTreeContainsMp1Name(chkBoxItem.Mp1Name, chkboxList, out mp1InTree))
                    {
                        //Mp1 exist....we have a value in mp2ChkBoxLstTree
                        mp1InTree.IsNullThrowException("Programming error. this should never be null.");

                        //does the MP2 exist in this MP1?
                        CheckBoxListTree mp2List;
                        if (checkBoxListTreeContainsMp1Name(chkBoxItem.Mp2Name, mp1InTree.Mp2List, out mp2List))
                        {
                            //Mp2List has been found.
                            //since the original list contains unique values and this is a new item,
                            //we can assume MP3 is not a part of this list... add it.
                            mp2List.CheckedBoxesList.Add(chkBoxItem);
                        }
                        else
                        {
                            //Mp2List has not been found.
                            //create a new Mp2List
                            mp2List      = new CheckBoxListTree();
                            mp2List.Name = chkBoxItem.Mp2Name;

                            //now since this is a new list... add the MP3 to cblt_MP2
                            mp2List.CheckedBoxesList.Add(chkBoxItem);
                            mp1InTree.Mp2List.Add(mp2List);
                        }
                        if (chkBoxItem.IsTrue)
                        {
                            mp1InTree.IsActve = true;
                            mp2List.IsActve   = true;
                        }
                        continue;
                    }

                    CheckBoxListTree cblt_MP1 = new CheckBoxListTree();
                    cblt_MP1.Name = chkBoxItem.Mp1Name;

                    //create the Mp2 as well, since it is the first
                    CheckBoxListTree cblt_MP2 = new CheckBoxListTree();
                    cblt_MP2.Name = chkBoxItem.Mp2Name;

                    //now since this is a new list... add the MP3 to cblt_MP2
                    cblt_MP2.CheckedBoxesList.Add(chkBoxItem);

                    if (chkBoxItem.IsTrue)
                    {
                        cblt_MP1.IsActve = true;
                        cblt_MP2.IsActve = true;
                    }

                    cblt_MP1.Mp2List.Add(cblt_MP2);
                    chkboxList.Add(cblt_MP1);
                }
            }

            return(chkboxList);
        }
Пример #2
0
 bool checkBoxListTreeContainsMp1Name(string name, List <CheckBoxListTree> checkBoxListTree, out CheckBoxListTree chkboxTree)
 {
     chkboxTree = null;
     if (!checkBoxListTree.IsNullOrEmpty())
     {
         foreach (CheckBoxListTree item in checkBoxListTree)
         {
             //this is checking for the MP name
             if (item.Name == name)
             {
                 chkboxTree = item;
                 return(true);
             }
         }
     }
     return(false);
 }