使用Xamarin表单从Azure提取数据

时间:2019-02-28 16:11:28

标签: azure xamarin xamarin.forms

我目前有些麻烦,将一些数据从我的Azure数据库中拉到我的应用程序中。在那一刻,我只是收到我设置的错误消息,而没有其他任何事情发生,我不确定它在哪里出错了,因此我们将不胜感激。

public ObservableCollection<usermedication> UserMedList = new ObservableCollection<usermedication>();
public ObservableCollection<usermedication> MedList = new ObservableCollection<usermedication>();


/// Object Manager Declarations
    /// </summary>
    public MedicineManager medicinemanager;
    public UserMedManager usermedicationmanager;

这是我目前的代码,每次加载页面时,我收到的都是“无药物”消息。我不确定到底出了什么问题,试图从Azure数据库中的表中填充列表视图。

/// Gets User Medication list
    /// </summary>
    /// <returns>The user meds.</returns>
    async public Task GetUserMeds()
    {


        MedicationList.ItemsSource = null;
        //UserMedTimes.Clear(); //Clears the list before calling API (prevents duplication)

        main.Children.Add(MedicationList);
        main.Children.Remove(NoMeds);

        if (!CrossConnectivity.Current.IsConnected)
        {

            main.Children.Remove(MedicationList);
            main.Children.Add(NoMeds);
            NoMeds.Text = "No Internet Connection - Please check your connection";
            NoMeds.Margin = new Thickness(35, 35, 20, 20);

            BusyIndicator.IsRunning = false;
        }

        else

        {
            BusyIndicator.IsRunning = true;



            try
            {

                var usermed = await medicinemanager.CurrentClient.InvokeApiAsync<IEnumerable<usermedication>>("getusermedname?userid=" + Helpers.Settings.UserKey + "", System.Net.Http.HttpMethod.Get, null);


                //Get the List of meds the user is on
                UserMedList = await usermedicationmanager.getUserMedication();


                if (usermed.Any())
                {
                    foreach (usermedication item in usermed)
                    {
                        if (item.IsActive != false)
                        {
                            UserMedList.Add(item);
                        }

                        else
                        {
                            Label MedLogo = new Label();
                            MedLogo.Text = peoplewithfonticon.meds;
                            MedLogo.FontFamily = "icomoon";
                            MedLogo.FontSize = 80;
                            MedLogo.Margin = new Thickness(30, 80, 0, 0);

                            Label MedTitle = new Label();
                            MedTitle.Text = "No \r\nMedications";
                            MedTitle.FontSize = 50;
                            MedTitle.FontAttributes = FontAttributes.Bold;
                            MedTitle.Margin = new Thickness(30, 0, 0, 0);

                            Label NoMeds = new Label();
                            NoMeds.Margin = new Thickness(30, 0, 0, 0);
                            main.Children.Remove(MedicationList);
                            main.Children.Remove(btnHistory);
                            main.Children.Add(MedLogo);
                            main.Children.Add(MedTitle);
                            main.Children.Add(NoMeds);
                            NoMeds.Text = "You haven't added any medications to your medication cupboard yet";
                            main.Children.Add(btnHistory);
                            BusyIndicator.IsRunning = false;

                        }
                    }
                }
            }

            catch (Exception ex)
            {
                Debug.WriteLine(ex.ToString());
            }

0 个答案:

没有答案