Esempio n. 1
0
        /// <summary>
        /// Creates an exact copy of a grouptype, including its list of ItemTypeOrders
        /// </summary>
        /// <param name="gt"></param>
        /// <returns></returns>
        public GroupType DeepCopyGroupType(GroupType gt)
        {
            GroupType deepCopyGroupType = new GroupType();
            deepCopyGroupType.DanishTranslationText = gt.DanishTranslationText;
            deepCopyGroupType.EnglishTranslationText = gt.EnglishTranslationText;
            deepCopyGroupType.GroupHeader = gt.GroupHeader;
            deepCopyGroupType.GroupTypeID = gt.GroupTypeID;
            deepCopyGroupType.ItemOrder = gt.ItemOrder;
            deepCopyGroupType.LanguageID = gt.LanguageID;
            deepCopyGroupType.ResourceID = gt.ResourceID;
            deepCopyGroupType.ResourceType = gt.ResourceType;
            deepCopyGroupType.ResourceTypeID = gt.ResourceTypeID;
            ObservableCollection<ItemTypeOrder> deepCopyItemTypeOrders = new ObservableCollection<ItemTypeOrder>();
            foreach (ItemTypeOrder ito in gt.ItemOrder)
            {
                ItemTypeOrder clonedito = new ItemTypeOrder();
                clonedito.DesignID = ito.DesignID;
                clonedito.GroupTypeID = ito.GroupTypeID;
                clonedito.IncludedTypeID = ito.IncludedTypeID;
                clonedito.Item = ito.Item;
                clonedito.ItemOrder = ito.ItemOrder;
                deepCopyItemTypeOrders.Add(clonedito);
            }

            deepCopyGroupType.ItemOrder = deepCopyItemTypeOrders;
            return deepCopyGroupType;
        }
 /// <summary>
 /// Handles drop logic on null field
 /// </summary>
 /// <param name="dropTargetItemTypeOrder"></param>
 /// <param name="tbi"></param>
 /// <param name="gt"></param>
 public void ToolboxItemDropOnNullField(ItemTypeOrder dropTargetItemTypeOrder, ToolboxItem tbi, GroupType gt)
 {
     dropTargetItemTypeOrder.DesignID = tbi.ItemType.DesignID;
     ItemType itemType = new ItemType();
     itemType.DesignID = tbi.ItemType.DesignID;
     itemType.Header = tbi.ItemType.Header;
     itemType.DanishTranslationText = tbi.ItemType.DanishTranslationText;
     itemType.EnglishTranslationText = tbi.ItemType.EnglishTranslationText;
     itemType.LanguageID = tbi.ItemType.LanguageID;
     dropTargetItemTypeOrder.GroupTypeID = gt.GroupTypeID;
     dropTargetItemTypeOrder.IncludedTypeID = "1";
     dropTargetItemTypeOrder.Item = itemType;
     gt.ItemOrder.Add(dropTargetItemTypeOrder);
     GenerateEmptyFields(gt);
 }
 /// <summary>
 /// Handles drop logic on emptyfield
 /// </summary>
 /// <param name="dropTargetItemTypeOrder"></param>
 /// <param name="tbi"></param>
 /// <param name="gt"></param>
 public void ToolboxItemDropOnEmptyField(ItemTypeOrder dropTargetItemTypeOrder, ToolboxItem tbi, GroupType gt)
 {
     dropTargetItemTypeOrder.DesignID = tbi.ItemType.DesignID;
     dropTargetItemTypeOrder.Item.Header = tbi.ItemType.Header;
     dropTargetItemTypeOrder.Item.DanishTranslationText = tbi.ItemType.DanishTranslationText;
     dropTargetItemTypeOrder.Item.EnglishTranslationText = tbi.ItemType.EnglishTranslationText;
     dropTargetItemTypeOrder.Item.LanguageID = tbi.ItemType.LanguageID;
     dropTargetItemTypeOrder.GroupTypeID = gt.GroupTypeID;
     dropTargetItemTypeOrder.IncludedTypeID = "1";
 }
 /// <summary>
 /// Removes an ItemTypeOrder from a group
 /// </summary>
 /// <param name="gt"></param>
 /// <param name="ito">The ItemTypeOrder to be removed</param>
 public void RemoveItemTypeOrder(GroupType gt, ItemTypeOrder ito)
 {
     gt.ItemOrder.Remove(ito);
     AdjustItemOrder(gt);
 }
        public void MoveItemsForward(int startPosition, ItemTypeOrder newItemType, GroupType gt)
        {
            ObservableCollection<ItemTypeOrder> itemTypeList = gt.ItemOrder;
            bool stopCounting = false;
            int i = startPosition;
            while (i < itemTypeList.Count && !stopCounting)
            {
                if (itemTypeList[i].DesignID.Equals("198"))
                {
                    if (itemTypeList[i].ItemOrder % 4 == 3)
                    {
                        itemTypeList.RemoveAt(i);
                    }
                    else
                    {
                        itemTypeList[i].ItemOrder++;
                    }
                    stopCounting = true;
                }
                else
                {
                    itemTypeList[i].ItemOrder++;
                    i++;
                }
            }
            itemTypeList.Add(newItemType);
            itemTypeList.Sort(ito => ito.ItemOrder);

            _wvm._changedFlag = true;
        }
 /// <summary>
 /// Inserts a group at the end of a list. Used when dropping a new group from toolbox on a page
 /// </summary>
 /// <param name="gt"></param>
 /// <param name="pageTypeID"></param>
 public void InsertGroupLast(GroupType gt, string pageTypeID)
 {
     GroupTypeOrder gtoCompare = GroupTypeOrderCollection.Last();
     GroupTypeOrder gto = new GroupTypeOrder();
     gto.DepartmentID = "-1";
     gto.PageTypeID = pageTypeID;
     gto.Group = gt;
     gto.GroupTypeID = gt.GroupTypeID;
     gto.GroupOrder = gtoCompare.GroupOrder + 1;
     GroupTypeOrderCollection.Add(gto);
 }
