Пример #1
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;
        }