private void AddRemoveSelectedItemIfValid(DataGridItem selectedItem)
        {
            if (selectedItem.Level == 0)
            {
                int index = GetIndexByID(TargetBillOfMaterial.ItemViewModels, selectedItem.ItemViewModel);

                if (index == -1)
                {
                    if (selectedItem.ItemViewModel.Quantity > 0)
                    {
                        TargetBillOfMaterial.Add(selectedItem.ItemViewModel);
                        TargetHierarchyDataGrid.Add(selectedItem.ItemViewModel);
                    }
                }
                else
                {
                    if (selectedItem.ItemViewModel.Quantity > 0)
                    {
                        TargetBillOfMaterial.ItemViewModels[index].Quantity = selectedItem.ItemViewModel.Quantity;
                    }
                    else
                    {
                        if (TargetHierarchyDataGrid.DataGridItems.Count == 1)
                        {
                            SelectedIndexInSource = -1;
                        }
                        TargetBillOfMaterial.Remove(index);
                        TargetHierarchyDataGrid.Remove(selectedItem.ItemViewModel);
                    }
                }
            }
            CalculateInfo();
        }
 protected override void AddByButton()
 {
     if (CalculateCanAddItem())
     {
         TargetBillOfMaterial.Add(_selectedItemInSource.ItemViewModel);
         TargetHierarchyDataGrid.Add(_selectedItemInSource.ItemViewModel);
     }
 }
 protected override void RemoveByButton()
 {
     if (CalculateCanRemoveItem())
     {
         int index = GetIndexByID(TargetBillOfMaterial.ItemViewModels, _selectedItemInSource.ItemViewModel);
         TargetBillOfMaterial.Remove(index);
         TargetHierarchyDataGrid.Remove(_selectedItemInSource.ItemViewModel);
     }
 }