Esempio n. 7
0
        public void ToolboxGroupsFilterList()
        {
            GroupType gt = new GroupType();
            gt.DanishTranslationText = "Øre, næse og hals";
            gt.EnglishTranslationText = "Ear, nose and throat";
            gt.GroupTypeID = "10";
            gt.ItemOrder = null;
            gt.LanguageID = "2";
            gt.ResourceID = "";
            gt.ResourceType = null;
            gt.ResourceTypeID = null;
            ToolboxGroup tbGroup = new ToolboxGroup();
            tbGroup.Group = gt;

            GroupType gt2 = new GroupType();
            gt2.DanishTranslationText = "Risikofaktorer for infektion";
            gt2.EnglishTranslationText = "Risk Factors for infection";
            gt2.GroupTypeID = "10";
            gt2.ItemOrder = null;
            gt2.LanguageID = "2";
            gt2.ResourceID = "";
            gt2.ResourceType = null;
            gt2.ResourceTypeID = null;
            ToolboxGroup tbGroup2 = new ToolboxGroup();
            tbGroup2.Group = gt2;

            glvm.GTList.Add(tbGroup);
            glvm.GTList.Add(tbGroup2);
            glvm.LanguageID = "1";
            glvm.SetupToolBoxItemCollectionView();
            glvm.FilterString = "Risk Factors";
            //ifvm.DesignItemsView = CollectionViewSource.GetDefaultView(ifvm.ToolboxItemList);
            Assert.IsTrue(glvm.DesignItemsView.Contains(tbGroup2));
            Assert.IsFalse(glvm.DesignItemsView.Contains(tbGroup));
        }
 /// <summary>
 /// Determines how the order of the items in a group should be adjusted
 /// </summary>
 /// <param name="gt"></param>
 /// <param name="targetPosition"></param>
 /// <param name="draggedPosition"></param>
 public void AdjustItemOrder(GroupType gt, int targetPosition, int draggedPosition)
 {
     if (targetPosition < draggedPosition)
     {
         IncrementItemOrder(gt, targetPosition, draggedPosition);
     }
     else
     {
         DecrementItemOrder(gt, targetPosition, draggedPosition);
     }
     _wvm._changedFlag = true;
 }
 /// <summary>
 /// Handles drop logic for items from toolbox. Drop logic depends on the type of the dropped item 
 /// </summary>
 /// <param name="gt"></param>
 /// <param name="tbi"></param>
 /// <param name="dropTargetItemTypeOrder"></param>
 public void HandleToolboxItemDrop(GroupType gt, ToolboxItem tbi, ItemTypeOrder dropTargetItemTypeOrder)
 {
     string dropTargetDesignID = dropTargetItemTypeOrder.DesignID;
     if (tbi.ItemType.DesignID.Equals("198") && dropTargetDesignID != null)
     {
         ToolboxSpecialNewLineItemDrop(dropTargetItemTypeOrder, tbi, gt);
     }
     if (dropTargetDesignID != null && !tbi.ItemType.DesignID.Equals("198") && !dropTargetDesignID.Equals("197"))
     {
         ToolboxItemDropOnStandardItem(dropTargetItemTypeOrder, tbi, gt);
     }
     if (dropTargetDesignID == null) //drop on null field
     {
         ToolboxItemDropOnNullField(dropTargetItemTypeOrder, tbi, gt);
     }
     if (dropTargetDesignID != null && dropTargetDesignID.Equals("197") && !tbi.ItemType.DesignID.Equals("198"))
     {
         ToolboxItemDropOnEmptyField(dropTargetItemTypeOrder, tbi, gt);
     }
 }
