-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainViewModel.cs
34 lines (29 loc) · 1.24 KB
/
MainViewModel.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
using DevExpress.Mvvm;
using DevExpress.Mvvm.DataAnnotations;
using DevExpress.XtraReports.UI;
using System.Collections.Generic;
using System.Data.Entity;
namespace PassDataFromViewModelToReport.Models {
public class MainViewModel : ViewModelBase {
readonly Data.NWindDBContext dbContext = new Data.NWindDBContext();
public IEnumerable<Data.Employee> Employees { get; }
public Data.Employee SelectedEmployee {
get => GetProperty(() => SelectedEmployee);
set => SetProperty(() => SelectedEmployee, value);
}
public MainViewModel() {
dbContext.Employees.Load();
Employees = dbContext.Employees.Local;
}
[Command(CanExecuteMethodName = nameof(CanShowPrintPreview))]
public void ShowPrintPreview() {
XtraReport report = new EmployeeReport(dbContext);
report.Parameters["EmployeeId"].Value = SelectedEmployee.EmployeeID;
using(report) {
GetService<IDialogService>()
.ShowDialog(null, "Print Preview", new DocumentPreviewViewModel(report));
}
}
public bool CanShowPrintPreview() => SelectedEmployee != null;
}
}