Esempio n. 1
0
        private async void buttonInsecticideDelete_Click(object sender, RoutedEventArgs e)
        {
            if (listInsecticides.SelectedIndex == -1)
            {
                return;
            }

            MessageBoxResult result = MessageBox.Show("Are you sure you want to delete this Insecticide?", "Are you sure?", MessageBoxButton.OKCancel);

            if (result == MessageBoxResult.OK)
            {
                Insect insect = Insects.ElementAt(listInsects.SelectedIndex);
                insect.InsecticideIds.RemoveAt(listInsecticides.SelectedIndex);
                await insect.SaveAsync();

                Insecticide i = LoadedInsecticides.ElementAt(listInsecticides.SelectedIndex);
                Insecticides.Remove(i);
                LoadedInsecticides.Remove(i);
                labelInsecticides.Content = insect.Name + ": Insecticides (" + LoadedInsecticides.Count + ")";
                if (LoadedInsecticides.Count == 0)
                {
                    labelNoInsecticides.Visibility = Visibility.Visible;
                }
                await i.DeleteAsync();

                MessageBox.Show("Insecticide deleted.");
            }
        }
Esempio n. 2
0
        void LoadInsecticides(Insect insect)
        {
            LoadedInsecticides.Clear();

            List <int> insecticideIds = insect.InsecticideIds.ToList();

            foreach (Insecticide i in Insecticides)
            {
                if (insecticideIds.Contains(i.InsecticideId))
                {
                    LoadedInsecticides.Add(i);
                }
            }

            if (LoadedInsecticides.Count == 0)
            {
                labelNoInsecticides.Visibility = Visibility.Visible;
            }
            else
            {
                labelNoInsecticides.Visibility = Visibility.Hidden;
            }

            labelInsecticides.Content = insect.Name + ": Insecticides (" + LoadedInsecticides.Count + ")";
        }
Esempio n. 3
0
        public InsectObjectEditor(Insect i)
        {
            InitializeComponent();
            CurrentInsect = i;

            textBoxName.Text         = i.Name;
            textBoxName.TextChanged += delegate
            {
                CurrentInsect.Name = textBoxName.Text;
            };
            textBoxCategory.Text         = i.Category;
            textBoxCategory.TextChanged += delegate
            {
                CurrentInsect.Category = textBoxCategory.Text;
            };
            textBoxDescription.Text         = i.Description;
            textBoxDescription.TextChanged += delegate
            {
                CurrentInsect.Description = textBoxDescription.Text;
            };

            this.Closing += async delegate
            {
                await CurrentInsect.SaveAsync();
            };

            GetPictures();
        }
Esempio n. 4
0
        private async void buttonInsectDelete_Click(object sender, RoutedEventArgs e)
        {
            if (listInsects.SelectedIndex == -1)
            {
                return;
            }

            MessageBoxResult result = MessageBox.Show("Are you sure you want to delete this insect and its insecticides and pictures?", "Are you sure?", MessageBoxButton.OKCancel);

            if (result == MessageBoxResult.OK)
            {
                String outputText = "Insect deleted.";

                outputText = "Insect deleted along with " + LoadedInsecticides.Count + " insecticides.";
                foreach (Insecticide i in LoadedInsecticides)
                {
                    await i.DeleteAsync();

                    Insecticides.Remove(i);
                }

                Insect insect = Insects.ElementAt(listInsects.SelectedIndex);

                var pictureQuery = from pic in new ParseQuery <Picture>()
                                   where pic.ItemId == insect.PictureId
                                   select pic;
                List <Picture> results = (await pictureQuery.FindAsync()).ToList();
                foreach (Picture p in results)
                {
                    await p.DeleteAsync();
                }

                int newIndex = listInsects.SelectedIndex - 1;
                if (newIndex < 0)
                {
                    newIndex = 0;
                }
                listInsects.SelectedIndex = newIndex;
                Insects.Remove(insect);
                await insect.DeleteAsync();

                labelInsects.Content = "Insects (" + Insects.Count + ")";
                MessageBox.Show(outputText);
            }
        }
Esempio n. 5
0
        private async void buttonInsectAdd_Click(object sender, RoutedEventArgs e)
        {
            Insect i = new Insect()
            {
                InsectId  = GetFirstInsectId(),
                PictureId = -1
            };
            await i.SaveAsync();

            Insects.Add(i);
            listInsects.SelectedIndex = Insects.Count - 1;
            InsectObjectEditor window = new InsectObjectEditor(i);

            window.Closing += async delegate
            {
                await i.SaveAsync();

                labelInsects.Content = "Insects (" + Insects.Count + ")";
            };
            window.ShowDialog();
        }