private static void GenEventLocations(int nRecords) { string[] suffixes = new string[] { "Hall", "Symporium", "Valley", "Farmer's Market", "Mart", "Centre", "Park", "Lounge", "Community Centre" }; for (int i = 0; i < nRecords; i++) { try { EventLocation eventLocation = new EventLocation(); eventLocation.Name = GenEventLocationName(suffixes); eventLocation.Address = new AuntRosieEntities.Address(); eventLocation.Address.City = Faker.Address.City(); eventLocation.Address.Province = GetRandProvince(); eventLocation.Address.Street = Faker.Address.StreetAddress(); eventLocation.Create(); } catch { } } }
/// <summary> /// Add new location /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnNewTypetClear_Click(object sender, EventArgs e) { if (validateAddLocation()) { try { Address address = new Address(txtProvince.Text, txtCity.Text, txtStreet.Text); EventLocation location = new EventLocation(); location.Name = txtnewLocName.Text; location.Address = address; location.Create(); cmbLocations.Items.Clear(); foreach (EventLocation loc in EventLocation.GetLocations()) { cmbLocations.Items.Add(loc); if (location.ToString() == loc.ToString()) { cmbLocations.SelectedItem = loc; } } System.Diagnostics.Debug.WriteLine($"{location}"); showLocPnlMsg("Successfully added location", true); } catch (SqlException se) { if (se.Message.Contains("duplicate key")) { showLocPnlMsg("Location already exists", false); } } } }