/// <summary>
        /// Function called when the user attempts to create a meeting.
        /// The ErrorProvider only set an error if the event TextBox_Validating is fired. If the user presses
        /// the schedule meeting button before this event can be triggered, it would appear as though the data is valid as
        /// there would be no ErrorProvider message. Therefore, when that button is pressed, each control
        /// must be validated.
        /// </summary>
        /// <returns>A boolean indicating whether the input data is valid or not.</returns>
        private bool ValidateForm_CreateMeeting()
        {
            bool isValid = true;
            //Lamda expression to compare the ErrorProviders error message with the constant ERRORMESSAGE.
            //If they are equal, compareString returns true.
            Func <string, bool> compareString = s => s == NULLDATAERRORMESSAGE;

            //Alternative to writing IF statements that improve readability since the use far less lines
            ClassLibrary.CheckTextBoxNotNull(TextBoxSelectedStudent, ErrorProvider);
            isValid = compareString(ErrorProvider.GetError(TextBoxSelectedStudent)) ? false : isValid;
            CheckDateTimePickerNotNull(DateTimePickerDate);
            isValid = compareString(ErrorProvider.GetError(DateTimePickerDate)) ? false : isValid;
            CheckDateTimePickerNotNull(DateTimePickerTime);
            isValid = compareString(ErrorProvider.GetError(DateTimePickerTime)) ? false : isValid;
            CheckListBoxNotNull(ListBoxStaffList);
            isValid = compareString(ErrorProvider.GetError(ListBoxStaffList)) ? false : isValid;

            //Whether the checkbox is checked or not determines which control to validate
            if (CheckBoxCustomLength.Checked)
            {
                ClassLibrary.CheckTextBoxNotNull(TextBoxCustomLength, ErrorProvider);
                isValid = compareString(ErrorProvider.GetError(TextBoxCustomLength)) ? false : isValid;
            }
            else
            {
                CheckListBoxNotNull(ListBoxMeetingLengths);
                isValid = compareString(ErrorProvider.GetError(ListBoxMeetingLengths)) ? false : isValid;
            }

            return(isValid);
        }
