示例#1
0
        //Set the group page to the group selected by the user
        private void groupName_Clicked(object sender, EventArgs e)
        {
            int groupSelectedID = 0;
            var row             = (int)((BindableObject)sender).GetValue(Grid.RowProperty);

            for (int i = 0; i < groupName.Count; i++)
            {
                if (groupName[i].BackgroundColor == Color.Red)
                {
                    groupName[i].BackgroundColor = Color.White;
                }
            }
            if (row == 0)
            {
                groupName[row].BackgroundColor = Color.Red;
                groupSelectedID = userGroups.ElementAt(row).Key;
                //Set the current group name in the app properties
                AppProperties.setCurrentGroup(groupName[row].Text);
                AppProperties.setCurrentGroupId(groupSelectedID);
                CreatePage.createHamburgerIcon(new GroupPage(), groupName[row].Text);
            }
            else
            {
                groupName[row / 2].BackgroundColor = Color.Red;
                groupSelectedID = userGroups.ElementAt(row / 2).Key;
                AppProperties.setCurrentGroup(groupName[row / 2].Text);
                AppProperties.setCurrentGroupId(groupSelectedID);
                CreatePage.createHamburgerIcon(new GroupPage(), groupName[row / 2].Text);
            }
        }
示例#2
0
 //Login
 private void BtnSubmit_Clicked(object sender, EventArgs e)
 {
     if (String.IsNullOrEmpty(entPassword.Text) || String.IsNullOrEmpty(entUsername.Text))
     {
         lblError.Text      = "Please enter your credentials first.";
         lblError.IsVisible = true;
     }
     else
     {
         int userID = NetworkUtils.Login(entUsername.Text, entPassword.Text);
         if (userID == 0)
         {
             lblError.Text      = "Not a valid username and password.";
             lblError.IsVisible = true;
         }
         else
         {
             AppProperties.setSavedUserId(userID);
             AppProperties.saveUserName(entUsername.Text);
             if (Application.Current.Properties.ContainsKey("currentGroupID"))
             {
                 String groupName = Application.Current.Properties["currentGroup"].ToString();
                 CreatePage.createHamburgerIcon(new GroupPage(), groupName);
             }
             else
             {
                 CreatePage.createHamburgerIcon(new MainPage(), entUsername.Text);
             }
         }
     }
 }
示例#3
0
 private void BtnBack_Clicked(object sender, EventArgs e)
 {
     CreatePage.createHamburgerIcon(new MainPage(), Application.Current.Properties["savedUserName"].ToString());
     //var otherPage = new MainPage { Title = Application.Current.Properties["savedUserName"].ToString() };
     //var homePage = App.navigationPage.Navigation.NavigationStack.First();
     //App.navigationPage.Navigation.InsertPageBefore(otherPage, homePage);
     //App.navigationPage.PopToRootAsync(false);
 }
示例#4
0
        //Add the user to the DB
        private void btnUsername_Clicked(object sender, EventArgs e)
        {
            //String userName = entryName.Text;
            //String password = entryPassword.Text;
            //Make sure the user entered a username
            if (string.IsNullOrWhiteSpace(entryName.Text))
            {
                lblNoUserName.IsVisible = true;
            }
            else if (string.IsNullOrEmpty(entryPassword.Text))
            {
                lblNoUserName.Text      = "You must enter a password";
                lblNoUserName.IsVisible = true;
            }
            else if (entryPassword.Text != entryPassword2.Text)
            {
                lblNoUserName.Text      = "Passwords do not match.";
                lblNoUserName.IsVisible = true;
            }
            else
            {
                //Insert user in DB and save username
                insertUser();
                if (userID == 0)
                {
                    lblNoUserName.Text      = "That user name already exists. Please choose a different username.";
                    lblNoUserName.IsVisible = true;
                }
                else
                {
                    AppProperties.saveUserName(entryName.Text);

                    string path     = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
                    string filename = Path.Combine(path, "YouSee.txt");

                    using (var streamWriter = new StreamWriter(filename, false))
                    {
                        streamWriter.WriteLine(entryName.Text);
                    }

                    using (var streamReader = new StreamReader(filename))
                    {
                        string content = streamReader.ReadToEnd();
                        System.Diagnostics.Debug.WriteLine(content);
                    }
                    //Launch MainPage

                    CreatePage.createHamburgerIcon(new MainPage(), Application.Current.Properties["savedUserName"].ToString());
                }
            }
        }
