Example #1
0
 /// <summary>
 /// Creates a copy of GroupTypeOrderList. GroupTypeOrder are deep copied and GroupType are referenced
 /// </summary>
 /// <param name="gtoList"></param>
 /// <returns></returns>
 public ObservableCollection<GroupTypeOrder> DeepCopyGroupTypeOrderList(ObservableCollection<GroupTypeOrder> gtoList)
 {
     ObservableCollection<GroupTypeOrder> deepCopyGroupTypeOrders = new ObservableCollection<GroupTypeOrder>();
     foreach (GroupTypeOrder gto in gtoList)
     {
         GroupTypeOrder clonedgto = new GroupTypeOrder();
         clonedgto.DepartmentID = gto.DepartmentID;
         clonedgto.Group = gto.Group;
         clonedgto.GroupOrder = gto.GroupOrder;
         clonedgto.GroupTypeID = gto.GroupTypeID;
         clonedgto.PageTypeID = gto.PageTypeID;
         deepCopyGroupTypeOrders.Add(clonedgto);
     }
     return deepCopyGroupTypeOrders;
 }
 public void AdjustGroupOrder(GroupTypeOrder draggedGroupTypeOrder, GroupTypeOrder targetGroupTypeOrder)
 {
     //GTCViewModel.AdjustGroupOrder(draggedGroupTypeOrder, targetGroupTypeOrder);
 }
        ///// <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);
            }
        }
        private void InsertGroupItem(GroupTypeOrder groupTypeOrder, int row, int column)
        {
            Border bCell = GetCellItem(row, column);
            bCell.DataContext = groupTypeOrder;
            Grid gridGroupCell = (Grid)bCell.Child;
            TextBlock tb = (TextBlock)gridGroupCell.Children[1];

            WorkspaceViewModel wvm = WorkspaceViewModel.Instance;
            List<GroupTypeOrder> gtoList = wvm.PageList.First(x => x.PageTypeID.Equals(wvm.SelectedPage)).GroupTypeOrders.Where(x => x.GroupTypeID.Equals(MyGroupTypeOrder.GroupTypeID)).ToList();
            List<string> departmentList = new List<string>();
            foreach (GroupTypeOrder gto in gtoList)
                departmentList.Add(gto.DepartmentID);
            departmentList.Sort();
            MultiBinding multiBinding = new MultiBinding();
            multiBinding.StringFormat = "{0} ({1})";
            multiBinding.Bindings.Add(new Binding("Group.GroupHeader"));
            multiBinding.Bindings.Add(new Binding() { Source = string.Join(",", departmentList.ToArray()) });
            tb.SetBinding(TextBlock.TextProperty, multiBinding);
        }
        public void PopulateGroupTable(GroupTypeOrder gto)
        {
            if (PreviousGroupTypeOrder == null || PreviousGroupTypeOrder.GroupTypeID != gto.GroupTypeID)
            {
                PreviousGroupTypeOrder = gto;
                GroupType gt = gto.Group;
                CreateColumns(GroupTable, 4);
                int counterRow = 0;
                int counterColumn = 0;
                AddNewGroupRow();
                InsertGroupItem(gto, 0, 0);
                if(!_specialGroups.Any(x => x.Equals(gt.GroupTypeID)))
                {
                    int skipped = 0;
                    for (int j = 0; j < gt.ItemOrder.Count - skipped; j++)
                    {
                        if (gt.ItemOrder[j + skipped].DesignID.Equals("198"))
                        {
                            if (j%4 == 0)
                            {
                                AddNewEmptyItemRow();
                                counterRow++;
                                gt.ItemOrder[j + skipped].Item.Header = "<NewLineItem>";
                                //gt.ItemOrder[j + skipped].ItemOrder = j + skipped;
                                InsertItem(gt.ItemOrder[j + skipped], counterRow, j%4);
                                j--;
                                skipped++;

                                continue;
                            }
                            gt.ItemOrder[j + skipped].Item.Header = "<NewLineItem>";
                            //gt.ItemOrder[j + skipped].ItemOrder = j + skipped;
                            InsertItem(gt.ItemOrder[j + skipped], counterRow, j%4);
                            skipped = skipped + j;
                            j = 0;
                        }
                        else if (j%4 == 0)
                        {
                            AddNewEmptyItemRow();
                            counterRow++;
                        }
                        if (gt.ItemOrder[j + skipped].DesignID.Equals("198"))
                        {
                            j--;
                            skipped++;
                            continue;
                        }
                        if (gt.ItemOrder[j + skipped].DesignID.Equals("197"))
                        {
                            gt.ItemOrder[j + skipped].Item.Header = "<EmptyField>";
                            InsertItem(gt.ItemOrder[j + skipped], counterRow, j%4);
                            //gt.ItemOrder[j + skipped].ItemOrder = j + skipped;
                        }
                        else
                        {
                            if (counterColumn >= 4)
                            {
                                counterColumn = 0;
                            }
                            InsertItem(gt.ItemOrder[j + skipped], counterRow, j%4);
                            //gt.ItemOrder[j + skipped].ItemOrder = j + skipped;
                        }
                        counterColumn++;
                    }
                    AddNewEmptyItemRow();
                }
            }
        }
 public void RemoveGroup(GroupTypeOrder gto)
 {
     List<GroupTypeOrder> gtoList = FindDuplicatesOfGroups(gto);
     foreach (GroupTypeOrder groupTypeOrder in gtoList)
     {
         GroupTypeOrderCollection.Remove(groupTypeOrder);
     }
     //RefreshGroupOrder();
     AdjustGroupOrder();
 }
 public void RefreshLanguage(GroupTypeOrder gto)
 {
     string languageID = gto.Group.LanguageID;
     gto.Group.LanguageID = languageID;
 }
 /// <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);
 }
        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);
        }
        public void HandleGroupTableDrop(GroupTypeOrder targetGroupTypeOrder, GroupTypeOrder draggedGroupTypeOrder)
        {
            List<GroupTypeOrder> draggedMultipleGTOList = FindDuplicatesOfGroups(draggedGroupTypeOrder); // For a particular group, there is an instance for each department
            //int draggedPosition = FindLastOccurrence(draggedGroupTypeOrder);
            //List<GroupTypeOrder> targetMultipleGTOList = FindDuplicatesOfGroups(targetGroupTypeOrder);
            int targetPosition = GroupTypeOrderCollection.IndexOf(targetGroupTypeOrder);
            double targetGroupOrder = targetGroupTypeOrder.GroupOrder;

            foreach (GroupTypeOrder gto in draggedMultipleGTOList)
            {
                GroupTypeOrderCollection.Remove(gto); // prepare for moving the group(s)
            }

            if (draggedGroupTypeOrder.GroupOrder > targetGroupTypeOrder.GroupOrder)
            {
                foreach (GroupTypeOrder gto in draggedMultipleGTOList)
                {
                    GroupTypeOrderCollection.Insert(targetPosition, gto);
                }
            }
            else
            {
                if (GroupTypeOrderCollection.Max(x => x.GroupOrder) != targetGroupOrder)
                {
                    foreach (GroupTypeOrder gto in draggedMultipleGTOList)
                    {
                        targetPosition = FindLastOccurrence(targetGroupTypeOrder); // make sure that the group(s) are inserted at the end of a sequence of duplicated gropus
                        GroupTypeOrderCollection.Insert(targetPosition, gto);
                    }
                }
                else
                {
                    foreach (GroupTypeOrder gto in draggedMultipleGTOList)
                    {
                        GroupTypeOrderCollection.Add(gto);
                    }
                }
            }
            AdjustGroupOrder();
            GroupTypeOrderCollection.Sort(gto => gto.GroupOrder);

            _wvm._changedFlag = true;
        }
        /// <summary>
        /// Finds the index of the last occurrence of a group. Used for group with multiple departments
        /// </summary>
        /// <param name="gto"></param>
        /// <returns></returns>
        public int FindLastOccurrence(GroupTypeOrder gto)
        {
            int i = GroupTypeOrderCollection.IndexOf(GroupTypeOrderCollection.First(x => x.GroupTypeID.Equals(gto.GroupTypeID)));

            while (i < GroupTypeOrderCollection.Count)
            {
                if (!GroupTypeOrderCollection[i].GroupTypeID.Equals(gto.GroupTypeID))
                    break;
                i++;
            }
            return i;
        }
 /// <summary>
 /// Finds duplications of a group. Duplications are caused by having multiple departments
 /// </summary>
 /// <param name="draggedGto"></param>
 /// <returns></returns>
 public List<GroupTypeOrder> FindDuplicatesOfGroups(GroupTypeOrder draggedGto)
 {
     List<GroupTypeOrder> gtoList = new List<GroupTypeOrder>();
     foreach (GroupTypeOrder gto in GroupTypeOrderCollection)
     {
         if (gto.GroupTypeID.Equals(draggedGto.GroupTypeID))
         {
             gtoList.Add(gto);
         }
     }
     return gtoList;
 }
        /// <summary>
        /// Edits group in terms of translation text and departments
        /// </summary>
        /// <param name="gto">the group to be edit</param>
        /// <param name="engTransText">english text</param>
        /// <param name="danTransText">danish text</param>
        /// <param name="departmentList">departments to be shown at</param>
        public void EditGroup(GroupTypeOrder gto, string engTransText, string danTransText, List<string> departmentList)
        {
            //PageType page = (from a in PageList where a.PageTypeID.Equals(pageTypeID) select a).FirstOrDefault();
            //GroupTypeOrder group = (from b in page.GroupTypeOrders where b.GroupTypeID.Equals(groupTypeID) select b).FirstOrDefault();

            gto.Group.DanishTranslationText = danTransText;
            gto.Group.EnglishTranslationText = engTransText;
            RefreshLanguage(gto);
            //if(departmentList.Contains("-1") && departmentList.Count == 1)
            //{
            //    GroupTypeOrder gtoRemoved = GroupTypeOrderCollection.First(x => x.DepartmentID.Equals("-1");
            //}
            //if(GroupTypeOrderCollection.Any<

            foreach (string departmentID in departmentList)
            {
                int i = 0;
                bool departmentIDExist = false;

                while (i < GroupTypeOrderCollection.Count && !departmentIDExist)
                {
                    if (departmentID.Equals(GroupTypeOrderCollection[i].DepartmentID) && GroupTypeOrderCollection[i].GroupTypeID.Equals(gto.GroupTypeID))
                    {
                        departmentIDExist = true;
                    }
                    i++;
                }
                if (!departmentIDExist)
                {
                    GroupTypeOrder clonedGto = new GroupTypeOrder();
                    clonedGto.DepartmentID = departmentID;
                    clonedGto.Group = gto.Group;
                    clonedGto.GroupOrder = gto.GroupOrder;
                    clonedGto.GroupTypeID = gto.GroupTypeID;
                    clonedGto.PageTypeID = gto.PageTypeID;
                    GroupTypeOrderCollection.Add(clonedGto);
                }

                //if (!GroupTypeOrderCollection.Any(x => x.DepartmentID.Equals(departmentID)) && GroupTypeOrderCollection.Any(x => x.GroupTypeID.Equals(gto.GroupTypeID)))
                //{
                //    GroupTypeOrder clonedGto = new GroupTypeOrder();
                //    clonedGto.DepartmentID = departmentID;
                //    clonedGto.Group = gto.Group;
                //    clonedGto.GroupOrder = gto.GroupOrder;
                //    clonedGto.GroupTypeID = gto.GroupTypeID;
                //    clonedGto.PageTypeID = gto.PageTypeID;
                //    GroupTypeOrderCollection.Add(clonedGto);
                //}

            }
            CleanUpRemovedDepartments(gto, departmentList);
            GroupTypeOrderCollection.Sort(gtoItem => gtoItem.GroupOrder);
        }
        /// <summary>
        /// Removes departments which do no exist in the list of departments for a group
        /// </summary>
        /// <param name="gto"></param>
        /// <param name="departmentList"></param>
        public void CleanUpRemovedDepartments(GroupTypeOrder gto, List<string> departmentList)
        {
            int j = 0;
            while (j < GroupTypeOrderCollection.Count)
            {
                GroupTypeOrder gtoItem = GroupTypeOrderCollection[j];
                if (gtoItem.GroupTypeID.Equals(gto.GroupTypeID))
                {
                    //bool remove = true;
                    //int i = 0;
                    //while (i < departmentList.Count && remove)
                    //{
                    //    if (gtoItem.DepartmentID.Equals(departmentList[i]))
                    //    {
                    //        remove = false;
                    //    }
                    //    i++;
                    //}

                    //if (remove)
                    //{
                    //    GroupTypeOrderCollection.Remove(gtoItem);
                    //}
                    if (!departmentList.Any(x => x.Equals(gtoItem.DepartmentID)))
                    {
                        GroupTypeOrderCollection.Remove(gtoItem);
                        j--;
                    }
                }
                j++;
            }
        }