Exemplo n.º 1
0
        private void createToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            CrGroup      grCr   = new CrGroup();
            DialogResult result = grCr.ShowDialog(this);

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

            group.Name = grCr.textBox1.Text;
            db.Groups.Add(group);
            db.SaveChanges();
            MessageBox.Show("New group is added!");
        }
Exemplo n.º 2
0
        private void updateToolStripMenuItem2_Click(object sender, EventArgs e)
        {
            try
            {
                int index = dataGridView1.SelectedRows[0].Index;
                int id    = 0;

                bool converted = Int32.TryParse(dataGridView1[0, index].Value.ToString(), out id);
                if (converted == false)
                {
                    return;
                }

                Group gr = db.Groups.Find(id);

                CrGroup grCr = new CrGroup();

                grCr.textBox1.Text = gr.Name;

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

                gr.Name = grCr.textBox1.Text;

                db.SaveChanges();
                dataGridView1.Refresh(); // обновляем грид
                MessageBox.Show("Employee is updated!");
            }
            catch (Exception outOfRange)
            {
                MessageBox.Show("Inconsistent operation !");
            }
        }