public void TakeMessage(string message, string userName)
        {
            string message2 = StringCipher.Decrypt(message, "1q2w3e4r");

            TextDisplayTextBox.Text += userName + ": " + message2 + "\n";
            TextDisplayTextBox.ScrollToEnd();
        }
Exemplo n.º 2
0
        public void TakeMessage(string message, string userName)


        {
            //Show username + message in the text box.
            //End user will also see message and username in this order.
            TextDisplayTextBox.Text += userName + ": " + message + "\n";
            TextDisplayTextBox.ScrollToEnd();
        }
        // This function takes a message and the username who posted it and prints the message to the text display box
        public void TakeMessage(string message, string userName, bool important)
        {
            // Decrypts the sent in message
            string message2 = StringCipher.Decrypt(message, "1q2w3e4r");

            // Checks if the important check box has been ticked, if it has then a sound is played
            if (important == true)
            {
                System.Media.SystemSounds.Beep.Play();
            }

            // sets the variable for the current user to whoever is logged in on the current window
            string currentUser = (string)UsernameTextBox.Text;

            // check done to see if the username passed in was from a private message
            if (userName.Contains("(PRIVATE)"))
            {
                // changes the message variable to include who send the message, to do and the date and time
                message = currentUser + " to " + userName + ": " + message + " at " + System.DateTime.Now;
                //saves the message to the file
                SaveToFile(message, currentUser, userName);
                // displays the message within the textbox
                TextDisplayTextBox.Text += userName + ": " + message2 + "\n";
                // scrolls to the end of the text box
                TextDisplayTextBox.ScrollToEnd();
            }
            // check done to ensure the message is to the group chat and not to the user themselfs
            else if (!userName.Contains("You"))
            {
                // changes the message variable to include date and time
                message = userName + ": " + message + " at " + System.DateTime.Now;
                SaveToFileGroup(message, currentUser);
                // displays the message within the textbox
                TextDisplayTextBox.Text += userName + ": " + message2 + "\n";
                // scrolls to the end of the text box
                TextDisplayTextBox.ScrollToEnd();
            }
            // this is only run for users to see their own messages
            else
            {
                // displays the message within the textbox
                TextDisplayTextBox.Text += userName + ": " + message2 + "\n";
                // scrolls to the end of the text box
                TextDisplayTextBox.ScrollToEnd();
            }
        }
        // function that checks/reads previous private conversations into the display window
        private void fileExistsPrivate(string theirUserName)
        {
            // textbox is cleared of text
            TextDisplayTextBox.Text = "";
            // variable setup to state who the active user is
            string userName = (string)UsernameTextBox.Text;
            // variable setup to state what the file name is
            string whosConversation = userName + " " + theirUserName + " conversation";
            string filePath         = @"c:\savedConversations\" + whosConversation + ".txt";
            // check to see if the file exists
            bool fileexists = File.Exists(filePath);

            // if the file exists
            if (fileexists)
            {
                int    counter = 0;
                string line;

                //reads in the file path
                System.IO.StreamReader file = new System.IO.StreamReader(filePath);
                while ((line = file.ReadLine()) != null)
                {
                    //creates an array to hold each section of the line
                    string[] words = line.Split(' ');
                    if (words[2] == theirUserName + ":")
                    {
                        // decrypts the 4th part in the message
                        words[3] = StringCipher.Decrypt(words[3], "1q2w3e4r");
                    }
                    else
                    {
                        // decrypts the 5th part in the message
                        words[4] = StringCipher.Decrypt(words[4], "1q2w3e4r");
                    }
                    // prints all the words to the display box
                    foreach (string word in words)
                    {
                        TextDisplayTextBox.Text += word + " ";
                    }
                    // scrolls the textbox to the end
                    TextDisplayTextBox.ScrollToEnd();
                    counter++;
                    TextDisplayTextBox.Text += "\n";
                }
            }
        }
        // function that checks/reads previous group conversations into the display window
        private void fileExists()
        {
            // textbox is cleared of text
            TextDisplayTextBox.Text = "";
            // variable setup to state who the active user is
            string userName = (string)UsernameTextBox.Text;
            // variable setup to state what the file name is
            string whosConversation = userName + " conversation";
            string filePath         = @"c:\savedConversations\" + whosConversation + ".txt";
            // check to see if the file exists
            bool fileexists = File.Exists(filePath);

            // if the file exists
            if (fileexists)
            {
                // set counted to 0
                int counter = 0;
                //create a string called line
                string line;

                //reads in the file path
                System.IO.StreamReader file = new System.IO.StreamReader(filePath);
                // while loop to read through each line of the file until there are no more lines to read
                while ((line = file.ReadLine()) != null)
                {
                    //creates an array to hold each section of the line
                    string[] words = line.Split(' ');
                    // decrypts the 2nd part in the message
                    words [1] = StringCipher.Decrypt(words[1], "1q2w3e4r");
                    // for each loop to print the word from "words"
                    foreach (string word in words)
                    {
                        // prints the word out to the test display box
                        TextDisplayTextBox.Text += word + " ";
                    }
                    // scrolls to the end of the text box
                    TextDisplayTextBox.ScrollToEnd();
                    // adds 1 onto the counter
                    counter++;
                    // displays a new line in the textbox
                    TextDisplayTextBox.Text += "\n";
                }
            }
        }
Exemplo n.º 6
0
 public void TakeMessage(string message, string username)
 {
     TextDisplayTextBox.Text += username + ": " + message + "\n";
     TextDisplayTextBox.ScrollToEnd();
 }