Example #1
0
        private void dtgvUser_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (dtgvUser.Columns[e.ColumnIndex].Name == "btnEdit")
            {
                DataGridViewRow row        = dtgvUser.SelectedCells[0].OwningRow;
                Login_User      login_User = new Login_User();
                login_User.STT      = int.Parse(row.Cells["STT"].Value.ToString());
                login_User.TaiKhoan = row.Cells["TaiKhoan"].Value.ToString();
                login_User.MatKhau  = row.Cells["MatKhau"].Value.ToString();
                login_User.HoTen    = row.Cells["HoTen"].Value.ToString();
                login_User.SDT      = row.Cells["SDT"].Value.ToString();
                login_User.LoaiDN   = row.Cells["LoaiDN"].Value.ToString();


                EditUser editform = new EditUser(login_User);
                editform.ShowDialog();
            }
            else if (dtgvUser.Columns[e.ColumnIndex].Name == "btnDelete")
            {
                DialogResult dialogResult = MessageBox.Show("Bạn có chắc là muốn làm việc này", "WARNING", MessageBoxButtons.YesNo);
                if (dialogResult == DialogResult.Yes)
                {
                    DataGridViewRow row = dtgvUser.SelectedCells[0].OwningRow;
                    values[0] = row.Cells["STT"].Value.ToString();

                    login_UserBUS.DeleteUser(values[0]);
                    MessageBox.Show("Delete complete.");
                }
                else if (dialogResult == DialogResult.No)
                {
                    //do something else
                }
            }
            LoadData();
        }
Example #2
0
        private void dtgvUser_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
        {
            // F1 : Thêm
            if (e.KeyCode == Keys.F1)
            {
                LoadAnimation();
            }
            // F4: sửa
            else if (e.KeyCode == Keys.F4)
            {
                DataGridViewRow row        = dtgvUser.SelectedCells[0].OwningRow;
                Login_User      login_User = new Login_User();
                login_User.STT      = int.Parse(row.Cells["STT"].Value.ToString());
                login_User.TaiKhoan = row.Cells["TaiKhoan"].Value.ToString();
                login_User.MatKhau  = row.Cells["MatKhau"].Value.ToString();
                login_User.HoTen    = row.Cells["HoTen"].Value.ToString();
                login_User.SDT      = row.Cells["SDT"].Value.ToString();
                login_User.LoaiDN   = row.Cells["LoaiDN"].Value.ToString();


                EditUser editform = new EditUser(login_User);
                editform.ShowDialog();
            }
            // F8 : xóa
            else if (e.KeyCode == Keys.F8)
            {
                DialogResult dialogResult = MessageBox.Show("Bạn có chắc là muốn làm việc này", "WARNING", MessageBoxButtons.YesNo);
                if (dialogResult == DialogResult.Yes)
                {
                    DataGridViewRow row = dtgvUser.SelectedCells[0].OwningRow;
                    values[0] = row.Cells["STT"].Value.ToString();

                    login_UserBUS.DeleteUser(values[0]);
                    MessageBox.Show("Delete complete.");
                }
                else if (dialogResult == DialogResult.No)
                {
                    //do something else
                }
            }


            LoadData();
        }