Exemplo 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.");
            }
        }
Exemplo n.º 2
0
        private async void buttonInsecticideAdd_Click(object sender, RoutedEventArgs e)
        {
            Insecticide i = new Insecticide()
            {
                InsecticideId = GetFirstInsecticideId()
            };
            await i.SaveAsync();

            Insecticides.Add(i);
            LoadedInsecticides.Add(i);
            labelNoInsecticides.Visibility = Visibility.Hidden;
            InsecticideObjectEditor window = new InsecticideObjectEditor(i);

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

                labelNoInsecticides.Visibility = Visibility.Hidden;

                if (Insects.ElementAt(listInsects.SelectedIndex).InsecticideIds.Count == 0)
                {
                    List <int> ids = new List <int>();
                    ids.Add(i.InsecticideId);
                    Insects.ElementAt(listInsects.SelectedIndex).InsecticideIds = ids;
                }
                else
                {
                    Insects.ElementAt(listInsects.SelectedIndex).InsecticideIds.Add(i.InsecticideId);
                }
                labelInsecticides.Content = Insects.ElementAt(listInsects.SelectedIndex).Name + ": Insecticides (" + LoadedInsecticides.Count + ")";
                await Insects.ElementAt(listInsects.SelectedIndex).SaveAsync();

                listInsecticides.SelectedIndex = LoadedInsecticides.Count - 1;
            };
            window.ShowDialog();
        }
        public InsecticideObjectEditor(Insecticide i)
        {
            InitializeComponent();
            CurrentInsecticide = i;

            textBoxName.Text         = i.Name;
            textBoxName.TextChanged += delegate
            {
                CurrentInsecticide.Name = textBoxName.Text;
            };

            textBoxOtherName.Text         = i.OtherName;
            textBoxOtherName.TextChanged += delegate
            {
                CurrentInsecticide.OtherName = textBoxOtherName.Text;
            };

            textBoxFormulation.Text         = i.Formulation;
            textBoxFormulation.TextChanged += delegate
            {
                CurrentInsecticide.Formulation = textBoxFormulation.Text;
            };

            textBoxActive.Text         = i.Active;
            textBoxActive.TextChanged += delegate
            {
                CurrentInsecticide.Active = textBoxActive.Text;
            };

            textBoxAcres.Text         = i.Acres;
            textBoxAcres.TextChanged += delegate
            {
                CurrentInsecticide.Acres = textBoxAcres.Text;
            };

            textBoxMinDays.Text         = (i.MinimumDays <= 0) ? "" : "" + i.MinimumDays;
            textBoxMinDays.TextChanged += delegate
            {
                try
                {
                    if (!textBoxMinDays.Text.Equals(""))
                    {
                        CurrentInsecticide.MinimumDays = int.Parse(textBoxMinDays.Text);
                    }
                    else
                    {
                        CurrentInsecticide.MinimumDays = -1;
                    }
                }
                catch
                {
                    textBoxMinDays.Text = (i.MinimumDays <= 0) ? "" : "" + i.MinimumDays;
                }
            };

            textBoxPerformance.Text         = (i.Performance <= 0) ? "" : "" + i.Performance;
            textBoxPerformance.TextChanged += delegate
            {
                try
                {
                    if (!textBoxPerformance.Text.Equals(""))
                    {
                        CurrentInsecticide.Performance = int.Parse(textBoxPerformance.Text);
                    }
                    else
                    {
                        CurrentInsecticide.Performance = -1;
                    }
                }
                catch
                {
                    textBoxPerformance.Text = (i.Performance <= 0) ? "" : "" + i.Performance;
                }
            };

            textBoxRestrictedInterval.Text         = (i.EntryInterval <= 0) ? "" : "" + i.EntryInterval;
            textBoxRestrictedInterval.TextChanged += delegate
            {
                try
                {
                    if (!textBoxRestrictedInterval.Text.Equals(""))
                    {
                        CurrentInsecticide.EntryInterval = int.Parse(textBoxRestrictedInterval.Text);
                    }
                    else
                    {
                        CurrentInsecticide.EntryInterval = -1;
                    }
                }
                catch
                {
                    textBoxRestrictedInterval.Text = (i.EntryInterval <= 0) ? "" : "" + i.EntryInterval;
                }
            };

            textBoxComments.Text         = i.Comments;
            textBoxComments.TextChanged += delegate
            {
                CurrentInsecticide.Comments = textBoxComments.Text;
            };

            comboBoxRestricted.SelectedIndex = (i.Restricted) ? 0 : 1;
            Console.WriteLine("Items in combo box: " + comboBoxRestricted.Items.Count);
            comboBoxRestricted.SelectionChanged += delegate
            {
                CurrentInsecticide.Restricted = (comboBoxRestricted.SelectedIndex == 0);
                Console.WriteLine("Restricted = " + CurrentInsecticide.Restricted);
            };
        }