public AddLabelView(MainWindow parent, bool editMode)
 {
     InitializeComponent();
     mainWindow  = parent;
     Editing     = editMode;
     DataContext = new model.Label();
     descriptionInput.Focus();
 }
        public AddLabelView()
        {
            InitializeComponent();
            Editing     = false;
            DataContext = new model.Label();

            descriptionInput.Focus();
        }
        public LabelsView()
        {
            InitializeComponent();

            SelectedLabel = null;
            DataContext   = this;
            Labels        = Repository.GetInstance().Labels;
            FilterInput.Focus();
        }
 private void editBtnClicked(object sender, RoutedEventArgs e)
 {
     model.Label target = SelectedLabel;
     if (target == null)
     {
         MessageBox.Show("Please select a label to edit.", "Edit failed", MessageBoxButton.OK, MessageBoxImage.Warning);
         return;
     }
     mainWindow.showLabelEditView(target.Id);
 }
 public void scrollTo(string labelId)
 {
     foreach (model.Label lab in Labels)
     {
         if (lab.Id == labelId)
         {
             SelectedLabel = lab;
             LabelsTable.ScrollIntoView(lab);
             break;
         }
     }
 }
        private void DeleteBtnClicked(object sender, RoutedEventArgs e)
        {
            model.Label target = SelectedLabel;
            if (target == null)
            {
                MessageBox.Show("Please select a label to delete.", "Delete failed", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }
            Repository rep = Repository.GetInstance();

            if (rep.LabelIsReferenced(target.Id))
            {
                MessageBox.Show($"Label {target.Id} can not be deleted because it being used by a manifestation. Please update or delete all manifestations using label {target.Id} and try again.", "Delete failed", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }

            MessageBoxResult choice = MessageBox.Show($"Are you sure that you want to permanently delete label \"{target.Id}\"?", "Delete label", MessageBoxButton.YesNoCancel);

            if (choice == MessageBoxResult.Yes)
            {
                rep.DeleteLabel(target.Id);
            }
        }
        private void SearchLabels()
        {
            string target        = SearchInput.Text;
            int    numberOfFound = 0;

            for (int i = 0; i < LabelsTable.Items.Count; i++)
            {
                DataGridRow row = (DataGridRow)LabelsTable.ItemContainerGenerator.ContainerFromIndex(i);

                if (row != null)
                {
                    int         index = row.GetIndex();
                    model.Label label = row.DataContext as model.Label;
                    if (label.Id.Contains(target))
                    {
                        numberOfFound = numberOfFound + 1;
                        SolidColorBrush brush = new SolidColorBrush(Color.FromArgb(100, 255, 104, 0));
                        row.Background = brush;
                    }
                    else
                    {
                        SolidColorBrush brush = new SolidColorBrush(Color.FromArgb(255, 255, 255, 255));
                        row.Background = brush;
                    }
                }
            }
            if (numberOfFound == 0)
            {
                searchMessage.Content    = "Nothing found with search!";
                searchMessage.Foreground = Brushes.Red;
            }
            else
            {
                searchMessage.Content = "";
            }
        }
        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;
                }
            }
        }
        private void addManifBtnClicked(object sender, RoutedEventArgs e) //ispraviti sa editom
        {
            bool isAutoChecked = autoGenerateId.IsChecked.Value;

            if (!Editing)
            {
                idInput.GetBindingExpression(TextBox.TextProperty).UpdateSource();
            }
            comboBoxTypes.GetBindingExpression(ComboBox.SelectedItemProperty).UpdateSource();
            nameInput.GetBindingExpression(TextBox.TextProperty).UpdateSource();
            isItOutside.GetBindingExpression(ComboBox.SelectedItemProperty).UpdateSource();
            alcoholConsumption.GetBindingExpression(ComboBox.SelectedItemProperty).UpdateSource();
            priceCategory.GetBindingExpression(ComboBox.SelectedItemProperty).UpdateSource();

            descriptionInput.GetBindingExpression(TextBox.TextProperty).UpdateSource();


            if (idInput.Text == "" || nameInput.Text == "" || comboBoxTypes.Text == "" || label.Text == "" ||
                descriptionInput.Text == "" || priceCategory.Text == "" || alcoholConsumption.Text == "" ||
                datePicker1.Text == "" || isItOutside.Text == "" || (Repository.GetInstance().FindManifestation(idInput.Text) != null && !isAutoChecked && !Editing))
            {
                AddedLabelMessage.Content    = "Manifestation has not been added successfully";
                AddedLabelMessage.Foreground = Brushes.Red;
            }
            else
            {
                Manifestation retVal = new Manifestation();
                retVal.MapCoordinates = new ObservableCollection <Coordinates>();
                if (isAutoChecked)
                {
                    Repository.GetInstance().ManifestationCounter = Repository.GetInstance().ManifestationCounter + 1;
                    retVal.Id    = "manifestation" + Repository.GetInstance().ManifestationCounter;
                    idInput.Text = retVal.Id;
                    while (Repository.GetInstance().FindManifestation(retVal.Id) != null)
                    {
                        Repository.GetInstance().ManifestationCounter = Repository.GetInstance().ManifestationCounter + 1;
                        retVal.Id    = "manifestation" + Repository.GetInstance().ManifestationCounter;
                        idInput.Text = retVal.Id;
                    }
                }
                else
                {
                    retVal.Id = idInput.Text;
                }
                retVal.Name = nameInput.Text;

                if (smokingAllowed.IsChecked.Value)
                {
                    retVal.SmokingAllowed = true;
                }
                else
                {
                    retVal.SmokingAllowed = false;
                }

                if (peopleWithSpecialSupport.IsChecked.Value)
                {
                    retVal.SupportHandicaped = true;
                }
                else
                {
                    retVal.SupportHandicaped = false;
                }

                string price = priceCategory.Text;
                if (price.Equals("Free"))
                {
                    retVal.Prices = PriceCategory.Free;
                }
                else if (price.Equals("Low price"))
                {
                    retVal.Prices = PriceCategory.LowPrices;
                }
                else if (price.Equals("Medium price"))
                {
                    retVal.Prices = PriceCategory.MediumPrices;
                }
                else if (price.Equals("High price"))
                {
                    retVal.Prices = PriceCategory.HighPrices;
                }
                else
                {
                    retVal.Prices = PriceCategory.Free;
                }

                string alcohol = alcoholConsumption.Text;
                if (alcohol.Equals("No alcohol"))
                {
                    retVal.Alcohol = AlcoholConusmption.Forbidden;
                }
                else if (alcohol.Equals("Allowed to bring alcohol"))
                {
                    retVal.Alcohol = AlcoholConusmption.BringAlcohol;
                }
                else if (alcohol.Equals("Allowed to buy alcohol"))
                {
                    retVal.Alcohol = AlcoholConusmption.BuyAlcohol;
                }
                else
                {
                    retVal.Alcohol = AlcoholConusmption.Forbidden;
                }

                string outside = isItOutside.Text;
                if (outside.Equals("Outside"))
                {
                    retVal.IsOutside = true;
                }
                else if (outside.Equals("Inside"))
                {
                    retVal.IsOutside = false;
                }
                else
                {
                    retVal.IsOutside = true;
                }

                retVal.Date        = DateTime.Parse(datePicker1.Text);
                retVal.Description = descriptionInput.Text;
                retVal.Type        = Repository.GetInstance().FindManifestationType(comboBoxTypes.Text);


                if (textBoxIconPath.Text == "")
                {
                    retVal.IconPath = retVal.Type.IconPath;
                }
                else
                {
                    retVal.IconPath = textBoxIconPath.Text;
                }

                foreach (model.Label lab in SelectedLabels)
                {
                    model.Label labela = Repository.GetInstance().FindLabel(lab.Id);
                    if (labela != null)
                    {
                        retVal.Addlabel(Repository.GetInstance().FindLabel(lab.Id));
                    }
                }

                Repository rep = Repository.GetInstance();
                if (!Editing)
                {
                    rep.AddManifestation(retVal);
                    AddedLabelMessage.Content    = "Manifestation " + retVal.Id + " has been added successfully.";
                    AddedLabelMessage.Foreground = Brushes.Green;
                    if (autoGenerateId.IsChecked.Value)
                    {
                        // ako je izabrano automatsko inkrementiranje, azurira se vrijednost za id
                        idInput.Text = $"manifestation{Repository.GetInstance().ManifestationCounter + 1}";
                        while (Repository.GetInstance().FindManifestation(idInput.Text) != null)
                        {
                            Repository.GetInstance().ManifestationCounter = Repository.GetInstance().ManifestationCounter + 1;
                            idInput.Text = $"manifestation{Repository.GetInstance().ManifestationCounter + 1}";
                        }
                    }
                }
                else
                {
                    rep.UpdateManifestation(retVal);
                    ManifestationsView manifs = new ManifestationsView(mainWindow);
                    manifs.scrollTo(retVal.Id);
                    mainWindow.MainContent.Content = manifs;
                }
            }
        }