Ejemplo 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);
            }
        }
Ejemplo n.º 2
0
        public static string RandomString()
        {
            var chars       = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
            var stringChars = new char[8];
            var random      = new System.Random();

            //Create the initial group code
            for (int i = 0; i < stringChars.Length; i++)
            {
                stringChars[i] = chars[random.Next(chars.Length)];
            }

            var finalString = new String(stringChars);

            //if the group code exists, create a new group code
            while (NetworkUtils.searchDBForRandom(finalString) > 0)
            {
                for (int i = 0; i < stringChars.Length; i++)
                {
                    stringChars[i] = chars[random.Next(chars.Length)];
                }
                finalString = new string(stringChars);
            }

            AppProperties.setSavedGroupCode(finalString);
            return(finalString);
        }//RandomString
Ejemplo n.º 3
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;
            }
        }
Ejemplo n.º 4
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);
             }
         }
     }
 }
Ejemplo n.º 5
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());
                }
            }
        }
Ejemplo n.º 6
0
        //Insert new users into DB
        public static int insertUser(String userIP, String userName, String password)
        {
            int    userID     = 0;
            String connString = @"Server=youseedatabase.cxj5odskcws0.us-east-2.rds.amazonaws.com,1433;DataBase=yousee;User ID=youseeDatabase; Password=yousee18";

            try
            {
                using (SqlConnection sqlConn = new SqlConnection(connString))
                {
                    String spName       = "insertUser";
                    String passUserName = "******";
                    String passUserIP   = "@userIP";
                    String passPassword = "******";

                    using (SqlCommand command = sqlConn.CreateCommand())
                    {
                        command.CommandType = CommandType.StoredProcedure;
                        command.CommandText = spName;
                        command.Parameters.Add(new SqlParameter(passUserIP, userIP));
                        command.Parameters.Add(new SqlParameter(passUserName, userName));
                        command.Parameters.Add(new SqlParameter(passPassword, password));

                        sqlConn.Open();
                        try
                        {
                            //Executes the stored procedure and returns the userID
                            userID = (int)command.ExecuteScalar();
                            AppProperties.setSavedUserId(userID);
                        }
                        catch (Exception exc)
                        {
                            Console.WriteLine(exc.Message);
                            userID = 0;
                        }
                        finally
                        {
                            sqlConn.Close();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            //App.Current.Properties.Add("savedUserID", userID);
            //Console.WriteLine(App.Current.Properties["savedUserID"]);

            return(userID);
        }//end InsertDB
Ejemplo n.º 7
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);
            }
        }
Ejemplo n.º 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);
            }
        }