示例#1
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            badgeCIN = e.Parameter as string;


            // check if user is in the database
            user = DrinkerDatabase.Instance.GetUser(badgeCIN);
            if (user == null)
            {
                // create user
                var action = Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, new Windows.UI.Core.DispatchedHandler(() =>
                {
                    this.Frame.Navigate(typeof(UserCreatePage), badgeCIN);
                }
                ));
            }
            else
            {
                // Show user profile
                userName.Text = user.Name;
                userBalance.Text = user.Balance.ToString();

                user.NumLogins++;
                DrinkerDatabase.Instance.UpdateUser(user);
            }
        }
示例#2
0
 private void listView_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     if (e.AddedItems.Count > 0)
     {
         currUser = (User)e.AddedItems[0];
         userName.Text = currUser.Name;
         ToggleUserDisplay(true);
     }
 }
示例#3
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            // last user
            lastUser = e.Parameter as User;

            var users = DrinkerDatabase.Instance.GetAllUsers();
            users.Sort(
                delegate (User u1, User u2)
                {
                    return u1.Balance.CompareTo(u2.Balance);
                }
             );

            listView.ItemsSource = users;

            if (lastUser != null)
            {
                int idx = -1;
                foreach (var swag in users)
                {
                    if (swag.BadgeCIN == lastUser.BadgeCIN)
                    {
                        idx = users.IndexOf(swag);
                        break;
                    }
                }

                try
                {
                    var selected = listView.Items[idx];
                    listView.SelectedIndex = users.IndexOf(lastUser);
                    listView.SelectedItem = selected;
                }
                catch
                {

                }

            }
        }
示例#4
0
 public void DeleteUser(User user)
 {
     var existingUser = Instance.GetUser(user.BadgeCIN);
     if (existingUser != null)
     {
         using (var delstmt = conn.Prepare("DELETE FROM Customer WHERE BadgeCIN=?"))
         {
             delstmt.Bind(1, user.BadgeCIN);
             delstmt.Step();
         }
     }
 }
示例#5
0
 public void UpdateUser(User user)
 {
     var existingUser = Instance.GetUser(user.BadgeCIN);
     if (existingUser != null)
     {
         using (var custstmt = conn.Prepare("UPDATE Customer SET Balance = ?, Name = ?, PictureUrl = ?, NumBags = ?, NumMilks = ?, NumShots = ?, NumLogins = ? WHERE BadgeCIN=?"))
         {
             custstmt.Bind(1, user.Balance);
             custstmt.Bind(2, user.Name);
             custstmt.Bind(3, user.PictureUrl);
             custstmt.Bind(4, user.NumBags);
             custstmt.Bind(5, user.NumMilks);
             custstmt.Bind(6, user.NumShots);
             custstmt.Bind(7, user.NumLogins);
             custstmt.Bind(8, user.BadgeCIN);
             custstmt.Step();
         }
     }
 }
示例#6
0
        public User GetUser(string badgeCIN)
        {
            User user = null;

            using (var statement = conn.Prepare("SELECT BadgeCIN, Name, Balance, NumBags, NumMilks, NumShots, NumLogins, PictureUrl FROM Customer WHERE BadgeCIN = ?"))
            {

                statement.Bind(1, badgeCIN);
                if (SQLiteResult.ROW == statement.Step())
                {
                    user = new User()
                    {
                        BadgeCIN = (string)statement[0],
                        Name = (string)statement[1],
                        Balance = (long)statement[2],
                        NumBags = (long)statement[3],
                        NumMilks = (long)statement[4],
                        NumShots = (long)statement[5],
                        NumLogins = (long)statement[6],
                        PictureUrl = (string)statement[7]
                    };
                }
            }
            return user;
        }
示例#7
0
 public List<User> GetAllUsers()
 {
     List<User> users = new List<User>();
     using (var statement = conn.Prepare("SELECT BadgeCIN, Name, Balance, NumBags, NumMilks, NumShots, NumLogins, PictureUrl FROM Customer"))
     {
         while (SQLiteResult.ROW == statement.Step())
         {
             var user = new User()
             {
                 BadgeCIN = (string)statement[0],
                 Name = (string)statement[1],
                 Balance = (long)statement[2],
                 NumBags = (long)statement[3],
                 NumMilks = (long)statement[4],
                 NumShots = (long)statement[5],
                 NumLogins = (long)statement[6],
                 PictureUrl = (string)statement[7]
             };
             users.Add(user);
         }
     }
     return users;
 }