public bool ChangePosDown_CanExecute(object parameter) { try { if (_selectedItem == null) { return(false); } if (_selectedItem is Chapter) { Chapter selectedChapter = _selectedItem as Chapter; if (Chapters.IndexOf(selectedChapter) == Chapters.Count - 1) { return(false); } return(true); } if (_selectedItem is Part) { Part selectedPart = _selectedItem as Part; List <Part> parts = Part.LoadPartListForChapter(selectedPart.ChapterID); if (selectedPart.OrderNumber == parts.Count) { return(false); } return(true); } return(true); } catch (Exception ex) { MessageBox.Show($"Критическая ошибка: {ex.Message}"); return(false); } }
private int LookUp(string groupName) { foreach (var group in Chapters) { if (group.GroupName == groupName) { return(Chapters.IndexOf(group)); } } throw new ArgumentOutOfRangeException(); }
private void ChangePosDown(object parameter) { if (_selectedItem is Chapter) { Chapter selectedChapter = _selectedItem as Chapter; int indexOfSwappingItem = Chapters.IndexOf(selectedChapter) + 1; Chapter swapingChapter = Chapters[indexOfSwappingItem] as Chapter; int temp = selectedChapter.OrderNumber; selectedChapter.OrderNumber = swapingChapter.OrderNumber; swapingChapter.OrderNumber = temp; Chapter.SaveChangesInXML(selectedChapter); Chapter.SaveChangesInXML(swapingChapter); OnPropertyChanged("Chapters"); } else if (_selectedItem is Part) { Part selectedPart = _selectedItem as Part; List <Part> parts = Part.LoadPartListForChapter(selectedPart.ChapterID); Part swapingPart = (from p in parts where p.OrderNumber == selectedPart.OrderNumber + 1 select p).First(); int temp = selectedPart.OrderNumber; selectedPart.OrderNumber = swapingPart.OrderNumber; swapingPart.OrderNumber = temp; Part.SaveChangesInXML(selectedPart); Part.SaveChangesInXML(swapingPart); OnPropertyChanged("Chapters"); } }
public string ChapterId(Chapter chapter) => $"{PartNumber}.{Chapters?.IndexOf(chapter)+1}";