in this code we are having a pulldown combobox for the user to select which status to display the data by. in some cases it is not refreshing – how can i add here a simple refresh ? here where the case starts:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OPTFDashboard.Common.Modules.Schedules.DataModel;
using OPTFDashboard.DataAccess;
using OPTFDashboard.DataModel;
namespace OPTFDashboard.Common.Modules.Schedules.DataAccess
{
public class SchedulesRepository
{
public static void Summary(IEnumerable<Facility> facilities, DateTime fromDate, DateTime toDate, Action<MonthlySchedules> completionHandler)
{
DBHelper.Execute(
DBHelper.StoredProcedure("OGEN.DBD_GET_MONTHLY_SCHEDULES",
new DBHelper.Parameter("@FACILITYKEY", String.Join(",", facilities.Select(f => String.Format("{0}", f.FacilityKey)))),
new DBHelper.Parameter("@FromDate", fromDate),
new DBHelper.Parameter("@ToDate", toDate)
),
(reader) =>
{
completionHandler((reader == null || !reader.Read()) ? null :
new MonthlySchedules((Decimal)reader["COMPLETED"], (Decimal)reader["UNCOMPLETED"], (Decimal)reader["LATE"]));
});
}
public static void Mixed(IEnumerable<Facility> facilities, Action<List<ScheduleMIXED>> completionHandler)
{
DBHelper.Execute(
DBHelper.StoredProcedure("OGEN.DBD_GET_SCHEDULE_MIX",
new DBHelper.Parameter("@FACILITYKEY", String.Join(",", facilities.Select(f => String.Format("{0}", f.FacilityKey))))
//,
//new DBHelper.Parameter("@UNITSTR", unit),
//new DBHelper.Parameter("@FromDate", fromDate),
//new DBHelper.Parameter("@ToDate", toDate)
),
(reader) =>
{
var schedules = new List<ScheduleMIXED>();
while (reader != null && reader.Read())
schedules.Add(new ScheduleMIXED((String)reader["ROW_NAME"], (Decimal)reader["COMP"], (Decimal)reader["EOT_COT"], (Decimal)reader["PPS"], (Decimal)reader["QUART"], (Decimal)reader["TRACK"], (Decimal)reader["OTHER"]));
completionHandler(schedules);
});
}
public static void Details(IEnumerable<Facility> facilities, String unit, String type, DateTime fromDate, DateTime toDate, Action<List<Schedule>> completionHandler)
{
String storeName = String.Empty;
switch (type)
// switch (type.Trim().ToUpper())
{
case "NOT STARTED - LATE":
storeName = "OGEN.DBD_GET_SCHEDULE_LATE_DETAIL";
break;
case "COMPLETED":
storeName = "OGEN.DBD_GET_SCHEDULE_COMPLETED_DETAIL";
break;
case "INCOMPLETE":
storeName = "OGEN.DBD_GET_SCHEDULE_UNCOMPLETED_DETAIL";
break;
case "All":
storeName = "OGEN.DBD_GET_SCHEDULE_ALL_DETAIL";
break;
case "SUBMITTED":
storeName = "OGEN.DBD_GET_SCHEDULE_SUBMITTED_DETAIL";
break;
// new ones:
case "SUBMITTED LATE":
storeName = "OGEN.DBD_GET_SCHEDULE_SUBMITTED_LATE";
break;
case "NOT STARTED":
storeName = "OGEN.DBD_GET_SCHEDULE_NOT_STARTED";
break;
case "COMPLETED LATE":
storeName = "OGEN.DBD_GET_SCHEDULE_COMPLETED_LATE";
break;
case "INCOMPLETE LATE":
storeName = "OGEN.DBD_GET_SCHEDULE_UNCOMPLETED_LATE";
break;
}
DBHelper.Execute(
DBHelper.StoredProcedure(storeName,
new DBHelper.Parameter("@FACILITYKEY", String.Join(",", facilities.Select(f => String.Format("{0}", f.FacilityKey)))),
new DBHelper.Parameter("@UNITSTR", unit),
new DBHelper.Parameter("@FromDate", fromDate),
new DBHelper.Parameter("@ToDate", toDate)
),
(reader) =>
{
var schedules = new List<Schedule>();
if (reader != null && !reader.IsClosed)
while (reader.Read())
{
Schedule objSchedule = new Schedule() { FACILITY_KEY = (String)reader ["FACILITY_KEY"], UNIT = (String)reader["UNIT_CODE"], PATIENT_ID = Convert.ToString(reader["PATIENT_ID"]).Trim(), PATIENT_NAME = (!DBNull.Value.Equals(reader["PATIENT_ID"]) ? (String)reader["PATIENT_NAME"] : String.Empty) };
// reference date taken out.
// if (!DBNull.Value.Equals(reader["REFERENCE_DATE"]))
{
// objSchedule.REFERENCE_DATE = (DateTime)reader["REFERENCE_DATE"];
}
if (!DBNull.Value.Equals(reader["A3A_DATE_USER"]))
{
objSchedule.A3A_DATE_USER = (DateTime)reader["A3A_DATE_USER"];
}
objSchedule.ASSESSMENTS = (String)reader["ASSESSMENTS"];
if (!DBNull.Value.Equals(reader["BASE_REASON"]))
{
objSchedule.BASE_REASON = (String)reader["BASE_REASON"];
}
if (!DBNull.Value.Equals(reader["TRACK_DESC"]))
{
objSchedule.TRACK_DESC = (String)reader["TRACK_DESC"];
}
schedules.Add(objSchedule);
}
completionHandler(schedules);
});
}
}
}
here is the code for loading the combobox
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.Composition;
using OPTFDashboard.ViewModel;
using System.Collections.ObjectModel;
using OPTFDashboard.Common.Ribbon;
using OPTFDashboard.Common.Utility;
using OPTFDashboard.DataModel;
using System.Windows.Data;
using OPTFDashboard.Common.Modules.Schedules.DataAccess;
namespace OPTFDashboard.Common.Modules.Schedules.ViewModels
{
[Export]
class ScheduleViewModel : TabViewModel, ISelectedContentTab
{
//
private readonly String[] _assessmentType = new String[] { "All", "INCOMPLETE", "COMPLETED", "COMPLETED LATE", "INCOMPLETE LATE", "NOT STARTED - LATE", "NOT STARTED", "SUBMITTED", "SUBMITTED LATE" };
//pk display ALL as default in detail tab.
//
public ScheduleViewModel()
: base()
{
DisplayName = "Schedules";
StartDate = DateTime.Now.AddMonths(-6);
EndDate = DateTime.Now;
GroupDataCollection = new ObservableCollection<GroupData>()
{
// here is the combo box
RibbonControlHelper.CreateFacilitySelection()
, new GroupData("Criterria"
, RibbonControlHelper.CreateDateSelection(StartDate,EndDate,(s, e) => { StartDate = s; EndDate = e; RefreshData(); })
, RibbonControlHelper.CreateUnitSelection(UnitChanged)
, RibbonControlHelper.CreateComboBox("Assessment", "Assessment", "Select Assessment to show.", _assessmentType, (type) => { AssessmentType = type; })
)
};
}
protected override void RefreshData()
{
if (FacilitiesAreChanging) { return; }
Loading = true;
SchedulesRepository.Details(FacilitySelectionService.SelectedFacilities, UnitCode, AssessmentType, StartDate, EndDate,
(schedules) =>
{
var data = new ListCollectionView(schedules);
data.GroupDescriptions.Add(new PropertyGroupDescription("FACILITY_KEY"));
data.GroupDescriptions.Add(new PropertyGroupDescription("UNIT"));
Data = data;
Loading = false;
});
}
private ListCollectionView _Data;
public ListCollectionView Data
{
get { return _Data; }
set { this.SetReferenceProperty("Data", ref _Data, value); }
}
private DateTime startDate;
public DateTime StartDate
{
get { return startDate; }
set { startDate = value; }
}
private DateTime endDate;
public DateTime EndDate
{
get { return endDate; }
set { endDate = value; }
}
public ObservableCollection<GroupData> GroupDataCollection { get; private set; }
private String UnitCode { get; set; }
private void UnitChanged(Unit unit)
{
UnitCode = unit == null ? "" : unit.Description;
RefreshData();
}
private String _Type;
private String AssessmentType
{
get { return _Type; }
set { if (this.SetReferenceProperty("AssessmentType", ref _Type, value)) { RefreshData(); } }
}
}
}
Set the DataContext of UserControl to something (a ViewModel) that implements INotifyPropertyChanged and has a ComboBoxSource property. Then bind the ComboBox ItemsSource to the property name. When you want to refresh, just set the property on the ViewModel. PropertyChanged will fire and the ItemsSource will be updated automatically.