private void button2_Click(object sender, RoutedEventArgs e) { Vrsta vrsta = (Vrsta)listBox.SelectedItem; //brisanje slike vrste sa canvasa foreach (Image im in ((MainWindow)App.Current.MainWindow).DropList.Children) { string temp = im.ToolTip.ToString(); if (temp.Contains("ID: " + vrsta.Id)) { ((MainWindow)App.Current.MainWindow).DropList.Children.Remove(im); break; } } /* * for (int i = 0; i < MainWindow.ListaVrsta.Count; i++) * { * if (MainWindow.ListaVrsta[i].Id.Equals(vrsta.Id)) * { * MainWindow.ListaVrsta.RemoveAt(i); * break; * } * }*/ listaVrstaIzmena.Remove(vrsta); MainWindow.ListaVrsta.Remove(vrsta); }
private void List_MouseMove(object sender, MouseEventArgs e) { // Get the current mouse position Point mousePos = e.GetPosition(null); Vector diff = startPoint - mousePos; if (e.LeftButton == MouseButtonState.Pressed && ( Math.Abs(diff.X) > SystemParameters.MinimumHorizontalDragDistance || Math.Abs(diff.Y) > SystemParameters.MinimumVerticalDragDistance)) { // Get the dragged ListViewItem ListView listView = sender as ListView; ListViewItem listViewItem = FindAnchestor <ListViewItem>((DependencyObject)e.OriginalSource); Vrsta vrsta = null; // Find the data behind the ListViewItem if (listViewItem != null) { vrsta = (Vrsta)listView.ItemContainerGenerator. ItemFromContainer(listViewItem); } else { return; } // Initialize the drag & drop operation DataObject dragData = new DataObject("myFormat", vrsta); DragDrop.DoDragDrop(listViewItem, dragData, DragDropEffects.Move); } }
public void updateCanvas() { foreach (var item in DropList.Children) { Image imageControl = (Image)item; Vrsta vrsta = (Vrsta)imageControl.DataContext; imageControl.ToolTip = " ID: " + vrsta.Id + "\n Ime: " + vrsta.Ime + "\n Tip: " + vrsta.Tip + "\n Ime tipa: " + vrsta.Tip.Ime; imageControl.Source = vrsta.Ikonica; } }
private void ImeTextBox_TextChanged(object sender, TextChangedEventArgs e) { collectionView.Filter = (et) => { Vrsta eti = et as Vrsta; if (eti.Ime.Contains(ImeTextBox.Text)) { return(true); } return(false); }; }
private void button_Click(object sender, RoutedEventArgs e) { if (validno()) { Vrsta novaVrsta = new Vrsta(); novaVrsta.Id = textBox_ID.Text; novaVrsta.Ime = textBox_IME.Text; novaVrsta.Opis = textBox_OPIS.Text; String statusU = "Default"; switch (comboBox_UGROZENOST.SelectedIndex) { case 0: statusU = "Kriticno ugrozena"; break; case 1: statusU = "Ugrozena"; break; case 2: statusU = "Ranjiva"; break; case 3: statusU = "Zavisna od ocuvanja stanista"; break; case 4: statusU = "Blizu rizika"; break; case 5: statusU = "Najmanjeg rizika"; break; } novaVrsta.StatusU = statusU; novaVrsta.Tip = (Tip)comboBox_TIP.SelectedItem; if (checkBox_OPASNA.IsChecked.HasValue && checkBox_OPASNA.IsChecked.Value) { novaVrsta.Opasna = true; } if (checkBox_IUCN.IsChecked.HasValue && checkBox_IUCN.IsChecked.Value) { novaVrsta.CrvenaLista = true; } if (checkBox_NASELJEN.IsChecked.HasValue && checkBox_NASELJEN.IsChecked.Value) { novaVrsta.NaseljenRegion = true; } String statusT = "Default"; switch (comboBox_TURISTICKI.SelectedIndex) { case 0: statusT = "Izolovana"; break; case 1: statusT = "Delimicno habituirana"; break; case 2: statusT = "Habituirana"; break; } novaVrsta.Etikete = new ObservableCollection <Etiketa>(); foreach (var item in listaEtiketaXAML.SelectedItems) { novaVrsta.Etikete.Add((Etiketa)item); } novaVrsta.TStatus = statusT; novaVrsta.Datum = datePicker_DATUM.SelectedDate.Value.Date; novaVrsta.Ikonica = (BitmapImage)image_ikonica.Source; if (novaVrsta.Ikonica == null) { novaVrsta.Ikonica = novaVrsta.Tip.Ikonica; } novaVrsta.Prihod = float.Parse(textBox_PRIHOD.Text); MainWindow.ListaVrsta.Add(novaVrsta); this.Close(); } }
private void pretrazi_Click(object sender, RoutedEventArgs e) { collectionView.Filter = (et) => { Vrsta eti = et as Vrsta; if (Tipovi.SelectedIndex != -1) { if (!eti.Tip.Id.Equals(((Tip)Tipovi.SelectedItem).Id)) { return(false); } } if (OpasnaDa.IsChecked.Value || OpasnaNe.IsChecked.Value) { if (eti.Opasna) { if (!OpasnaDa.IsChecked.Value) { return(false); } } else { if (!OpasnaNe.IsChecked.Value) { return(false); } } } if (RegionDa.IsChecked.Value || RegionNe.IsChecked.Value) { if (eti.NaseljenRegion) { if (!RegionDa.IsChecked.Value) { return(false); } } else { if (!RegionNe.IsChecked.Value) { return(false); } } } if (CrvenaDa.IsChecked.Value || CrvenaNe.IsChecked.Value) { if (eti.CrvenaLista) { if (!CrvenaDa.IsChecked.Value) { return(false); } } else { if (!CrvenaNe.IsChecked.Value) { return(false); } } } return(true); }; }
private void listBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { Vrsta v = (Vrsta)listBox.SelectedItem; if (v != null) { if (comboBox_TIP != null) { for (int i = 0; i < listaTipovaIzmena.Count; i++) { if (v.Tip.Id.Equals(listaTipovaIzmena[i].Id)) { comboBox_TIP.SelectedIndex = i; } } if (v.StatusU.Equals("Kriticno ugrozena")) { comboBox_UGROZENOST.SelectedIndex = 0; } else if (v.StatusU.Equals("Ugrozena")) { comboBox_UGROZENOST.SelectedIndex = 1; } else if (v.StatusU.Equals("Ranjiva")) { comboBox_UGROZENOST.SelectedIndex = 2; } else if (v.StatusU.Equals("Zavisna od ocuvanja stanista")) { comboBox_UGROZENOST.SelectedIndex = 3; } else if (v.StatusU.Equals("Blizu rizika")) { comboBox_UGROZENOST.SelectedIndex = 4; } else { comboBox_UGROZENOST.SelectedIndex = 5; } } if (comboBox_TURISTICKI != null) { if (v.TStatus.Equals("Izolovana")) { comboBox_TURISTICKI.SelectedIndex = 0; } else if (v.TStatus.Equals("Delimicno habituirana")) { comboBox_TURISTICKI.SelectedIndex = 1; } else { comboBox_TURISTICKI.SelectedIndex = 2; } } if (listBox1 != null) { listBox1.SelectedItems.Clear(); for (int i = 0; i < listBox1.Items.Count; i++) { Etiketa temp = (Etiketa)listBox1.Items[i]; for (int k = 0; k < v.Etikete.Count; k++) { Etiketa temp2 = v.Etikete[k]; if (temp.Id.Equals(temp2.Id)) { listBox1.SelectedItems.Add(listBox1.Items[i]); } } } } } }
private void button_izmeni_Click(object sender, RoutedEventArgs e) { if ((listBox.SelectedItem != null) && validno()) { Vrsta temp = (Vrsta)listBox.SelectedItem; temp.Id = textBlock.Text; temp.Ime = textBlock1.Text; temp.Opis = textBlock2.Text; temp.Tip = (Tip)comboBox_TIP.SelectedItem; String statusU = "Default"; switch (comboBox_UGROZENOST.SelectedIndex) { case 0: statusU = "Kriticno ugrozena"; break; case 1: statusU = "Ugrozena"; break; case 2: statusU = "Ranjiva"; break; case 3: statusU = "Zavisna od ocuvanja stanista"; break; case 4: statusU = "Blizu rizika"; break; case 5: statusU = "Najmanjeg rizika"; break; } temp.StatusU = statusU; if (checkBox_OPASNA.IsChecked.HasValue && checkBox_OPASNA.IsChecked.Value) { temp.Opasna = true; } if (checkBox_IUCN.IsChecked.HasValue && checkBox_IUCN.IsChecked.Value) { temp.CrvenaLista = true; } if (checkBox_NASELJEN.IsChecked.HasValue && checkBox_NASELJEN.IsChecked.Value) { temp.NaseljenRegion = true; } temp.Ikonica = (BitmapImage)image_ikonica.Source; if (temp.Ikonica == null) { temp.Ikonica = temp.Tip.Ikonica; } String statusT = "Default"; switch (comboBox_TURISTICKI.SelectedIndex) { case 0: statusT = "Izolovana"; break; case 1: statusT = "Delimicno habituirana"; break; case 2: statusT = "Habituirana"; break; } temp.Etikete = new ObservableCollection <Etiketa>(); foreach (var item in listBox1.SelectedItems) { temp.Etikete.Add((Etiketa)item); } temp.TStatus = statusT; temp.Prihod = float.Parse(textBox_PRIHOD.Text); temp.Datum = datePicker_DATUM.SelectedDate.Value.Date; ((MainWindow)App.Current.MainWindow).updateCanvas(); this.Close(); } }
private void Image_RightClick(object sender, MouseButtonEventArgs e) { if (e.ChangedButton == MouseButton.Right) { Image image = sender as Image; string tooltip = (string)image.ToolTip; string[] elements = tooltip.Split('\n'); string id1 = elements[0]; string[] elements1 = id1.Split(' '); string id = elements1[2]; //Console.WriteLine("ID VRSTE JE: " + id); ContextMenu contextMenu = new ContextMenu(); MenuItem item1 = new MenuItem(); item1.Header = "Detalji"; int indexDetails = 0; for (int i = 0; i < ListaVrsta.Count; i++) { if (id.Equals(ListaVrsta[i].Id)) { indexDetails = i; break; } } item1.Click += delegate { VrstePrikaz vp = new VrstePrikaz(indexDetails); }; contextMenu.Items.Add(item1); MenuItem item2 = new MenuItem(); item2.Header = "Izmeni"; Vrsta zaIzmenu = null; foreach (Vrsta v in MainWindow.ListaVrsta) { if (id.Equals(v.Id)) { zaIzmenu = v; break; } } int indexIzmena = 0; for (int i = 0; i < ListaVrsta.Count; i++) { if (id.Equals(ListaVrsta[i].Id)) { indexIzmena = i; break; } } item2.Click += delegate { IzmenaVrsta re = new IzmenaVrsta(indexIzmena); image.ToolTip = " ID: " + zaIzmenu.Id + "\n Ime: " + zaIzmenu.Ime + "\n Tip: " + zaIzmenu.Tip + "\n Ime tipa: " + zaIzmenu.Tip.Ime; image.Source = zaIzmenu.Ikonica; }; contextMenu.Items.Add(item2); MenuItem item3 = new MenuItem(); item3.Header = "Obriši"; item3.Click += delegate { for (int i = 0; i < DropList.Children.Count; i++) { Image img = (Image)DropList.Children[i]; if (img.Equals(image)) { DropList.Children.RemoveAt(i); string text = img.ToolTip.ToString(); string[] prvaPodela = text.Split('\n'); // " ID: id" string[] drugaPodela = prvaPodela[0].Split(' '); listaZaMapu.Remove(drugaPodela[2]); } } }; contextMenu.Items.Add(item3); image.ContextMenu = contextMenu; contextMenu.PlacementTarget = image; contextMenu.IsOpen = true; } }
private void DropList_Drop(object sender, DragEventArgs e) { Image imageControl = new Image(); if (e.Data.GetDataPresent("myFormat")) { Vrsta vrsta = e.Data.GetData("myFormat") as Vrsta; imageControl = new Image() { Width = 60, Height = 50, Source = vrsta.Ikonica, DataContext = vrsta }; imageControl.ToolTip = " ID: " + vrsta.Id + "\n Ime: " + vrsta.Ime + "\n Tip: " + vrsta.Tip + "\n Ime tipa: " + vrsta.Tip.Ime; imageControl.AllowDrop = false; imageControl.MouseRightButtonDown += Image_RightClick; if (DropList.Children.Count > 0) { foreach (Image i in DropList.Children) { string tooltip = (string)i.ToolTip; string[] elements = tooltip.Split('\n'); string id = elements[0]; if (id.Contains(vrsta.Id)) { MessageBox.Show("Zeljena vrsta se već nalazi na mapi!"); return; } } } //List<double> temp = new List<double>(); //temp.Add(e.GetPosition(this.DropList).X - imageControl.Width / 2); //temp.Add(e.GetPosition(this.DropList).Y - imageControl.Height / 2); //listaZaMapu.Add(vrsta.Id, temp); //Console.WriteLine("KORDINATE UNETE U LISTU!\n"); //Console.WriteLine("U listi ima trenutno:" + listaZaMapu.Count + "\n"); } else { if ((e.Data.GetData(typeof(Image)) != null)) { Image image = e.Data.GetData(typeof(Image)) as Image; imageControl = image; if (this.DropList.Children.Contains(image)) { this.DropList.Children.Remove(image); } } } Canvas.SetLeft(imageControl, e.GetPosition(this.DropList).X - imageControl.Width / 2); Canvas.SetTop(imageControl, e.GetPosition(this.DropList).Y - imageControl.Height / 2); string text = imageControl.ToolTip.ToString(); string[] prvaPodela = text.Split('\n'); // " ID: id" string[] drugaPodela = prvaPodela[0].Split(' '); if (listaZaMapu.ContainsKey(drugaPodela[2])) { listaZaMapu[drugaPodela[2]][0] = e.GetPosition(this.DropList).X - imageControl.Width / 2; listaZaMapu[drugaPodela[2]][1] = e.GetPosition(this.DropList).Y - imageControl.Height / 2; } else { List <double> temp = new List <double>(); temp.Add(e.GetPosition(this.DropList).X - imageControl.Width / 2); temp.Add(e.GetPosition(this.DropList).Y - imageControl.Height / 2); listaZaMapu.Add(drugaPodela[2], temp); } imageControl.MouseLeftButtonDown += imageControl_MouseLeftButtonDown; this.DropList.Children.Add(imageControl); }