簡體   English   中英

將Windows Azure連接到Microsoft Visual Studio 2012-Windows Phone 8

[英]Connect Windows Azure to Microsoft Visual Studio 2012 - windows phone 8

我是計算機科學專業的最終學生,正在嘗試開發Windows 8手機應用程序,對於這種類型的開發我還是很陌生。 我正在使用具有移動服務和數據庫連接的Windows Azure帳戶來連接到Visual Studio 2012。

我試圖允許用戶創建一個帳戶來使用我的應用程序,但是當他們輸入任何詳細信息時,他們並沒有保存到數據庫中的表中。 運行代碼並按注冊按鈕時,出現以下調試錯誤:

“ Application_UnhandledException”

下面是我的代碼的樣子。

這來自CreateAccount.xaml.cs文件:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using Microsoft.WindowsAzure.MobileServices;
using Newtonsoft.Json;

namespace IME.Miscellaneous
{

public class accountDetails
{
// Setting up the items for inclusion in the createAccount table
public string Id { get; set; }

[JsonProperty(PropertyName = "userpassword")]
public string Password { get; set; }

[JsonProperty(PropertyName = "securityQuestion1")]
public string SecurityQuestion1 { get; set; }

[JsonProperty(PropertyName = "securityQuestion2")]
public string SecurityQuestion2 { get; set; }

[JsonProperty(PropertyName = "securityQuestion3")]
public string SecurityQuestion3 { get; set; }

[JsonProperty(PropertyName = "answer1")]
public string SecurityAnswer1 { get; set; }

[JsonProperty(PropertyName = "answer2")]
public string SecurityAnswer2 { get; set; }

[JsonProperty(PropertyName = "answer3")]
public string SecurityAnswer3 { get; set; }
}

public partial class CreateAccount : PhoneApplicationPage
{

private MobileServiceCollection<accountDetails, accountDetails> items;

private IMobileServiceTable<accountDetails> accountTable =         App.MobileService.GetTable<accountDetails>();

public CreateAccount()
{
    InitializeComponent();
}


private async void InsertAccountInfo(accountDetails accountDetailsItem)
{
    // This code inserts a new item into the database. When the operation completes
    // and Mobile Services has assigned an Id, the item is added

    await accountTable.InsertAsync(accountDetailsItem);
    items.Add(accountDetailsItem);

}


private async void RefreshAccountInfo()
{
    // This code refreshes the entries in the list view be querying the createAccount table.
    try
    {
        items = await accountTable
            .Where(accountDetailsItem => accountDetailsItem.Password == "")
            .ToCollectionAsync();
    }
    catch (MobileServiceInvalidOperationException e)
    {
        MessageBox.Show(e.Message, "Error loading items", MessageBoxButton.OK);
    }

}

private void Register_Button_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
    // Brings the user to the Home hub page
    NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));

    // When button is clicked the accountDetails table is updated with the password
    //var user = new accountDetails { Id = ID_textbox.Text, Password =     Password_Text.Password, SecurityQuestion1 = Security_Question_1.Text, SecurityQuestion2 = Security_Question_2.Text, 
    //  SecurityQuestion3 = Security_Question_3.Text, SecurityAnswer1 = Security_Question_1_Answer.Text, SecurityAnswer2 = Security_Question_2_Answer.Text, 
    // SecurityAnswer3 = Security_Question_3_Answer.Text};
    // InsertAccountInfo(user);
}

protected override void OnNavigatedTo(NavigationEventArgs e)
{
    RefreshAccountInfo();
}

private void Security_Question_1_Answer_GotFocus(object sender, RoutedEventArgs e)
{
    // Sets the  textbox to empty when the user clicks on it
    TextBox securityAnswerOne = (TextBox)sender;
    securityAnswerOne.Text = string.Empty;
    securityAnswerOne.GotFocus -= Security_Question_1_Answer_GotFocus;
}

private void Security_Question_2_Answer_GotFocus(object sender, RoutedEventArgs e)
{
    // Sets the  textbox to empty when the user clicks on it
    TextBox securityAnswerTwo = (TextBox)sender;
    securityAnswerTwo.Text = string.Empty;
    securityAnswerTwo.GotFocus -= Security_Question_2_Answer_GotFocus;
}

private void Security_Question_3_Answer_GotFocus(object sender, RoutedEventArgs e)
{
    // Sets the  textbox to empty when the user clicks on it
    TextBox securityAnswerThree = (TextBox)sender;
    securityAnswerThree.Text = string.Empty;
    securityAnswerThree.GotFocus -= Security_Question_3_Answer_GotFocus;
}

private void Security_Question_3_Answer_LostFocus(object sender, RoutedEventArgs e)
{
    TextBox securityAnswerThree = (TextBox)sender;
    if (String.IsNullOrEmpty(Security_Question_3_Answer.Text))
    {
        securityAnswerThree.Text = "Please Enter an answer";
        securityAnswerThree.LostFocus -= Security_Question_3_Answer_LostFocus;
    }

}

private void Security_Question_2_Answer_LostFocus(object sender, RoutedEventArgs e)
{
    TextBox securityAnswerTwo = (TextBox)sender;
    if (String.IsNullOrEmpty(Security_Question_2_Answer.Text))
    {
        securityAnswerTwo.Text = "Please Enter an answer";
        securityAnswerTwo.LostFocus -= Security_Question_2_Answer_LostFocus;
    }
}

private void Security_Question_1_Answer_LostFocus(object sender, RoutedEventArgs e)
{
    TextBox securityAnswerOne = (TextBox)sender;
    if (String.IsNullOrEmpty(Security_Question_3_Answer.Text))
    {
        securityAnswerOne.Text = "Please Enter an answer";
        securityAnswerOne.LostFocus -= Security_Question_3_Answer_LostFocus;
    }
}
}
}

這來自App.xaml.cs文件:

// Creating account details table
 public class accountDetails
 {
     public int id { get; set; }
     public string userpassword { get; set; }
     public string securityQuestion1 { get; set; }
     public string securityQuestion2 { get; set; }
     public string securityQuestion3 { get; set; }
     public string answer1 { get; set; }
     public string answer2 { get; set; }
     public string answer3 { get; set; }     

 public accountDetails(string p, string sq1, string sq2, string sq3, string a1, string a2, string a3)
     {
         // Creating the constructor
         userpassword = p;
         securityQuestion1 = sq1;
         securityQuestion2 = sq2;
         securityQuestion3 = sq3;
         answer1 = a1;
         answer2 = a2;
         answer3 = a3;
     }
 }

數據庫中的表也稱為“ CreateAccount”。

任何幫助將不勝感激。

您應該添加更多錯誤處理-目前尚不清楚您的錯誤是在Register_Button_Tap事件處理程序中還是在RefreshAccountInfo方法中發生的。

另外,您說數據庫中的表稱為“ CreateAccount”,但您的Mobile Services參考使用的表名為“ accountDetails”。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM