Example #1
0
        // Valide inputs
        private bool inputValidation()
        {
            // Bool to return indicating if inputs are valid
            bool isValid = true;
            // Obtain current DateTime for comparison
            DateTime currentDateTime = DateTime.Parse(DataInterface.getCurrentDateTime());

            // Check if required TextBoxes are empty
            if (string.IsNullOrWhiteSpace(appointmentCustomerComboBox.Text))
            {
                // If empty, change background color to salmon, display message, and indicate inputs are not valid
                appointmentCustomerComboBox.BackColor = Color.Salmon;
                MessageBox.Show("Customer field cannot be empty. Please select a customer and try again.");
                isValid = false;
            }
            if (string.IsNullOrWhiteSpace(appointmentTitleTextBox.Text))
            {
                appointmentTitleTextBox.BackColor = Color.Salmon;
                MessageBox.Show("Title field cannot be empty. Please enter a title and try again.");
                isValid = false;
            }
            if (string.IsNullOrWhiteSpace(appointmentDescriptionTextBox.Text))
            {
                appointmentDescriptionTextBox.BackColor = Color.Salmon;
                MessageBox.Show("Description field cannot be empty. Please enter a description and try again.");
                isValid = false;
            }
            // Check if appointment is before the current time
            if (appointmentStartDate.Value < currentDateTime || appointmentEndDate.Value < currentDateTime)
            {
                // If appointment is before current time, display message and set inputs to invalid
                MessageBox.Show("Start and end dates/times must occur after the current date/time.");
                isValid = false;
            }
            if (appointmentEndDate.Value < appointmentStartDate.Value)
            {
                MessageBox.Show("End time must be after start time.");
                isValid = false;
            }

            // Return whether inputs are valid or not -- True is valid, false is not valid
            return(isValid);
        }
Example #2
0
 // Check if any appointments are within 15 minutes of occurring
 public static void checkForReminders()
 {
     // Iterate through appointments in DataTable
     foreach (DataRow row in appointmentsDT.Rows)
     {
         // Obtain start time for each appointment
         DateTime startTime = DateTime.Parse(row["Start"].ToString());
         // Obtain the current time
         DateTime currentTime = DateTime.Parse(DataInterface.getCurrentDateTime());
         // Set 15 minute mark for comparison
         TimeSpan reminderMark      = new TimeSpan(0, 15, 0);
         TimeSpan appointmentPassed = new TimeSpan(0, 0, 0);
         // Obtain difference between start time and the current time
         TimeSpan difference = startTime.Subtract(currentTime);
         // If difference is less than 15 minutes but has not passed the current time, display reminder
         if (difference <= reminderMark && difference > appointmentPassed)
         {
             MessageBox.Show($"The event, {row["Title"].ToString()}, with customer, {row["Customer Name"].ToString()}, is starting soon.");
         }
     }
 }
        // Validate inputs before saving
        private bool inputValidation()
        {
            // Variable determining if inputs are valid
            bool isValid = true;
            // Obtain current DateTime for comparing
            DateTime currentDateTime = DateTime.Parse(DataInterface.getCurrentDateTime());

            // Check if required fields contain text
            if (string.IsNullOrWhiteSpace(appointmentCustomerComboBox.Text))
            {
                // If invalid, change BackColor, prompt user, and set isValid to false
                appointmentCustomerComboBox.BackColor = Color.Salmon;
                MessageBox.Show("Customer field cannot be empty. Please select a customer and try again.");
                isValid = false;
            }
            if (string.IsNullOrWhiteSpace(appointmentTitleTextBox.Text))
            {
                appointmentTitleTextBox.BackColor = Color.Salmon;
                MessageBox.Show("Title field cannot be empty. Please enter a title and try again.");
                isValid = false;
            }
            if (string.IsNullOrWhiteSpace(appointmentDescriptionTextBox.Text))
            {
                appointmentDescriptionTextBox.BackColor = Color.Salmon;
                MessageBox.Show("Description field cannot be empty. Please enter a description and try again.");
                isValid = false;
            }
            if (appointmentStartDate.Value < currentDateTime || appointmentEndDate.Value < currentDateTime)
            {
                MessageBox.Show("Start and end dates/times must occur after the current date/time.");
                isValid = false;
            }
            if (appointmentEndDate.Value < appointmentStartDate.Value)
            {
                MessageBox.Show("End time must be after start time.");
                isValid = false;
            }
            // return bool to show validity -- true is valid, false is not valid
            return(isValid);
        }
Example #4
0
        // Generate Log of Logins
        private void recordLogin(string username)
        {
            string        path     = "C:/SchedulingApp/Logs";
            string        fileName = "log.txt";
            string        fullPath = path + fileName;
            string        logEntry = $"{username} logged in at {DataInterface.getCurrentDateTime()}" + Environment.NewLine;
            DirectoryInfo dir      = new DirectoryInfo(path);

            try
            {
                // Check if folder exists, if not, create
                if (!dir.Exists)
                {
                    dir.Create();
                }
                // Append logEntry to file
                File.AppendAllText(fullPath, logEntry);
            }
            catch (Exception e)
            {
                MessageBox.Show("An error occurred when generating log. " + $"\n\n{e.Message}" + $"\n\n{e.StackTrace}");
            }
        }