Esempio n. 10
0
        /// <summary>
        /// Handles drop logic for items from a group. Drop logic depends on both drop target and dragged item
        /// </summary>
        /// <param name="gt"></param>
        /// <param name="targetItemType"></param>
        /// <param name="draggedItemType"></param>
        public void HandleDropAndDropBetweenItems(GroupType gt, ItemTypeOrder targetItemType, ItemTypeOrder draggedItemType)
        {
            if (!gt.Equals(Group)) //dropping an item from one group to another
            {
                ToolboxItem tbi = new ToolboxItem();
                RemoveItemTypeOrder(gt, draggedItemType);
                tbi.ItemType = draggedItemType.Item;
                HandleToolboxItemDrop(Group, tbi, targetItemType);
                GroupTypeOrderCollection.Sort(x => x.GroupOrder); //refresh all groups to show the changes
            }
            else
            {
                int draggedPosition = gt.ItemOrder.IndexOf(draggedItemType);
                double targetItemTypeNo = targetItemType.ItemOrder; //affected item
                int targetPosition = gt.ItemOrder.IndexOf(targetItemType);

                if (targetItemType != draggedItemType)
                {
                    gt.ItemOrder.Remove(draggedItemType);
                    if (targetItemType.DesignID == null && !draggedItemType.DesignID.Equals("198"))
                    {
                        AdjustItemOrder(gt);
                        draggedItemType.ItemOrder = targetItemType.ItemOrder;
                        gt.ItemOrder.Add(draggedItemType);
                        gt.ItemOrder.Sort(i => i.ItemOrder);
                        GenerateEmptyFields(gt);
                    }
                    else if (targetItemType.DesignID == null && draggedItemType.DesignID.Equals("198"))
                    {

                        draggedItemType.ItemOrder = targetItemType.ItemOrder;
                        gt.ItemOrder.Add(draggedItemType);
                        gt.ItemOrder.Sort(i => i.ItemOrder);
                        GenerateEmptyFields(gt);
                        AdjustItemOrder(gt);

                    }

                    else if (draggedItemType.DesignID.Equals("198"))
                    {
                        if (draggedItemType.ItemOrder > targetItemType.ItemOrder)
                        {
                            gt.ItemOrder.Insert(targetPosition, draggedItemType);
                            draggedItemType.ItemOrder = targetItemTypeNo;
                            gt.ItemOrder.Sort(i => i.ItemOrder);
                            AdjustItemOrder(gt);
                        }
                        else
                        {
                            draggedItemType.ItemOrder = targetItemTypeNo;

                            //gt.ItemOrder.Insert(targetPosition - 1, draggedItemType);
                            gt.ItemOrder.Insert(targetPosition - 1, draggedItemType);
                            gt.ItemOrder.Sort(i => i.ItemOrder);
                            GenerateEmptyFields(gt);
                            AdjustItemOrder(gt);
                        }
                        //GenerateEmptyFields(gt);
                        gt.ItemOrder.Sort(i => i.ItemOrder);
                    }

                    else if (targetItemType.DesignID != null && draggedItemType.DesignID != null /*&& !draggedItemType.DesignID.Equals("198")*/)
                    {
                        if (draggedItemType.ItemOrder > targetItemType.ItemOrder)
                        {
                            gt.ItemOrder.Insert(targetPosition, draggedItemType);
                            draggedItemType.ItemOrder = targetItemTypeNo;
                        }
                        else
                        {
                            if (gt.ItemOrder.Count != targetPosition)
                            {
                                draggedItemType.ItemOrder = targetItemTypeNo;
                                gt.ItemOrder.Insert(targetPosition, draggedItemType);
                            }
                            else
                            {
                                draggedItemType.ItemOrder = targetItemTypeNo;
                                gt.ItemOrder.Add(draggedItemType);
                            }
                        }
                        AdjustItemOrder(gt, targetPosition, draggedPosition);

                        GenerateEmptyFields(gt);
                        gt.ItemOrder.Sort(i => i.ItemOrder);
                    }
                }
            }
        }
