Example #1
0
        private void SendParcel_Click(object sender, RoutedEventArgs e)
        {
            var        parcelAddViewModel = (ParcelAddViewModel)DataContext;
            InfoWindow info = new InfoWindow();

            if (!CalculateCost())
            {
                return;
            }

            DataModel.Region senderRegion = null;
            if (parcelAddViewModel.ParcelSendMethodSelected.id == 2)
            {
                senderRegion = ParcelMap.GetCurrentRegion(From, companyEntities);
                if (senderRegion == null)
                {
                    info.ShowInfo("Lokalizacja nadania przesyłki znajduje się w nieobsługiwanym regionie!", "Nadanie przesyłki", "Ok");
                    return;
                }
            }
            DataModel.Region receiverRegion = null;
            receiverRegion = ParcelMap.GetCurrentRegion(To, companyEntities);
            if (receiverRegion == null)
            {
                info.ShowInfo("Lokalizacja odbioru przesyłki znajduje się w nieobsługiwanym regionie!", "Nadanie przesyłki", "Ok");
                return;
            }

            if (parcelAddViewModel.ParcelTypeSelected.id == (int)EnumTypeOfParcel.CashOnDelivery)
            {
                info.ShowInfo($"Przesyłka została wyceniona na kwotę {parcelAddViewModel.MyTariff.cost + 10} zł. Chcesz nadać przesyłkę?", "Nadanie przeyłki", "Nie", "Tak");
            }
            else
            {
                info.ShowInfo($"Przesyłka została wyceniona na kwotę {parcelAddViewModel.MyTariff.cost} zł. Chcesz nadać przesyłkę?", "Nadanie przeyłki", "Nie", "Tak");
            }

            if (!info.Answer)
            {
                return;
            }

            if (parcelAddViewModel.SendParcel(senderRegion, receiverRegion, From, To, (bool)generateLabel.IsChecked, (bool)generateConfirmate.IsChecked))
            {
                info.ShowInfo("Przesyłka została nadana!", "Nadanie przesyłki", "Ok");
                ParcelMap.ClearAllMap();
                Worth.Text = "0,00 zł";
                generateLabel.IsChecked             = false;
                generateConfirmate.IsChecked        = false;
                parcelAddViewModel.VisibilityOption = Visibility.Hidden;
            }
            else
            {
                info.ShowInfo("Nie udało się nadać przesyłki!", "Nadanie przesyłki", "Ok");
            }
        }
Example #2
0
 public static MapPolyline GetPolyline(this Map MyMap, DataModel.Region region)
 {
     foreach (var child in MyMap.Children)
     {
         if (child is MapPolyline)
         {
             var polyline = (MapPolyline)child;
             if (polyline.Locations.Any(l => l.Latitude == double.Parse(region.Localization.latitude) && l.Longitude == double.Parse(region.Localization.longitude)))
             {
                 return(polyline);
             }
         }
     }
     return(null);
 }
Example #3
0
        private void ContextMenu_RightClick(object sender, MouseButtonEventArgs e)
        {
            if (activationFunction)
            {
                Location location = MyMap.ViewportPointToLocation(Mouse.GetPosition(MyMap));
                var      temp     = MyMap.GetCurrentRegion(location, companyEntities);
                if (temp != null && regionVisibility)
                {
                    ContextMenu context = new ContextMenu();
                    context.IsOpen = true;
                    var editRegion = new MenuItem()
                    {
                        Header = "Edytuj region"
                    };
                    var removeRegion = new MenuItem()
                    {
                        Header = "Usuń region"
                    };
                    var infoRegion = new MenuItem()
                    {
                        Header = "Info"
                    };

                    infoRegion.Click += (s, es) => MessageBox.Show($"Kod: {temp.code}");
                    editRegion.Click += async(s, es) =>
                    {
                        MyMap.Children.Remove(MyMap.GetPolyline(temp));
                        while (e.LeftButton == MouseButtonState.Released)
                        {
                            await Task.Delay(25);
                        }
                        var viewModel = (RegionViewModel)this.DataContext;
                        viewModel.WarehouseSelectedRegion = viewModel.Warehouses.FirstOrDefault(w => w.id == temp.idWarehouse);
                        viewModel.EmployeeSelectedRegion  = viewModel.Employees.FirstOrDefault(e => e.idRegion == temp.id);
                        CreateRegions_ClickAsync(s, es);
                        region = temp;
                    };
                    removeRegion.Click += (s, es) =>
                    {
                        System.Windows.Forms.DialogResult result = (System.Windows.Forms.DialogResult)MessageBox.Show($"Na pewno chcesz usunąć region {temp.code}?", "", MessageBoxButton.YesNo, MessageBoxImage.Question);
                        if (result == System.Windows.Forms.DialogResult.Yes)
                        {
                            var emplTemp = companyEntities.Employee.Where(e => e.idRegion == temp.id);
                            foreach (var employee in emplTemp)
                            {
                                employee.idRegion = null;
                            }
                            MyMap.Children.Remove(MyMap.GetPolyline(temp));
                            companyEntities.Localization.Remove(temp.Localization);
                            companyEntities.Localization.Remove(temp.Localization1);
                            temp.idWarehouse = null;
                            companyEntities.Region.Remove(temp);
                            companyEntities.SaveChanges();
                        }
                    };
                    context.Items.Add(editRegion);
                    context.Items.Add(removeRegion);
                    context.Items.Add(infoRegion);
                }
                else
                {
                    ContextMenu context = new ContextMenu();
                    context.IsOpen = true;
                    var createRegions = new MenuItem()
                    {
                        Header = "Dodaj nowy region"
                    };
                    var connectPushPins = new MenuItem()
                    {
                        Header = "Połącz pinezki"
                    };
                    var clear = new MenuItem()
                    {
                        Header = "Wyczyść trase"
                    };
                    clear.Click           += ClearPolyline_Click;
                    connectPushPins.Click += ConnectPushPins_Click;
                    createRegions.Click   += CreateRegions_ClickAsync;
                    context.Items.Add(createRegions);
                    context.Items.Add(connectPushPins);
                    context.Items.Add(clear);
                }
            }
        }
Example #4
0
 private void ClearPolyline_Click(object sender, RoutedEventArgs e)
 {
     MyMap.ClearAllMap();
     regionVisibility = false;
     region           = null;
 }
Example #5
0
        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);
        }
Example #6
0
        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);
            }
        }