示例#1
0
        private void Mnu_MergeGroup_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                List <CarboGroup> selectedCarboGroupList = new List <CarboGroup>();
                selectedCarboGroupList = dgv_Overview.SelectedItems.Cast <CarboGroup>().ToList();


                if (selectedCarboGroupList != null && selectedCarboGroupList.Count > 1)
                {
                    CarboGroup FirstCarboGroup = selectedCarboGroupList[0];

                    CarboGroup mergedCarboGroup = FirstCarboGroup.Copy();
                    mergedCarboGroup.AllElements = new List <CarboElement>();

                    foreach (CarboGroup gc in selectedCarboGroupList)
                    {
                        if (gc.AllElements.Count > 0)
                        {
                            foreach (CarboElement ce in gc.AllElements)
                            {
                                mergedCarboGroup.AllElements.Add(ce);
                            }
                        }
                    }
                    CarboLifeProject.AddGroup(mergedCarboGroup);
                    foreach (CarboGroup cg in selectedCarboGroupList)
                    {
                        CarboLifeProject.DeleteGroup(cg);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Warning", MessageBoxButton.OK);
            }
        }
示例#2
0
        private void Mnu_MoveToNewGroup_Click(object sender, RoutedEventArgs e)
        {
            //IList<DataGridCellInfo> selectedElementList = dgv_Elements.SelectedCells;
            try
            {
                List <CarboElement> selectedCarboElementList = new List <CarboElement>();
                selectedCarboElementList = dgv_Elements.SelectedItems.Cast <CarboElement>().ToList();

                if (selectedCarboElementList.Count > 0)
                {
                    CarboGroup selectedCarboGroup = (CarboGroup)dgv_Overview.SelectedItem;

                    //Reset all findme flags.
                    CarboLifeProject.ResetElementFlags();

                    //Flag the elements that require updating
                    foreach (CarboElement ce in selectedCarboElementList)
                    {
                        ce.isUpdated = true;
                    }

                    int carbogroupId = selectedCarboGroup.Id;
                    List <CarboElement> allCarboElementList = selectedCarboGroup.AllElements;
                    CarboGroup          newGroup            = selectedCarboGroup.Copy();

                    //move all elements to the new group
                    newGroup.AllElements = selectedCarboElementList;
                    newGroup.Description = "A new Group";

                    int delcounter = 0;

                    //remove the old ones from the list
                    foreach (CarboElement ce in selectedCarboElementList)
                    {
                        for (int i = 0; i >= 0; i--)
                        {
                            CarboElement oldce = allCarboElementList[i];
                            if (oldce.isUpdated == true)
                            {
                                allCarboElementList.RemoveAt(i);
                                delcounter++;
                            }
                        }
                    }
                    //Now there should be two lists, one with the selcted items and one without.
                    foreach (CarboGroup cg in CarboLifeProject.getGroupList)
                    {
                        if (cg.Id == carbogroupId)
                        {
                            cg.AllElements = allCarboElementList;
                        }
                    }
                    CarboLifeProject.AddGroup(newGroup);

                    MessageBox.Show(delcounter + " Elements moved to new group", "Message", MessageBoxButton.OK);

                    CarboLifeProject.CalculateProject();
                    refreshData();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Warning", MessageBoxButton.OK);
            }

            //List<CarboElement> selectedElement = dgv_Elements.SelectedCells;
        }