Esempio n. 11
0
        /// <summary>
        /// Generates emptyfields for gaps between items of any time. Takes NewLineItem into account when generating
        /// </summary>
        /// <param name="gt"></param>
        public void GenerateEmptyFields(GroupType gt)
        {
            int i = 0;
            while (i < gt.ItemOrder.Count)
            {
                int noOfEmptyFieldsCounter = 0;
                if (gt.ItemOrder.Count > 1)
                {
                    if (gt.ItemOrder[i].ItemOrder != i)
                    {
                        int totalNumberOfEmptyFields = 0;
                        if (i != 0 && !gt.ItemOrder[i - 1].DesignID.Equals("198"))
                        {
                            noOfEmptyFieldsCounter = (int)gt.ItemOrder[i].ItemOrder - (int)gt.ItemOrder[i - 1].ItemOrder;
                            totalNumberOfEmptyFields = noOfEmptyFieldsCounter;
                            while (noOfEmptyFieldsCounter > 1) //Insert Empty fields
                            {
                                gt.ItemOrder.Insert(i, CreateEmptyField(gt, i + noOfEmptyFieldsCounter - 2));
                                noOfEmptyFieldsCounter--;
                            }
                            //i = totalNumberOfEmptyFields - 1;
                            if (totalNumberOfEmptyFields > 1)
                            {
                                i = i + totalNumberOfEmptyFields - 1;
                            }
                        }
                        else
                        {
                            if (i != 0)
                            {
                                totalNumberOfEmptyFields = (int)gt.ItemOrder[i].ItemOrder -
                                                           ((int)gt.ItemOrder[i - 1].ItemOrder +
                                                            (4 - (((int)gt.ItemOrder[i - 1].ItemOrder) % 4)));
                            }
                            else
                            {
                                totalNumberOfEmptyFields = (int)gt.ItemOrder[i].ItemOrder;

                            }

                            ItemTypeOrder firstEmptyFieldGenerated = null;
                            noOfEmptyFieldsCounter = totalNumberOfEmptyFields;
                            while (noOfEmptyFieldsCounter > 0)
                            {

                                //gt.ItemOrder.Insert(i, CreateEmptyField(gt, (int)gt.ItemOrder[i].ItemOrder - noOfEmptyFieldsCounter));
                                ItemTypeOrder emptyField = CreateEmptyField(gt,
                                    (int)gt.ItemOrder[i].ItemOrder - noOfEmptyFieldsCounter);
                                if (noOfEmptyFieldsCounter == totalNumberOfEmptyFields)
                                    firstEmptyFieldGenerated = emptyField;
                                gt.ItemOrder.Insert(i, emptyField);
                                noOfEmptyFieldsCounter--;
                            }
                            if (totalNumberOfEmptyFields > 0)
                            {
                                //i = gt.ItemOrder.Count - 1;
                                i = gt.ItemOrder.IndexOf(firstEmptyFieldGenerated) + 1;
                            }
                        }
                    }
                    i++;

                }
                else
                {
                    noOfEmptyFieldsCounter = (int)gt.ItemOrder[i].ItemOrder;
                    //totalNumberOfEmptyFields = noOfEmptyFieldsCounter + i;
                    while (noOfEmptyFieldsCounter > 0)
                    {
                        gt.ItemOrder.Insert(i, CreateEmptyField(gt, i + noOfEmptyFieldsCounter - 2));
                        noOfEmptyFieldsCounter--;
                    }
                    break;
                }
            }
            _wvm._changedFlag = true;
        }
