jeudi 1 octobre 2015

How to maintain users data with respect to the particular user after logging in sqlite, windows phone 8.1

I created a login page and registration page. The values were stored in sqlite database. If the user enters the correct username and password the login will be successful. After logging in, the list items should be displayed with respect to that particular user. Similar to a mailbox. How to retrieve the specific user data after he logged in.

 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();
        }
    }

To save the user data I think we should modify the above code.

After logging in a new page with the below code is executed.

protected async override void OnNavigatedTo(NavigationEventArgs e)
    {
        var dbpath = ApplicationData.Current.LocalFolder.Path + "/ebook.db";
        var con = new SQLiteAsyncConnection(dbpath);
        await con.CreateTableAsync<DownloadList>();
        try
        {
            lv2.ItemsSource = new List<DownloadList>();
            List<DownloadList> mylist = await con.QueryAsync<DownloadList>("select * from DownloadList");
            if (mylist.Count != 0)
            {

                lv2.ItemsSource = mylist;
                lv2.DisplayMemberPath = "Mylist";
            }
        }

So in the above code only the recent items in the database is displayed in the listview but I am trying to display the data with respect to particular user.Help me..

Aucun commentaire:

Enregistrer un commentaire