private void CancelBtnClicked(object sender, RoutedEventArgs e) { LabelsView labels = new LabelsView(mainWindow); if (Editing) { labels.scrollTo(idInput.Text); } mainWindow.MainContent.Content = labels; }
private void AddOrEditButtonClick(object sender, RoutedEventArgs e) { bool isAutoChecked = autoGenerateId.IsChecked.Value; if (!Editing) { idInput.GetBindingExpression(TextBox.TextProperty).UpdateSource(); } descriptionInput.GetBindingExpression(TextBox.TextProperty).UpdateSource(); if (descriptionInput.Text == "" || idInput.Text == "" && !isAutoChecked || (idInput.Text != "" && !isAutoChecked && Repository.GetInstance().FindLabel(idInput.Text) != null && !Editing)) { AddedLabelMessage.Content = "Label has not been added successfully."; AddedLabelMessage.Foreground = Brushes.Red; } else if (colorPicker.SelectedColor.ToString() == "") { AddedLabelMessage.Content = "Please, pick some color."; AddedLabelMessage.Foreground = Brushes.Red; } else { model.Label retVal = new model.Label(); if (isAutoChecked && !Editing) { Repository.GetInstance().LabelCounter = Repository.GetInstance().LabelCounter + 1; retVal.Id = "lab" + Repository.GetInstance().LabelCounter; idInput.Text = retVal.Id; while (Repository.GetInstance().FindLabel(retVal.Id) != null) { Repository.GetInstance().LabelCounter = Repository.GetInstance().LabelCounter + 1; retVal.Id = "lab" + Repository.GetInstance().LabelCounter; idInput.Text = retVal.Id; } } else { retVal.Id = idInput.Text; } retVal.Color = colorPicker.SelectedColor.ToString(); retVal.Description = descriptionInput.Text; Repository rep = Repository.GetInstance(); if (!Editing) { rep.Addlabel(retVal); AddedLabelMessage.Content = "Label \"" + retVal.Id + "\" has been added successfully."; AddedLabelMessage.Foreground = Brushes.Green; descriptionInput.Text = ""; colorPicker.SelectedColor = null; if (autoGenerateId.IsChecked.Value) { //ako je izabrano automatsko inkrementiranje, azurira se vrijednost za id idInput.Text = $"lab{Repository.GetInstance().LabelCounter + 1}"; while (Repository.GetInstance().FindLabel(idInput.Text) != null) { Repository.GetInstance().LabelCounter = Repository.GetInstance().LabelCounter + 1; idInput.Text = $"lab{Repository.GetInstance().LabelCounter + 1}"; } descriptionInput.Focus(); } else { idInput.Text = ""; idInput.Focus(); } } else { rep.UpdateLabel(retVal); LabelsView labels = new LabelsView(mainWindow); labels.scrollTo(retVal.Id); mainWindow.MainContent.Content = labels; } } }