private void CancelBtnClicked(object sender, RoutedEventArgs e) { ManifestationTypesView manifestationTypes = new ManifestationTypesView(mainWindow); if (Editing) { manifestationTypes.scrollTo(idInput.Text); } mainWindow.MainContent.Content = manifestationTypes; }
private void addTypeBtnClicked(object sender, RoutedEventArgs e) { bool isAutoChecked = autoGenerateId.IsChecked.Value; string typeName = nameInput.Text; string desc = descriptionInput.Text; string iconPath = textBoxIconPath.Text; Repository rep = Repository.GetInstance(); string id; if (!Editing) { idInput.GetBindingExpression(TextBox.TextProperty).UpdateSource(); } nameInput.GetBindingExpression(TextBox.TextProperty).UpdateSource(); descriptionInput.GetBindingExpression(TextBox.TextProperty).UpdateSource(); textBoxIconPath.GetBindingExpression(TextBox.TextProperty).UpdateSource(); if (isAutoChecked && !Editing) { id = $"type{Repository.GetInstance().ManifestationTypeCounter + 1}"; while (rep.FindManifestationType(id) != null) { Repository.GetInstance().ManifestationTypeCounter = Repository.GetInstance().ManifestationTypeCounter + 1; id = $"type{Repository.GetInstance().ManifestationTypeCounter + 1}"; } } else { id = idInput.Text; } if (id == "" || (rep.FindManifestationType(id) != null && !Editing) || typeName == "" || desc == "" || iconPath == "") { AddedTypeMessage.Content = "Manifestation type has not been added successfully."; AddedTypeMessage.Foreground = Brushes.Red; } else { ManifestationType newType = new ManifestationType() { Id = id, Name = typeName, Description = desc, IconPath = iconPath, }; if (!Editing) { rep.AddManifestationType(newType); AddedTypeMessage.Content = $"Successfully added manifestation type: {newType.Id}"; AddedTypeMessage.Foreground = Brushes.Green; nameInput.Text = ""; descriptionInput.Text = ""; textBoxIconPath.Text = ""; if (isAutoChecked) { Repository.GetInstance().ManifestationTypeCounter = Repository.GetInstance().ManifestationTypeCounter + 1; idInput.Text = $"type{Repository.GetInstance().ManifestationTypeCounter + 1}"; while (Repository.GetInstance().FindManifestationType(idInput.Text) != null) { Repository.GetInstance().ManifestationTypeCounter = Repository.GetInstance().ManifestationTypeCounter + 1; idInput.Text = $"type{Repository.GetInstance().ManifestationTypeCounter + 1}"; } nameInput.Focus(); } else { idInput.Text = ""; idInput.Focus(); } } else { rep.UpdateManifestationType(newType); ManifestationTypesView types = new ManifestationTypesView(mainWindow); types.scrollTo(newType.Id); mainWindow.MainContent.Content = types; } } }