private void simpleButtonDelete_Click(object sender, EventArgs e) { if (MessageBox.Show("確定要刪除?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { shreet = this.listBoxControlStreet.SelectedValue as Shreet; if (shreet != null) { ShreetManager.Delete(shreet.ShreetId); if (district != null) { //this.bindingSourceStreet.DataSource = ShreetManager.GetShreetByDistrictId(district.DistrictId); IList <Shreet> list = null; DataTable table1 = ShreetManager.GetShreetByDistrictIdTwo(district.DistrictId); if (table1 != null) { if (table1.Rows.Count > 0) { list = new List <Shreet>(); foreach (DataRow row in table1.Rows) { Shreet shreet1 = new Shreet(); shreet1.ShreetId = int.Parse(row["shreetId"].ToString()); shreet1.ShreetName = row["shreetName"].ToString(); shreet1.DistrictId = int.Parse(row["districtId"].ToString()); list.Add(shreet1); } } } this.bindingSourceStreet.DataSource = list; } shreet = this.listBoxControlStreet.SelectedValue as Shreet; this.textEditStreet.Text = ""; } else { if (district != null) { district = this.listBoxControlDistrict.SelectedValue as District; DistrictManager.Delete(district.DistrictId); if (city != null) { //this.bindingSourceDistrict.DataSource = DistrictManager.GetDistrictByCityID(city.CityId); IList <District> list1 = null; DataTable table = DistrictManager.GetDistrictByCityIDTwo(city.CityId); if (table != null) { if (table.Rows.Count > 0) { list1 = new List <District>(); foreach (DataRow row in table.Rows) { District district1 = new District(); district1.DistrictId = int.Parse(row["districtId"].ToString()); district1.DistrictName = row["districtName"].ToString(); district1.CityId = int.Parse(row["cityId"].ToString()); list1.Add(district1); } } } this.bindingSourceDistrict.DataSource = list1; } district = this.listBoxControlDistrict.SelectedValue as District; this.textEditStreet.Text = ""; this.textEditDistrict.Text = ""; } else { if (city != null) { bool i = CityManager.Delete(city.CityId); this.bindingSourceCity.DataSource = CityManager.GetCity(); } city = this.listBoxControlCity.SelectedValue as City; this.textEditCity.Text = ""; this.textEditDistrict.Text = ""; this.textEditStreet.Text = ""; } } } Bind(); }