Esempio n. 1
0
        private void BDelete_Click(object sender, EventArgs e)
        {
            using (var context = new BotanicalGardenContext())
            {
                DialogResult dr = MessageBox.Show("Подтверждение удаления!", "Удаление", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
                if (dr == DialogResult.OK)
                {
                    switch (TabControl.SelectedIndex)
                    {
                    case 0:
                        foreach (DataGridViewRow row in DGVTree.SelectedRows)
                        {
                            var deleteTree = context.Trees.Find(row.Cells[0].Value);
                            deleteTree.Statistics.Clear();
                            context.Trees.Remove(deleteTree);
                        }
                        context.SaveChanges();
                        InitDGVTree();
                        break;

                    case 1:
                        foreach (DataGridViewRow row in DGVPlant.SelectedRows)
                        {
                            var deletePlant = context.Plants.Find(row.Cells[0].Value);
                            deletePlant.Statistics.Clear();
                            context.Plants.Remove(deletePlant);
                        }
                        context.SaveChanges();
                        InitDGVPlants();
                        break;

                    case 2:
                        foreach (DataGridViewRow row in DGVStatistics.SelectedRows)
                        {
                            var deleteStatistics = context.Statistics.Find(row.Cells[0].Value);
                            context.Statistics.Remove(deleteStatistics);
                        }
                        context.SaveChanges();
                        InitDGVStatistics();
                        break;
                    }
                }
            }
        }
Esempio n. 2
0
        private void BSave_Click(object sender, EventArgs e)
        {
            var dateTime         = TBDateTime.Text;
            var livingСonditions = TBLivingСonditions.Text;
            var condition        = TBCondition.Text;
            var population       = TBPopulation.Text;
            var key = TreeView.SelectedNode != null?int.Parse(TreeView.SelectedNode.Name) : -1;

            if (dateTime.Equals("") || livingСonditions.Equals("") || condition.Equals("") || population.Equals("") || key == -1)
            {
                MessageBox.Show("Укажите все параметры", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            var stat = new Statistic();

            using (var context = new BotanicalGardenContext())
            {
                switch (param)
                {
                case ActionParameters.AddStatistics:
                    stat.DateTime         = Convert.ToDateTime(dateTime);
                    stat.LivingСonditions = livingСonditions;
                    stat.Сondition        = condition;
                    stat.Population       = int.Parse(population);
                    if (RBTree.Checked)
                    {
                        stat.TreeId = key;
                    }
                    if (RBPlant.Checked)
                    {
                        stat.PlantId = key;
                    }
                    context.Statistics.Add(stat);
                    break;

                case ActionParameters.EditStatistics:
                    stat                  = context.Statistics.Find(selectedCells[0].Value);
                    stat.DateTime         = Convert.ToDateTime(dateTime);
                    stat.LivingСonditions = livingСonditions;
                    stat.Сondition        = condition;
                    stat.Population       = int.Parse(population);
                    if (RBTree.Checked)
                    {
                        stat.TreeId = key; stat.PlantId = null;
                    }
                    if (RBPlant.Checked)
                    {
                        stat.PlantId = key; stat.TreeId = null;
                    }
                    break;
                }
                context.SaveChanges();
            }
            Hide();
            fsClass.InitDGVStatistics();
        }
Esempio n. 3
0
        private void ButtonSave_Click(object sender, EventArgs e)
        {
            var name   = TBName.Text;
            var type   = TBType.Text;
            var family = TBFamily.Text;
            var rod    = TBRod.Text;

            using (var context = new BotanicalGardenContext())
            {
                switch (param)
                {
                case ActionParameters.AddTree:
                    context.Trees.Add(new Tree {
                        Name = name, View = type, Family = family, Rod = rod
                    });
                    break;

                case ActionParameters.AddPlant:
                    context.Plants.Add(new Plant {
                        Name = name, Type = type
                    });
                    break;

                case ActionParameters.EditTree:
                    var tree = context.Trees.Find(selectedCells[0].Value);
                    tree.Name   = name;
                    tree.View   = type;
                    tree.Family = family;
                    tree.Rod    = rod;
                    context.Entry(tree).State = EntityState.Modified;
                    break;

                case ActionParameters.EditPlant:
                    var plant = context.Plants.Find(selectedCells[0].Value);
                    plant.Name = name;
                    plant.Type = type;
                    context.Entry(plant).State = EntityState.Modified;
                    break;
                }
                context.SaveChanges();
            }
            Hide();
            switch (param)
            {
            case ActionParameters.AddTree:
            case ActionParameters.EditTree:
                fsClass.InitDGVTree();
                break;

            case ActionParameters.AddPlant:
            case ActionParameters.EditPlant:
                fsClass.InitDGVPlants();
                break;
            }
        }