public void CreateCityManagerAndPopulateWithCitiesTest() { // Cities we want managed City.City city1 = new City.City(500000); City.City city2 = new City.City(2500000); City.City city3 = new City.City(40000); Assert.IsNotNull(city1); Assert.IsNotNull(city2); Assert.IsNotNull(city3); // Add them to city manager CityManager cityManager = new CityManager(); // List of cities should be instantiated when a citymanager is created Assert.IsNotNull(cityManager); Assert.IsNotNull(cityManager.Cities); cityManager.Add(city1); cityManager.Add(city2); cityManager.Add(city3); Assert.AreEqual(3, cityManager.Cities.Count, "City Manager did not add cities correctly"); Assert.AreEqual(city1, cityManager.Cities[0], "Incorrect city was added to city manager"); Assert.AreEqual(city2, cityManager.Cities[1], "Incorrect city was added to city manager"); Assert.AreEqual(city3, cityManager.Cities[2], "Incorrect city was added to city manager"); }
private void btnSave_Click(object sender, EventArgs e) { try { if (txtCityName.Text == "") { MessageBox.Show("You Must Enter City Name"); return; } city.Add(new City() { City_Code = int.Parse(txtCityCode.Text), City_Name = txtCityName.Text, Country_Code = int.Parse(cmbCountry.SelectedValue.ToString()) }); btnSave.Enabled = false; btnAddNew.Enabled = btnModify.Enabled = true; txtCityCode.Text = txtCityName.Text = ""; MessageBox.Show("New City Successfully Added"); FRM_City_Load(null, null); btnLast_Click(null, null); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public ActionResult Entry(CityEntryVm model) { var cities = Mapper.Map <City>(model); bool isSave = _cityManager.Add(cities); if (isSave) { return(RedirectToAction("Index")); } return(View()); }
public ActionResult Add(CityVM cityVM) { City city = Mapper.Map <City>(cityVM); if (_cityManager.Add(city)) { TempData["saved"] = "Saved Successfully"; return(RedirectToAction("Add")); } return(RedirectToAction("Add")); }
private CityManager BuildPopulationOfCities(int cities) { CityManager cityManager = new CityManager(); for (int i = 1; i <= cities; i++) { string inputPopulation = Console.ReadLine(); int populationPerCity; int.TryParse(inputPopulation, out populationPerCity); City.City city = new City.City(populationPerCity); cityManager.Add(city); } return(cityManager); }
public void Add_AddCity_ReturnTrueResult() { ICityService cityService = new CityManager(_mockCityDal.Object); City city = new City() { Id = 4, CountryId = 1, Name = "City4", CreateDate = DateTime.Now, Active = true }; var result = cityService.Add(city); Assert.IsTrue(result.Success); }
public void CityManagerTest() { CityManager cityManager = new CityManager(new UnitOfWork(new DataContext())); CountryManager countryManager = new CountryManager(new UnitOfWork(new DataContext())); ContinentManager continentManager = new ContinentManager(new UnitOfWork(new DataContext())); //Verwijder alles in tabels cityManager.RemoveAll(); countryManager.RemoveAllCountries(); continentManager.RemoveAll(); //Aanmaak Continent continentManager.Add(new Continent("TestContinent")); List <Continent> continents = continentManager.GetAllContinents(); Continent continent = continents[0]; Assert.AreEqual(1, continents.Count); //Toevoegen van Country countryManager.Add(new Country("TestCountry", continent, 100, 10)); List <Country> countries = countryManager.GetAllCountries(); Country country = countries[0]; Assert.AreEqual(1, countries.Count); Assert.AreEqual("TestCountry", country.Name); //Toevoegen van City cityManager.Add(new City("TestCity", 5000, country, true)); List <City> cities = cityManager.GetAllCities(); City city = cities[0]; Assert.AreEqual(1, cities.Count); Assert.AreEqual("TestCity", city.Name); cityManager.RemoveCityById(city.ID); List <City> citiesAangepast = cityManager.GetAllCities(); Assert.AreEqual(0, citiesAangepast.Count); //Verwijder alles in tabels cityManager.RemoveAll(); countryManager.RemoveAllCountries(); continentManager.RemoveAll(); }
private void form_save_Click(object sender, EventArgs e) { if (city == null) { ClientForm clientForm = (ClientForm)this.Owner; City city = new City() { City_Name = XYEEncoding.strCodeHex(textBox1.Text.Trim()), City_ParentId = XYEEncoding.strCodeHex(city_code), City_Clear = 1, City_Enable = 1, City_Code = XYEEncoding.strCodeHex(BuildCode.ModuleCode("City")) }; try { int result = cm.Add(city); if (result > 0) { clientForm.Isflag = true; MessageBox.Show("地区名称:" + textBox1.Text + " \n添加成功"); Close(); } else { clientForm.Isflag = false; MessageBox.Show("添加失败,请重新添加"); Close(); } } catch (Exception ex) { MessageBox.Show("新增地区资料错误,请检查服务器连接.错误信息:" + ex.Message); } } else { city.City_Name = textBox1.Text.Trim(); try { bool result = cm.UpdateByCode(city); if (result) { ClientForm clientForm = (ClientForm)this.Owner; clientForm.Isflag = true; MessageBox.Show("地区名称:" + textBox1.Text + " \n修改成功"); Close(); } else { ClientForm clientForm = (ClientForm)this.Owner; clientForm.Isflag = false; MessageBox.Show("修改失败,请重新修改"); Close(); } } catch (Exception ex) { MessageBox.Show("新增地区资料错误,请检查服务器连接.错误信息:" + ex.Message); } } }
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(); }
public void City_Manager_Test() { CityManager tempCity = new CityManager(new UnitOfWork(new DataContext("test"))); CountryManager tempCountry = new CountryManager(new UnitOfWork(new DataContext("test"))); ContinentManager tempContinent = new ContinentManager(new UnitOfWork(new DataContext("test"))); tempCity.RemoveAll(); tempCountry.RemoveAll(); tempContinent.RemoveAll(); tempContinent.Add(new Continent("test-Continent")); tempContinent.Add(new Continent("test-Continent1")); List <Continent> continents = tempContinent.GetAll(); Assert.AreEqual(2, continents.Count); tempCountry.Add(new Country("test", 500, 200, continents[0])); tempCountry.Add(new Country("test-Country1", 50, 20, continents[0])); List <Country> countries = tempCountry.GetAll(); Country country1 = tempCountry.Get(countries[0].ID); Country country2 = tempCountry.Get(countries[1].ID); Assert.AreEqual(2, countries.Count); Assert.AreEqual("test", country1.Name); Assert.AreEqual("test-Country1", country2.Name); Assert.AreEqual(500, country1.Population); Assert.AreEqual(50, country2.Population); Assert.AreEqual(200, country1.Surface); Assert.AreEqual(20, country2.Surface); tempCity.Add(new City("test-city", 50, country1, true)); tempCity.Add(new City("test-city1", 150, country1, false)); tempCity.Add(new City("test-city2", 200, country1, false)); tempCity.Add(new City("test-city3", 10, country1, false)); var cities = tempCity.GetAll(); City city = tempCity.Get(cities[0].ID); City city1 = tempCity.Get(cities[1].ID); City city2 = tempCity.Get(cities[2].ID); City city3 = tempCity.Get(cities[3].ID); Assert.AreEqual(city.Name, "test-city"); Assert.AreEqual(city1.Name, "test-city1"); Assert.AreEqual(city2.Name, "test-city2"); Assert.AreEqual(city3.Name, "test-city3"); Assert.AreEqual(city.IsCapital, true); Assert.AreEqual(city1.IsCapital, false); Assert.AreEqual(city2.IsCapital, false); Assert.AreEqual(city3.IsCapital, false); Assert.AreEqual(city.Population, 50); Assert.AreEqual(city1.Population, 150); Assert.AreEqual(city2.Population, 200); Assert.AreEqual(city3.Population, 10); tempCity.Update(city3, "test", 50, false, country2); cities = tempCity.GetAll(); city = tempCity.Get(cities[0].ID); city1 = tempCity.Get(cities[1].ID); city2 = tempCity.Get(cities[2].ID); city3 = tempCity.Get(cities[3].ID); Assert.AreEqual(4, cities.Count); Assert.AreEqual(city.Name, "test-city"); Assert.AreEqual(city1.Name, "test-city1"); Assert.AreEqual(city2.Name, "test-city2"); Assert.AreEqual(city3.Name, "test"); Assert.AreEqual(city.IsCapital, true); Assert.AreEqual(city1.IsCapital, false); Assert.AreEqual(city2.IsCapital, false); Assert.AreEqual(city3.IsCapital, false); Assert.AreEqual(city.Population, 50); Assert.AreEqual(city1.Population, 150); Assert.AreEqual(city2.Population, 200); Assert.AreEqual(city3.Population, 50); tempCity.Remove(city.ID); cities = tempCity.GetAll(); Assert.AreEqual(3, cities.Count); tempCountry.Update(country1, country1.Name, 350, 250, country1.Continent); tempCity = new CityManager(new UnitOfWork(new DataContext("test"))); tempCountry = new CountryManager(new UnitOfWork(new DataContext("test"))); tempContinent = new ContinentManager(new UnitOfWork(new DataContext("test"))); tempCity.RemoveAll(); tempCountry.RemoveAll(); tempContinent.RemoveAll(); }