コード例 #1
0
ファイル: MainPage.xaml.cs プロジェクト: progiter/fuelGR
        private async void FuelStationLogo_Tapped(object sender, TappedRoutedEventArgs e)
        {
            int numOfPins = int.Parse(gsNumLabel.Text.ToString());

            //+1 γιατί υπάρχει και το pin της θέσης του χρήστη!
            numOfPins += 1;

            if (myMap.Children.Count > numOfPins)
            {
                myMap.Children.RemoveAt(myMap.Children.Count - 1);
            }

            Image      img = (Image)sender;
            GasStation gs  = (GasStation)img.Tag;
            // Ελεγχος σε τι συσκευή τρέχει για την εμφάνιση του ανάλογου infoBox


            var deviceType = CommonMethods.GetDeviceFamily();

            if (deviceType == CommonMethods.DeviceFamily.Desktop)
            {
                //Τρέχει σε desktop
                InfoBoxDesktop infoBox = new InfoBoxDesktop();
                infoBox.Name   = "MyInfoBox";
                infoBox.Margin = new Thickness(0, 0, 0, 60);

                infoBox.actions_grid.Tapped += Actions_grid_Tapped;
                infoBox.actions_grid.Tag     = gs.LT + ", " + gs.LG;

                double maxmin25precent = (double)(maxPrice - minPrice) * 25 / 100;
                double price           = Double.Parse(gs.FT_PR);

                if (price >= minPrice && price <= minPrice + maxmin25precent)
                {
                    infoBox.gs_price.Foreground = new SolidColorBrush(Colors.Green);
                }
                else if (price <= maxPrice && price >= maxPrice - maxmin25precent)
                {
                    infoBox.gs_price.Foreground = new SolidColorBrush(Colors.Red);
                }
                else
                {
                    infoBox.gs_price.Foreground = new SolidColorBrush(Colors.Blue);
                }

                if (gs.AC == "ROOFTOP")
                {
                    infoBox.gs_location_accuracy.Text = "Άριστη";
                }
                else
                {
                    infoBox.gs_location_accuracy.Text = "Μέτρια";
                }

                infoBox.gs_fuel_type.Text = gs.FT;
                infoBox.gs_price.Text     = gs.FT_PR + " €";
                infoBox.gs_distance.Text  = gs.DIS + " Km";
                infoBox.gs_logo.Source    = new BitmapImage(CommonMethods.GetFuelStationIcon(gs.BR_ID));

                if (gs.BR == "ΑΝΕΞΑΡΤΗΤΟ ΠΡΑΤΗΡΙΟ")
                {
                    infoBox.gs_name.Text = "ΑΠ";
                }
                else if (gs.BR == "ΑΙΓΑΙΟ (AEGEAN)")
                {
                    infoBox.gs_name.Text = "AEGEAN";
                }
                else
                {
                    infoBox.gs_name.Text = gs.BR;
                }

                infoBox.gs_owner.Text      = gs.OW;
                infoBox.gs_address.Text    = gs.AD;
                infoBox.gs_date.Text       = gs.FT_DT;
                infoBox.gs_CloseBtn.Click += Gs_CloseBtn_Click;
                infoBox.gs_CloseBtn.Tag    = infoBox;
                string phone1 = string.Empty;
                string phone2 = string.Empty;

                if (string.IsNullOrWhiteSpace(gs.PH1))
                {
                    phone1 = string.Empty;
                }
                else
                {
                    phone1 = gs.PH1;
                }

                if (string.IsNullOrWhiteSpace(gs.PH2))
                {
                    phone2 = string.Empty;
                }
                else
                {
                    phone2 = gs.PH2;
                }


                if (string.IsNullOrWhiteSpace(phone1) && string.IsNullOrWhiteSpace(phone2))
                {
                    infoBox.gs_phone.Text = "Μη διαθέσιμο";
                }
                else
                {
                    if (!string.IsNullOrWhiteSpace(phone1) && !string.IsNullOrWhiteSpace(phone2))
                    {
                        infoBox.gs_phone.Text = gs.PH1 + ", " + gs.PH2;
                    }
                    if (!string.IsNullOrWhiteSpace(phone1) && string.IsNullOrWhiteSpace(phone2))
                    {
                        infoBox.gs_phone.Text = gs.PH1;
                    }
                    if (string.IsNullOrWhiteSpace(phone1) && !string.IsNullOrWhiteSpace(phone2))
                    {
                        infoBox.gs_phone.Text = gs.PH2;
                    }
                }

                double latitude  = Double.Parse(gs.LT);
                double longitude = Double.Parse(gs.LG);

                myMap.Children.RemoveAt(myMap.Children.Count - 1);
                myMap.Children.Add(infoBox);

                var position = new Geopoint(new BasicGeoposition()
                {
                    Latitude  = latitude,
                    Longitude = longitude
                });

                MapControl.SetLocation(infoBox, position);
                MapControl.SetNormalizedAnchorPoint(infoBox, new Point(0.5, 1));

                await myMap.TrySetViewAsync(position, 17);
            }
            else if (deviceType == CommonMethods.DeviceFamily.Mobile)
            {
                //Τρέχει σε κινητό
                InfoBox infoBox = new InfoBox();
                infoBox.Name = "MyInfoBox";

                infoBox.actions_grid.Tapped += Actions_grid_Tapped;
                infoBox.actions_grid.Tag     = gs.LT + ", " + gs.LG;

                infoBox.Margin = new Thickness(0, 0, 0, 60);

                double maxmin25precent = (double)(maxPrice - minPrice) * 25 / 100;
                double price           = Double.Parse(gs.FT_PR);

                if (price >= minPrice && price <= minPrice + maxmin25precent)
                {
                    infoBox.gs_price.Foreground = new SolidColorBrush(Colors.Green);
                }
                else if (price <= maxPrice && price >= maxPrice - maxmin25precent)
                {
                    infoBox.gs_price.Foreground = new SolidColorBrush(Colors.Red);
                }
                else
                {
                    infoBox.gs_price.Foreground = new SolidColorBrush(Colors.Blue);
                }

                if (gs.AC == "ROOFTOP")
                {
                    infoBox.gs_location_accuracy.Text = "Άριστη";
                }
                else
                {
                    infoBox.gs_location_accuracy.Text = "Μέτρια";
                }

                infoBox.gs_fuel_type.Text = gs.FT;
                infoBox.gs_price.Text     = gs.FT_PR + " €";
                infoBox.gs_distance.Text  = gs.DIS + " Km";
                infoBox.gs_logo.Source    = new BitmapImage(CommonMethods.GetFuelStationIcon(gs.BR_ID));

                if (gs.BR == "ΑΝΕΞΑΡΤΗΤΟ ΠΡΑΤΗΡΙΟ")
                {
                    infoBox.gs_name.Text = "ΑΠ";
                }
                else if (gs.BR == "ΑΙΓΑΙΟ (AEGEAN)")
                {
                    infoBox.gs_name.Text = "AEGEAN";
                }
                else
                {
                    infoBox.gs_name.Text = gs.BR;
                }

                infoBox.gs_owner.Text      = gs.OW;
                infoBox.gs_address.Text    = gs.AD;
                infoBox.gs_date.Text       = gs.FT_DT;
                infoBox.gs_CloseBtn.Click += Gs_CloseBtn_Click;
                infoBox.gs_CloseBtn.Tag    = infoBox;

                string phone1 = string.Empty;
                string phone2 = string.Empty;

                if (string.IsNullOrWhiteSpace(gs.PH1))
                {
                    phone1 = string.Empty;
                }
                else
                {
                    phone1 = gs.PH1;
                }

                if (string.IsNullOrWhiteSpace(gs.PH2))
                {
                    phone2 = string.Empty;
                }
                else
                {
                    phone2 = gs.PH2;
                }


                if (string.IsNullOrWhiteSpace(phone1) && string.IsNullOrWhiteSpace(phone2))
                {
                    infoBox.gs_phone.Text = "Μη διαθέσιμο";
                }
                else
                {
                    if (!string.IsNullOrWhiteSpace(phone1) && !string.IsNullOrWhiteSpace(phone2))
                    {
                        infoBox.gs_phone.Text = gs.PH1 + ", " + gs.PH2;
                    }
                    if (!string.IsNullOrWhiteSpace(phone1) && string.IsNullOrWhiteSpace(phone2))
                    {
                        infoBox.gs_phone.Text = gs.PH1;
                    }
                    if (string.IsNullOrWhiteSpace(phone1) && !string.IsNullOrWhiteSpace(phone2))
                    {
                        infoBox.gs_phone.Text = gs.PH2;
                    }
                }

                double latitude  = Double.Parse(gs.LT);
                double longitude = Double.Parse(gs.LG);

                myMap.Children.RemoveAt(myMap.Children.Count - 1);
                myMap.Children.Add(infoBox);

                var position = new Geopoint(new BasicGeoposition()
                {
                    Latitude  = latitude,
                    Longitude = longitude
                });

                MapControl.SetLocation(infoBox, position);
                MapControl.SetNormalizedAnchorPoint(infoBox, new Point(0.5, 1));

                await myMap.TrySetViewAsync(position, 17);
            }
        }