Exemplo n.º 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);
            }
        }
Exemplo n.º 2
0
        //When user clicks create group run spInsertGroup on DB
        private void BtnCreateGroup_Clicked(object sender, EventArgs e)
        {
            String groupName = txtGroupName.Text;
            Dictionary <int, String> tempGroupDict = NetworkUtils.getUserGroups();

            //List<String> tempGroupList = NetworkUtils.getUserGroups();
            if (tempGroupDict.Values.Contains(groupName))
            {
                lblError.Text      = "You are already a member of a group with that name.";
                lblError.IsVisible = true;
            }
            else if (!String.IsNullOrEmpty(txtGroupName.Text))
            {
                groupName = txtGroupName.Text;
                String groupCode = RandomString();
                String hostid    = Application.Current.Properties["savedUserID"].ToString();
                AppProperties.setSavedGroupName(groupName);
                int hostID  = Convert.ToInt32(hostid);
                int groupID = NetworkUtils.insertGroup(groupName, groupCode, hostID);
                AppProperties.setCurrentGroupId(groupID);
                NetworkUtils.groupsDictionary.Add(groupID, groupName);
                AppProperties.setCurrentGroup(Application.Current.Properties["savedGroupName"].ToString());
                createHamburgerIcon(new GroupPage(), Application.Current.Properties["savedGroupName"].ToString());
            }
            else
            {
                lblError.Text      = "You must enter a group name.";
                lblError.IsVisible = true;
            }
        }
Exemplo n.º 3
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);
            }
        }
Exemplo n.º 4
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);
            }
        }