Пример #1
0
        private void ListaBox_MouseMove(object sender, MouseEventArgs e)
        {
            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 ListBoxItem
                ListBox     lb  = sender as ListBox;
                ListBoxItem lbI = FindAncestor <ListBoxItem>((DependencyObject)e.OriginalSource);

                if (lbI == null)
                {
                    return;
                }

                // Find the data behind the ListViewItem
                Model.Lista ls = (Model.Lista)lb.ItemContainerGenerator.ItemFromContainer(lbI);

                // Initialize the drag & drop operation
                DataObject dragData = new DataObject("myFormat", ls);
                DragDrop.DoDragDrop(lbI, dragData, DragDropEffects.Move);
            }
        }
Пример #2
0
        private void ObirisSpomeniTb_Click(object sender, RoutedEventArgs e)
        {
            Boolean upaljen = false;

            foreach (Window w in Application.Current.Windows)
            {
                if (w is Tutorial.Tutor)
                {
                    w.Activate();
                    upaljen = true;
                }
            }
            if (!upaljen)
            {
                Model.Lista ml = ListaBox.SelectedItem as Model.Lista;

                if (ml == null)
                {
                    MessageBox.Show("Morate selektovati spomenik");
                    return;
                }

                String oznaka = ml.Onaka;

                if (MessageBox.Show("Da li ste sigurni da zelite da obrisete spomenik?", "Obrisi", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
                {
                    SQLiteConnection sqliteCon = new SQLiteConnection(dbConn);
                    try
                    {
                        sqliteCon.Open();
                        string        query   = "delete from spomenik where oznaka='" + oznaka + "'";
                        SQLiteCommand command = new SQLiteCommand(query, sqliteCon);
                        command.ExecuteNonQuery();

                        string        query2   = "delete from zaDodavanje where oznaka='" + oznaka + "'";
                        SQLiteCommand command2 = new SQLiteCommand(query2, sqliteCon);
                        command2.ExecuteNonQuery();

                        int idx = list.FindIndex(x => x.Onaka.Equals(oznaka));



                        list.RemoveAt(idx);
                        Listaspom.RemoveAt(idx);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
            }
            else
            {
                MessageBox.Show("Morate zavrsiti ili ugasiti tutorijal za dodavanje spomenika");
            }
        }
Пример #3
0
        private void Slika_MouseMove(object sender, MouseEventArgs e)
        {
            Point  mousePos = e.GetPosition(Kanvas);
            Vector diff     = startPoint - mousePos;

            if (e.LeftButton == MouseButtonState.Pressed &&
                (Math.Abs(diff.X) > SystemParameters.MinimumHorizontalDragDistance ||
                 Math.Abs(diff.Y) > SystemParameters.MinimumVerticalDragDistance))
            {
                // Get the dragged ListBoxItem
                Image img = sender as Image;

                String oz = img.Name.Substring(7);

                Image lbI = FindAncestor <Image>((DependencyObject)e.OriginalSource);
                // Find the data behind the ListViewItem
                Model.Lista ls = (Model.Lista)list.Find(x => x.Onaka.Equals(oz));

                // Initialize the drag & drop operation
                DataObject dragData = new DataObject("Slika", img);
                DragDrop.DoDragDrop(lbI, dragData, DragDropEffects.Copy);
            }
        }
Пример #4
0
        private void Kanvas_Drop(object sender, DragEventArgs e)
        {
            Point PustioSliku = e.GetPosition(Kanvas);

            if (e.Data.GetDataPresent("myFormat"))
            {
                //MessageBox.Show("Dodato");
                Model.Lista ls = e.Data.GetData("myFormat") as Model.Lista;

                Image img = new Image()
                {
                    Width = 30, Height = 30
                };
                img.Source = new BitmapImage(new Uri(ls.Ikonica));

                img.ContextMenu = this.FindResource("Slicica") as ContextMenu;

                img.Name    = "Oznaka_" + ls.Onaka;
                img.ToolTip = ls.Naziv;


                img.MouseDown += Slika_MouseDown;
                img.PreviewMouseLeftButtonDown += ListaBox_PreviewMouseLeftButtonDown;
                img.MouseMove += Slika_MouseMove;
                //img.PreviewMouseRightButtonUp += Desni_Klik_slika;



                SQLiteConnection sqliteCon = new SQLiteConnection(dbConn);
                Boolean          moze      = true;
                try
                {
                    sqliteCon.Open();
                    string        prov = "select * from spomenikmapa";
                    SQLiteCommand coma = new SQLiteCommand(prov, sqliteCon);
                    coma.ExecuteNonQuery();
                    SQLiteDataReader dre = coma.ExecuteReader();

                    while (dre.Read())
                    {
                        double xkor = (double)dre.GetValue(3);
                        double ykor = (double)dre.GetValue(4);


                        if (e.GetPosition(Kanvas).X >= xkor - 10 && e.GetPosition(Kanvas).X <= xkor + 30 && e.GetPosition(Kanvas).Y >= ykor - 10 && e.GetPosition(Kanvas).Y <= ykor + 30)
                        {
                            moze = false;
                        }
                    }
                    sqliteCon.Close();
                }
                catch (Exception x)
                {
                    MessageBox.Show(x.Message);
                }
                //Boolean moze = provera(e.GetPosition(Kanvas).X, e.GetPosition(Kanvas).Y, ls.Onaka);

                if (moze)
                {
                    if (PustioSliku.Y >= 385)
                    {
                        Canvas.SetLeft(img, e.GetPosition(this.Kanvas).X);
                        Canvas.SetTop(img, e.GetPosition(this.Kanvas).Y - 40);
                    }
                    else if (PustioSliku.X >= 590)
                    {
                        Canvas.SetLeft(img, e.GetPosition(this.Kanvas).X - 30);
                        Canvas.SetTop(img, e.GetPosition(this.Kanvas).Y);
                    }
                    else
                    {
                        Canvas.SetLeft(img, e.GetPosition(this.Kanvas).X);
                        Canvas.SetTop(img, e.GetPosition(this.Kanvas).Y);
                    }
                    this.Kanvas.Children.Add(img);

                    Listaspom.Remove((Model.Lista)ListaBox.SelectedItem);

                    //Ubacivanje u BAZU

                    //SQLiteConnection sqliteCon = new SQLiteConnection(dbConn);

                    try
                    {
                        if (PustioSliku.Y >= 385)
                        {
                            sqliteCon.Open();
                            string        query   = "insert into spomenikmapa (oznaka,naziv,ikonica,X,Y) values('" + ls.Onaka + "','" + ls.Naziv + "','" + ls.Ikonica + "','" + e.GetPosition(this.Kanvas).X + "','" + (e.GetPosition(this.Kanvas).Y - 40) + "') ";
                            SQLiteCommand command = new SQLiteCommand(query, sqliteCon);
                            command.ExecuteNonQuery();

                            string        query2   = "delete from zaDodavanje where oznaka='" + ls.Onaka + "'";
                            SQLiteCommand command2 = new SQLiteCommand(query2, sqliteCon);
                            command2.ExecuteNonQuery();
                        }
                        else if (PustioSliku.X >= 590)
                        {
                            sqliteCon.Open();
                            string        query   = "insert into spomenikmapa (oznaka,naziv,ikonica,X,Y) values('" + ls.Onaka + "','" + ls.Naziv + "','" + ls.Ikonica + "','" + (e.GetPosition(this.Kanvas).X - 30) + "','" + e.GetPosition(this.Kanvas).Y + "') ";
                            SQLiteCommand command = new SQLiteCommand(query, sqliteCon);
                            command.ExecuteNonQuery();

                            string        query2   = "delete from zaDodavanje where oznaka='" + ls.Onaka + "'";
                            SQLiteCommand command2 = new SQLiteCommand(query2, sqliteCon);
                            command2.ExecuteNonQuery();
                        }
                        else
                        {
                            sqliteCon.Open();
                            string        query   = "insert into spomenikmapa (oznaka,naziv,ikonica,X,Y) values('" + ls.Onaka + "','" + ls.Naziv + "','" + ls.Ikonica + "','" + e.GetPosition(this.Kanvas).X + "','" + e.GetPosition(this.Kanvas).Y + "') ";
                            SQLiteCommand command = new SQLiteCommand(query, sqliteCon);
                            command.ExecuteNonQuery();

                            string        query2   = "delete from zaDodavanje where oznaka='" + ls.Onaka + "'";
                            SQLiteCommand command2 = new SQLiteCommand(query2, sqliteCon);
                            command2.ExecuteNonQuery();
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
                else
                {
                    MessageBox.Show("Ikonice se ne smeju preklapati");
                }
            }

            if (e.Data.GetDataPresent("Slika"))
            {
                //Lista ls = e.Data.GetData("myFormat") as Lista;
                Image slika = e.Data.GetData("Slika") as Image;

                Image img = new Image()
                {
                    Width = 30, Height = 30
                };
                img.Source = slika.Source;

                img.Name = slika.Name;
                //img.ToolTip = slika.Name;

                img.MouseDown += Slika_MouseDown;
                img.PreviewMouseLeftButtonDown += ListaBox_PreviewMouseLeftButtonDown;
                img.MouseMove += Slika_MouseMove;
                //img.PreviewMouseRightButtonUp += Desni_Klik_slika;
                img.ContextMenu = FindResource("Slicica") as ContextMenu;

                string ozna = img.Name.Substring(7);

                SQLiteConnection sqliteCon = new SQLiteConnection(dbConn);
                Boolean          moze      = true;
                try
                {
                    sqliteCon.Open();
                    string        prov = "select * from spomenikmapa";
                    SQLiteCommand coma = new SQLiteCommand(prov, sqliteCon);
                    coma.ExecuteNonQuery();
                    SQLiteDataReader dre = coma.ExecuteReader();

                    while (dre.Read())
                    {
                        string oz   = dre.GetString(0);
                        double xkor = (double)dre.GetValue(3);
                        double ykor = (double)dre.GetValue(4);

                        if (oz.Equals(ozna))
                        {
                            continue;
                        }

                        if (e.GetPosition(Kanvas).X >= xkor - 10 && e.GetPosition(Kanvas).X <= xkor + 30 && e.GetPosition(Kanvas).Y >= ykor - 10 && e.GetPosition(Kanvas).Y <= ykor + 30)
                        {
                            moze = false;
                        }
                    }
                    sqliteCon.Close();
                }
                catch (Exception x)
                {
                    MessageBox.Show(x.Message);
                }
                if (moze)
                {
                    if (PustioSliku.Y >= 380)
                    {
                        Canvas.SetLeft(img, e.GetPosition(this.Kanvas).X);
                        Canvas.SetTop(img, e.GetPosition(this.Kanvas).Y - 40);
                    }
                    else if (PustioSliku.X >= 590)
                    {
                        Canvas.SetLeft(img, e.GetPosition(this.Kanvas).X - 30);
                        Canvas.SetTop(img, e.GetPosition(this.Kanvas).Y);
                    }
                    else
                    {
                        Canvas.SetLeft(img, e.GetPosition(this.Kanvas).X);
                        Canvas.SetTop(img, e.GetPosition(this.Kanvas).Y);
                    }


                    this.Kanvas.Children.Add(img);
                    this.Kanvas.Children.Remove(slika);

                    //Izmena koordinaata u bazi


                    //SQLiteConnection sqliteCon = new SQLiteConnection(dbConn);
                    try
                    {
                        if (PustioSliku.Y >= 380)
                        {
                            sqliteCon.Open();
                            string        query   = "update spomenikmapa set X='" + e.GetPosition(this.Kanvas).X + "',Y='" + (e.GetPosition(this.Kanvas).Y - 40) + "'where oznaka='" + img.Name.Substring(7) + "'";
                            SQLiteCommand command = new SQLiteCommand(query, sqliteCon);
                            command.ExecuteNonQuery();
                        }
                        else if (PustioSliku.X >= 590)
                        {
                            sqliteCon.Open();
                            string        query   = "update spomenikmapa set X='" + (e.GetPosition(this.Kanvas).X - 30) + "',Y='" + e.GetPosition(this.Kanvas).Y + "'where oznaka='" + img.Name.Substring(7) + "'";
                            SQLiteCommand command = new SQLiteCommand(query, sqliteCon);
                            command.ExecuteNonQuery();
                        }
                        else
                        {
                            sqliteCon.Open();
                            string        query   = "update spomenikmapa set X='" + e.GetPosition(this.Kanvas).X + "',Y='" + e.GetPosition(this.Kanvas).Y + "'where oznaka='" + img.Name.Substring(7) + "'";
                            SQLiteCommand command = new SQLiteCommand(query, sqliteCon);
                            command.ExecuteNonQuery();
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
                else
                {
                    MessageBox.Show("Ikonice se ne smeju preklapati");
                }
            }
        }