Esempio n. 12
0
 public void DecrementItemOrder(GroupType gt, int targetPosition, int draggedPosition)
 {
     int i = targetPosition - 1;
     while (i >= draggedPosition)
     {
         if (!gt.ItemOrder[i].DesignID.Equals("198"))
         {
             gt.ItemOrder[i].ItemOrder--;
         }
         else
         {
             gt.ItemOrder[i].ItemOrder--;
             break;
         }
         i--;
     }
     _wvm._changedFlag = true;
 }
Esempio n. 13
0
        public ItemTypeOrder CreateEmptyField(GroupType gt, int itemOrder)
        {
            ItemTypeOrder itemTypeOrder = new ItemTypeOrder();
            itemTypeOrder.GroupTypeID = gt.GroupTypeID;
            itemTypeOrder.DesignID = "197";
            ItemType emptyFieldItemType = new ItemType();
            emptyFieldItemType.DesignID = "197";
            emptyFieldItemType.Header = "<EmptyField>";
            itemTypeOrder.IncludedTypeID = "1";
            itemTypeOrder.ItemOrder = itemOrder;
            itemTypeOrder.Item = emptyFieldItemType;

            _wvm._changedFlag = true;

            return itemTypeOrder;
        }
Esempio n. 14
0
 /// <summary>
 /// Adjust the order of the items in a group in relation to drop of a NewLineItem
 /// </summary>
 /// <param name="gt"></param>
 /// <param name="draggedPosition"></param>
 public void AdjustItemOrderNewLineItemDrop(GroupType gt, int draggedPosition)
 {
     int j = 0;
     bool stop = false;
     while (j < gt.ItemOrder.Count && !stop)
     {
         if (gt.ItemOrder[j].Item.DesignID.Equals("198"))
         {
             stop = true;
         }
         gt.ItemOrder[j].ItemOrder = j;
         j++;
     }
     int i = draggedPosition;
     while (i < gt.ItemOrder.Count)
     {
         if (gt.ItemOrder[i].DesignID.Equals("198"))
         {
             if (i != 0)
                 gt.ItemOrder[i].ItemOrder = gt.ItemOrder[i - 1].ItemOrder + 1;
             i++;
             gt.ItemOrder[i].ItemOrder = gt.ItemOrder[i - 1].ItemOrder + (4 - (gt.ItemOrder[i - 1].ItemOrder % 4));
             i++;
         }
         else
         {
             gt.ItemOrder[i].ItemOrder = gt.ItemOrder[i - 1].ItemOrder + 1;
             i++;
         }
     }
     _wvm._changedFlag = true;
 }
