Esempio n. 1
0
        private void btnEdit_Click(object sender, EventArgs e)
        {
            if (dataGridView.SelectedRows.Count > 0)
            {
                int  index     = dataGridView.SelectedRows[0].Index;
                int  id        = 0;
                bool converted = Int32.TryParse(dataGridView[0, index].Value.ToString(), out id);
                if (converted == false)
                {
                    return;
                }

                ConsCategory cCat = context.ConsCategoryList.Find(id);

                ConsCtForm consCtForm = new ConsCtForm();
                consCtForm.txtName.Text = cCat.Name;


                DialogResult result = consCtForm.ShowDialog(this);
                if (result == DialogResult.Cancel)
                {
                    return;
                }

                cCat.Name = consCtForm.txtName.Text;


                context.Entry(cCat).State = EntityState.Modified;
                context.SaveChanges();
                MessageBox.Show("Категория обновлена");
            }
        }
Esempio n. 2
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            ConsCtForm   ccaeForm = new ConsCtForm();
            DialogResult result   = ccaeForm.ShowDialog(this);

            if (result == DialogResult.Cancel)
            {
                return;
            }

            ConsCategory conCat = new ConsCategory();

            conCat.Name = ccaeForm.txtName.Text;
            context.ConsCategoryList.Add(conCat);
            context.SaveChanges();
            MessageBox.Show("Новая категория добавлена");
        }