在這段代碼中,我們有一個下拉組合框供用戶選擇顯示數據的狀態。在某些情況下,它不會令人耳目一新 - 我如何在這裏添加一個簡單的刷新?在這些地方的情況下啓動:如何刷新下拉並不總是刷新數據?
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);
});
}
}
}
這裏是實現INotifyPropertyChanged,並具有用於裝載組合框
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(); } }
}
}
}
謝謝你,雷切爾,你可能會專門爲我的代碼編寫代碼,我沒有得到它。 – Booksman
@Booksman你可以將實際加載項目的代碼發佈到你的ComboBox中嗎?我沒有看到你現在發佈的內容。 – Rachel
是的,這裏你有這個選項卡的幾個文件,它可能會更快http://www.mediafire.com/download.php?o2mq15e22iu3cvc現在我會發布以及我們在這裏我們有代碼爲cb的負載。 – Booksman