示例#5
0
        public App()
        {
            InitializeComponent();
            Dictionary <int, String> userGroups = NetworkUtils.getUserGroups();

            //Determine which screen should be displayed on load
            //https://forums.xamarin.com/discussion/105085/app-launch-login-page-when-launched-first-time-next-time-when-app-is-open-enter-pin-is-asked-how
            if (Application.Current.Properties.ContainsKey("currentGroupID") && userGroups.Count > 0)
            {
                CreatePage.createHamburgerIcon(new GroupPage(), Application.Current.Properties["currentGroup"].ToString());
            }
            else if (Application.Current.Properties.ContainsKey("savedUserName"))
            {
                //createHamburgerIcon();
                CreatePage.createHamburgerIcon(new MainPage(), Application.Current.Properties["savedUserName"].ToString());
            }
            else
            {
                MainPage = new NameScreen();
            }
        }
示例#6
0
        //Insert the user into group
        private void BtnSubmit_Clicked(object sender, EventArgs e)
        {
            String groupCode = entInviteCode.Text;
            int    groupID   = NetworkUtils.getGroupIdFromGroupCode(groupCode);
            int    userID    = (int)Application.Current.Properties["savedUserID"];

            Console.WriteLine(NetworkUtils.groupsDictionary.Count);
            if (groupID == 0)
            {
                lblError.Text      = "Something went wrong. Please make sure the group code you entered was correct.";
                lblError.IsVisible = true;
            }
            else if (NetworkUtils.groupsDictionary.Keys.Contains(groupID))
            {
                lblError.Text      = "You are already a member of that group.";
                lblError.IsVisible = true;
            }
            else
            {
                String groupName = NetworkUtils.getGroupNameFromGroupCode(groupCode);
                try
                {
                    //Add the dictionary to the app properties
                    NetworkUtils.groupsDictionary.Add(groupID, groupName);
                    AppProperties.setGroupsDictionary();
                    NetworkUtils.insertIntoGroup(groupID, userID);
                }
                catch (Exception ex)
                {
                    lblError.Text      = "You are already a member of that group";
                    lblError.IsVisible = true;
                }
                AppProperties.setCurrentGroup(groupName);
                AppProperties.setCurrentGroupId(groupID);
                CreatePage.createHamburgerIcon(new GroupPage(), groupName);
            }
        }
