How to save particular user data with respect to the user logged in. When the user login to the mainpage his data should be displayed.
I successfully created login and registration page and I can insert values to the database. After navigating to the new page what should I code in order to show the data of the logged in user .
protected async override void OnNavigatedTo(NavigationEventArgs e)
{
var dbpath = ApplicationData.Current.LocalFolder.Path + "/ebook.db";
var con = new SQLiteAsyncConnection(dbpath);
await con.CreateTableAsync<Register>();
}
private async void Button_Click(object sender, RoutedEventArgs e)
{
var dbpath = ApplicationData.Current.LocalFolder.Path + "/ebook.db";
var con = new SQLiteAsyncConnection(dbpath);
await con.CreateTableAsync<Register>();
Register m = new Register();
m.Name = text_reg.Text;
m.Password = text_password.Password;
string r = "";
if (radio_male.IsChecked == true)
{
r = "Male";
}
else
{
r = "Female";
}
m.Gender = r;
m.State = ((ComboBoxItem)combo_box.SelectedItem).Content.ToString();
await con.InsertAsync(m);
MessageDialog md = new MessageDialog("success");
await md.ShowAsync();
}
private async void Button_Click_1(object sender, RoutedEventArgs e)
{
Windows.Storage.ApplicationDataContainer data = Windows.Storage.ApplicationData.Current.LocalSettings;
data.Values["check"] = text_reg.Text;
var dbpath = ApplicationData.Current.LocalFolder.Path + "/ebook.db";
var con = new SQLiteAsyncConnection(dbpath);
Register t = new Register();
string query = string.Format("select Name,Password from Register where Name='{0}' and Password='{1}'", text_user.Text, text_pass.Password);
List<Register> mylist = await con.QueryAsync<Register>(query);
if (mylist.Count == 1)
{
t = mylist[0];
}
if (t.Name == text_user.Text && t.Password == text_pass.Password)
{
this.Frame.Navigate(typeof(MainPage));
}
else
{
var messagedialog = new MessageDialog("Unsuccessful").ShowAsync();
}
}
The above code runs successfully. After navigating to next page(i.e MainPage). In my new page I created a list and inserted them in to database. Now how to display the particular list with respect to the user. When other user logs in, his list should be displayed
Aucun commentaire:
Enregistrer un commentaire