/// <summary> /// 从DataSet中加载城市信息 /// </summary> /// <param name="ds"></param> void InitZoneFromDataSet(DataSet ds) { var dtZone = ds.Tables[0]; var dtArea = ds.Tables[1]; this.ZoneList.Clear(); foreach (DataRow dr in dtZone.Rows) { var zone = new Models.Zone() { ID = Convert.ToInt32(dr["ID"]), Name = dr["Zone"].ToString() }; var drAreas = dtArea.Select("ZoneID=" + zone.ID); foreach (DataRow drArea in drAreas) { var area = new Models.Area() { ID = Convert.ToInt32(drArea["ID"]), ZoneID = Convert.ToInt32(drArea["ZoneID"]), Name = drArea["Area"].ToString(), AreaCode = drArea["AreaCode"].ToString() //Zone = zone }; zone.AreaList.Add(area); } this.ZoneList.Add(zone); } }
public static Search.Models.Zone AsSearchModel(this Models.Zone source) => new Search.Models.Zone { Id = source.Id.Value, Name = source.Name, Notes = source.Notes };
internal static Models.Zone ToDestinationModel(this Zone zone) { Models.Zone destination = new Models.Zone { Id = zone.Id, Name = zone.Name, }; destination.Stations.AddRange(zone.Stations.Select(x => x.ToStation())); return(destination); }
/// <summary> /// Map <see cref="Models.Zone"/> to <see cref="DataContext.Zone"/> /// </summary> public static DataContext.Zone Convert(this Models.Zone zone) { return(new DataContext.Zone() { UserId = zone.UserId, Longitude = zone.Longitude, Latitude = zone.Latitude, Name = zone.Name, Radius = zone.Radius, ZoneId = zone.ZoneId }); }
public bool ListZones(string zoneType, ref string errorMessage, ref List <IO.Swagger.Models.Zone> results) { bool retVal = true; try { using (COPDBContext.monica_cnetContext context = new COPDBContext.monica_cnetContext()) { //Make query var locations = (from d in context.Location join f in context.LocationTemplates on d.Locationtemplateid equals f.Locationtemplateid where f.Name == zoneType select new { id = d.Locationid, name = d.Name, descripton = d.Description, metadata = d.Metadata, bpol = d.Boundingpolygon, capacity = d.Capacity, type = f.Name } ).ToList(); if (locations == null) { errorMessage = "No locations"; retVal = false; } else { foreach (var loc in locations) { int?count = null; try { var things = context.LocationThings .Single(b => b.Locationid == loc.id); var values = (from d in context.LatestObservation where d.Locationid == loc.id && d.Type == "PEOPLE_DENSITY" select new { type = d.Type, obs = d.Observationresult } ).ToList(); if (values.Count > 0) { string str = values[0].obs; dynamic json = JValue.Parse(str); count = json.result.density_count; } } catch (Exception exx) { System.Console.WriteLine(exx.Message); } IO.Swagger.Models.Zone z = new Models.Zone(); z.Name = loc.name; z.Id = (int)loc.id; z.Description = loc.descripton; z.Metadata = loc.metadata; z.Type = loc.type; z.Capacity = loc.capacity; z.Peoplecount = count; z.BoundingPolygon = CreateBoundingPol(loc.bpol); results.Add(z); } } //Insert role connection; } return(retVal); } catch (Exception e) { errorMessage = "Database Excaption:" + e.Message + " " + e.StackTrace; return(false); } }
private static double GetDistanceInMeters(Xamarin.Essentials.Location location, Models.Zone zone) { double differenceInLatitude = DegreeToRadian(zone.OffsetLocation.Latitude - location.Latitude); double differenceInLongitude = DegreeToRadian(zone.OffsetLocation.Longitude - location.Longitude); double latitudeHaversine = Math.Cos(DegreeToRadian(zone.OffsetLocation.Latitude)) * Math.Cos(DegreeToRadian(location.Latitude)); double longitudeHaversine = Math.Sin(differenceInLongitude / 2) * Math.Sin(differenceInLongitude / 2); double innerHaversine = latitudeHaversine * longitudeHaversine; double haversine = (Math.Sin((differenceInLatitude) / 2) * Math.Sin((differenceInLatitude) / 2)) + (innerHaversine); var distanceInMeters = AverageRadiusOfTheEarthInMeters * 2 * Math.Atan2(Math.Sqrt(haversine), Math.Sqrt(1 - haversine)); return(distanceInMeters); }
private static bool IsLocationInsideZone(double distanceFromZoneNexus, Models.Zone zone) { return(distanceFromZoneNexus < zone.Radius); }
private static double GetRelativeDistanceFromZoneNexus(double distanceFromZoneNexus, Models.Zone zone) { return(distanceFromZoneNexus / zone.Radius); }
private void SaveZoneMap() { using (var uow = DIContainer.CreateUnitOfWork()) { var repo = DIContainer.CreateRepository<Repositories.IZoneMapRepository>(uow); var zoneMap = repo.Find(this.ZoneMapID); //Set the ZoneMap's Description and IsEnabled zoneMap.Description = txtZoneMapDescription.Text; zoneMap.IsEnabled = chkIsEnabled.Checked; //Get a list of the Zone descriptions that were changed string[] cellIds = hidZoneChanges.Value.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); //For each changed Zone description foreach (string cellId in cellIds) { //The cellId is cell:<ZoneId> or new:<n> string[] parts = cellId.Split(':'); bool isNew = parts[0].Contains("new"); int zoneID = int.Parse(parts[1]); string description = this.Request.Form[cellId].Trim(); Models.Zone zone = null; //If the description is blank then delete the zone if (string.IsNullOrEmpty(description)) { if (isNew) { //do nothing } else { if (repo.DoesZoneHaveTariffRates(zoneID)) { this.MessageBox(string.Format("The zone {0} that you have tried to delete has Tariff Rates assigned to it. Please remove these before attempting to delete this zone again.", zone.Description)); return; } zone = zoneMap.Zones.Single(z => z.ZoneID == zoneID); if (zone.ZonePostcodeAreas.Any()) { this.MessageBox(string.Format("The zone {0} that you have tried to delete has Postcode Areas assigned to it. Please remove these before attempting to delete this zone again.", zone.Description)); return; } repo.RemoveZone(zone); } } else { if (isNew) { zone = new Models.Zone { ZoneType = zoneMap.ZoneType }; zoneMap.Zones.Add(zone); } else { zone = zoneMap.Zones.Single(z => z.ZoneID == zoneID); } zone.Description = this.Request.Form[cellId]; } } uow.SaveChanges(); LoadZones(zoneMap); } }