/* * roomListComboBox_DropDownClosed() is used to make an entry to excel of which meetingroom is selected. */ private void roomListComboBox_DropDownClosed(object sender, System.EventArgs e) { dts.MeetingRoomSelected = roomListComboBox.SelectedItem.ToString(); string confirmationString = "Do you want to book meeting room " + dts.MeetingRoomSelected + " on " + dts.Date + " from " + dts.FromString + " to " + dts.TooString + "?"; MessageBoxResult res = MessageBox.Show(confirmationString, "Query", MessageBoxButton.YesNo, MessageBoxImage.Question); if (res == MessageBoxResult.Yes) { bool status = ExcelHandler.WriteDataToExcel(dts); string successString = "Meeting room " + dts.MeetingRoomSelected + " is booked successfully on " + dts.Date + " from " + dts.FromString + " to " + dts.TooString + "!"; if (status) { MessageBox.Show(successString, "Success", MessageBoxButton.OK, MessageBoxImage.Information); Application.Current.Shutdown(); } } else { roomListComboBox.IsEnabled = false; } }
/* * submitButton_Click(): * This method carries out data collection from GUI and sends it to WriteDataToExcel(). */ private void submitButton_Click(object sender, RoutedEventArgs e) { bool executionFlag = true; #region DatePicker Validation if (!string.IsNullOrEmpty(dateDatePicker.SelectedDate.ToString())) { string[] dateInput = dateDatePicker.SelectedDate.ToString().Split(' '); //Get data from DatePicker dts.Date = dateInput[0]; } else { MessageBox.Show("Please select Date!", "Error", MessageBoxButton.OK, MessageBoxImage.Error); executionFlag = false; } #endregion #region TimePicker Validations if (fromTimeComboBox.SelectedIndex == -1 || toTimeComboBox.SelectedIndex == -1) { MessageBox.Show("Please select Time!", "Error", MessageBoxButton.OK, MessageBoxImage.Error); executionFlag = false; } else { if (fromTimeComboBox.SelectedIndex == toTimeComboBox.SelectedIndex) { MessageBox.Show("Start time and End time cannot be same!!", "Error", MessageBoxButton.OK, MessageBoxImage.Error); executionFlag = false; } if (this.fromTimeComboBox.Items.IndexOf(fromTimeComboBox.SelectedItem) > this.fromTimeComboBox.Items.IndexOf(toTimeComboBox.SelectedItem)) { MessageBox.Show("Start time cannot be after End time!", "Error", MessageBoxButton.OK, MessageBoxImage.Error); executionFlag = false; } } #endregion if (executionFlag) { dts.FromString = this.fromTimeComboBox.SelectedItem.ToString(); dts.TooString = this.toTimeComboBox.SelectedItem.ToString(); dts.From = this.fromTimeComboBox.Items.IndexOf(fromTimeComboBox.SelectedItem) + 1; dts.To = this.fromTimeComboBox.Items.IndexOf(toTimeComboBox.SelectedItem) + 1; dts.MeetingRoomList = ExcelHandler.GetDataFromExcel(dts); roomListComboBox.Items.Clear(); //binding list to dropdown if (dts.MeetingRoomList.Count > 0) { foreach (var val in dts.MeetingRoomList) { roomListComboBox.Items.Add(val); } roomListComboBox.SelectedIndex = 0; roomListComboBox.IsEnabled = true; } else { MessageBox.Show("No Meeting Room is free for the selected dates and time!", "Critical Warning", MessageBoxButton.OK, MessageBoxImage.Warning); } } }