Esempio n. 2
0
        /// <summary>
        /// Function to send data to the client.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ButtonSendMessage_Click(object sender, EventArgs e)
        {
            const string NULLDATAERRORMESSAGE = "Field cannot be left empty";

            //If there is no message to send, display an error message in the ErrorProvider
            ClassLibrary.CheckTextBoxNotNull(TextBoxTypeMessage, ErrorProvider);
            if (ErrorProvider.GetError(TextBoxTypeMessage) == NULLDATAERRORMESSAGE)
            {
                return;
            }

            //Encrypt the message and transmit it
            string encryptedMessage = ClassLibrary.SymmetricEncryptDecrypt(TextBoxTypeMessage.Text, symmetricKey);

            byte[] bt = Encoding.UTF8.GetBytes(encryptedMessage);
            try
            {
                connectedClient.Client.Send(bt);
            }
            catch (Exception ex)
            {
                MyMessageBox.ShowMessage(ex.ToString());
                return;
            }

            //Display the text in the list box
            ListBoxChat.Items.Add(staffMember.StaffFirstName + ": " + TextBoxTypeMessage.Text + Environment.NewLine);
            TextBoxTypeMessage.Clear();
        }
        private void ButtonSendMessage_Click(object sender, EventArgs e)
        {
            const string NULLDATAERRORMESSAGE = "Field cannot be left empty";

            ClassLibrary.CheckTextBoxNotNull(TextBoxTypeMessage, ErrorProvider);
            //As long as the user has some sort of input in the textbox, the message will send
            if (ErrorProvider.GetError(TextBoxTypeMessage) == NULLDATAERRORMESSAGE)
            {
                return;
            }

            //Encrypt the message
            string encryptedMessage = ClassLibrary.SymmetricEncryptDecrypt(TextBoxTypeMessage.Text, symmetricKey);

            //Encode the message and send it
            serverStream.Write(Encoding.UTF8.GetBytes(encryptedMessage), 0, Encoding.UTF8.GetByteCount(encryptedMessage));
            serverStream.Flush();

            //Display the message to the rich text box
            sbSend.Clear();
            sbSend.Append(student.StudentFirstName);
            sbSend.Append(": ");
            sbSend.Append(TextBoxTypeMessage.Text);
            sbSend.Append(Environment.NewLine);

            RichTextBoxChatWindow.SelectionColor = Color.Blue;
            RichTextBoxChatWindow.AppendText(sbSend.ToString());
            TextBoxTypeMessage.Clear();
        }
        /// <summary>
        /// Checks that the user input data is valid.
        /// </summary>
        /// <returns>A boolean indicating whether the input data is
        /// valid or not.</returns>
        private bool ValidateForm()
        {
            const string        NULLDATAERRORMESSAGE = "Field cannot be left empty";
            bool                isValid       = true;
            Func <string, bool> compareString = s => s == NULLDATAERRORMESSAGE;

            ClassLibrary.CheckTextBoxNotNull(TextBoxOldPassword, ErrorProvider);
            isValid = compareString(ErrorProvider.GetError(TextBoxOldPassword)) ? false : isValid;
            ClassLibrary.CheckTextBoxNotNull(TextBoxNewPassword, ErrorProvider);
            isValid = compareString(ErrorProvider.GetError(TextBoxNewPassword)) ? false : isValid;
            ClassLibrary.CheckTextBoxNotNull(TextBoxReTypePassword, ErrorProvider);
            isValid = compareString(ErrorProvider.GetError(TextBoxReTypePassword)) ? false : isValid;

            return(isValid);
        }
        /// <summary>
        /// Checks that the user input data is valid.
        /// </summary>
        /// <returns>A boolean indicating whether the
        /// input data is valid or not.</returns>
        private bool ValidateForm_AddNote()
        {
            bool isValid = true;
            //Lamda expression to compare the ErrorProviders
            //error message with the constant NULLDATAERRORMESSAGE.
            //If they are equal, compareString returns true.
            Func <string, bool> compareString = s => s == NULLDATAERRORMESSAGE;

            ClassLibrary.CheckTextBoxNotNull(TextBoxNote, ErrorProvider);
            //Alternative to writing IF statements that improves
            //readability since they use far less lines.
            isValid = compareString(ErrorProvider.GetError(TextBoxNote)) ? false : isValid;

            return(isValid);
        }
Esempio n. 6
0
        /// <summary>
        /// Checks that the user input data is valid.
        /// </summary>
        /// <returns>A boolean indicating whether the input data is valid or not.</returns>
        private bool ValidateForm()
        {
            const string NULLDATAERRORMESSAGE = "Field cannot be left empty";
            bool         isValid = true;
            //Lamda expression to compare the ErrorProviders error message with the
            //constant NULLDATAERRORMESSAGE. If they are equal, compareString returns true.
            Func <string, bool> compareString = s => s == NULLDATAERRORMESSAGE;

            //Each control that has user input data must be checked.
            ClassLibrary.CheckTextBoxNotNull(TextBoxUsername, ErrorProvider);
            //Alternative to writing IF statements that improves readability since they use far less lines.
            //If compareString returns true, then isValid is set to false as this means the
            //ErrorProvider has set an error so the input is invalid.
            isValid = compareString(ErrorProvider.GetError(TextBoxUsername)) ? false : isValid;
            ClassLibrary.CheckTextBoxNotNull(TextBoxPassword, ErrorProvider);
            isValid = compareString(ErrorProvider.GetError(TextBoxPassword)) ? false : isValid;

            return(isValid);
        }
Esempio n. 7
0
 private void TextBoxPassword_Validating(object sender, CancelEventArgs e)
 {
     //Checks that the TextBoxPassword contains data
     ClassLibrary.CheckTextBoxNotNull(TextBoxPassword, ErrorProvider);
 }
 private void TextBoxSelectedStudent_Validating(object sender, CancelEventArgs e)
 {
     ClassLibrary.CheckTextBoxNotNull(TextBoxSelectedStudent, ErrorProvider);
 }
 //Events
 private void TextBoxCustomLength_Validating(object sender, CancelEventArgs e)
 {
     ClassLibrary.CheckTextBoxNotNull(TextBoxCustomLength, ErrorProvider);
 }