private void listBoxControlCity_Click(object sender, EventArgs e) { city = this.listBoxControlCity.SelectedValue as City; if (city != null) { this.textEditCity.Text = city.CityName; this.textEditDistrict.Text = ""; this.textEditStreet.Text = ""; IList <District> list = null; DataTable table = DistrictManager.GetDistrictByCityIDTwo(city.CityId); if (table != null) { if (table.Rows.Count > 0) { list = new List <District>(); foreach (DataRow row in table.Rows) { District district = new District(); district.DistrictId = int.Parse(row["districtId"].ToString()); district.DistrictName = row["districtName"].ToString(); district.CityId = int.Parse(row["cityId"].ToString()); list.Add(district); } } } this.bindingSourceDistrict.DataSource = list; this.bindingSourceStreet.DataSource = null; } else { this.textEditDistrict.Text = ""; this.textEditStreet.Text = ""; this.textEditCity.Text = ""; } }
private void simpleButtonSave_Click(object sender, EventArgs e) { if (this.textEditCity.Text == "") { MessageBox.Show("資料不全,無法儲存!"); return; } if (this.textEditDistrict.Text == "") { MessageBox.Show("資料不全,無法儲存!"); return; } if (this.textEditStreet.Text == "") { MessageBox.Show("資料不全,無法儲存!"); return; } if (city == null) { city = new City(); } if (district == null) { district = new District(); } if (shreet == null) { shreet = new Shreet(); } city.CityName = this.textEditCity.Text; district.DistrictName = this.textEditDistrict.Text; shreet.ShreetName = this.textEditStreet.Text; if (flog == 1) { if (CityManager.GetCityByName(city.CityName) == null) { bool i = CityManager.Add(city); if (i == true) { district.CityId = CityManager.GetCityByName(city.CityName)[0].CityId; bool j = DistrictManager.Add(district); if (j == true) { shreet.DistrictId = DistrictManager.GetDistrictByNameAndCityId(district.DistrictName, district.CityId)[0].DistrictId; bool k = ShreetManager.Add(shreet); if (k == true) { MessageBox.Show("添加成功!"); //this.bindingSourceDistrict.DataSource = DistrictManager.GetDistrictByCityID(district.CityId); //this.bindingSourceStreet.DataSource = ShreetManager.GetShreetByDistrictId(shreet.DistrictId); IList <District> list1 = null; DataTable table = DistrictManager.GetDistrictByCityIDTwo(district.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; IList <Shreet> list = null; DataTable table1 = ShreetManager.GetShreetByDistrictIdTwo(shreet.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; } } } } else { if (DistrictManager.GetDistrictByName(district.DistrictName) == null) { district.CityId = CityManager.GetCityByName(city.CityName)[0].CityId; bool i = DistrictManager.Add(district); if (i == true) { shreet.DistrictId = DistrictManager.GetDistrictByName(district.DistrictName)[0].DistrictId; bool k = ShreetManager.Add(shreet); if (k == true) { MessageBox.Show("添加成功!"); //this.bindingSourceDistrict.DataSource = DistrictManager.GetDistrictByCityID(district.CityId); //this.bindingSourceStreet.DataSource = ShreetManager.GetShreetByDistrictId(shreet.DistrictId); IList <District> list1 = null; DataTable table = DistrictManager.GetDistrictByCityIDTwo(district.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; IList <Shreet> list = null; DataTable table1 = ShreetManager.GetShreetByDistrictIdTwo(shreet.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; } } } else { if (DistrictManager.GetDistrictByNameAndCityId(district.DistrictName, district.CityId) == null) { district.CityId = CityManager.GetCityByName(city.CityName)[0].CityId; bool i = DistrictManager.Add(district); if (i == true) { shreet.DistrictId = DistrictManager.GetDistrictByNameAndCityId(district.DistrictName, district.CityId)[0].DistrictId; bool k = ShreetManager.Add(shreet); if (k == true) { MessageBox.Show("添加成功!"); //this.bindingSourceDistrict.DataSource = DistrictManager.GetDistrictByCityID(district.CityId); //this.bindingSourceStreet.DataSource = ShreetManager.GetShreetByDistrictId(shreet.DistrictId); IList <District> list1 = null; DataTable table = DistrictManager.GetDistrictByCityIDTwo(district.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; IList <Shreet> list = null; DataTable table1 = ShreetManager.GetShreetByDistrictIdTwo(shreet.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; } } } else { if (DistrictManager.GetDistrictByNameAndCityId(district.DistrictName, district.CityId)[0].CityId != CityManager.GetCityByName(city.CityName)[0].CityId) { district.CityId = CityManager.GetCityByName(city.CityName)[0].CityId; bool i = DistrictManager.Add(district); if (i == true) { shreet.DistrictId = DistrictManager.GetDistrictByNameAndCityId(district.DistrictName, district.CityId)[0].DistrictId; bool k = ShreetManager.Add(shreet); if (k == true) { MessageBox.Show("添加成功!"); //this.bindingSourceDistrict.DataSource = DistrictManager.GetDistrictByCityID(district.CityId); //this.bindingSourceStreet.DataSource = ShreetManager.GetShreetByDistrictId(shreet.DistrictId); IList <District> list1 = null; DataTable table = DistrictManager.GetDistrictByCityIDTwo(district.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; IList <Shreet> list = null; DataTable table1 = ShreetManager.GetShreetByDistrictIdTwo(shreet.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; } } } else { if (ShreetManager.GetShreetByName(shreet.ShreetName) == null) { shreet.DistrictId = DistrictManager.GetDistrictByNameAndCityId(district.DistrictName, district.CityId)[0].DistrictId; bool i = ShreetManager.Add(shreet); if (i == true) { MessageBox.Show("添加成功!"); //this.bindingSourceStreet.DataSource = ShreetManager.GetShreetByDistrictId(shreet.DistrictId); IList <Shreet> list = null; DataTable table1 = ShreetManager.GetShreetByDistrictIdTwo(shreet.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; } } else { int iCount = 0; foreach (Shreet ss in ShreetManager.GetShreetByName(shreet.ShreetName)) { if (ss.DistrictId == DistrictManager.GetDistrictByNameAndCityId(district.DistrictName, district.CityId)[0].DistrictId) { iCount = 1; } } if (iCount == 0) { shreet.DistrictId = DistrictManager.GetDistrictByNameAndCityId(district.DistrictName, district.CityId)[0].DistrictId; bool i = ShreetManager.Add(shreet); if (i == true) { MessageBox.Show("添加成功!"); //this.bindingSourceStreet.DataSource = ShreetManager.GetShreetByDistrictId(shreet.DistrictId); IList <Shreet> list = null; DataTable table1 = ShreetManager.GetShreetByDistrictIdTwo(shreet.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; } } else { iCount = 0; jjyy = 1; MessageBox.Show("資料重複,無法新增此筆資料!"); } } } } } } } if (flog == 2) { ShreetManager.Update(shreet); if (DistrictManager.GetDistrictByName(district.DistrictName) == null) { DistrictManager.Update(district); } else { int iCount = 0; foreach (District d in DistrictManager.GetDistrictByName(district.DistrictName)) { if (d.CityId == city.CityId) { iCount = 1; } } if (iCount == 0) { DistrictManager.Update(district); } iCount = 0; } if (CityManager.GetCityByName(city.CityName) == null) { CityManager.Update(city); } MessageBox.Show("修改成功!"); //this.bindingSourceDistrict.DataSource = DistrictManager.GetDistrictByCityID(district.CityId); //this.bindingSourceStreet.DataSource = ShreetManager.GetShreetByDistrictId(shreet.DistrictId); IList <District> list1 = null; DataTable table = DistrictManager.GetDistrictByCityIDTwo(district.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; IList <Shreet> list = null; DataTable table1 = ShreetManager.GetShreetByDistrictIdTwo(shreet.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; } flog = 0; Bind(); }
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(); }