Esempio n. 1
0
 private void Button_Click_4(object sender, RoutedEventArgs e)
 {
     for (int i = 0; i < ListItems.Items.Count; i++)
     {
         location2 item = new location2();
         item = ListItems.Items[i] as location2;
         if (item.user_id == user.UserId.ToString())
             DeleteTodoItem(item);
     }
 }
Esempio n. 2
0
        private void TextInput_KeyUp(object sender, KeyRoutedEventArgs e)
        {
            pick2 = true;//确定marker2已选
            if (e.Key == Windows.System.VirtualKey.Enter)
            {
                if (nameinput.Visibility == Windows.UI.Xaml.Visibility.Collapsed)
                {
                    for (int i = 0; i < ListItems.Items.Count; i++)
                    {
                        location2 item = new location2();
                        item = ListItems.Items[i] as location2;
                        if (item.Text == TextInput.Text)
                        {
                            marker2.LngLat = new ALngLat(item.x, item.y);
                            marker2.IconURI = new Uri("ms-appx:///Assets/icon/marker_sprite.png", UriKind.Absolute);
                            if (!map.Children.Contains(marker2))
                                map.Children.Add(marker2);
                            tip2.Title = item.Text;

                            map.SetZoomAndCenter(15, marker2.LngLat);
                            break;
                        }
                    }
                }

            }
        }
Esempio n. 3
0
        private async void uploadme_Click(object sender, RoutedEventArgs e)
        {
            //pick = true;//确定marker已选
            /*AGeolocator ageol = new AGeolocator();    //初始化一个AGeolocator对象
            //设置位置改变监听器,调用ageol_PositionChanged 函数  
            ageol.PositionChanged += ageol_PositionChanged;*/
            if (!pick)
            {
                MessageDialog msg = new MessageDialog("请先定位");
                await msg.ShowAsync();
            }
            else
            {
                Boolean check = false;
                if (ListItems.Items.Count == 0)
                    check = true;

                for (int i = 0; i < ListItems.Items.Count; i++)
                {
                    location2 item = new location2();
                    item = ListItems.Items[i] as location2;

                    if (item.user_id.Equals(user.UserId.ToString()))
                    {
                        check = true;

                        item.x = marker.LngLat.LngX;
                        item.y = marker.LngLat.LatY;
                        UpdateCheckedTodoItem(item);
                        /*MessageDialog msg = new MessageDialog(item.x.ToString() + " " + item.y.ToString());
                        msg.ShowAsync();*/

                        //break;
                    }

                }


                if (!check)
                {
                    var location_item = new location { x = marker.LngLat.LngX, y = marker.LngLat.LatY, Text = name, user_id = user.UserId.ToString() };
                    InsertTodoItem(location_item);
                }

                me_x = marker.LngLat.LngX;
                me_y = marker.LngLat.LatY;

                for (int i = 0; i < items2_t.Count; i++)
                {
                    if (items2_t[i].value>0&&items2_t[i].Text!=name)
                    {
                        //MessageDialog msg = new MessageDialog(items2_t[i].value.ToString());
                        /*MessageDialog msg = new MessageDialog(GetDistance(me_y,me_x,items2_t[i].y,items2_t[i].x).ToString());
                        await msg.ShowAsync();*/
                        double dist=GetDistance(me_y,me_x,items2_t[i].y,items2_t[i].x);
                        if (dist < 2000)
                        {
                            senttalkcontent("0","0",items2_t[i].Text,items2_t[i].user_id,name+"在您附近"+dist.ToString()+"米");
                        }
                    }
                }
            }
        }
