/// <summary> /// Timeslot selection change /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void TimeSlotComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { //_log.Info("Inside TimeSlotComboBox_SelectionChanged"); var monthlyViewSchedulerViewModel = (MonthlyViewSchedulerViewModel)DataContext; string currentTimeSlot = (string)TimeSlotComboBox.SelectedItem; //_log.Info("Current TimeSlot: " + currentTimeSlot); monthlyViewSchedulerViewModel.CurrentTimeSlot = currentTimeSlot; DataContext = monthlyViewSchedulerViewModel; MonthlyViewCalendar.Refresh(); if (!currentTimeSlot.Equals("All Slots")) //if (currentTimeSlot == null || !currentTimeSlot.Equals("All Slots")) { DayQuota dayQuota = monthlyViewSchedulerViewModel.MonthlyQuota[monthlyViewSchedulerViewModel.CurrentDateSelected]; if (dayQuota != null) { float timeSlotQuota = dayQuota.TimeSlotQuota[currentTimeSlot]; if (timeSlotQuota > monthlyViewSchedulerViewModel.RedQuotaCutoff || monthlyViewSchedulerViewModel.IsManagerOverride) { updateRecordFields(currentTimeSlot, monthlyViewSchedulerViewModel.CurrentDateSelected); } } TimeSlotDataGrid.Visibility = System.Windows.Visibility.Collapsed; } else { monthlyViewSchedulerViewModel.ShowTimeSlotInDataGrid(monthlyViewSchedulerViewModel.CurrentDateSelected); TimeSlotDataGrid.Visibility = System.Windows.Visibility.Visible; } }
/// <summary> /// Show the time slots in the DataGrid /// </summary> /// <param name="date"></param> public void ShowTimeSlotInDataGrid(DateTime date) { _log.Notice("Inside ShowTimeSlotInDataGrid"); TimeSlotRowInDataGrid.Clear(); //CurrentDateSelected = date; DayQuota dailyQuota = monthlyQuota[date]; Dictionary <string, float> tsQuotas = dailyQuota.TimeSlotQuota; List <TimeSlotCell[]> listTimeSlots = new List <TimeSlotCell[]>(); TimeSlotCell[] listTimeSlot = new TimeSlotCell[4]; int i = 0; foreach (KeyValuePair <string, float> tsQuota in tsQuotas.OrderBy(key => key.Key)) { string quotaColor; if (tsQuota.Value <= RedQuotaCutoff) { quotaColor = "Red"; } else if (tsQuota.Value >= GreenQuotaCutoff) { quotaColor = "Green"; } else { quotaColor = "Yellow"; } TimeSlotCell cell = new TimeSlotCell(tsQuota.Key, quotaColor); listTimeSlot[i] = cell; if (i == 3) { listTimeSlots.Add(listTimeSlot); listTimeSlot = new TimeSlotCell[4]; i = 0; } else { i++; } } if (listTimeSlot.Length > 0) { listTimeSlots.Add(listTimeSlot); } foreach (TimeSlotCell[] superList in listTimeSlots) { TimeSlotRow timeSlotRow = new TimeSlotRow(superList[0], superList[1], superList[2], superList[3]); if (superList[0] != null) { TimeSlotRowInDataGrid.Add(timeSlotRow); } } }
/// <summary> /// Handle selection of TimeSlot from DataGrid /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void TimeSlotDataGrid_MouseDoubleClick(object sender, MouseButtonEventArgs e) { //_log.Info("Inside TimeSlotDataGrid_MouseDoubleClick"); TimeSlotRow row = (TimeSlotRow)TimeSlotDataGrid.CurrentItem; TextBlock timeSlot = (TextBlock)TimeSlotDataGrid.CurrentColumn.GetCellContent(row); var monthlyViewSchedulerViewModel = (MonthlyViewSchedulerViewModel)DataContext; DayQuota dayQuota = monthlyViewSchedulerViewModel.MonthlyQuota[monthlyViewSchedulerViewModel.CurrentDateSelected]; if (dayQuota != null) { float timeSlotQuota = dayQuota.TimeSlotQuota[timeSlot.Text]; if (timeSlotQuota > monthlyViewSchedulerViewModel.RedQuotaCutoff || monthlyViewSchedulerViewModel.IsManagerOverride) { updateRecordFields(timeSlot.Text, monthlyViewSchedulerViewModel.CurrentDateSelected); } } }
/// <summary> /// Show Quota for TimeSlots /// </summary> private void showQuotaForTimeSlots() { _log.Notice("Inside showQuotaForTimeSlots"); int i = getStartDateIndex(); for (int index = 0; index < 42; index++) { p_HighlightedDateText[index] = null; } foreach (KeyValuePair <DateTime, DayQuota> date in monthlyQuota.OrderBy(key => key.Key)) //foreach (var date in monthlyQuota.Keys) { //DayQuota dayQuota = monthlyQuota[date]; DayQuota dayQuota = date.Value; if (CurrentTimeSlot != null && CurrentTimeSlot.Equals("All Slots")) { int totalSlots = dayQuota.TimeSlotQuota.Count; int availableSlots = 0; int unAvailableSlots = 0; foreach (KeyValuePair <string, float> timeSlotQuota in dayQuota.TimeSlotQuota) { if (timeSlotQuota.Value <= RedQuotaCutoff) { unAvailableSlots++; } else if (timeSlotQuota.Value >= GreenQuotaCutoff) { availableSlots++; } } if (unAvailableSlots == totalSlots) { p_HighlightedDateText[i] = "Red"; } else if (availableSlots == totalSlots) { p_HighlightedDateText[i] = "Green"; } else { p_HighlightedDateText[i] = "Yellow"; } } else { float quota = dayQuota.TimeSlotQuota[CurrentTimeSlot]; if (quota <= RedQuotaCutoff) { p_HighlightedDateText[i] = "Red"; } else if (quota >= GreenQuotaCutoff) { p_HighlightedDateText[i] = "Green"; } else { p_HighlightedDateText[i] = "Yellow"; } } i++; } }
/// <summary> /// Get Quota for month /// </summary> /// <param name="capacityModel"></param> /// <returns></returns> public ToaRequestResult GetQuotaForMonth(CapacityModel capacityModel) { _log.Notice("Inside GetQuotaForMonth"); var toaRequestResult = new ToaRequestResult(); try { capacity_element[] capacityElement = capacityModel.getCapacityElement(); time_slot_info_element[] timeSlotInfoElement = capacityModel.getTimeSlotInfoElement(); long activityTravelTime = capacityModel.ActivityTravelTime; bool activityTravelTimeSpecified = capacityModel.ActivityTravelTimeSpecified; long activityDuration = capacityModel.ActivityDuration; bool activityDurationSpecified = capacityModel.ActivityDurationSpecified; _toaCapacityInterface.get_capacity(ToaUserUtil.GetCapacityUser(), capacityModel.QuotaDates, capacityModel.Location, capacityModel.CalculateDuration, capacityModel.CalculateDurationSpecified, capacityModel.CalculateTravelTime, capacityModel.CalculateTravelTimeSpecified, capacityModel.CalculateWorkSkill, capacityModel.CalculateWorkSkillSpecified, capacityModel.ReturnTimeSlotInfo, capacityModel.ReturnTimeSlotInfoSpecified, capacityModel.DetermineLocationByWorkZone, capacityModel.DetermineLocationByWorkZoneSpecified, capacityModel.DontAggregateResults, capacityModel.DontAggregateResultsSpecified, capacityModel.MinTimeEndOfTimeSlot, capacityModel.MinTimeEndOfTimeSlotSpecified, capacityModel.DefaultDuration, capacityModel.DefaultDurationSpecified, capacityModel.Timeslots, capacityModel.WorkSkill, capacityModel.getActivityFieldElement(), out activityDuration, out activityDurationSpecified, out activityTravelTime, out activityTravelTimeSpecified, out capacityElement, out timeSlotInfoElement); CapacityModel response = new CapacityModel(); if (activityDuration != null) { response.ActivityDuration = activityDuration; } if (activityTravelTime != null) { response.ActivityTravelTime = activityTravelTime; } Dictionary <DateTime, DayQuota> dayQuota = new Dictionary <DateTime, DayQuota>(); if (capacityElement != null) { foreach (capacity_element ce in capacityElement) { if (dayQuota.ContainsKey(ce.date)) { DayQuota quota = dayQuota[ce.date]; if (quota.TimeSlotQuota == null) { quota.TimeSlotQuota = new Dictionary <string, float>(); } float quotaAvailable = (((ce.available - (activityDuration + activityTravelTime)) * 100) / ce.quota); quota.TimeSlotQuota.Add(ce.time_slot, quotaAvailable); } else { DayQuota quota = new DayQuota(); quota.QuotaDate = ce.date; quota.TimeSlotQuota = new Dictionary <string, float>(); float quotaAvailable = (((ce.available - (activityDuration + activityTravelTime)) * 100) / ce.quota); quota.TimeSlotQuota.Add(ce.time_slot, quotaAvailable); dayQuota.Add(ce.date, quota); } } } _log.Debug("Monthy Quota Response: ", Json.Encode(capacityElement)); _log.Debug("TimeSlots: ", Json.Encode(timeSlotInfoElement)); HashSet <string> timeSlotSet = new HashSet <string>(); if (timeSlotInfoElement != null) { foreach (time_slot_info_element ts in timeSlotInfoElement) { timeSlotSet.Add(ts.label); } } if (timeSlotSet.Count > 0) { response.Timeslots = new string[timeSlotSet.Count]; timeSlotSet.CopyTo(response.Timeslots); Array.Sort(response.Timeslots); } DateTime currentDate = DateTime.Today; bool todayExists = Array.IndexOf(capacityModel.QuotaDates, currentDate) >= 0; //Fix the closing quota issue if (todayExists) { for (int i = 0; i < 2; i++) { if (dayQuota.ContainsKey(currentDate)) { DayQuota quota = dayQuota[currentDate]; foreach (string timeSlot in response.Timeslots) { if (!quota.TimeSlotQuota.ContainsKey(timeSlot)) { quota.TimeSlotQuota.Add(timeSlot, 0); } } } else { DayQuota quota = new DayQuota(); quota.QuotaDate = currentDate; quota.TimeSlotQuota = new Dictionary <string, float>(); foreach (string timeSlot in response.Timeslots) { quota.TimeSlotQuota.Add(timeSlot, 0); } dayQuota.Add(currentDate, quota); } currentDate = DateTime.Today.AddDays(1); bool currentDateExists = Array.IndexOf(capacityModel.QuotaDates, currentDate) >= 0; if (!currentDateExists) { break; } } } response.DayQuota = dayQuota; // initialize toa result and activity model object toaRequestResult.DataModels.Add(response); if (dayQuota.Count == 0 || timeSlotSet.Count == 0) { toaRequestResult.ResultCode = ToaRequestResultCode.Failure; } else { toaRequestResult.ResultCode = ToaRequestResultCode.Success; } return(toaRequestResult); } catch (Exception exception) { _log.Error("Unable to fetch Quota for given dates"); _log.Error(exception.StackTrace); MessageBox.Show("No quota available for the Work Order Type and Work Order Area selected. Please reselect, if you continue to receive this warning, please contact support for assistance.", "Warning: No Quota Available", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Warning); toaRequestResult.ResultCode = ToaRequestResultCode.Failure; } return(toaRequestResult); }
/// <summary> /// Selected dates changes /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void MonthlyViewCalendar_SelectedDatesChanged(object sender, SelectionChangedEventArgs e) { //_log.Info("Inside MonthlyViewCalendar_SelectedDatesChanged"); var calendar = sender as Calendar; // ... See if a date is selected. if (calendar.SelectedDate.HasValue) { DateTime date = DateTime.Parse(calendar.SelectedDate.Value.ToString("yyyy-MM-dd")); if (date < DateTime.Today) { return; } var monthlyViewSchedulerViewModel = (MonthlyViewSchedulerViewModel)DataContext; if (!monthlyViewSchedulerViewModel.MonthlyQuota.ContainsKey(date)) { return; } isMonthChanging = false; if (date.Month != monthlyViewSchedulerViewModel.CurrentDateSelected.Month) { isMonthChanging = true; } monthlyViewSchedulerViewModel.CurrentDateSelected = date; DataContext = monthlyViewSchedulerViewModel; string timeSlot = (string)TimeSlotComboBox.SelectedItem; monthlyViewSchedulerViewModel.CurrentTimeSlot = timeSlot; //if (monthlyViewSchedulerViewModel.CurrentTimeSlot.Equals("All Slots")) //{ // //TimeSlotDataGrid.Visibility = System.Windows.Visibility.Visible; // monthlyViewSchedulerViewModel.ShowTimeSlotInDataGrid(date); //} //else //{ // updateRecordFields(monthlyViewSchedulerViewModel.CurrentTimeSlot, date); //} if (timeSlot.Equals("All Slots")) { monthlyViewSchedulerViewModel.ShowTimeSlotInDataGrid(date); TimeSlotDataGrid.Visibility = System.Windows.Visibility.Visible; } else { DayQuota dayQuota = monthlyViewSchedulerViewModel.MonthlyQuota[monthlyViewSchedulerViewModel.CurrentDateSelected]; if (dayQuota != null) { float timeSlotQuota = dayQuota.TimeSlotQuota[monthlyViewSchedulerViewModel.CurrentTimeSlot]; if (timeSlotQuota > monthlyViewSchedulerViewModel.RedQuotaCutoff || monthlyViewSchedulerViewModel.IsManagerOverride) { updateRecordFields(monthlyViewSchedulerViewModel.CurrentTimeSlot, date); } TimeSlotDataGrid.Visibility = System.Windows.Visibility.Collapsed; } } } }