Esempio n. 15
0
 /// <summary>
 /// Adjust the order of the items in a group
 /// </summary>
 /// <param name="gt"></param>
 public void AdjustItemOrder(GroupType gt)
 {
     int j = 0;
     bool stop = false;
     while (j < gt.ItemOrder.Count && !stop)
     {
         if (gt.ItemOrder[j].Item.DesignID.Equals("198"))
         {
             stop = true;
         }
         gt.ItemOrder[j].ItemOrder = j;
         j++;
     }
     int i = j - 1;
     if (i > 0)
     {
         while (i < gt.ItemOrder.Count)
         {
             if (gt.ItemOrder[i].DesignID.Equals("198") && i + 1 != gt.ItemOrder.Count)
             {
                 i++;
                 gt.ItemOrder[i].ItemOrder = gt.ItemOrder[i - 1].ItemOrder +
                                             (4 - (gt.ItemOrder[i - 1].ItemOrder % 4));
                 i++;
             }
             else
             {
                 gt.ItemOrder[i].ItemOrder = gt.ItemOrder[i - 1].ItemOrder + 1;
                 i++;
             }
         }
     }
     _wvm._changedFlag = true;
 }
Esempio n. 16
0
 /// <summary>
 /// Handles drop logic for standard item from toolbox
 /// </summary>
 /// <param name="dropTargetItemTypeOrder"></param>
 /// <param name="tbi"></param>
 /// <param name="gt"></param>
 public void ToolboxItemDropOnStandardItem(ItemTypeOrder dropTargetItemTypeOrder, ToolboxItem tbi, GroupType gt)
 {
     ItemTypeOrder itemTypeOrder = new ItemTypeOrder();
     itemTypeOrder.DesignID = tbi.ItemType.DesignID;
     ItemType itemType = new ItemType { DesignID = tbi.ItemType.DesignID, Header = tbi.ItemType.Header };
     itemTypeOrder.ItemOrder = dropTargetItemTypeOrder.ItemOrder;
     itemType.DanishTranslationText = tbi.ItemType.DanishTranslationText;
     itemType.EnglishTranslationText = tbi.ItemType.EnglishTranslationText;
     itemType.LanguageID = tbi.ItemType.LanguageID;
     itemTypeOrder.GroupTypeID = gt.GroupTypeID;
     itemTypeOrder.IncludedTypeID = "1";
     itemTypeOrder.Item = itemType;
     int startPosition = gt.ItemOrder.IndexOf(dropTargetItemTypeOrder);
     MoveItemsForward(startPosition, itemTypeOrder, gt);
 }
Esempio n. 17
0
        /// <summary>
        /// Handles drop logic for NewLineItem from toolbox
        /// </summary>
        /// <param name="dropTargetItemTypeOrder"></param>
        /// <param name="tbi"></param>
        /// <param name="gt"></param>
        public void ToolboxSpecialNewLineItemDrop(ItemTypeOrder dropTargetItemTypeOrder, ToolboxItem tbi, GroupType gt)
        {
            CheckForNewLineItem(dropTargetItemTypeOrder);
            ItemTypeOrder itemTypeOrder = new ItemTypeOrder();
            itemTypeOrder.DesignID = tbi.ItemType.DesignID;
            ItemType itemType = new ItemType();
            itemType.DesignID = tbi.ItemType.DesignID;
            itemType.Header = tbi.ItemType.Header;
            itemTypeOrder.ItemOrder = dropTargetItemTypeOrder.ItemOrder;
            itemType.DanishTranslationText = tbi.ItemType.DanishTranslationText;
            itemType.EnglishTranslationText = tbi.ItemType.EnglishTranslationText;
            itemType.LanguageID = tbi.ItemType.LanguageID;
            itemTypeOrder.GroupTypeID = gt.GroupTypeID;
            itemTypeOrder.IncludedTypeID = "1";
            itemTypeOrder.Item = itemType;

            int index = gt.ItemOrder.IndexOf(dropTargetItemTypeOrder);

            gt.ItemOrder.Insert(index, itemTypeOrder);
            int draggedIndex = gt.ItemOrder.IndexOf(itemTypeOrder);

            AdjustItemOrderNewLineItemDrop(gt, draggedIndex);
            //AdjustItemOrder(gt);
        }
