// Check if times overlap any existing appointments public static bool checkForOverlap(DateTime start, DateTime end) { // Bool returned to show if overlap exists bool overlap = false; // Create DataTable containing appointments DataTable appointments = DataInterface.getAppointments(DataInterface.getCurrentUserName()); // Iterate through DataTable foreach (DataRow row in appointments.Rows) { // Obtain start and end times DateTime appointmentStart = DateTime.Parse(row["start"].ToString()).ToLocalTime(); DateTime appointmentEnd = DateTime.Parse(row["end"].ToString()).ToLocalTime(); // Lambda expression to check if provided time is within start and end times of appointment being evaluated overlaps = (time) => { return(time <= appointmentEnd && time >= appointmentStart); }; // Use lambda to check if the provided start and end times in the form overlap appointment being evaluated if (overlaps(start) || overlaps(end)) { // if either start or end are within an existing appointment, set overlap to true to indicate overlap overlap = true; } } // return state of overlap -- true indicates overlap, false indicates no overlap return(overlap); }
// Obtain data and append text into TextBox private void generateReport() { // Obtain datatable from getAppointments DataTable appointments = DataInterface.getAppointments(); // Create DataView to query DataView view = new DataView(appointments); // Create new distinct DataTable for customers DataTable customers = view.ToTable(true, "customerId"); // Iterate through customers foreach (DataRow customer in customers.Rows) { // Add Customer ID to textbox reportTextBox.AppendText($"Customer ID: {customer["customerId"].ToString()}\n\n"); // Create array of DataRows for appointments associated with customer DataRow[] appointmentArray = appointments.Select($"customerId = '{customer["customerId"].ToString()}'"); // Iterate through appointments foreach (DataRow row in appointmentArray) { // Append data for each appointment to TextBox reportTextBox.AppendText($" ID: {row["appointmentId"]}"); reportTextBox.AppendText($" Title: {row["title"]}"); reportTextBox.AppendText($" Start: {row["start"]}"); reportTextBox.AppendText($" End: {row["end"]}\n\n"); } } }
// Obtain and populate textbox with data private void generateReport() { // Obtain DataTable returned by getAppointments() DataTable appointments = DataInterface.getAppointments(); // Create view to query DataView view = new DataView(appointments); // Create distinct table of consultants DataTable consultants = view.ToTable(true, "createdBy"); // Iterate through consultants foreach (DataRow consultant in consultants.Rows) { // Add Consultant Name to text box reportTextBox.AppendText($"Consultant: {consultant["createdBy"].ToString()}\n\n"); // Create array of DataRows containing appointments for consultant being iterated DataRow[] appointmentArray = appointments.Select($"createdBy = '{consultant["createdBy"].ToString()}'"); // Iterate through appointments associated with this consultant foreach (DataRow row in appointmentArray) { // Append text detailing information about appointments reportTextBox.AppendText($" ID: {row["appointmentId"]}"); reportTextBox.AppendText($" Title: {row["title"]}"); reportTextBox.AppendText($" CustomerID: {row["customerId"]}"); reportTextBox.AppendText($" Start: {row["start"]}"); reportTextBox.AppendText($" End: {row["end"]}\n\n"); } } }