Exemple #1
0
 private void BtnClearRegion_Click(object sender, RoutedEventArgs e)
 {
     activationFunction = true;
     MyMap.Children.Remove(polyline);
     MyMap.ClearTextInMap();
     RegionOption.Visibility = Visibility.Hidden;
 }
Exemple #2
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);
        }