Beispiel #1
0
        private void dataGridViewGroups_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            DataGridView             dataGrid = (DataGridView)sender;
            DataGridViewButtonColumn button   = dataGrid.Columns[e.ColumnIndex] as DataGridViewButtonColumn;

            int id = ((int)dataGrid.Rows[e.RowIndex].Cells[0].Value);

            if (e.ColumnIndex == dataGrid.Columns["ColumnEditGroupButton"].Index && e.RowIndex >= 0)
            {
                using (Model.KeynerContext db = new Model.KeynerContext())
                {
                    Model.Group  group = db.GroupSet.FirstOrDefault(g => g.Id == id);
                    FormNewGroup form  = new FormNewGroup(ref group);
                    form.ShowDialog();
                    if (form.DialogResult == DialogResult.Yes)
                    {
                        this.FillDataGridGroups();
                    }
                }
            }

            if (e.ColumnIndex == dataGrid.Columns["ColumnDeleteGroupButton"].Index && e.RowIndex >= 0)
            {
                if (MessageBox.Show("Do you want delete this group?", "Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    using (Model.KeynerContext db = new Model.KeynerContext())
                    {
                        db.Entry(db.GroupSet.FirstOrDefault(g => g.Id == id)).State = System.Data.Entity.EntityState.Deleted;
                        db.SaveChanges();
                        dataGrid.Rows.RemoveAt(e.RowIndex);
                    }
                }
            }
        }
Beispiel #2
0
        private void buttonNewGroup_Click(object sender, EventArgs e)
        {
            FormNewGroup form = new FormNewGroup();

            form.ShowDialog();
            if (form.DialogResult == DialogResult.Yes)
            {
                this.FillDataGridGroups();
            }
        }