コード例 #1
0
        private void deleteButton_Click(object sender, EventArgs e)
        {
            if (dataGridView.SelectedCells.Count > 0)
            {
                int selectedrowindex = dataGridView.SelectedCells[0].RowIndex;

                DataGridViewRow selectedRow = dataGridView.Rows[selectedrowindex];

                Id = int.Parse(Convert.ToString(selectedRow.Cells["Id"].Value));

                if (MessageBox.Show(String.Format("Are you sure to delete {0}({1})?", Convert.ToString(selectedRow.Cells["Name"].Value), Convert.ToString(selectedRow.Cells["RegistrationNumber"].Value)), "Deleting...", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    if (TripBl.VehicleInUse(Id) || RefillBl.VehicleInUse(Id))
                    {
                        MessageBox.Show("Vehicle is in use, can't be deleted.");
                        return;
                    }

                    VehicleBl vehicleBl = new VehicleBl();
                    vehicleBl.Delete(Id);
                    Id = 0;

                    RefreshGrid();
                }
            }
        }