public static void DrawSquare(this Map MyMap, DataModel.Localization startLocal, DataModel.Localization endLocal) { MapPolyline polyline = new MapPolyline(); polyline.Stroke = new SolidColorBrush(Colors.Blue); polyline.StrokeThickness = 2; polyline.Opacity = 0.7; LocationCollection locations = new LocationCollection(); locations.Add(new Location() { Latitude = double.Parse(startLocal.latitude), Longitude = double.Parse(startLocal.longitude) }); locations.Add(new Location() { Latitude = double.Parse(endLocal.latitude), Longitude = double.Parse(startLocal.longitude) }); locations.Add(new Location() { Latitude = double.Parse(endLocal.latitude), Longitude = double.Parse(endLocal.longitude) }); locations.Add(new Location() { Latitude = double.Parse(startLocal.latitude), Longitude = double.Parse(endLocal.longitude) }); locations.Add(new Location() { Latitude = double.Parse(startLocal.latitude), Longitude = double.Parse(startLocal.longitude) }); polyline.Locations = locations; MyMap.Children.Add(polyline); }
public static bool IsPolylineInLocalization(this Map MyMap, DataModel.Localization localization) { foreach (var child in MyMap.Children) { if (!(child is MapPolyline)) { continue; } var polyline = (MapPolyline)child; if (polyline.Locations.Any(l => l.Latitude == double.Parse(localization.latitude) && l.Longitude == double.Parse(localization.longitude))) { return(true); } } return(false); }
private void BtnAddRegion_Click(object sender, RoutedEventArgs e) { var info = new InfoWindow(); activationFunction = true; MyMap.Children.Remove(polyline); MyMap.ClearTextInMap(); RegionOption.Visibility = Visibility.Hidden; DataModel.Localization startLocal = new DataModel.Localization() { latitude = location.Latitude.ToString(), longitude = location.Longitude.ToString() }; DataModel.Localization endLocal = new DataModel.Localization() { latitude = polyline.Locations[2].Latitude.ToString(), longitude = polyline.Locations[2].Longitude.ToString() }; Warehouse warehouse = (Warehouse)RegionWarehouse.SelectedItem; Employee empl = (Employee)RegionEmployee.SelectedItem; var employee = companyEntities.Employee.FirstOrDefault(e => e.id == empl.id); if (region != null) { if (MyMap.IsAllowRegion(location, polyline.Locations[2], companyEntities, region.id)) { var start = companyEntities.Localization.First(l => l.id == region.idStartLocalization); var end = companyEntities.Localization.First(l => l.id == region.idEndLocalization); start.latitude = startLocal.latitude; start.longitude = startLocal.longitude; end.latitude = endLocal.latitude; end.longitude = endLocal.longitude; var reg = companyEntities.Region.Find(region.id); reg.code = $"{warehouse.code}/{reg.id}"; reg.idWarehouse = warehouse.id; employee.idRegion = reg.id; employee.Region = reg; companyEntities.SaveChanges(); info.ShowInfo("Region edytowano pomyślnie", "Region", "OK"); } else { info.ShowInfo("Nowy region nie może pokrywać regionów już istniejących!", "Region", "OK"); } } else if (MyMap.IsAllowRegion(location, polyline.Locations[2], companyEntities)) { DataModel.Region newRegion = new DataModel.Region(); companyEntities.Localization.Add(startLocal); companyEntities.Localization.Add(endLocal); companyEntities.SaveChanges(); newRegion.idWarehouse = warehouse.id; newRegion.idStartLocalization = startLocal.id; newRegion.idEndLocalization = endLocal.id; companyEntities.Region.Add(newRegion); companyEntities.SaveChanges(); var temp = companyEntities.Region.OrderByDescending(r => r.id).First(); temp.code = $"{warehouse.code}/{temp.id}"; employee.idRegion = temp.id; employee.Region = temp; companyEntities.SaveChanges(); info.ShowInfo("Region zapisano pomyślnie", "Region", "OK"); } else { info.ShowInfo("Nowy region nie może pokrywać regionów już istniejących!", "Region", "OK"); } region = null; BtnShowRegions_Click(sender, e); }
public bool SendParcel(DataModel.Region senderRegion, DataModel.Region receiverRegion, Location senderLocation, Location receiverLocation, bool generateLabel, bool generateConfirmation) { try { Customer sender = new Customer() { firstName = SenderFirstName ?? "", lastName = SenderLastName ?? "", tel = int.Parse(SenderTel) }; Customer receiver = new Customer() { firstName = ReceiverFirstName ?? "", lastName = ReceiverLastName ?? "", tel = int.Parse(ReceiverTel) }; if (!string.IsNullOrWhiteSpace(SenderCompanyNIP)) { Company senderCompany = new Company() { name = SenderCompanyName, NIP = decimal.Parse(SenderCompanyNIP) }; CompanyEntities.Company.Add(senderCompany); CompanyEntities.SaveChanges(); sender.Company = senderCompany; sender.idCompany = senderCompany.id; } if (!string.IsNullOrWhiteSpace(ReceiverCompanyNIP)) { Company receiverCompany = new Company() { name = ReceiverCompanyName, NIP = decimal.Parse(ReceiverCompanyNIP) }; CompanyEntities.Company.Add(receiverCompany); CompanyEntities.SaveChanges(); receiver.Company = receiverCompany; receiver.idCompany = receiverCompany.id; } Address senderAddress = new Address() { country = SenderCountry ?? "", city = SenderCity ?? "", postalCode = SenderPostalCode ?? "", street = SenderStreet ?? "", numberOfHouse = SenderNumberOfHouse ?? "" }; Address receiverAddress = new Address() { country = ReceiverCountry ?? "", city = ReceiverCity ?? "", postalCode = ReceiverPostalCode ?? "", street = ReceiverStreet ?? "", numberOfHouse = ReceiverNumberOfHouse ?? "" }; var senderLocalization = new DataModel.Localization() { latitude = senderLocation.Latitude.ToString(), longitude = senderLocation.Longitude.ToString() }; var receiverLocalization = new DataModel.Localization() { latitude = receiverLocation.Latitude.ToString(), longitude = receiverLocation.Longitude.ToString() }; CompanyEntities.Localization.Add(senderLocalization); CompanyEntities.Localization.Add(receiverLocalization); CompanyEntities.SaveChanges(); senderAddress.Localization = senderLocalization; senderAddress.idLocalization = senderLocalization.id; receiverAddress.Localization = receiverLocalization; receiverAddress.idLocalization = receiverLocalization.id; CompanyEntities.Address.Add(senderAddress); CompanyEntities.Address.Add(receiverAddress); CompanyEntities.SaveChanges(); sender.Address = senderAddress; sender.idAddress = senderAddress.id; receiver.Address = receiverAddress; receiver.idAddress = receiverAddress.id; CompanyEntities.Customer.Add(sender); CompanyEntities.Customer.Add(receiver); CompanyEntities.SaveChanges(); Parcel parcel = new Parcel() { idSender = sender.id, idReceiver = receiver.id, idReceiverRegion = receiverRegion.id, height = (decimal)double.Parse(ParcelHeight), width = (decimal)double.Parse(ParcelWidth), length = (decimal)double.Parse(ParcelLength), amount = (decimal)double.Parse(ParcelWorth), weight = (decimal)double.Parse(ParcelWeight), idTariff = MyTariff.id, idTypeOfParcel = ParcelTypeSelected.id, idMethodOfSend = ParcelSendMethodSelected.id, dateOfShipment = DateTime.Now, idStatus = (int)EnumParcelStatus.registered }; if (senderRegion != null) { parcel.idSenderRegion = senderRegion.id; parcel.code = $"{senderRegion.Warehouse.code}/{receiverRegion.Warehouse.code}/{DateTime.Now.Year - 2000}"; } else { parcel.code = $"{receiverRegion.Warehouse.code}/{DateTime.Now.Year - 2000}"; } CompanyEntities.Parcel.Add(parcel); CompanyEntities.SaveChanges(); parcel.code = $"{parcel.id}/{parcel.code}"; CompanyEntities.SaveChanges(); if (generateLabel) { GenerateLabel(parcel.id); } if (generateConfirmation) { GenerateConfirmation(parcel.id); } return(true); }catch (Exception e) { return(false); } }