private void btnRemove_Click(object sender, EventArgs e) { if (DialogResult.OK == MessageBox.Show("You may delete Gears and Gear Boxes associated. Do you want to continue ?", "Caution", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning)) { if (listShaft.SelectedItems.Count > 0) { Shaft shaftToDelete = new Shaft(); shaftToDelete = (Shaft)listShaft.SelectedItems[0]; Program.shaftList.Remove(shaftToDelete); Database1DataSet1TableAdapters.Shaft1TableAdapter sta = new Database1DataSet1TableAdapters.Shaft1TableAdapter(); Database1DataSet1TableAdapters.GearsTableAdapter gta = new Database1DataSet1TableAdapters.GearsTableAdapter(); Database1DataSet1TableAdapters.GearBoxTableAdapter gbta = new Database1DataSet1TableAdapters.GearBoxTableAdapter(); List<int> gearIds = Util.listOfGearIds(shaftToDelete.ID, gta); try { foreach (int g in gearIds) { gbta.DeleteInputGearQuery(g); gbta.DeleteOutputGearQuery(g); Gear gear = Util.getGearById(g); Program.gearList.Remove(gear); } gta.DeleteShaftQuery(shaftToDelete.ID); sta.Delete(shaftToDelete.ID, shaftToDelete.Name, shaftToDelete.Diameter, shaftToDelete.Material.ID, shaftToDelete.KeyCutWidth, shaftToDelete.KeyCutHeigth, shaftToDelete.KeyCutLength); Util.refreshGearBoxList(); } catch (Exception ex) { } } refreshList(); treeViewShaft.Nodes.Clear(); propertyGridShaft.SelectedObject = null; btnRemove.Enabled = false; btnEdit.Enabled = false; btnSelect.Enabled = false; } }
private void btnRemove_Click(object sender, EventArgs e) { if (DialogResult.OK == MessageBox.Show("You may delete the Shafts, Gears and Gear Boxes associated. Do you want to continue ?", "Caution", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning)) { if (listMaterial.SelectedItems.Count > 0) { Material materialToDelete = new Material(); materialToDelete = (Material)listMaterial.SelectedItems[0]; Program.materialList.Remove(materialToDelete); Database1DataSet1TableAdapters.MaterialsTableAdapter mta = new Database1DataSet1TableAdapters.MaterialsTableAdapter(); Database1DataSet1TableAdapters.Shaft1TableAdapter sta = new Database1DataSet1TableAdapters.Shaft1TableAdapter(); Database1DataSet1TableAdapters.GearsTableAdapter gta = new Database1DataSet1TableAdapters.GearsTableAdapter(); Database1DataSet1TableAdapters.GearBoxTableAdapter gbta = new Database1DataSet1TableAdapters.GearBoxTableAdapter(); List<int> shaftIds = Util.listOfShaftIds(materialToDelete.ID, sta); List<int> gearIds = Util.listOfGearIds(materialToDelete.ID, shaftIds, gta); try { foreach (int g in gearIds) { gbta.DeleteInputGearQuery(g); gbta.DeleteOutputGearQuery(g); Gear gear = Util.getGearById(g); Program.gearList.Remove(gear); } foreach (int s in shaftIds) { gta.DeleteShaftQuery(s); Shaft shaft = Util.getShaftById(s); Program.shaftList.Remove(shaft); } sta.DeleteQuery(materialToDelete.ID); mta.Delete(materialToDelete.ID, materialToDelete.Name, materialToDelete.youngsModulus, materialToDelete.Density, materialToDelete.yieldStress); Util.refreshGearBoxList(); } catch (Exception ex) { } } refreshList(); propertyGridMaterial.SelectedObject = null; btnRemove.Enabled = false; btnEdit.Enabled = false; btnSelect.Enabled = false; } }