Esempio n. 4
0
        private void Button_Click_3(object sender, RoutedEventArgs e)
        {
            pick2 = true;//确定marker2已选
            for (int i = 0; i < ListItems.Items.Count; i++)
            {
                location2 item = new location2();
                item = ListItems.Items[i] as location2;
                if (item.Text == TextInput.Text)
                {
                    marker2.LngLat = new ALngLat(item.x, item.y);
                    marker2.IconURI = new Uri("ms-appx:///Assets/icon/marker_sprite.png", UriKind.Absolute);
                    if (!map.Children.Contains(marker2))
                        map.Children.Add(marker2);
                    tip2.Title = item.Text;

                    map.SetZoomAndCenter(15, marker2.LngLat);

                    globalid = item.user_id;
                    globalname = item.Text;
                    talkbox.Visibility = Windows.UI.Xaml.Visibility.Visible;
                    talkbox.Text = "";
                    talkboard.Visibility = Windows.UI.Xaml.Visibility.Visible;

                    break;
                }
            }
        }
Esempio n. 5
0
        private async void UpdateCheckedTodoItem(location2 item)
        {
            // This code takes a freshly completed TodoItem and updates the database. When the MobileService 
            // responds, the item is removed from the list 
            location location_item2 = new location();
            location_item2.Id = item.Id;
            location_item2.Text = item.Text;
            location_item2.user_id = item.user_id;
            location_item2.x = item.x;
            location_item2.y = item.y;

            await todoTable.UpdateAsync(location_item2);
            await RefreshTodoItems();
            //items.Remove(item);
        }
Esempio n. 6
0
        private async System.Threading.Tasks.Task RefreshTodoItems()
        //private async void RefreshTodoItems()//ready to delete
        {
            MobileServiceInvalidOperationException exception = null;
            try
            {
                // This code refreshes the entries in the list view by querying the TodoItems table.
                // The query excludes completed TodoItems
                items = await todoTable.ToCollectionAsync();
                    //.Where(location_item => location_item.x == 1)
                    //.ToCollectionAsync();
            }
            catch (MobileServiceInvalidOperationException e)
            {
                exception = e;
            }

            /*if (exception != null)
            {
                await new MessageDialog(exception.Message, "Error loading items").ShowAsync();
            }
            else
            {
                ListItems.ItemsSource = items;
            }*/

            try
            {
                // This code refreshes the entries in the list view by querying the TodoItems table.
                // The query excludes completed TodoItems
                items2 = await todoTable2.ToCollectionAsync();
                    //.Where(location_item => location_item.x == 1)
                    //.ToCollectionAsync();
            }
            catch (MobileServiceInvalidOperationException e)
            {
                exception = e;
            }

            items2_t = new List<location2>();
            items2_t.Clear();
            string userid = user.UserId;
            int len1 = items.Count;
            for (int i = 0; i < len1; i++)
            {
                
                    location2 item2 = new location2();
                    item2.Id = items[i].Id;
                    item2.Text = items[i].Text;
                    item2.user_id = items[i].user_id;
                    item2.x = items[i].x;
                    item2.y = items[i].y;
                    item2.value = 0;

                    if (item2.user_id.Equals(userid))
                    {
                        item2.value = 10;
                        item2.image = new BitmapImage(new Uri("ms-appx:///Assets/res/本尊.png", UriKind.Absolute));
                        items2_t.Add(item2);
                        continue;
                    }

                    int len2 = items2.Count;
                    for (int j = 0; j < len2; j++)
                    {
                        if ((items2[j].userid1.Equals(userid) && items2[j].userid2.Equals(item2.user_id)) || (items2[j].userid1.Equals(item2.user_id) && items2[j].userid2.Equals(userid)))
                        {
                            item2.value = items2[j].value;
                            break;
                        }
                    }


                    if (item2.value == 10)
                        item2.image = new BitmapImage(new Uri("ms-appx:///Assets/res/本尊.png", UriKind.Absolute));
                    else
                    if (item2.value==2)
                        item2.image = new BitmapImage(new Uri("ms-appx:///Assets/res/熟悉.png", UriKind.Absolute));
                    else
                        item2.image = new BitmapImage(new Uri("ms-appx:///Assets/res/陌生.png", UriKind.Absolute));

                    items2_t.Add(item2);
            
            }

            if (exception != null)
            {
                await new MessageDialog(exception.Message, "Error loading items").ShowAsync();
            }
            else
            {
                IEnumerable<location2> query = items2_t.OrderByDescending(i => i.value);//降序
                //IEnumerable<location2> query = items2_t.OrderBy(i => i.value);//升序

                ListItems.ItemsSource = query;
            }
        }