示例#7
0
        private void setupPage()
        {
            if (gridIsTrueListIsFalse)
            {
                int groupCol  = 2;
                int delBtnCol = 0;

                //Add the groups to the page
                for (int i = 0; i < myGroups.Count; i++)
                {
                    //Define the groupName label properties
                    groupName.Add(new MyButton());
                    groupName[i].Text = myGroups[i];
                    groupName[i].HorizontalOptions = LayoutOptions.FillAndExpand;
                    groupName[i].VerticalOptions   = LayoutOptions.Center;
                    groupName[i].BackgroundColor   = Color.White;
                    groupName[i].TextColor         = Color.Black;
                    groupName[i].Clicked          += groupName_Clicked;

                    //Add spacers between groups
                    groupSpacer.Add(new BoxView());
                    groupSpacer[i].BackgroundColor = Color.SlateGray;

                    //Row to add spacer between group names
                    groupSpacerRow.Add(new RowDefinition());
                    groupSpacerRow[i].Height = 1;

                    //Create a new row definition for new users
                    groupRow.Add(new RowDefinition());
                    groupRow[i].Height = 55;

                    //Define delete button properties
                    deleteBtns.Add(new Button());
                    deleteBtns[i].BackgroundColor = Color.Black;
                    deleteBtns[i].Image           = "trashcan.png";
                    deleteBtns[i].Clicked        += BtnDelete_Clicked;

                    //Add spacers between delete buttons
                    delRowSpacer.Add(new BoxView());
                    delRowSpacer[i].BackgroundColor = Color.SlateGray;

                    //Box view to set background color for delete icons
                    deleteBoxView.Add(new BoxView());
                    deleteBoxView[i].BackgroundColor = Color.Black;

                    //Increment i by 1 with temp var to add spacer/spacerRow
                    int spacerRowIndex = i + 1;
                    int groupRowIndex  = i;

                    //After first iteration, row index MUST add i to correctly add rows, users, and spacers
                    if (i > 0)
                    {
                        spacerRowIndex += i;
                        groupRowIndex  += i;
                    }

                    //Add the row definitions for the group names and the spacer bar between groups
                    grdGroups.RowDefinitions.Add(groupRow[i]);
                    grdGroups.RowDefinitions.Add(groupSpacerRow[i]);

                    ////Add everything to the page
                    //grdGroups.Children.Add(groupBoxView[i], groupCol, groupRowIndex);
                    grdGroups.Children.Add(groupName[i], groupCol, groupRowIndex);
                    grdGroups.Children.Add(groupSpacer[i], groupCol, spacerRowIndex);
                    grdGroups.Children.Add(delRowSpacer[i], delBtnCol, spacerRowIndex);
                    grdGroups.Children.Add(deleteBoxView[i], delBtnCol, groupRowIndex);
                    grdGroups.Children.Add(deleteBtns[i], delBtnCol, groupRowIndex);
                }

                //Set the selected group name button color
                if (Application.Current.Properties.ContainsKey("currentGroupID"))
                {
                    try
                    {
                        NetworkUtils.getUserGroups();
                        List <int> groupIds      = userGroups.Keys.ToList();
                        int        selectedGroup = groupIds.IndexOf((int)Application.Current.Properties["currentGroupID"]);
                        groupName[selectedGroup].BackgroundColor = Color.Red;
                    }
                    catch
                    {
                        Application.Current.Properties.Remove("currentGroupID");
                        Application.Current.Properties.Remove("currentGroup");
                        CreatePage.createHamburgerIcon(new MainPage(), Application.Current.Properties["savedUserName"].ToString());
                    }
                }
            }
            else if (!gridIsTrueListIsFalse)
            {
                //Warning... ListView selectedItem is ugly as shit
                int delBtnCol = 0;
                MyListView.IsVisible = true;

                //Add the groups to the page
                for (int i = 0; i < myGroups.Count; i++)
                {
                    //Create a new row definition for new users
                    groupRow.Add(new RowDefinition());
                    groupRow[i].Height = 55;

                    //Box view to set background color for delete icons
                    deleteBoxView.Add(new BoxView());
                    deleteBoxView[i].BackgroundColor = Color.Black;

                    //Define delete button properties
                    deleteBtns.Add(new Button());
                    deleteBtns[i].BackgroundColor = Color.Black;
                    deleteBtns[i].Image           = "trashcan.png";
                    deleteBtns[i].Clicked        += BtnDelete_Clicked;

                    //Row to add spacer between group names
                    groupSpacerRow.Add(new RowDefinition());
                    groupSpacerRow[i].Height = 1;

                    //Add everything to the page
                    grdGroups.Children.Add(grdDeleteBtns, 0, 0);
                    grdDeleteBtns.RowDefinitions.Add(groupRow[i]);
                    grdDeleteBtns.Children.Add(deleteBoxView[i], delBtnCol, i);
                    grdDeleteBtns.Children.Add(deleteBtns[i], delBtnCol, i);
                    grdGroups.Children.Add(MyListView, 2, 0);
                }
            }
        }
