private void ukloni_Click(object sender, RoutedEventArgs e)
        {
            if (tab1.IsSelected)
            {
                Dogadjaj d = (Dogadjaj)listView1.SelectedItem;
                for (int i = 0; i < listaDog.Count; i++)
                {
                    if (listaDog.ElementAt(i).Equals(d))
                    {
                        listaDog.RemoveAt(i);
                        MainWindow.listaDog.RemoveAt(i);
                        break;
                    }
                }

                FileStream      stream = new FileStream("data1.bin", FileMode.OpenOrCreate, FileAccess.Write);
                BinaryFormatter bin    = new BinaryFormatter();
                bin.Serialize(stream, listaDog);
                stream.Close();
            }
            else if (tab2.IsSelected)
            {
                TipDogadjaja t = (TipDogadjaja)listView2.SelectedItem;
                listaTip.Remove(t);

                FileStream      stream = new FileStream("data.bin", FileMode.OpenOrCreate, FileAccess.Write);
                BinaryFormatter bin    = new BinaryFormatter();
                bin.Serialize(stream, listaTip);
                stream.Close();
            }
            else if (tab3.IsSelected)
            {
                EtiketaDogadjaja et = (EtiketaDogadjaja)listView3.SelectedItem;
                listaEt.Remove(et);

                FileStream      stream = new FileStream("data2.bin", FileMode.OpenOrCreate, FileAccess.Write);
                BinaryFormatter bin    = new BinaryFormatter();
                bin.Serialize(stream, listaEt);
                stream.Close();
            }
        }
Esempio n. 2
0
        private void dodaj_Click(object sender, RoutedEventArgs e)
        {
            bool   dodato        = true;
            string oznakaEtiketa = textBox1.Text;
            string nazivEtiketa  = textBox2.Text;
            Color  clr           = ((SolidColorBrush)grid1.Background).Color;
            string bojaEtiketa   = clr.ToString();

            for (int i = 0; i < listaEtiketa.Count(); i++)
            {
                if (listaEtiketa.ElementAt(i).oznaka.Equals(oznakaEtiketa))
                {
                    MessageBox.Show("Etiketa sa tom oznakom već postoji!");
                    dodato = false;
                    break;
                }
                else
                {
                    dodato = true;
                }
            }

            //provera da li je oznaka broj
            int    num    = 0;
            string s      = textBox1.Text;
            bool   result = int.TryParse(s, out num);


            if (textBox1.Text != "Unesite oznaku..." && textBox2.Text != "Unesite opis..." && result)
            {
                if (textBox1.Text != "" && textBox2.Text != "")
                {
                    if (dodato)
                    {
                        EtiketaDogadjaja et = new EtiketaDogadjaja(oznakaEtiketa, bojaEtiketa, nazivEtiketa);
                        listaEtiketa.Add(et);

                        MessageBox.Show("Uspešno ste napravili etiketu događaja!");

                        FileStream      stream = new FileStream("data2.bin", FileMode.OpenOrCreate, FileAccess.Write);
                        BinaryFormatter bin    = new BinaryFormatter();
                        bin.Serialize(stream, listaEtiketa);

                        Color           clr1  = (Color)ColorConverter.ConvertFromString("#FFFFFFFF");
                        SolidColorBrush brush = new SolidColorBrush(clr1);
                        grid1.Background = brush;

                        dataGrid.ItemsSource       = null;
                        dataGrid.ItemsSource       = listaEtiketa;
                        dataGrid.Columns[0].Header = "Oznaka";
                        dataGrid.Columns[1].Header = "Boja";
                        dataGrid.Columns[2].Header = "Opis";
                        clearAll();
                        stream.Close();
                    }
                }
                else
                {
                    MessageBox.Show("Odgovarajuća polja ne smeju biti prazna!");
                }
            }
            else
            {
                MessageBox.Show("Molimo Vas unesite odgovarajuće vrednosti!");
            }
        }