Esempio n. 7
0
        private async void DeleteTodoItem(location2 location_item)
        {
            //await todoTable.DeleteAsync(location_item);
            location location_item2 = new location();
            location_item2.Id = location_item.Id;
            location_item2.Text = location_item.Text;
            location_item2.user_id = location_item.user_id;
            location_item2.x = location_item.x;
            location_item2.y = location_item.y;


            items2_t.Remove(location_item);
            await todoTable.DeleteAsync(location_item2);
            await RefreshTodoItems();
            //items.Remove(location_item);
        }
Esempio n. 8
0
        private async void InsertTodoItem(location location_item)
        {
            // This code inserts a new TodoItem into the database. When the operation completes
            // and Mobile Services has assigned an Id, the item is added to the CollectionView
            await todoTable.InsertAsync(location_item);
            location2 location_item2 = new location2();
            location_item2.Id = location_item.Id;
            location_item2.Text = location_item.Text;
            location_item2.user_id = location_item.user_id;
            location_item2.x = location_item.x;
            location_item2.y = location_item.y;

            location_item2.value = 10;
            location_item2.image = new BitmapImage(new Uri("ms-appx:///Assets/res/我.png", UriKind.Absolute));

            items2_t.Add(location_item2);
            await RefreshTodoItems();
            //items.Add(location_item);                        
        }
Esempio n. 9
0
        private async System.Threading.Tasks.Task Authenticate()
        {
            while (user == null)
            {
                string message;
                try
                {
                    user = await App.MobileService
                        .LoginAsync(MobileServiceAuthenticationProvider.MicrosoftAccount);
              
                    message =
                        string.Format("登陆成功");
                    //RefreshTodoItems();
               
                }
                catch (InvalidOperationException)
                {
                    message = "您必须登陆";
                }

                
                var dialog = new MessageDialog(message);
                dialog.Commands.Add(new UICommand("OK"));
                await dialog.ShowAsync();
            }
            /*if (user != null)
            {
                await RefreshTodoItems();

                Boolean check = false;
                //MessageDialog msg = new MessageDialog(ListItems.Items.Count.ToString());
                //await msg.ShowAsync();

                for (int i = 0; i < ListItems.Items.Count; i++)
                {
                    location item = new location();
                    item = ListItems.Items[i] as location;

                    if (item.user_id.Equals(user.UserId.ToString()))
                    {
                        if (item.Text != "")
                            name = item.Text;
                        check = true;
                        //break;
                    }

                }
                if (!check)
                    nameinput.Visibility = Windows.UI.Xaml.Visibility.Visible;
                else
                    nameinput.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
            }*/
            if (user != null)
            {
                await RefreshTodoItems();

                Boolean check = false;
                name = "";
                //MessageDialog msg = new MessageDialog(ListItems.Items.Count.ToString());
                //await msg.ShowAsync();

                for (int i = 0; i < ListItems.Items.Count; i++)
                {
                    location2 item = new location2();
                    item = ListItems.Items[i] as location2;

                    if (item.user_id.Equals(user.UserId.ToString()))
                    {
                        if (item.Text != "")
                            name = item.Text;
                        check = true;
                        //break;
                    }

                }
                if (!check)
                    nameinput.Visibility = Windows.UI.Xaml.Visibility.Visible;
                else
                    nameinput.Visibility = Windows.UI.Xaml.Visibility.Collapsed;

                AcquirePushChannel();

                for (int i = 0; i < items2_t.Count; i++)
                    if (items2_t[i].Text.Equals(name))
                    {
                        me_x = items2_t[i].x;
                        me_y = items2_t[i].y;
                    }
            }

        }