示例#1
0
        public FindedWorkplace GetAppropriationPercentage(List <SearchingModel> searchingModel,
                                                          Workplace workplaceInRadius, int wantedCost)
        {
            List <int> workplaceEquipmentIds = workplaceEquipmentDB.GetEntityList()
                                               .Where(e => e.WorkplaceId == workplaceInRadius.Id).Select(e => e.EquipmentId)
                                               .ToList();

            double oneImportancePart = 100 / searchingModel.Count();

            double resultingPercentage = 0;

            foreach (var searchInstance in searchingModel)
            {
                if (workplaceEquipmentIds.Contains(searchInstance.EquipmentId))
                {
                    resultingPercentage += oneImportancePart;
                }
                else
                {
                    resultingPercentage += (oneImportancePart * (1 - searchInstance.Importancy));
                }
            }

            double costPercantage = (workplaceInRadius.Cost * 100 / wantedCost) - 100;

            FindedWorkplace findedWorkplace = new FindedWorkplace(workplaceInRadius.Id, resultingPercentage, costPercantage);

            return(findedWorkplace);
        }
示例#2
0
        private void MapOnInfoWindowClick(object sender, GoogleMap.InfoWindowClickEventArgs e)
        {
            Marker                   myMarker = e.Marker;
            ISharedPreferences       prefs    = PreferenceManager.GetDefaultSharedPreferences(Android.App.Application.Context);
            ISharedPreferencesEditor editor   = prefs.Edit();
            KeyValuePair <Building, List <Workplace> > buildingInstance = CompositeMarkers[myMarker.Id];
            TextView  markerMenu = FindViewById <TextView>(Resource.Id.marker_menu);
            PopupMenu menu       = new PopupMenu(this, markerMenu);

            foreach (Workplace workplace in buildingInstance.Value)
            {
                FindedWorkplace finded = findedWorkplaces.FirstOrDefault(x => x.WorkplaceId == workplace.Id);
                menu.Menu.Add("Workplace number:" + workplace.Id.ToString() + ",\nWorkplace cost: " + workplace.Cost.ToString()
                              + ",\nAppropriation: " + finded.AppropriationPercentage.ToString() + ",\nCost approp: " + finded.CostColor
                              + ", Address: " + buildingInstance.Key.Country + ", " + buildingInstance.Key.City + ", "
                              + buildingInstance.Key.Street + ", " + buildingInstance.Key.House.ToString() + ", " + buildingInstance.Key.Flat.ToString());
            }
            menu.MenuItemClick += (s1, arg1) =>
            {
                AlertDialog.Builder alert = new AlertDialog.Builder(this);
                alert.SetTitle("Workplace");
                alert.SetMessage(arg1.Item.TitleFormatted.ToString());
                alert.SetPositiveButton("Visit", async(senderAlert, arg) =>
                {
                    ISharedPreferences prefs1        = PreferenceManager.GetDefaultSharedPreferences(Android.App.Application.Context);
                    ISharedPreferencesEditor editor1 = prefs1.Edit();
                    string workplId = arg1.Item.TitleFormatted.ToString().Split(':', ',')[1];
                    editor1.PutString("workplaceId", workplId);
                    editor1.Apply();

                    var intent = new Intent(this, typeof(WorkplaceActivity));
                    StartActivity(intent);
                });

                alert.SetNegativeButton("Cancel", (senderAlert, arg) =>
                {
                    Toast.MakeText(this, "Cancelled!", ToastLength.Short).Show();
                });

                Dialog dialog = alert.Create();
                dialog.Show();
            };

            menu.DismissEvent += (s2, arg2) =>
            {
                Console.WriteLine("menu dismissed");
            };
            menu.Show();
            //editor.PutString("restaurant", Markers[myMarker.Id].ToString());
            //editor.Apply();

            //var intent = new Intent(this, typeof(RestaurantActivity));
            //StartActivity(intent);
        }