private void dgvBaseUnitList_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 đơn vị tính này?", "Xoá đơn vị tính này", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { DataGridViewRow currentRow = dgvBaseUnitList.Rows[e.RowIndex]; MeasurementUnitService measurementUnitService = new MeasurementUnitService(); int id = ObjectHelper.GetValueFromAnonymousType <int>(currentRow.DataBoundItem, "Id"); ProductLogService productLogService = new ProductLogService(); ProductLog log = productLogService.GetProductLogs().Where(p => p.UnitId == id && p.Status == BHConstant.ACTIVE_STATUS).FirstOrDefault(); if (log == null) { if (!measurementUnitService.DeleteMeasurementUnit(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); } loadMeasurementUnitList(); } else { MessageBox.Show("Đơn vị tính này đang được sử dụng!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } } } }
private void dgvBaseUnitList_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 đơn vị tính này?", "Xoá đơn vị tính này", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { DataGridViewRow currentRow = dgvBaseUnitList.Rows[e.RowIndex]; MeasurementUnitService measurementUnitService = new MeasurementUnitService(); int id = ObjectHelper.GetValueFromAnonymousType<int>(currentRow.DataBoundItem, "Id"); ProductLogService productLogService = new ProductLogService(); ProductLog log = productLogService.GetProductLogs().Where(p => p.UnitId == id && p.Status == BHConstant.ACTIVE_STATUS).FirstOrDefault(); if (log == null) { if (!measurementUnitService.DeleteMeasurementUnit(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); } loadMeasurementUnitList(); } else { MessageBox.Show("Đơn vị tính này đang được sử dụng!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } } } }