Пример #1
0
        private void usersDataGridview_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == 5)
            {
                var   context = new informsysEntities();
                Users users   = context.Users.Find(Convert.ToInt32(usersDataGridview.Rows[e.RowIndex].Cells[0].Value));

                context.Users.Remove(users);
                context.SaveChanges();

                UpdateDataGridView();
            }

            if (e.ColumnIndex == 4)
            {
                using (var context = new informsysEntities())
                {
                    Users users = context.Users.Find(Convert.ToInt32(usersDataGridview.Rows[e.RowIndex].Cells[0].Value));
                    if (users != null)
                    {
                        if (!(String.IsNullOrEmpty(usersDataGridview.Rows[e.RowIndex].Cells[1].Value.ToString())) && !(String.IsNullOrEmpty(usersDataGridview.Rows[e.RowIndex].Cells[2].Value.ToString())) &&
                            !(String.IsNullOrEmpty(usersDataGridview.Rows[e.RowIndex].Cells[3].Value.ToString())))
                        {
                            warning.Visible = false;
                            users.username  = usersDataGridview.Rows[e.RowIndex].Cells[1].Value.ToString();
                            users.Email     = usersDataGridview.Rows[e.RowIndex].Cells[2].Value.ToString();
                            users.passwordd = usersDataGridview.Rows[e.RowIndex].Cells[3].Value.ToString();

                            context.Entry(users).State = EntityState.Modified;
                            context.SaveChanges();

                            UpdateDataGridView();
                        }
                        else
                        {
                            warning.Visible = true;
                        }
                    }
                    else
                    {
                        MessageBox.Show("Пользователь не найден");
                    }
                }
            }
        }
Пример #2
0
        private void adminDataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == 3)
            {
                informsysEntities context = new informsysEntities();
                Admins            admins  = context.Admins.Find(adminDataGridView.Rows[e.RowIndex].Cells[0].Value);

                if (admins != null)
                {
                    if (!(String.IsNullOrEmpty(adminDataGridView.Rows[e.RowIndex].Cells[1].Value.ToString())) && !(String.IsNullOrEmpty(adminDataGridView.Rows[e.RowIndex].Cells[2].Value.ToString())))
                    {
                        warning1.Visible            = false;
                        admins.username             = adminDataGridView.Rows[e.RowIndex].Cells[1].Value.ToString();
                        admins.passwords            = adminDataGridView.Rows[e.RowIndex].Cells[2].Value.ToString();
                        context.Entry(admins).State = EntityState.Modified;
                        context.SaveChanges();

                        this.adminsTableAdapter.Fill(this.informsysDataSet.Admins);
                    }
                    else
                    {
                        warning1.Visible = true;
                    }
                }
                else
                {
                    MessageBox.Show("Такого пользователя не сущетвует");
                }
            }

            if (e.ColumnIndex == 4)
            {
                informsysEntities context     = new informsysEntities();
                Admins            deliteadmin = context.Admins.Find(adminDataGridView.Rows[e.RowIndex].Cells[0].Value);

                context.Admins.Remove(deliteadmin);
                context.SaveChanges();

                this.adminsTableAdapter.Fill(this.informsysDataSet.Admins);
            }
        }