private void dgvProductAttributeList_CellClick(object sender, DataGridViewCellEventArgs e) { if (sender is DataGridView) { DataGridViewCell cell = ((DataGridView)sender).CurrentCell; if (cell.ColumnIndex == ((DataGridView)sender).ColumnCount - 1) { DialogResult result = MessageBox.Show("Bạn có muốn xóa Quy cách sản phẩm này?", "Xoá Quy cách sản phẩm này", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { DataGridViewRow currentRow = dgvProductAttributeList.Rows[e.RowIndex]; BaseAttributeService baseAttributeService = new BaseAttributeService(); int id = ObjectHelper.GetValueFromAnonymousType <int>(currentRow.DataBoundItem, "Id"); ProductAttributeService productAttributeService = new ProductAttributeService(); List <ProductAttribute> productList = productAttributeService.SelectProductAttributeByWhere(x => x.AttributeId == id); if (productList.Count > 0) { MessageBox.Show("Quy cách sản phẩm này đang được sử dụng. Không xóa được!"); } else { if (!baseAttributeService.DeleteBaseAttribute(id)) { MessageBox.Show("Hiện tại hệ thống đang có lỗi. Vui lòng thử lại sau!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } loadProductAttributeList(); } } } } }
private void dgvProductAttributeList_CellClick(object sender, DataGridViewCellEventArgs e) { if (sender is DataGridView) { DataGridViewCell cell = ((DataGridView)sender).CurrentCell; if (cell.ColumnIndex == ((DataGridView)sender).ColumnCount - 1) { DialogResult result = MessageBox.Show("Bạn có muốn xóa Quy cách sản phẩm này?", "Xoá Quy cách sản phẩm này", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { DataGridViewRow currentRow = dgvProductAttributeList.Rows[e.RowIndex]; BaseAttributeService baseAttributeService = new BaseAttributeService(); int id = ObjectHelper.GetValueFromAnonymousType<int>(currentRow.DataBoundItem, "Id"); ProductAttributeService productAttributeService = new ProductAttributeService(); List<ProductAttribute> productList = productAttributeService.SelectProductAttributeByWhere(x => x.AttributeId == id); if (productList.Count > 0) { MessageBox.Show("Quy cách sản phẩm này đang được sử dụng. Không xóa được!"); } else { if (!baseAttributeService.DeleteBaseAttribute(id)) { MessageBox.Show("Hiện tại hệ thống đang có lỗi. Vui lòng thử lại sau!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } loadProductAttributeList(); } } } } }