示例#8
0
        //Remove the user from the DB Group and hide the row for the group that was deleted
        private void BtnDelete_Clicked(object sender, EventArgs e)
        {
            String groupToDelete   = null;
            int    GroupIdToDelete = 0;

            //Get the selected grid row number
            //https://forums.xamarin.com/discussion/19915/how-to-isentify-the-selected-row-in-a-grid
            var row = (int)((BindableObject)sender).GetValue(Grid.RowProperty);

            if (gridIsTrueListIsFalse)
            {
                //Group name starts at row 0 and then appears on every other row
                if (row == 0)
                {
                    groupToDelete   = myGroups[0];
                    GroupIdToDelete = userGroups.ElementAt(0).Key;
                    if ((int)Application.Current.Properties["currentGroupID"] == GroupIdToDelete)
                    {
                        if (userGroups.Count > 1)
                        {
                            AppProperties.setCurrentGroupId(userGroups.ElementAt(row + 1).Key);
                            AppProperties.setCurrentGroup(myGroups[row + 1]);
                            grdGroups.RowDefinitions.ElementAt <RowDefinition>(row).Height = 0;
                            NetworkUtils.DeleteUserFromGroup(GroupIdToDelete);
                            NetworkUtils.getUserGroups();
                            NetworkUtils.getUserGroups();
                            CreatePage.createHamburgerIcon(new GroupPage(), Application.Current.Properties["currentGroup"].ToString());
                        }
                    }
                    grdGroups.RowDefinitions.ElementAt <RowDefinition>(row).Height = 0;
                    NetworkUtils.DeleteUserFromGroup(GroupIdToDelete);
                    NetworkUtils.getUserGroups();
                    if (NetworkUtils.groupsDictionary.Count == 0)
                    {
                        //CreatePage.createHamburgerIcon(new MainPage(), Application.Current.Properties["savedUserName"].ToString());
                        var otherPage = new MainPage {
                            Title = Application.Current.Properties["savedUserName"].ToString()
                        };
                        var homePage = App.navigationPage.Navigation.NavigationStack.First();
                        App.navigationPage.Navigation.InsertPageBefore(otherPage, homePage);
                        App.navigationPage.PopToRootAsync(false);
                    }
                }
                else
                {
                    groupToDelete   = myGroups[row / 2];
                    GroupIdToDelete = userGroups.ElementAt(row / 2).Key;
                    //THROWS ERROR IF CURRENT GROUP ID IS NULL - only happens if trying to delete group after fresh install before user selects a current group
                    if ((int)Application.Current.Properties["currentGroupID"] == GroupIdToDelete)
                    {
                        AppProperties.setCurrentGroupId(userGroups.ElementAt(row / 2 - 1).Key);
                        AppProperties.setCurrentGroup(myGroups[row / 2 - 1]);
                        grdGroups.RowDefinitions.ElementAt <RowDefinition>(row).Height = 0;
                        NetworkUtils.DeleteUserFromGroup(GroupIdToDelete);
                        NetworkUtils.getUserGroups();
                        NetworkUtils.getUserGroups();
                        CreatePage.createHamburgerIcon(new GroupPage(), Application.Current.Properties["currentGroup"].ToString());
                    }
                    grdGroups.RowDefinitions.ElementAt <RowDefinition>(row).Height = 0;
                    NetworkUtils.DeleteUserFromGroup(GroupIdToDelete);
                    NetworkUtils.getUserGroups();
                    NetworkUtils.getUserGroups();
                    if (NetworkUtils.groupsDictionary.Count == 0)
                    {
                        var otherPage = new MainPage {
                            Title = Application.Current.Properties["savedUserName"].ToString()
                        };
                        var homePage = App.navigationPage.Navigation.NavigationStack.First();
                        App.navigationPage.Navigation.InsertPageBefore(otherPage, homePage);
                        App.navigationPage.PopToRootAsync(false);
                    }
                }
            }
            else
            {
                groupToDelete = myGroups[row];
                UpdateRow(GroupIdToDelete, row);
            }
        }
示例#9
0
 //
 private void BtnBack_Clicked(object sender, EventArgs e)
 {
     CreatePage.createHamburgerIcon(new MainPage(), Application.Current.Properties["savedUserName"].ToString());
 }