Esempio n. 18
0
 public void IncrementItemOrder(GroupType gt, int position, int startPosition)
 {
     int i = position + 1;
     while (i <= startPosition)
     {
         if (!gt.ItemOrder[i].DesignID.Equals("198"))
         {
             gt.ItemOrder[i].ItemOrder++;
         }
         else
         {
             break;
         }
         i++;
     }
     _wvm._changedFlag = true;
 }
Esempio n. 19
0
        ///// <summary>
        ///// Creates a new group on a the page
        ///// </summary>
        ///// <param name="pageTypeId">The id for the selected page</param>
        ///// <param name="languageId">The selected language of the application</param>
        ///// <param name="groupOrder">The group order number on the selected page</param>
        ///// <param name="englishTranslationText">The english group name</param>
        ///// <param name="danishTranslationText">The danish group name</param>
        //public void CreateGroup(string pageTypeId, string languageId, double groupOrder, string englishTranslationText, string danishTranslationText)
        //{
        //    GroupTypeOrder gtOrder = new GroupTypeOrder();
        //    GroupType groupType = new GroupType();
        //    //Create new GroupTypeOrder
        //    gtOrder.DepartmentID = "-1";
        //    gtOrder.PageTypeID = pageTypeId;
        //    int highestId = 0;
        //    foreach (PageType page in PageList)
        //    {
        //        int index = 0;
        //        while (index < page.GroupTypeOrders.Count)
        //        {
        //            if (Convert.ToInt32(page.GroupTypeOrders[index].GroupTypeID) > highestId)
        //            {
        //                highestId = Convert.ToInt32(page.GroupTypeOrders[index].GroupTypeID);
        //            }
        //            index++;
        //        }
        //    }
        //    gtOrder.GroupTypeID = (highestId + 1).ToString();
        //    gtOrder.GroupOrder = groupOrder;
        //    //Create new GroupType
        //    groupType.GroupTypeID = (highestId + 1).ToString();
        //    groupType.DanishTranslationText = danishTranslationText;
        //    groupType.EnglishTranslationText = englishTranslationText;
        //    groupType.LanguageID = languageId;
        //    string hej = englishTranslationText.Replace(" ", string.Empty);
        //    int i = 1;
        //    foreach (PageType page in PageList)
        //    {
        //        while ((from a in page.GroupTypeOrders where a.Group.ResourceType.Equals(hej + i) select a).Any())
        //        {
        //            i++;
        //        }
        //    }
        //    hej = hej + i;
        //    groupType.ResourceType = hej;
        //    groupType.ResourceID = (_groupCounter + 1).ToString();
        //    _groupCounter++;
        //    groupType.ResourceTypeID = "1";
        //    //Reference GroupTypeOrder with GroupType
        //    gtOrder.Group = groupType;
        //    int hello = 0;
        //    while (hello < PageList.Count)
        //    {
        //        if (PageList[hello].PageTypeID.Equals(pageTypeId))
        //        {
        //            PageList[hello].GroupTypeOrders.Add(gtOrder);
        //        }
        //        hello++;
        //    }
        //}
        /// <summary>
        /// Creates a new group on a the page
        /// </summary>
        /// <param name="pageTypeId">The id for the selected page</param>
        /// <param name="englishTranslationText">The english group name</param>
        /// <param name="danishTranslationText">The danish group name</param>
        /// <param name="departmentList">The selected departments the group is in</param>
        public void CreateGroup(string pageTypeId, string englishTranslationText, string danishTranslationText, List<string> departmentList)
        {
            GroupType groupType = new GroupType();

            //Create new GroupTypeOrder

            int highestId = 0;

            foreach (PageType page in PageList)
            {
                int highestIdOnPage = Convert.ToInt32(page.GroupTypeOrders.Max(x => x.GroupTypeID));
                if (highestIdOnPage > highestId)
                    highestId = highestIdOnPage;
                //int index = 0;

                //while (index < page.GroupTypeOrders.Count)
                //{
                //    if (Convert.ToInt32(page.GroupTypeOrders[index].GroupTypeID) > highestId)
                //    {
                //        highestId = Convert.ToInt32(page.GroupTypeOrders[index].GroupTypeID);
                //    }

                //    index++;
                //}
            }

            ObservableCollection<GroupTypeOrder> groupTypeOrderCollection = PageList.First(x => x.PageTypeID.Equals(pageTypeId)).GroupTypeOrders;
            GroupTypeOrder gtoCompare = groupTypeOrderCollection.Last();

            //Create new GroupType
            groupType.GroupTypeID = (highestId + 1).ToString();
            groupType.DanishTranslationText = danishTranslationText;
            groupType.EnglishTranslationText = englishTranslationText;
            groupType.LanguageID = gtoCompare.Group.LanguageID;

            string hej = englishTranslationText.Replace(" ", string.Empty);
            int i = 1;
            foreach (PageType page in PageList)
            {
                while ((from a in page.GroupTypeOrders where a.Group.ResourceType.Equals(hej + i) select a).Any())
                {
                    i++;
                }
            }

            hej = hej + i;

            groupType.ResourceType = hej;

            groupType.ResourceID = (_groupCounter + 1).ToString();
            _groupCounter++;
            groupType.ResourceTypeID = "1";

            //Reference GroupTypeOrder with GroupType

            ToolboxGroupsViewModel glvm = ToolboxGroupsViewModel.Instance;
            ToolboxGroup tbg = new ToolboxGroup();
            tbg.Group = groupType;
            glvm.GTList.Add(tbg);

            //int hello = 0;
            //while (hello < PageList.Count)
            //{
            //    if (PageList[hello].PageTypeID.Equals(pageTypeId))
            //    {
            //        PageList[hello].GroupTypeOrders.Add(gtOrder);
            //    }
            //    hello++;
            //}

            foreach (string departmentID in departmentList)
            {

                    GroupTypeOrder clonedGto = new GroupTypeOrder();
                    clonedGto.DepartmentID = departmentID;
                    clonedGto.Group = groupType;
                    //clonedGto.GroupOrder = gtoCompare.GroupOrder + 1;
                    clonedGto.GroupOrder = groupTypeOrderCollection.Max(x => x.GroupOrder) + 1;
                    clonedGto.GroupTypeID = (highestId + 1).ToString();
                    clonedGto.PageTypeID = pageTypeId;
                    groupTypeOrderCollection.Add(clonedGto);
            }
        }
Esempio n. 20
0
        public void InsertGroup(GroupTypeOrder targetGroupTypeOrder, GroupType groupType)
        {
            int targetPosition = GroupTypeOrderCollection.IndexOf(targetGroupTypeOrder);

            GroupTypeOrder gto = new GroupTypeOrder();
            gto.DepartmentID = "-1";
            gto.GroupOrder = targetGroupTypeOrder.GroupOrder - 1;
            gto.PageTypeID = targetGroupTypeOrder.PageTypeID;
            gto.GroupTypeID = groupType.GroupTypeID;
            gto.Group = groupType;

            GroupTypeOrderCollection.Insert(targetPosition, gto);
        }