mirror of
https://github.com/DevExpress/netcore-winforms-demos.git
synced 2026-01-06 08:47:14 +00:00
Add Outlook Inspired and Stock Market demos
This commit is contained in:
@@ -0,0 +1,104 @@
|
||||
namespace DevExpress.DevAV.ViewModels {
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using DevExpress.DevAV.DevAVDbDataModel;
|
||||
|
||||
public static class AnalysisPeriod {
|
||||
public static readonly DateTime Start = new DateTime(DateTime.Now.Year - 3, 10, 1);
|
||||
public static readonly DateTime End = new DateTime(DateTime.Now.Year, 09, 30);
|
||||
public static int MonthOffsetFromStart(DateTime dateTime) {
|
||||
return (dateTime.Year - Start.Year) * 12 + dateTime.Month - Start.Month;
|
||||
}
|
||||
public class Item {
|
||||
public decimal Total { get; set; }
|
||||
public int Year { get; set; }
|
||||
public int Month { get; set; }
|
||||
public DateTime Date {
|
||||
get { return new DateTime(Year, Month, 1); }
|
||||
}
|
||||
}
|
||||
}
|
||||
public static class ProductsAnalysis {
|
||||
public static IEnumerable<Item> GetFinancialReport(this IDevAVDbUnitOfWork UnitOfWork) {
|
||||
var orders = UnitOfWork.Orders;
|
||||
var orderItems =
|
||||
from oi in UnitOfWork.OrderItems
|
||||
join o in orders on oi.OrderId equals o.Id
|
||||
where (o.OrderDate >= AnalysisPeriod.Start && o.OrderDate <= AnalysisPeriod.End)
|
||||
select new
|
||||
{
|
||||
Product = oi.Product,
|
||||
Total = oi.Total,
|
||||
FY = ((o.OrderDate.Year - AnalysisPeriod.Start.Year) * 12 + (o.OrderDate.Month - AnalysisPeriod.Start.Month)) / 12
|
||||
};
|
||||
return
|
||||
from oi in orderItems
|
||||
group oi by new { oi.Product, oi.FY } into g
|
||||
select new Item
|
||||
{
|
||||
ProductName = g.Key.Product.Name,
|
||||
Year = AnalysisPeriod.Start.Year + g.Key.FY,
|
||||
Month = AnalysisPeriod.Start.Month,
|
||||
Total = g.Select(o => (decimal?)o.Total).Sum() ?? 0
|
||||
};
|
||||
}
|
||||
public static IEnumerable<Item> GetFinancialData(this IDevAVDbUnitOfWork UnitOfWork) {
|
||||
var orders = UnitOfWork.Orders;
|
||||
var orderItems =
|
||||
from oi in UnitOfWork.OrderItems
|
||||
join o in orders on oi.OrderId equals o.Id
|
||||
where (o.OrderDate >= AnalysisPeriod.Start && o.OrderDate <= AnalysisPeriod.End)
|
||||
select new { Product = oi.Product, Date = o.OrderDate, Total = oi.Total };
|
||||
return
|
||||
from oi in orderItems
|
||||
group oi by new { oi.Product.Category, oi.Date.Year, oi.Date.Month } into g
|
||||
select new Item { ProductCategory = g.Key.Category, Year = g.Key.Year, Month = g.Key.Month, Total = g.Select(o => (decimal?)o.Total).Sum() ?? 0 };
|
||||
}
|
||||
public class Item : AnalysisPeriod.Item {
|
||||
public string ProductName { get; set; }
|
||||
public ProductCategory ProductCategory { get; set; }
|
||||
}
|
||||
}
|
||||
public static class CustomersAnalysis {
|
||||
public static IEnumerable<Item> GetSalesReport(this IDevAVDbUnitOfWork UnitOfWork) {
|
||||
var orders = UnitOfWork.Orders;
|
||||
var orderItems =
|
||||
from oi in UnitOfWork.OrderItems
|
||||
join o in orders on oi.OrderId equals o.Id
|
||||
where (o.OrderDate >= AnalysisPeriod.Start && o.OrderDate <= AnalysisPeriod.End)
|
||||
select new
|
||||
{
|
||||
Customer = o.Customer,
|
||||
Total = oi.Total,
|
||||
FY = ((o.OrderDate.Year - AnalysisPeriod.Start.Year) * 12 + (o.OrderDate.Month - AnalysisPeriod.Start.Month)) / 12
|
||||
};
|
||||
return
|
||||
from oi in orderItems
|
||||
group oi by new { oi.Customer, oi.FY } into g
|
||||
select new Item
|
||||
{
|
||||
CustomerName = g.Key.Customer.Name,
|
||||
Year = AnalysisPeriod.Start.Year + g.Key.FY,
|
||||
Month = AnalysisPeriod.Start.Month,
|
||||
Total = g.Select(o => (decimal?)o.Total).Sum() ?? 0
|
||||
};
|
||||
}
|
||||
public static IEnumerable<Item> GetSalesData(this IDevAVDbUnitOfWork UnitOfWork) {
|
||||
var orders = UnitOfWork.Orders;
|
||||
var orderItems =
|
||||
from oi in UnitOfWork.OrderItems
|
||||
join o in orders on oi.OrderId equals o.Id
|
||||
where (o.OrderDate >= AnalysisPeriod.Start && o.OrderDate <= AnalysisPeriod.End)
|
||||
select new { State = o.Store.Address.State, Date = o.OrderDate, Total = oi.Total };
|
||||
return
|
||||
from oi in orderItems
|
||||
group oi by new { oi.State, oi.Date.Year, oi.Date.Month } into g
|
||||
select new Item { State = g.Key.State, Year = g.Key.Year, Month = g.Key.Month, Total = g.Select(o => (decimal?)o.Total).Sum() ?? 0 };
|
||||
}
|
||||
public class Item : AnalysisPeriod.Item {
|
||||
public string CustomerName { get; set; }
|
||||
public StateEnum State { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
namespace DevExpress.DevAV.ViewModels {
|
||||
using System;
|
||||
using System.IO;
|
||||
using DevExpress.Utils;
|
||||
|
||||
public enum AnalysisTemplate {
|
||||
CustomerSales,
|
||||
ProductSales
|
||||
}
|
||||
public static class AnalysisTemplatesHelper {
|
||||
public static Stream GetAnalysisTemplate(AnalysisTemplate template) {
|
||||
switch(template) {
|
||||
case AnalysisTemplate.CustomerSales:
|
||||
return GetTemplateStream("CustomerAnalysis.xlsx");
|
||||
case AnalysisTemplate.ProductSales:
|
||||
return GetTemplateStream("ProductAnalysis.xlsx");
|
||||
default:
|
||||
throw new NotSupportedException(template.ToString());
|
||||
}
|
||||
}
|
||||
static Stream GetTemplateStream(string templateName) {
|
||||
return AssemblyHelper.GetEmbeddedResourceStream(typeof(AnalysisTemplatesHelper).Assembly, templateName, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
namespace DevExpress.DevAV.ViewModels {
|
||||
using System;
|
||||
using DevExpress.Mvvm.DataAnnotations;
|
||||
using DevExpress.Mvvm.POCO;
|
||||
|
||||
public class CollectionUIViewModel {
|
||||
#region ViewKind
|
||||
public virtual CollectionViewKind ViewKind { get; set; }
|
||||
[Command]
|
||||
public void ShowCard() {
|
||||
ViewKind = CollectionViewKind.CardView;
|
||||
}
|
||||
public bool CanShowCard() {
|
||||
return ViewKind != CollectionViewKind.CardView;
|
||||
}
|
||||
[Command]
|
||||
public void ShowList() {
|
||||
ViewKind = CollectionViewKind.ListView;
|
||||
}
|
||||
public bool CanShowList() {
|
||||
return ViewKind != CollectionViewKind.ListView;
|
||||
}
|
||||
[Command]
|
||||
public void ShowCarousel() {
|
||||
ViewKind = CollectionViewKind.Carousel;
|
||||
}
|
||||
public bool CanShowCarousel() {
|
||||
return ViewKind != CollectionViewKind.Carousel;
|
||||
}
|
||||
[Command]
|
||||
public void ShowMasterDetail() {
|
||||
ViewKind = CollectionViewKind.MasterDetailView;
|
||||
}
|
||||
public bool CanShowMasterDetail() {
|
||||
return ViewKind != CollectionViewKind.MasterDetailView;
|
||||
}
|
||||
protected virtual void OnViewKindChanged() {
|
||||
this.RaiseCanExecuteChanged(x => x.ShowList());
|
||||
this.RaiseCanExecuteChanged(x => x.ShowCard());
|
||||
this.RaiseCanExecuteChanged(x => x.ShowCarousel());
|
||||
this.RaiseCanExecuteChanged(x => x.ShowMasterDetail());
|
||||
this.RaiseCanExecuteChanged(x => x.ResetView());
|
||||
RaiseViewKindChanged();
|
||||
}
|
||||
#endregion
|
||||
#region ViewLayout
|
||||
public virtual CollectionViewMasterDetailLayout ViewLayout { get; set; }
|
||||
public bool IsDetailHidden {
|
||||
get { return ViewLayout == CollectionViewMasterDetailLayout.DetailHidden; }
|
||||
}
|
||||
public bool IsHorizontalLayout {
|
||||
get { return ViewLayout == CollectionViewMasterDetailLayout.Horizontal; }
|
||||
}
|
||||
[Command]
|
||||
public void ShowHorizontalLayout() {
|
||||
ViewLayout = CollectionViewMasterDetailLayout.Horizontal;
|
||||
}
|
||||
public bool CanShowHorizontalLayout() {
|
||||
return ViewLayout != CollectionViewMasterDetailLayout.Horizontal;
|
||||
}
|
||||
[Command]
|
||||
public void ShowVerticalLayout() {
|
||||
ViewLayout = CollectionViewMasterDetailLayout.Vertical;
|
||||
}
|
||||
public bool CanShowVerticalLayout() {
|
||||
return ViewLayout != CollectionViewMasterDetailLayout.Vertical;
|
||||
}
|
||||
[Command]
|
||||
public void HideDetail() {
|
||||
ViewLayout = CollectionViewMasterDetailLayout.DetailHidden;
|
||||
}
|
||||
public bool CanHideDetail() {
|
||||
return ViewLayout != CollectionViewMasterDetailLayout.DetailHidden;
|
||||
}
|
||||
protected virtual void OnViewLayoutChanged() {
|
||||
this.RaiseCanExecuteChanged(x => x.ShowHorizontalLayout());
|
||||
this.RaiseCanExecuteChanged(x => x.ShowVerticalLayout());
|
||||
this.RaiseCanExecuteChanged(x => x.HideDetail());
|
||||
this.RaiseCanExecuteChanged(x => x.ResetView());
|
||||
RaiseViewLayoutChanged();
|
||||
}
|
||||
#endregion
|
||||
#region Reset
|
||||
public CollectionViewKind DefaultViewKind { get; set; }
|
||||
public CollectionViewMasterDetailLayout DefaultViewLayout { get; set; }
|
||||
[Command]
|
||||
public void ResetView() {
|
||||
ViewKind = DefaultViewKind;
|
||||
ViewLayout = DefaultViewLayout;
|
||||
}
|
||||
public bool CanResetView() {
|
||||
return
|
||||
(ViewKind != DefaultViewKind) ||
|
||||
(ViewLayout != DefaultViewLayout);
|
||||
}
|
||||
#endregion
|
||||
public event EventHandler ViewKindChanged;
|
||||
public event EventHandler ViewLayoutChanged;
|
||||
void RaiseViewKindChanged() {
|
||||
EventHandler handler = ViewKindChanged;
|
||||
if(handler != null)
|
||||
handler(this, EventArgs.Empty);
|
||||
}
|
||||
void RaiseViewLayoutChanged() {
|
||||
EventHandler handler = ViewLayoutChanged;
|
||||
if(handler != null)
|
||||
handler(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace DevExpress.DevAV.ViewModels {
|
||||
public enum CollectionViewFiltersVisibility {
|
||||
Visible,
|
||||
Minimized,
|
||||
Hidden
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace DevExpress.DevAV.ViewModels {
|
||||
public enum CollectionViewKind {
|
||||
ListView,
|
||||
CardView,
|
||||
Carousel,
|
||||
MasterDetailView,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace DevExpress.DevAV.ViewModels {
|
||||
public enum CollectionViewMasterDetailLayout {
|
||||
Horizontal,
|
||||
Vertical,
|
||||
DetailHidden,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
namespace DevExpress.DevAV.ViewModels {
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using DevExpress.DevAV;
|
||||
using DevExpress.DevAV.ViewModels;
|
||||
using DevExpress.Mvvm;
|
||||
using DevExpress.Mvvm.POCO;
|
||||
using DevExpress.DevAV.DevAVDbDataModel;
|
||||
|
||||
public class CustomerAnalysisViewModel : DocumentContentViewModelBase {
|
||||
IDevAVDbUnitOfWork unitOfWork;
|
||||
|
||||
public static CustomerAnalysisViewModel Create() {
|
||||
return ViewModelSource.Create(() => new CustomerAnalysisViewModel());
|
||||
}
|
||||
protected CustomerAnalysisViewModel() {
|
||||
unitOfWork = UnitOfWorkSource.GetUnitOfWorkFactory().CreateUnitOfWork();
|
||||
}
|
||||
public IEnumerable<CustomersAnalysis.Item> GetSalesReport() {
|
||||
return CustomersAnalysis.GetSalesReport(unitOfWork);
|
||||
}
|
||||
public IEnumerable<CustomersAnalysis.Item> GetSalesData() {
|
||||
return CustomersAnalysis.GetSalesData(unitOfWork);
|
||||
}
|
||||
public IEnumerable<string> GetStates(IEnumerable<StateEnum> states) {
|
||||
return QueriesHelper.GetStateNames(unitOfWork.States, states);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using DevExpress.Mvvm.POCO;
|
||||
using DevExpress.DevAV.Common.Utils;
|
||||
using DevExpress.DevAV.DevAVDbDataModel;
|
||||
using DevExpress.Mvvm.DataModel;
|
||||
using DevExpress.DevAV;
|
||||
using DevExpress.DevAV.Common.ViewModel;
|
||||
|
||||
namespace DevExpress.DevAV.ViewModels {
|
||||
/// <summary>
|
||||
/// Represents the Customers collection view model.
|
||||
/// </summary>
|
||||
public partial class CustomerCollectionViewModel : CollectionViewModel<Customer, long, IDevAVDbUnitOfWork> {
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of CustomerCollectionViewModel as a POCO view model.
|
||||
/// </summary>
|
||||
/// <param name="unitOfWorkFactory">A factory used to create a unit of work instance.</param>
|
||||
public static CustomerCollectionViewModel Create(IUnitOfWorkFactory<IDevAVDbUnitOfWork> unitOfWorkFactory = null) {
|
||||
return ViewModelSource.Create(() => new CustomerCollectionViewModel(unitOfWorkFactory));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the CustomerCollectionViewModel class.
|
||||
/// This constructor is declared protected to avoid undesired instantiation of the CustomerCollectionViewModel type without the POCO proxy factory.
|
||||
/// </summary>
|
||||
/// <param name="unitOfWorkFactory">A factory used to create a unit of work instance.</param>
|
||||
protected CustomerCollectionViewModel(IUnitOfWorkFactory<IDevAVDbUnitOfWork> unitOfWorkFactory = null)
|
||||
: base(unitOfWorkFactory ?? UnitOfWorkSource.GetUnitOfWorkFactory(), x => x.Customers, query => query.OrderBy(x => x.Name)) {
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,163 @@
|
||||
namespace DevExpress.DevAV.ViewModels {
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using DevExpress.DevAV;
|
||||
using DevExpress.DevAV.DevAVDbDataModel;
|
||||
using DevExpress.DevAV.ViewModels;
|
||||
using DevExpress.Mvvm;
|
||||
using DevExpress.Mvvm.DataAnnotations;
|
||||
using DevExpress.Mvvm.POCO;
|
||||
|
||||
partial class CustomerCollectionViewModel : ISupportMap, ISupportAnalysis, ISupportCustomFilters {
|
||||
public override void Refresh() {
|
||||
base.Refresh();
|
||||
RaiseReload();
|
||||
}
|
||||
protected override void OnSelectedEntityChanged() {
|
||||
base.OnSelectedEntityChanged();
|
||||
this.RaiseCanExecuteChanged(x => x.ShowMap());
|
||||
this.RaiseCanExecuteChanged(x => x.PrintProfile());
|
||||
this.RaiseCanExecuteChanged(x => x.PrintSalesDetail());
|
||||
this.RaiseCanExecuteChanged(x => x.PrintSalesSummary());
|
||||
this.RaiseCanExecuteChanged(x => x.PrintProfile());
|
||||
this.RaiseCanExecuteChanged(x => x.QuickReport(CustomerReportType.Profile));
|
||||
}
|
||||
public virtual IEnumerable<Customer> Selection { get; set; }
|
||||
protected virtual void OnSelectionChanged() {
|
||||
this.RaiseCanExecuteChanged(x => x.GroupSelection());
|
||||
}
|
||||
public event EventHandler Reload;
|
||||
public event EventHandler CustomFilter;
|
||||
public event EventHandler CustomFiltersReset;
|
||||
public event EventHandler CustomGroup;
|
||||
public event EventHandler<GroupEventArgs<Customer>> CustomGroupFromSelection;
|
||||
[Command]
|
||||
public void ShowAnalysis() {
|
||||
ShowDocument<CustomerAnalysisViewModel>("Analysis", null);
|
||||
}
|
||||
[Command]
|
||||
public void ShowMap() {
|
||||
ShowMapCore(SelectedEntity);
|
||||
}
|
||||
public bool CanShowMap() {
|
||||
return CanShowMapCore(SelectedEntity);
|
||||
}
|
||||
protected internal void ShowMapCore(Customer customer) {
|
||||
ShowDocument<CustomerMapViewModel>("MapView", customer.Id);
|
||||
}
|
||||
protected internal bool CanShowMapCore(Customer customer) {
|
||||
return customer != null;
|
||||
}
|
||||
[Command]
|
||||
public void ShowViewSettings() {
|
||||
var dms = this.GetService<IDocumentManagerService>("View Settings");
|
||||
if(dms != null) {
|
||||
var document = dms.Documents.FirstOrDefault(d => d.Content is ViewSettingsViewModel);
|
||||
if(document == null)
|
||||
document = dms.CreateDocument("View Settings", null, null, this);
|
||||
document.Show();
|
||||
}
|
||||
}
|
||||
[Command]
|
||||
public void NewGroup() {
|
||||
RaiseCustomGroup();
|
||||
}
|
||||
[Command]
|
||||
public void GroupSelection() {
|
||||
RaiseCustomGroupFromSelection();
|
||||
}
|
||||
public bool CanGroupSelection() {
|
||||
return (Selection != null) && Selection.Any();
|
||||
}
|
||||
[Command]
|
||||
public void NewCustomFilter() {
|
||||
RaiseCustomFilter();
|
||||
}
|
||||
[Command(UseCommandManager = false, CanExecuteMethodName = "CanPrint")]
|
||||
public void PrintProfile() {
|
||||
RaisePrint(CustomerReportType.Profile);
|
||||
}
|
||||
[Command]
|
||||
public void PrintContactDirectory() {
|
||||
RaisePrint(CustomerReportType.ContactDirectory);
|
||||
}
|
||||
[Command(UseCommandManager = false, CanExecuteMethodName = "CanPrint")]
|
||||
public void PrintSalesSummary() {
|
||||
RaisePrint(CustomerReportType.SalesSummary);
|
||||
}
|
||||
[Command(UseCommandManager = false, CanExecuteMethodName = "CanPrint")]
|
||||
public void PrintSalesDetail() {
|
||||
RaisePrint(CustomerReportType.SalesDetail);
|
||||
}
|
||||
[Command]
|
||||
public void QuickReport(CustomerReportType reportType) {
|
||||
RaisePrint(reportType);
|
||||
}
|
||||
public bool CanQuickReport(CustomerReportType reportType) {
|
||||
return SelectedEntity != null;
|
||||
}
|
||||
public bool CanPrint() {
|
||||
return SelectedEntity != null;
|
||||
}
|
||||
[Command]
|
||||
public void ShowAllFolders() {
|
||||
RaiseShowAllFolders();
|
||||
}
|
||||
[Command]
|
||||
public void ResetCustomFilters() {
|
||||
RaiseCustomFiltersReset();
|
||||
}
|
||||
void RaisePrint(CustomerReportType reportType) {
|
||||
MainViewModel mainViewModel = ViewModelHelper.GetParentViewModel<MainViewModel>(this);
|
||||
if(mainViewModel != null)
|
||||
mainViewModel.RaisePrint(reportType);
|
||||
}
|
||||
void RaiseShowAllFolders() {
|
||||
MainViewModel mainViewModel = ViewModelHelper.GetParentViewModel<MainViewModel>(this);
|
||||
if(mainViewModel != null)
|
||||
mainViewModel.RaiseShowAllFolders();
|
||||
}
|
||||
void RaiseReload() {
|
||||
EventHandler handler = Reload;
|
||||
if(handler != null)
|
||||
handler(this, EventArgs.Empty);
|
||||
}
|
||||
void RaiseCustomFilter() {
|
||||
EventHandler handler = CustomFilter;
|
||||
if(handler != null)
|
||||
handler(this, EventArgs.Empty);
|
||||
}
|
||||
void RaiseCustomFiltersReset() {
|
||||
EventHandler handler = CustomFiltersReset;
|
||||
if(handler != null)
|
||||
handler(this, EventArgs.Empty);
|
||||
}
|
||||
void RaiseCustomGroup() {
|
||||
EventHandler handler = CustomGroup;
|
||||
if(handler != null)
|
||||
handler(this, EventArgs.Empty);
|
||||
}
|
||||
void RaiseCustomGroupFromSelection() {
|
||||
EventHandler<GroupEventArgs<Customer>> handler = CustomGroupFromSelection;
|
||||
if(handler != null)
|
||||
handler(this, new GroupEventArgs<Customer>(Selection));
|
||||
}
|
||||
void ShowDocument<TViewModel>(string documentType, object parameter) {
|
||||
var document = FindDocument<TViewModel>();
|
||||
if(parameter is long)
|
||||
document = FindDocument<TViewModel>((long)parameter);
|
||||
if(document == null)
|
||||
document = DocumentManagerService.CreateDocument(documentType, null, parameter, this);
|
||||
else
|
||||
ViewModelHelper.EnsureViewModel(document.Content, this, parameter);
|
||||
document.Show();
|
||||
}
|
||||
public override void Delete(Customer entity) {
|
||||
MessageBoxService.ShowMessage("To ensure data integrity, the Customers module doesn't allow records to be deleted. Record deletion is supported by the Employees module.", "Delete Customer", MessageButton.OK);
|
||||
}
|
||||
internal IQueryable<OrderItem> GetOrderItems() {
|
||||
return CreateUnitOfWork().OrderItems;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
namespace DevExpress.DevAV.ViewModels {
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using DevExpress.DevAV.ViewModels;
|
||||
using DevExpress.Mvvm.DataAnnotations;
|
||||
using DevExpress.Mvvm.POCO;
|
||||
|
||||
public class CustomerMapViewModel : CustomerViewModel, ISalesMapViewModel {
|
||||
public virtual Period Period { get; set; }
|
||||
[Command]
|
||||
public void SetLifetimePeriod() {
|
||||
Period = Period.Lifetime;
|
||||
}
|
||||
public bool CanSetLifetimePeriod() {
|
||||
return Period != Period.Lifetime;
|
||||
}
|
||||
[Command]
|
||||
public void SetThisYearPeriod() {
|
||||
Period = Period.ThisYear;
|
||||
}
|
||||
public bool CanSetThisYearPeriod() {
|
||||
return Period != Period.ThisYear;
|
||||
}
|
||||
[Command]
|
||||
public void SetThisMonthPeriod() {
|
||||
Period = Period.ThisMonth;
|
||||
}
|
||||
public bool CanSetThisMonthPeriod() {
|
||||
return Period != Period.ThisMonth;
|
||||
}
|
||||
protected virtual void OnPeriodChanged() {
|
||||
this.RaiseCanExecuteChanged(x => x.SetLifetimePeriod());
|
||||
this.RaiseCanExecuteChanged(x => x.SetThisYearPeriod());
|
||||
this.RaiseCanExecuteChanged(x => x.SetThisMonthPeriod());
|
||||
RaisePeriodChanged();
|
||||
}
|
||||
public event EventHandler PeriodChanged;
|
||||
void RaisePeriodChanged() {
|
||||
EventHandler handler = PeriodChanged;
|
||||
if(handler != null)
|
||||
handler(this, EventArgs.Empty);
|
||||
}
|
||||
#region Properties
|
||||
public string Name {
|
||||
get { return (Entity != null) ? Entity.Name : null; }
|
||||
}
|
||||
public Image Image {
|
||||
get { return (Entity != null) ? Entity.Image : null; }
|
||||
}
|
||||
public string AddressLine1 {
|
||||
get { return (Entity != null) ? Entity.HomeOffice.Line : null; }
|
||||
}
|
||||
public string AddressLine2 {
|
||||
get { return (Entity != null) ? Entity.HomeOffice.CityLine : null; }
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using DevExpress.Mvvm;
|
||||
using DevExpress.Mvvm.POCO;
|
||||
using DevExpress.DevAV.Common.Utils;
|
||||
using DevExpress.DevAV.DevAVDbDataModel;
|
||||
using DevExpress.Mvvm.DataModel;
|
||||
using DevExpress.DevAV;
|
||||
using DevExpress.DevAV.Common.ViewModel;
|
||||
|
||||
namespace DevExpress.DevAV.ViewModels {
|
||||
/// <summary>
|
||||
/// Represents the single Customer object view model.
|
||||
/// </summary>
|
||||
public partial class CustomerViewModel : SingleObjectViewModel<Customer, long, IDevAVDbUnitOfWork> {
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of CustomerViewModel as a POCO view model.
|
||||
/// </summary>
|
||||
/// <param name="unitOfWorkFactory">A factory used to create a unit of work instance.</param>
|
||||
public static CustomerViewModel Create(IUnitOfWorkFactory<IDevAVDbUnitOfWork> unitOfWorkFactory = null) {
|
||||
return ViewModelSource.Create(() => new CustomerViewModel(unitOfWorkFactory));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the CustomerViewModel class.
|
||||
/// This constructor is declared protected to avoid undesired instantiation of the CustomerViewModel type without the POCO proxy factory.
|
||||
/// </summary>
|
||||
/// <param name="unitOfWorkFactory">A factory used to create a unit of work instance.</param>
|
||||
protected CustomerViewModel(IUnitOfWorkFactory<IDevAVDbUnitOfWork> unitOfWorkFactory = null)
|
||||
: base(unitOfWorkFactory ?? UnitOfWorkSource.GetUnitOfWorkFactory(), x => x.Customers, x => x.Name) {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The view model for the CustomerEmployees detail collection.
|
||||
/// </summary>
|
||||
public CollectionViewModel<CustomerEmployee, long, IDevAVDbUnitOfWork> CustomerEmployeesDetails {
|
||||
get { return GetDetailsCollectionViewModel((CustomerViewModel x) => x.CustomerEmployeesDetails, x => x.CustomerEmployees, x => x.CustomerId, (x, key) => x.CustomerId = key); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The view model for the CustomerOrders detail collection.
|
||||
/// </summary>
|
||||
public CollectionViewModel<Order, long, IDevAVDbUnitOfWork> CustomerOrdersDetails {
|
||||
get { return GetDetailsCollectionViewModel((CustomerViewModel x) => x.CustomerOrdersDetails, x => x.Orders, x => x.CustomerId, (x, key) => x.CustomerId = key, query => query.ActualOrders()); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The view model for the CustomerQuotes detail collection.
|
||||
/// </summary>
|
||||
public CollectionViewModel<Quote, long, IDevAVDbUnitOfWork> CustomerQuotesDetails {
|
||||
get { return GetDetailsCollectionViewModel((CustomerViewModel x) => x.CustomerQuotesDetails, x => x.Quotes, x => x.CustomerId, (x, key) => x.CustomerId = key, query => query.ActualQuotes()); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The view model for the CustomerCustomerStores detail collection.
|
||||
/// </summary>
|
||||
public CollectionViewModel<CustomerStore, long, IDevAVDbUnitOfWork> CustomerCustomerStoresDetails {
|
||||
get { return GetDetailsCollectionViewModel((CustomerViewModel x) => x.CustomerCustomerStoresDetails, x => x.CustomerStores, x => x.CustomerId, (x, key) => x.CustomerId = key); }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
namespace DevExpress.DevAV.ViewModels {
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using DevExpress.DevAV;
|
||||
using DevExpress.DevAV.DevAVDbDataModel;
|
||||
using DevExpress.DevAV.ViewModels;
|
||||
using DevExpress.Mvvm;
|
||||
|
||||
partial class CustomerViewModel {
|
||||
public event System.EventHandler EntityChanged;
|
||||
protected override void OnEntityChanged() {
|
||||
base.OnEntityChanged();
|
||||
System.EventHandler handler = EntityChanged;
|
||||
if(handler != null)
|
||||
handler(this, System.EventArgs.Empty);
|
||||
}
|
||||
public IEnumerable<CustomerStore> GetSalesStores(Period period = Period.Lifetime) {
|
||||
return QueriesHelper.GetDistinctStoresForPeriod(UnitOfWork.Orders, Entity.Id, period);
|
||||
}
|
||||
public IEnumerable<DevAV.MapItem> GetSales(Period period = Period.Lifetime) {
|
||||
return QueriesHelper.GetSaleMapItemsByCustomer(UnitOfWork.OrderItems, Entity.Id, period);
|
||||
}
|
||||
public IEnumerable<DevAV.MapItem> GetSalesByCity(string city, Period period = Period.Lifetime) {
|
||||
return QueriesHelper.GetSaleMapItemsByCustomerAndCity(UnitOfWork.OrderItems, Entity.Id, city, period);
|
||||
}
|
||||
public override void Delete() {
|
||||
MessageBoxService.ShowMessage("To ensure data integrity, the Customers module doesn't allow records to be deleted. Record deletion is supported by the Employees module.", "Delete Customer", MessageButton.OK);
|
||||
}
|
||||
}
|
||||
public partial class SynchronizedCustomerViewModel : CustomerViewModel {
|
||||
protected override bool EnableSelectedItemSynchronization {
|
||||
get { return true; }
|
||||
}
|
||||
protected override bool EnableEntityChangedSynchronization {
|
||||
get { return true; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
namespace DevExpress.DevAV.ViewModels {
|
||||
using System;
|
||||
using DevExpress.DevAV;
|
||||
using DevExpress.DevAV.DevAVDbDataModel;
|
||||
using DevExpress.DevAV.ViewModels;
|
||||
using DevExpress.DevAV.Properties;
|
||||
using DevExpress.Mvvm.POCO;
|
||||
|
||||
public class CustomersFilterTreeViewModel : FilterTreeViewModel<Customer, long, IDevAVDbUnitOfWork> {
|
||||
public static CustomersFilterTreeViewModel Create(CustomerCollectionViewModel collectionViewModel) {
|
||||
return ViewModelSource.Create(() => new CustomersFilterTreeViewModel(collectionViewModel));
|
||||
}
|
||||
protected CustomersFilterTreeViewModel(CustomerCollectionViewModel collectionViewModel)
|
||||
: base(collectionViewModel, new FilterTreeModelPageSpecificSettings<Settings>(Settings.Default, StaticFiltersName, x => x.CustomersStaticFilters, x => x.CustomersCustomFilters, x => x.CustomersGroupFilters)) {
|
||||
}
|
||||
protected new CustomerCollectionViewModel CollectionViewModel {
|
||||
get { return base.CollectionViewModel as CustomerCollectionViewModel; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
namespace DevExpress.DevAV.ViewModels {
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using DevExpress.DevAV;
|
||||
using DevExpress.DevAV.DevAVDbDataModel;
|
||||
using DevExpress.DevAV.ViewModels;
|
||||
using DevExpress.Mvvm.POCO;
|
||||
|
||||
public class CustomersReportViewModel :
|
||||
ReportViewModelBase<CustomerReportType, Customer, long, IDevAVDbUnitOfWork> {
|
||||
IDevAVDbUnitOfWork unitOfWork;
|
||||
|
||||
public static CustomersReportViewModel Create() {
|
||||
return ViewModelSource.Create(() => new CustomersReportViewModel());
|
||||
}
|
||||
protected CustomersReportViewModel() {
|
||||
unitOfWork = UnitOfWorkSource.GetUnitOfWorkFactory().CreateUnitOfWork();
|
||||
}
|
||||
public IList<CustomerEmployee> CustomerEmployees {
|
||||
get { return unitOfWork.CustomerEmployees.ToList(); }
|
||||
}
|
||||
public IList<CustomerStore> CustomerStores {
|
||||
get { return unitOfWork.CustomerStores.ToList(); }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace DevExpress.DevAV.ViewModels {
|
||||
public enum CustomerReportType {
|
||||
None,
|
||||
[Display(Name="Profile Report")]
|
||||
Profile,
|
||||
[Display(Name = "Contact Directory Report")]
|
||||
SelectedContactDirectory,
|
||||
[Display(Name = "Contact Directory Report")]
|
||||
ContactDirectory,
|
||||
[Display(Name = "Sales Summary Report")]
|
||||
SalesSummary,
|
||||
[Display(Name = "Sales Detail Report")]
|
||||
SalesDetail,
|
||||
[Display(Name = "Customer Stores Report")]
|
||||
LocationsDirectory,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using DevExpress.Mvvm.POCO;
|
||||
using DevExpress.DevAV.Common.Utils;
|
||||
using DevExpress.DevAV.DevAVDbDataModel;
|
||||
using DevExpress.Mvvm.DataModel;
|
||||
using DevExpress.DevAV;
|
||||
using DevExpress.DevAV.Common.ViewModel;
|
||||
|
||||
namespace DevExpress.DevAV.ViewModels {
|
||||
/// <summary>
|
||||
/// Represents the Employees collection view model.
|
||||
/// </summary>
|
||||
public partial class EmployeeCollectionViewModel : CollectionViewModel<Employee, long, IDevAVDbUnitOfWork> {
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of EmployeeCollectionViewModel as a POCO view model.
|
||||
/// </summary>
|
||||
/// <param name="unitOfWorkFactory">A factory used to create a unit of work instance.</param>
|
||||
public static EmployeeCollectionViewModel Create(IUnitOfWorkFactory<IDevAVDbUnitOfWork> unitOfWorkFactory = null) {
|
||||
return ViewModelSource.Create(() => new EmployeeCollectionViewModel(unitOfWorkFactory));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the EmployeeCollectionViewModel class.
|
||||
/// This constructor is declared protected to avoid undesired instantiation of the EmployeeCollectionViewModel type without the POCO proxy factory.
|
||||
/// </summary>
|
||||
/// <param name="unitOfWorkFactory">A factory used to create a unit of work instance.</param>
|
||||
protected EmployeeCollectionViewModel(IUnitOfWorkFactory<IDevAVDbUnitOfWork> unitOfWorkFactory = null)
|
||||
: base(unitOfWorkFactory ?? UnitOfWorkSource.GetUnitOfWorkFactory(), x => x.Employees) {
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,180 @@
|
||||
namespace DevExpress.DevAV.ViewModels {
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using DevExpress.DevAV;
|
||||
using DevExpress.Mvvm.DataAnnotations;
|
||||
using DevExpress.Mvvm.POCO;
|
||||
|
||||
partial class EmployeeCollectionViewModel : ISupportMap, ISupportCustomFilters {
|
||||
public override void Refresh() {
|
||||
base.Refresh();
|
||||
RaiseReload();
|
||||
}
|
||||
protected override void OnEntityChanged(Employee entity) {
|
||||
entity.ResetBindable();
|
||||
}
|
||||
protected override void OnSelectedEntityChanged() {
|
||||
base.OnSelectedEntityChanged();
|
||||
this.RaiseCanExecuteChanged(x => x.ShowMap());
|
||||
this.RaiseCanExecuteChanged(x => x.PrintProfile());
|
||||
this.RaiseCanExecuteChanged(x => x.MailMerge());
|
||||
this.RaiseCanExecuteChanged(x => x.QuickLetter(EmployeeMailTemplate.ThankYouNote));
|
||||
}
|
||||
public virtual IEnumerable<Employee> Selection { get; set; }
|
||||
protected virtual void OnSelectionChanged() {
|
||||
this.RaiseCanExecuteChanged(x => x.GroupSelection());
|
||||
}
|
||||
public event EventHandler Reload;
|
||||
public event EventHandler CustomFilter;
|
||||
public event EventHandler CustomFiltersReset;
|
||||
public event EventHandler CustomGroup;
|
||||
public event EventHandler<GroupEventArgs<Employee>> CustomGroupFromSelection;
|
||||
[Command]
|
||||
public void ShowMap() {
|
||||
ShowMapCore(SelectedEntity);
|
||||
}
|
||||
public bool CanShowMap() {
|
||||
return CanShowMapCore(SelectedEntity);
|
||||
}
|
||||
protected internal void ShowMapCore(Employee employee) {
|
||||
ShowDocument<EmployeeMapViewModel>("MapView", employee.Id);
|
||||
}
|
||||
protected internal bool CanShowMapCore(Employee employee) {
|
||||
return employee != null;
|
||||
}
|
||||
[Command]
|
||||
public void ShowViewSettings() {
|
||||
var dms = this.GetService<DevExpress.Mvvm.IDocumentManagerService>("View Settings");
|
||||
if(dms != null) {
|
||||
var document = dms.Documents.FirstOrDefault(d => d.Content is ViewSettingsViewModel);
|
||||
if(document == null)
|
||||
document = dms.CreateDocument("View Settings", null, null, this);
|
||||
document.Show();
|
||||
}
|
||||
}
|
||||
[Command]
|
||||
public void NewGroup() {
|
||||
RaiseCustomGroup();
|
||||
}
|
||||
[Command]
|
||||
public void GroupSelection() {
|
||||
RaiseCustomGroupFromSelection();
|
||||
}
|
||||
public bool CanGroupSelection() {
|
||||
return (Selection != null) && Selection.Any();
|
||||
}
|
||||
[Command]
|
||||
public void NewCustomFilter() {
|
||||
RaiseCustomFilter();
|
||||
}
|
||||
[Command]
|
||||
public void PrintProfile() {
|
||||
PrintCore(SelectedEntity, EmployeeReportType.Profile);
|
||||
}
|
||||
public bool CanPrintProfile() {
|
||||
return CanPrintProfileCore(SelectedEntity);
|
||||
}
|
||||
protected internal void PrintCore(Employee employee, EmployeeReportType reportType) {
|
||||
RaisePrint(reportType);
|
||||
}
|
||||
protected internal bool CanPrintProfileCore(Employee employee) {
|
||||
return employee != null;
|
||||
}
|
||||
static readonly string scheduler = "This demo does not include integration with our WinForms Scheduler Suite but you can easily introduce" + Environment.NewLine +
|
||||
"Outlook-inspired scheduling and task management capabilities to your apps with DevExpress Tools.";
|
||||
[Command]
|
||||
public void ShowMeeting() {
|
||||
SchedulerMessage("Meeting");
|
||||
}
|
||||
[Command]
|
||||
public void ShowTask() {
|
||||
SchedulerMessage("Tasks");
|
||||
}
|
||||
void SchedulerMessage(string caption) {
|
||||
MessageBoxService.Show(scheduler, caption, DevExpress.Mvvm.MessageButton.OK, DevExpress.Mvvm.MessageIcon.Information, DevExpress.Mvvm.MessageResult.OK);
|
||||
}
|
||||
[Command]
|
||||
public void PrintSummary() {
|
||||
RaisePrint(EmployeeReportType.Summary);
|
||||
}
|
||||
[Command]
|
||||
public void PrintDirectory() {
|
||||
RaisePrint(EmployeeReportType.Directory);
|
||||
}
|
||||
[Command]
|
||||
public void PrintTaskList() {
|
||||
RaisePrint(EmployeeReportType.TaskList);
|
||||
}
|
||||
[Command(UseCommandManager = false, CanExecuteMethodName = "CanPrintProfile")]
|
||||
public void MailMerge() {
|
||||
ShowDocument<EmployeeMailMergeViewModel>("MailMerge", null);
|
||||
}
|
||||
[Command]
|
||||
public void QuickLetter(EmployeeMailTemplate mailTemplate) {
|
||||
QuickLetterCore(SelectedEntity, mailTemplate);
|
||||
}
|
||||
public bool CanQuickLetter(EmployeeMailTemplate mailTemplate) {
|
||||
return CanQuickLetterCore(SelectedEntity, mailTemplate);
|
||||
}
|
||||
protected internal void QuickLetterCore(Employee employee, EmployeeMailTemplate mailTemplate) {
|
||||
ShowDocument<EmployeeMailMergeViewModel>("MailMerge", mailTemplate);
|
||||
}
|
||||
protected internal bool CanQuickLetterCore(Employee employee, EmployeeMailTemplate mailTemplate) {
|
||||
return employee != null;
|
||||
}
|
||||
[Command]
|
||||
public void ShowAllFolders() {
|
||||
RaiseShowAllFolders();
|
||||
}
|
||||
[Command]
|
||||
public void ResetCustomFilters() {
|
||||
RaiseCustomFiltersReset();
|
||||
}
|
||||
void RaisePrint(EmployeeReportType reportType) {
|
||||
MainViewModel mainViewModel = ViewModelHelper.GetParentViewModel<MainViewModel>(this);
|
||||
if(mainViewModel != null)
|
||||
mainViewModel.RaisePrint(reportType);
|
||||
}
|
||||
void RaiseShowAllFolders() {
|
||||
MainViewModel mainViewModel = ViewModelHelper.GetParentViewModel<MainViewModel>(this);
|
||||
if(mainViewModel != null)
|
||||
mainViewModel.RaiseShowAllFolders();
|
||||
}
|
||||
void RaiseReload() {
|
||||
EventHandler handler = Reload;
|
||||
if(handler != null)
|
||||
handler(this, EventArgs.Empty);
|
||||
}
|
||||
void RaiseCustomFilter() {
|
||||
EventHandler handler = CustomFilter;
|
||||
if(handler != null)
|
||||
handler(this, EventArgs.Empty);
|
||||
}
|
||||
void RaiseCustomFiltersReset() {
|
||||
EventHandler handler = CustomFiltersReset;
|
||||
if(handler != null)
|
||||
handler(this, EventArgs.Empty);
|
||||
}
|
||||
void RaiseCustomGroup() {
|
||||
EventHandler handler = CustomGroup;
|
||||
if(handler != null)
|
||||
handler(this, EventArgs.Empty);
|
||||
}
|
||||
void RaiseCustomGroupFromSelection() {
|
||||
EventHandler<GroupEventArgs<Employee>> handler = CustomGroupFromSelection;
|
||||
if(handler != null)
|
||||
handler(this, new GroupEventArgs<Employee>(Selection));
|
||||
}
|
||||
void ShowDocument<TViewModel>(string documentType, object parameter) {
|
||||
var document = FindDocument<TViewModel>();
|
||||
if(parameter is long)
|
||||
document = FindDocument<TViewModel>((long)parameter);
|
||||
if(document == null)
|
||||
document = DocumentManagerService.CreateDocument(documentType, null, parameter, this);
|
||||
else
|
||||
ViewModelHelper.EnsureViewModel(document.Content, this, parameter);
|
||||
document.Show();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
using System.Diagnostics;
|
||||
using DevExpress.DevAV.Common.ViewModel;
|
||||
using DevExpress.Mvvm;
|
||||
using DevExpress.Mvvm.DataAnnotations;
|
||||
using DevExpress.Mvvm.POCO;
|
||||
|
||||
namespace DevExpress.DevAV.ViewModels {
|
||||
public class EmployeeContactsViewModel : SingleObjectChildViewModel<Employee> {
|
||||
public new static EmployeeContactsViewModel Create() {
|
||||
return ViewModelSource.Create(() => new EmployeeContactsViewModel());
|
||||
}
|
||||
|
||||
public EmployeeContactsViewModel() { }
|
||||
|
||||
protected IMessageBoxService MessageBoxService { get { return this.GetRequiredService<IMessageBoxService>(); } }
|
||||
|
||||
[Command]
|
||||
public void Message() {
|
||||
MessageBoxService.Show("Send an IM to: " + Entity.Skype);
|
||||
}
|
||||
public bool CanMessage() {
|
||||
return Entity != null && !string.IsNullOrEmpty(Entity.Skype);
|
||||
}
|
||||
[Command]
|
||||
public void Phone() {
|
||||
MessageBoxService.Show("Phone Call: " + Entity.MobilePhone);
|
||||
}
|
||||
public bool CanPhone() {
|
||||
return Entity != null && !string.IsNullOrEmpty(Entity.MobilePhone);
|
||||
}
|
||||
[Command]
|
||||
public void HomeCall() {
|
||||
MessageBoxService.Show("Home Call: " + Entity.HomePhone);
|
||||
}
|
||||
public bool CanHomeCall() {
|
||||
return Entity != null && !string.IsNullOrEmpty(Entity.HomePhone);
|
||||
}
|
||||
[Command]
|
||||
public void MobileCall() {
|
||||
MessageBoxService.Show("Mobile Call: " + Entity.MobilePhone);
|
||||
}
|
||||
public bool CanMobileCall() {
|
||||
return Entity != null && !string.IsNullOrEmpty(Entity.MobilePhone);
|
||||
}
|
||||
[Command]
|
||||
public void Call() {
|
||||
MessageBoxService.Show("Call: " + Entity.Skype);
|
||||
}
|
||||
public bool CanCall() {
|
||||
return Entity != null && !string.IsNullOrEmpty(Entity.Skype);
|
||||
}
|
||||
[Command]
|
||||
public void VideoCall() {
|
||||
MessageBoxService.Show("Video Call: " + Entity.Skype);
|
||||
}
|
||||
public bool CanVideoCall() {
|
||||
return Entity != null && !string.IsNullOrEmpty(Entity.Skype);
|
||||
}
|
||||
[Command]
|
||||
public void MailTo() {
|
||||
ExecuteMailTo(MessageBoxService, Entity.Email);
|
||||
}
|
||||
public bool CanMailTo() {
|
||||
return Entity != null && !string.IsNullOrEmpty(Entity.Email);
|
||||
}
|
||||
protected override void OnEntityChanged() {
|
||||
base.OnEntityChanged();
|
||||
this.RaiseCanExecuteChanged(x => x.Message());
|
||||
this.RaiseCanExecuteChanged(x => x.Phone());
|
||||
this.RaiseCanExecuteChanged(x => x.MobileCall());
|
||||
this.RaiseCanExecuteChanged(x => x.HomeCall());
|
||||
this.RaiseCanExecuteChanged(x => x.Call());
|
||||
this.RaiseCanExecuteChanged(x => x.VideoCall());
|
||||
this.RaiseCanExecuteChanged(x => x.MailTo());
|
||||
}
|
||||
public static void ExecuteMailTo(IMessageBoxService messageBoxService, string email) {
|
||||
try {
|
||||
Process.Start("mailto://" + email);
|
||||
}
|
||||
catch {
|
||||
if(messageBoxService != null)
|
||||
messageBoxService.Show("Mail To: " + email);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
namespace DevExpress.DevAV.ViewModels {
|
||||
using DevExpress.DevAV.ViewModels;
|
||||
using DevExpress.Mvvm.POCO;
|
||||
|
||||
public class EmployeeMailMergeViewModel :
|
||||
MailMergeViewModelBase<EmployeeMailTemplate> {
|
||||
|
||||
public static EmployeeMailMergeViewModel Create() {
|
||||
return ViewModelSource.Create(() => new EmployeeMailMergeViewModel());
|
||||
}
|
||||
protected EmployeeMailMergeViewModel() { }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
namespace DevExpress.DevAV.ViewModels {
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using DevExpress.DevAV;
|
||||
using DevExpress.Mvvm.DataAnnotations;
|
||||
using DevExpress.Mvvm.POCO;
|
||||
using DevExpress.XtraMap;
|
||||
|
||||
public class EmployeeMapViewModel : EmployeeViewModel, IRouteMapViewModel {
|
||||
public virtual BingTravelMode TravelMode { get; set; }
|
||||
[Command]
|
||||
public void SetDrivingTravelMode() {
|
||||
TravelMode = BingTravelMode.Driving;
|
||||
}
|
||||
public bool CanSetDrivingTravelMode() {
|
||||
return TravelMode != BingTravelMode.Driving;
|
||||
}
|
||||
[Command]
|
||||
public void SetWalkingTravelMode() {
|
||||
TravelMode = BingTravelMode.Walking;
|
||||
}
|
||||
public bool CanSetWalkingTravelMode() {
|
||||
return TravelMode != BingTravelMode.Walking;
|
||||
}
|
||||
protected virtual void OnTravelModeChanged() {
|
||||
this.RaiseCanExecuteChanged(x => x.SetDrivingTravelMode());
|
||||
this.RaiseCanExecuteChanged(x => x.SetWalkingTravelMode());
|
||||
RaiseTravelModeChanged();
|
||||
}
|
||||
public event EventHandler TravelModeChanged;
|
||||
void RaiseTravelModeChanged() {
|
||||
EventHandler handler = TravelModeChanged;
|
||||
if(handler != null)
|
||||
handler(this, EventArgs.Empty);
|
||||
}
|
||||
[Command]
|
||||
public void SwapRoutePoints() {
|
||||
Address a = PointA;
|
||||
PointA = PointB;
|
||||
PointB = a;
|
||||
RaiseUpdateRoute();
|
||||
}
|
||||
public string FullName {
|
||||
get { return (Entity != null) ? Entity.FullNameBindable : null; }
|
||||
}
|
||||
public string AddressLine1 {
|
||||
get { return (Entity != null) ? Entity.Address.Line : null; }
|
||||
}
|
||||
public string AddressLine2 {
|
||||
get { return (Entity != null) ? Entity.Address.CityLine : null; }
|
||||
}
|
||||
public Image Picture {
|
||||
get { return (Entity != null) ? Entity.Photo : null; }
|
||||
}
|
||||
public string PointAAddress {
|
||||
get { return (PointA != null) ? PointA.ToString() : null; }
|
||||
}
|
||||
public string PointBAddress {
|
||||
get { return (PointB != null) ? PointB.ToString() : null; }
|
||||
}
|
||||
public virtual string RouteResult {
|
||||
get {
|
||||
return string.Format("{0:F1} mi, {1:hh\\:mm} min ", RouteDistance, RouteTime) +
|
||||
((TravelMode == BingTravelMode.Walking) ? "walking" : "driving");
|
||||
}
|
||||
}
|
||||
public virtual double RouteDistance { get; set; }
|
||||
protected virtual void OnRouteDistanceChanged() {
|
||||
this.RaisePropertyChanged(x => x.RouteResult);
|
||||
}
|
||||
public virtual TimeSpan RouteTime { get; set; }
|
||||
protected virtual void OnRouteTimeChanged() {
|
||||
this.RaisePropertyChanged(x => x.RouteResult);
|
||||
}
|
||||
protected override void OnEntityChanged() {
|
||||
PointA = AddressHelper.DevAVHomeOffice;
|
||||
PointB = (Entity != null) ? Entity.Address : AddressHelper.DevAVHomeOffice;
|
||||
this.RaisePropertyChanged(x => x.FullName);
|
||||
this.RaisePropertyChanged(x => x.Title);
|
||||
this.RaisePropertyChanged(x => x.PointA);
|
||||
this.RaisePropertyChanged(x => x.PointB);
|
||||
this.RaisePropertyChanged(x => x.AddressLine1);
|
||||
this.RaisePropertyChanged(x => x.AddressLine2);
|
||||
base.OnEntityChanged();
|
||||
}
|
||||
public virtual Address PointA { get; set; }
|
||||
protected virtual void OnPointAChanged() {
|
||||
this.RaisePropertyChanged(x => x.PointAAddress);
|
||||
RaisePointAChanged();
|
||||
}
|
||||
public virtual Address PointB { get; set; }
|
||||
protected virtual void OnPointBChanged() {
|
||||
this.RaisePropertyChanged(x => x.PointBAddress);
|
||||
RaisePointBChanged();
|
||||
}
|
||||
public event EventHandler PointAChanged;
|
||||
void RaisePointAChanged() {
|
||||
EventHandler handler = PointAChanged;
|
||||
if(handler != null)
|
||||
handler(this, EventArgs.Empty);
|
||||
}
|
||||
public event EventHandler PointBChanged;
|
||||
void RaisePointBChanged() {
|
||||
EventHandler handler = PointBChanged;
|
||||
if(handler != null)
|
||||
handler(this, EventArgs.Empty);
|
||||
}
|
||||
public event EventHandler UpdateRoute;
|
||||
void RaiseUpdateRoute() {
|
||||
EventHandler handler = UpdateRoute;
|
||||
if(handler != null)
|
||||
handler(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using DevExpress.Mvvm;
|
||||
using DevExpress.Mvvm.POCO;
|
||||
using DevExpress.DevAV.Common.Utils;
|
||||
using DevExpress.DevAV.DevAVDbDataModel;
|
||||
using DevExpress.Mvvm.DataModel;
|
||||
using DevExpress.DevAV;
|
||||
using DevExpress.DevAV.Common.ViewModel;
|
||||
|
||||
namespace DevExpress.DevAV.ViewModels {
|
||||
/// <summary>
|
||||
/// Represents the single Employee object view model.
|
||||
/// </summary>
|
||||
public partial class EmployeeViewModel : SingleObjectViewModel<Employee, long, IDevAVDbUnitOfWork> {
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of EmployeeViewModel as a POCO view model.
|
||||
/// </summary>
|
||||
/// <param name="unitOfWorkFactory">A factory used to create a unit of work instance.</param>
|
||||
public static EmployeeViewModel Create(IUnitOfWorkFactory<IDevAVDbUnitOfWork> unitOfWorkFactory = null) {
|
||||
return ViewModelSource.Create(() => new EmployeeViewModel(unitOfWorkFactory));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the EmployeeViewModel class.
|
||||
/// This constructor is declared protected to avoid undesired instantiation of the EmployeeViewModel type without the POCO proxy factory.
|
||||
/// </summary>
|
||||
/// <param name="unitOfWorkFactory">A factory used to create a unit of work instance.</param>
|
||||
protected EmployeeViewModel(IUnitOfWorkFactory<IDevAVDbUnitOfWork> unitOfWorkFactory = null)
|
||||
: base(unitOfWorkFactory ?? UnitOfWorkSource.GetUnitOfWorkFactory(), x => x.Employees, x => x.FullName) {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The view model that contains a look-up collection of Pictures for the corresponding navigation property in the view.
|
||||
/// </summary>
|
||||
public IEntitiesViewModel<Picture> LookUpPictures {
|
||||
get { return GetLookUpEntitiesViewModel((EmployeeViewModel x) => x.LookUpPictures, x => x.Pictures); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The view model that contains a look-up collection of Probations for the corresponding navigation property in the view.
|
||||
/// </summary>
|
||||
public IEntitiesViewModel<Probation> LookUpProbations {
|
||||
get { return GetLookUpEntitiesViewModel((EmployeeViewModel x) => x.LookUpProbations, x => x.Probations); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The view model for the EmployeeAssignedTasks detail collection.
|
||||
/// </summary>
|
||||
public CollectionViewModel<EmployeeTask, long, IDevAVDbUnitOfWork> EmployeeAssignedTasksDetails {
|
||||
get { return GetDetailsCollectionViewModel((EmployeeViewModel x) => x.EmployeeAssignedTasksDetails, x => x.Tasks, x => x.AssignedEmployeeId, (x, key) => x.AssignedEmployeeId = key); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The view model for the EmployeeOwnedTasks detail collection.
|
||||
/// </summary>
|
||||
public CollectionViewModel<EmployeeTask, long, IDevAVDbUnitOfWork> EmployeeOwnedTasksDetails {
|
||||
get { return GetDetailsCollectionViewModel((EmployeeViewModel x) => x.EmployeeOwnedTasksDetails, x => x.Tasks, x => x.OwnerId, (x, key) => x.OwnerId = key); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The view model for the EmployeeEvaluations detail collection.
|
||||
/// </summary>
|
||||
public CollectionViewModel<Evaluation, long, IDevAVDbUnitOfWork> EmployeeEvaluationsDetails {
|
||||
get { return GetDetailsCollectionViewModel((EmployeeViewModel x) => x.EmployeeEvaluationsDetails, x => x.Evaluations, x => x.EmployeeId, (x, key) => x.EmployeeId = key); }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
namespace DevExpress.DevAV.ViewModels {
|
||||
using System;
|
||||
using DevExpress.Mvvm.DataAnnotations;
|
||||
using DevExpress.Mvvm.POCO;
|
||||
|
||||
partial class EmployeeViewModel {
|
||||
public new bool IsNew() { return base.IsNew(); }
|
||||
EmployeeContactsViewModel contacts;
|
||||
public EmployeeContactsViewModel Contacts {
|
||||
get {
|
||||
if(contacts == null)
|
||||
contacts = EmployeeContactsViewModel.Create().SetParentViewModel(this);
|
||||
return contacts;
|
||||
}
|
||||
}
|
||||
protected override string GetTitle() {
|
||||
return Entity.FullName;
|
||||
}
|
||||
protected override void OnEntityChanged() {
|
||||
base.OnEntityChanged();
|
||||
Contacts.Entity = Entity;
|
||||
this.RaiseCanExecuteChanged(x => x.ShowMap());
|
||||
this.RaiseCanExecuteChanged(x => x.MailMerge());
|
||||
this.RaiseCanExecuteChanged(x => x.Print(EmployeeReportType.Profile));
|
||||
this.RaiseCanExecuteChanged(x => x.QuickLetter(EmployeeMailTemplate.ThankYouNote));
|
||||
EventHandler handler = EntityChanged;
|
||||
if(handler != null)
|
||||
handler(this, EventArgs.Empty);
|
||||
}
|
||||
public event EventHandler EntityChanged;
|
||||
[Command]
|
||||
public void QuickLetter(EmployeeMailTemplate mailTemplate) {
|
||||
EmployeeCollectionViewModel collectionViewModel = ViewModelHelper.GetParentViewModel<EmployeeCollectionViewModel>(this);
|
||||
if(collectionViewModel != null)
|
||||
collectionViewModel.QuickLetterCore(Entity, mailTemplate);
|
||||
}
|
||||
public bool CanQuickLetter(EmployeeMailTemplate mailTemplate) {
|
||||
if(Entity == null || IsNew()) return false;
|
||||
EmployeeCollectionViewModel collectionViewModel = ViewModelHelper.GetParentViewModel<EmployeeCollectionViewModel>(this);
|
||||
return (collectionViewModel != null) && collectionViewModel.CanQuickLetterCore(Entity, mailTemplate);
|
||||
}
|
||||
[Command]
|
||||
public void Print(EmployeeReportType reportType) {
|
||||
EmployeeCollectionViewModel collectionViewModel = ViewModelHelper.GetParentViewModel<EmployeeCollectionViewModel>(this);
|
||||
if(collectionViewModel != null)
|
||||
collectionViewModel.PrintCore(Entity, reportType);
|
||||
}
|
||||
public bool CanPrint(EmployeeReportType reportType) {
|
||||
if(Entity == null || IsNew()) return false;
|
||||
EmployeeCollectionViewModel collectionViewModel = ViewModelHelper.GetParentViewModel<EmployeeCollectionViewModel>(this);
|
||||
return (collectionViewModel != null) && collectionViewModel.CanPrintProfileCore(Entity);
|
||||
}
|
||||
[Command]
|
||||
public void MailMerge() {
|
||||
EmployeeCollectionViewModel collectionViewModel = ViewModelHelper.GetParentViewModel<EmployeeCollectionViewModel>(this);
|
||||
if(collectionViewModel != null)
|
||||
collectionViewModel.MailMerge();
|
||||
}
|
||||
public bool CanMailMerge() {
|
||||
return (Entity != null) && !IsNew();
|
||||
}
|
||||
[Command]
|
||||
public void ShowMap() {
|
||||
EmployeeCollectionViewModel collectionViewModel = ViewModelHelper.GetParentViewModel<EmployeeCollectionViewModel>(this);
|
||||
if(collectionViewModel != null)
|
||||
collectionViewModel.ShowMapCore(Entity);
|
||||
}
|
||||
public bool CanShowMap() {
|
||||
if(Entity == null || IsNew()) return false;
|
||||
EmployeeCollectionViewModel collectionViewModel = ViewModelHelper.GetParentViewModel<EmployeeCollectionViewModel>(this);
|
||||
return (collectionViewModel != null) && collectionViewModel.CanShowMapCore(Entity);
|
||||
}
|
||||
[Command]
|
||||
public void ShowMeeting() {
|
||||
EmployeeCollectionViewModel collectionViewModel = ViewModelHelper.GetParentViewModel<EmployeeCollectionViewModel>(this);
|
||||
if(collectionViewModel != null)
|
||||
collectionViewModel.ShowMeeting();
|
||||
}
|
||||
public bool CanShowMeeting() {
|
||||
return (Entity != null) && !IsNew();
|
||||
}
|
||||
[Command]
|
||||
public void ShowTask() {
|
||||
EmployeeCollectionViewModel collectionViewModel = ViewModelHelper.GetParentViewModel<EmployeeCollectionViewModel>(this);
|
||||
if(collectionViewModel != null)
|
||||
collectionViewModel.ShowTask();
|
||||
}
|
||||
public bool CanShowTask() {
|
||||
return (Entity != null) && !IsNew();
|
||||
}
|
||||
}
|
||||
public partial class SynchronizedEmployeeViewModel : EmployeeViewModel {
|
||||
protected override bool EnableSelectedItemSynchronization {
|
||||
get { return true; }
|
||||
}
|
||||
protected override bool EnableEntityChangedSynchronization {
|
||||
get { return true; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
namespace DevExpress.DevAV.ViewModels {
|
||||
using System;
|
||||
using DevExpress.DevAV;
|
||||
using DevExpress.DevAV.DevAVDbDataModel;
|
||||
using DevExpress.DevAV.ViewModels;
|
||||
using DevExpress.DevAV.Properties;
|
||||
using DevExpress.Mvvm.POCO;
|
||||
|
||||
public class EmployeesFilterTreeViewModel : FilterTreeViewModel<Employee, long, IDevAVDbUnitOfWork> {
|
||||
public static EmployeesFilterTreeViewModel Create(EmployeeCollectionViewModel collectionViewModel) {
|
||||
return ViewModelSource.Create(() => new EmployeesFilterTreeViewModel(collectionViewModel));
|
||||
}
|
||||
protected EmployeesFilterTreeViewModel(EmployeeCollectionViewModel collectionViewModel)
|
||||
: base(collectionViewModel, new FilterTreeModelPageSpecificSettings<Settings>(Settings.Default, StaticFiltersName, x => x.EmployeesStaticFilters, x => x.EmployeesCustomFilters, x => x.EmployeesGroupFilters)) {
|
||||
}
|
||||
protected new EmployeeCollectionViewModel CollectionViewModel {
|
||||
get { return base.CollectionViewModel as EmployeeCollectionViewModel; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
namespace DevExpress.DevAV.ViewModels {
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using DevExpress.DevAV;
|
||||
using DevExpress.DevAV.DevAVDbDataModel;
|
||||
using DevExpress.DevAV.ViewModels;
|
||||
using DevExpress.Mvvm.POCO;
|
||||
|
||||
public class EmployeesReportViewModel :
|
||||
ReportViewModelBase<EmployeeReportType, Employee, long, IDevAVDbUnitOfWork> {
|
||||
IDevAVDbUnitOfWork unitOfWork;
|
||||
|
||||
public static EmployeesReportViewModel Create() {
|
||||
return ViewModelSource.Create(() => new EmployeesReportViewModel());
|
||||
}
|
||||
protected EmployeesReportViewModel() {
|
||||
unitOfWork = UnitOfWorkSource.GetUnitOfWorkFactory().CreateUnitOfWork();
|
||||
}
|
||||
public IList<EmployeeTask> Tasks {
|
||||
get { return unitOfWork.Tasks.ToList(); }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace DevExpress.DevAV.ViewModels {
|
||||
public enum EmployeeMailTemplate {
|
||||
[Display(Name = "Employee of The Month")]
|
||||
EmployeeOfTheMonth,
|
||||
[Display(Name = "Probation Notice")]
|
||||
ProbationNotice,
|
||||
[Display(Name = "Service Excellence")]
|
||||
ServiceExcellence,
|
||||
[Display(Name = "Thank you note")]
|
||||
ThankYouNote,
|
||||
[Display(Name = "Welcome to DevAV")]
|
||||
WelcomeToDevAV
|
||||
}
|
||||
public static class EmployeeMailTemplateExtension {
|
||||
public static string ToFileName(this EmployeeMailTemplate mailTemplate) {
|
||||
switch(mailTemplate) {
|
||||
case EmployeeMailTemplate.ProbationNotice:
|
||||
return ("Employee Probation Notice");
|
||||
case EmployeeMailTemplate.ServiceExcellence:
|
||||
return ("Employee Service Excellence");
|
||||
case EmployeeMailTemplate.ThankYouNote:
|
||||
return ("Employee Thank You Note");
|
||||
case EmployeeMailTemplate.WelcomeToDevAV:
|
||||
return ("Welcome to DevAV");
|
||||
default:
|
||||
return ("Employee of the Month");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace DevExpress.DevAV.ViewModels {
|
||||
public enum EmployeeReportType {
|
||||
None,
|
||||
[Display(Name = "Profile Report")]
|
||||
Profile,
|
||||
[Display(Name = "Summary Report")]
|
||||
Summary,
|
||||
[Display(Name = "Employees Directory Report")]
|
||||
Directory,
|
||||
[Display(Name = "Task List Report")]
|
||||
TaskList
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,309 @@
|
||||
namespace DevExpress.DevAV.ViewModels {
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using DevExpress.Data.Filtering;
|
||||
using DevExpress.Mvvm.DataModel;
|
||||
using DevExpress.DevAV.Common.Utils;
|
||||
using DevExpress.DevAV.Common.ViewModel;
|
||||
using DevExpress.DevAV.ViewModels;
|
||||
using DevExpress.Mvvm;
|
||||
using DevExpress.Mvvm.DataAnnotations;
|
||||
using DevExpress.Mvvm.POCO;
|
||||
using System.Linq;
|
||||
using System.Collections.ObjectModel;
|
||||
using DevExpress.Data.Utils;
|
||||
using System.Linq.Expressions;
|
||||
|
||||
public class FilterTreeViewModel<TEntity, TPrimaryKey, TUnitOfWork> : FilterTreeViewModelBase
|
||||
where TEntity : class
|
||||
where TUnitOfWork : class, IUnitOfWork {
|
||||
|
||||
public const string StaticFiltersName = "Favorites";
|
||||
public const string CustomFiltersName = "Custom Filters";
|
||||
public const string GroupFiltersName = "Groups";
|
||||
|
||||
public FilterTreeViewModel(
|
||||
CollectionViewModel<TEntity, TPrimaryKey, TUnitOfWork> collectionViewModel,
|
||||
IFilterTreeModelPageSpecificSettings settings) :
|
||||
base(settings) {
|
||||
SetViewModel(collectionViewModel);
|
||||
ViewModelHelper.EnsureViewModel(this, collectionViewModel);
|
||||
Init();
|
||||
ISupportCustomFilters scf = collectionViewModel as ISupportCustomFilters;
|
||||
if(scf != null)
|
||||
scf.CustomFiltersReset += scf_CustomFiltersReset;
|
||||
}
|
||||
void scf_CustomFiltersReset(object sender, EventArgs e) {
|
||||
ResetCustomFilters();
|
||||
}
|
||||
protected internal CollectionViewModel<TEntity, TPrimaryKey, TUnitOfWork> CollectionViewModel {
|
||||
get { return (CollectionViewModel<TEntity, TPrimaryKey, TUnitOfWork>)ViewModel; }
|
||||
}
|
||||
protected virtual void OnSelectedItemChanged() {
|
||||
this.RaiseCanExecuteChanged(x => x.Select(null));
|
||||
RaiseSelectedItemChanged();
|
||||
ApplyFilter(SelectedItem);
|
||||
}
|
||||
public bool CanSelectModule(FilterItem item) {
|
||||
return SelectedItem != item;
|
||||
}
|
||||
[Command]
|
||||
public void Select(FilterItem item) {
|
||||
SelectedItem = item;
|
||||
}
|
||||
public event EventHandler SelectedItemChanged;
|
||||
void RaiseSelectedItemChanged() {
|
||||
if(SelectedItemChanged != null)
|
||||
SelectedItemChanged(this, EventArgs.Empty);
|
||||
}
|
||||
void ApplyFilter(FilterItemBase filterItem) {
|
||||
if(filterItem != null && !object.ReferenceEquals(filterItem.FilterCriteria, null))
|
||||
CollectionViewModel.FilterExpression = GetFilterExpression(filterItem);
|
||||
else
|
||||
CollectionViewModel.FilterExpression = null;
|
||||
}
|
||||
public event EventHandler FilterTreeChanged;
|
||||
void RaiseFilterTreeChanged() {
|
||||
if(FilterTreeChanged != null)
|
||||
FilterTreeChanged(this, EventArgs.Empty);
|
||||
}
|
||||
protected override FilterItemBase CreateFilterItem(string name, CriteriaOperator filterCriteria, string imageUri) {
|
||||
return FilterItem.Create(name, filterCriteria);
|
||||
}
|
||||
//
|
||||
[Command]
|
||||
public void New() {
|
||||
var newFilterItem = CreateFilterItem(null, null, null);
|
||||
CustomFilterViewModel viewModel = CreateCustomFilterViewModel<CustomFilterViewModel>(newFilterItem);
|
||||
if(ShowFilterDialog(viewModel, "Custom Filter")) {
|
||||
if(viewModel.Save) {
|
||||
AddNewCustomFilter(newFilterItem);
|
||||
RaiseFilterTreeChanged();
|
||||
}
|
||||
SelectedItem = newFilterItem;
|
||||
}
|
||||
}
|
||||
[Command]
|
||||
public void Modify(FilterItem item) {
|
||||
CustomFilterViewModel viewModel = CreateCustomFilterViewModel<CustomFilterViewModel>(item);
|
||||
if(ShowFilterDialog(viewModel, "Custom Filter")) {
|
||||
if(viewModel.Save) {
|
||||
SaveCustomFilters();
|
||||
RaiseFilterTreeChanged();
|
||||
}
|
||||
ApplyFilter(item);
|
||||
}
|
||||
}
|
||||
[Command]
|
||||
public void Delete(FilterItem item) {
|
||||
DeleteCustomFilter(item);
|
||||
RaiseFilterTreeChanged();
|
||||
if(SelectedItem == item)
|
||||
SelectedItem = null;
|
||||
}
|
||||
[Command]
|
||||
public void NewGroup() {
|
||||
NewGroupCore(CreateFilterItem(null, null, null));
|
||||
}
|
||||
[Command]
|
||||
public void NewGroupFromSelection(IEnumerable<TEntity> selection) {
|
||||
NewGroupCore(CreateFilterItem(null, CollectionViewModel.GetInOperator(selection), null));
|
||||
}
|
||||
|
||||
public virtual ObservableCollection<FilterItemBase> Groups { get; protected set; }
|
||||
public virtual void AddNewGroupFilter(FilterItemBase filterItem) {
|
||||
Groups.Add(filterItem);
|
||||
SaveGroupFilters();
|
||||
}
|
||||
public virtual void DeleteGroupFilter(FilterItemBase filterItem) {
|
||||
Groups.Remove(filterItem);
|
||||
SaveGroupFilters();
|
||||
}
|
||||
public virtual void ModifyGroupFilter(FilterItemBase filterItem) {
|
||||
SaveGroupFilters();
|
||||
}
|
||||
void SaveGroupFilters() {
|
||||
settings.GroupFilters = SaveToSettings(Groups);
|
||||
settings.Settings.Save();
|
||||
}
|
||||
|
||||
public override void Init() {
|
||||
Groups = CreateFilterItems(settings.GroupFilters);
|
||||
base.Init();
|
||||
}
|
||||
|
||||
void NewGroupCore(FilterItemBase newFilterItem) {
|
||||
GroupFilterViewModel viewModel = CreateCustomFilterViewModel<GroupFilterViewModel>(newFilterItem);
|
||||
if(ShowFilterDialog(viewModel, "Group Filter")) {
|
||||
if(viewModel.Save) {
|
||||
AddNewGroupFilter(newFilterItem);
|
||||
RaiseFilterTreeChanged();
|
||||
}
|
||||
SelectedItem = newFilterItem;
|
||||
}
|
||||
}
|
||||
[Command]
|
||||
public void ModifyGroup(FilterItem item) {
|
||||
GroupFilterViewModel viewModel = CreateCustomFilterViewModel<GroupFilterViewModel>(item);
|
||||
if(ShowFilterDialog(viewModel, "Group Filter")) {
|
||||
if(viewModel.Save) {
|
||||
ModifyGroupFilter(item);
|
||||
RaiseFilterTreeChanged();
|
||||
}
|
||||
ApplyFilter(item);
|
||||
}
|
||||
}
|
||||
[Command]
|
||||
public void DeleteGroup(FilterItem item) {
|
||||
DeleteGroupFilter(item);
|
||||
RaiseFilterTreeChanged();
|
||||
if(SelectedItem == item)
|
||||
SelectedItem = null;
|
||||
}
|
||||
public override void ResetCustomFilters() {
|
||||
base.ResetCustomFilters();
|
||||
RaiseFilterTreeChanged();
|
||||
}
|
||||
protected virtual T CreateCustomFilterViewModel<T>(FilterItemBase filterItem) where T : FilterViewModelBase, new() {
|
||||
T viewModel = ViewModelSource.Create<T>();
|
||||
ViewModelHelper.EnsureViewModel(viewModel, CollectionViewModel, filterItem);
|
||||
return viewModel;
|
||||
}
|
||||
bool ShowFilterDialog(FilterViewModelBase viewModel, string key) {
|
||||
var service = this.GetService<IDocumentManagerService>(key);
|
||||
if(service != null) {
|
||||
var document = service.CreateDocument(key, viewModel, null, CollectionViewModel);
|
||||
viewModel.Document = document;
|
||||
document.Show();
|
||||
return viewModel.Result.GetValueOrDefault();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
protected virtual bool EnableGroups {
|
||||
get { return true; }
|
||||
}
|
||||
public string GetFilterName(object filtersCollection, FilterItemBase filter) {
|
||||
if(filter != null) {
|
||||
var count = CollectionViewModel.GetEntities(GetFilterExpression(filter)).Count();
|
||||
if(count > 0)
|
||||
return filter.Name + " (" + count + ")";
|
||||
else
|
||||
return filter.Name;
|
||||
}
|
||||
else {
|
||||
if(object.Equals(filtersCollection, StaticFilters))
|
||||
return StaticFiltersName;
|
||||
if(object.Equals(filtersCollection, CustomFilters))
|
||||
return CustomFiltersName;
|
||||
if(object.Equals(filtersCollection, Groups))
|
||||
return GroupFiltersName;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public IList GetСhildren(object dataItem) {
|
||||
if(dataItem == this) {
|
||||
if(EnableGroups)
|
||||
return (IList)(new List<object> { StaticFilters, CustomFilters, Groups });
|
||||
else
|
||||
return (IList)(new List<object> { StaticFilters, CustomFilters });
|
||||
}
|
||||
if(dataItem is System.Collections.ObjectModel.ObservableCollection<FilterItemBase>)
|
||||
return (IList)dataItem;
|
||||
return null;
|
||||
}
|
||||
internal static Expression<Func<TEntity, bool>> GetFilterExpression(CriteriaOperator criteria) {
|
||||
try {
|
||||
return CriteriaOperatorToExpressionConverter.GetGenericWhere<TEntity>(criteria);
|
||||
}
|
||||
catch(Exception e) {
|
||||
throw new NotSupportedException("Error in Filter:" + CriteriaOperator.ToString(criteria), e);
|
||||
}
|
||||
}
|
||||
static Expression<Func<TEntity, bool>> GetFilterExpression(FilterItemBase filter) {
|
||||
return GetFilterExpression(filter.FilterCriteria);
|
||||
}
|
||||
#region Filter Item ViewModels
|
||||
public class FilterItem : FilterItemBase {
|
||||
public static FilterItem Create(string name, CriteriaOperator filterCriteria) {
|
||||
return ViewModelSource.Create(() => new FilterItem(name, filterCriteria));
|
||||
}
|
||||
protected FilterItem(string name, CriteriaOperator filterCriteria) {
|
||||
this.Name = name;
|
||||
this.FilterCriteria = filterCriteria;
|
||||
}
|
||||
}
|
||||
#endregion Items
|
||||
}
|
||||
#region Custom Filter ViewModel
|
||||
[POCOViewModelAttribute(ImplementIDataErrorInfo = true)]
|
||||
public abstract class FilterViewModelBase : ISupportParameter {
|
||||
public FilterViewModelBase() {
|
||||
Save = true;
|
||||
}
|
||||
FilterItemBase filterItem;
|
||||
public IDocument Document { get; set; }
|
||||
public bool? Result { get; private set; }
|
||||
public virtual bool Save { get; set; }
|
||||
[Required]
|
||||
public virtual string Name { get; set; }
|
||||
public CriteriaOperator FilterCriteria {
|
||||
get { return filterItem.FilterCriteria; }
|
||||
}
|
||||
public event EventHandler<QueryFilterCriteriaEventArgs> QueryFilterCriteria;
|
||||
void RaiseQueryFilterCriteria() {
|
||||
EventHandler<QueryFilterCriteriaEventArgs> handler = QueryFilterCriteria;
|
||||
if(handler != null)
|
||||
handler(this, new QueryFilterCriteriaEventArgs(filterItem));
|
||||
}
|
||||
protected IMessageBoxService MessageBoxService { get { return this.GetService<IMessageBoxService>(); } }
|
||||
protected abstract string GetDefaultName();
|
||||
//
|
||||
[Command]
|
||||
public void OK() {
|
||||
Result = true;
|
||||
if(string.IsNullOrEmpty(Name))
|
||||
Name = GetDefaultName();
|
||||
if(Save)
|
||||
filterItem.Name = Name;
|
||||
RaiseQueryFilterCriteria();
|
||||
Document.Close();
|
||||
}
|
||||
[Command]
|
||||
public void Cancel() {
|
||||
Result = false;
|
||||
Document.Close();
|
||||
}
|
||||
object ISupportParameter.Parameter {
|
||||
get { return filterItem; }
|
||||
set {
|
||||
filterItem = (FilterItemBase)value;
|
||||
Name = filterItem.Name;
|
||||
}
|
||||
}
|
||||
}
|
||||
public class QueryFilterCriteriaEventArgs : EventArgs {
|
||||
FilterItemBase item;
|
||||
public QueryFilterCriteriaEventArgs(FilterItemBase item) {
|
||||
this.item = item;
|
||||
}
|
||||
public CriteriaOperator FilterCriteria {
|
||||
get { return item.FilterCriteria; }
|
||||
set { item.FilterCriteria = value; }
|
||||
}
|
||||
}
|
||||
public class CustomFilterViewModel : FilterViewModelBase {
|
||||
static int id = 0;
|
||||
protected override string GetDefaultName() {
|
||||
return "Custom Filter " + (id++).ToString();
|
||||
}
|
||||
}
|
||||
public class GroupFilterViewModel : FilterViewModelBase {
|
||||
static int id = 0;
|
||||
protected override string GetDefaultName() {
|
||||
return "Group " + (id++).ToString();
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,168 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Xml;
|
||||
using System.Xml.Serialization;
|
||||
using DevExpress.Data.Filtering;
|
||||
using System.Windows.Media;
|
||||
using System.Configuration;
|
||||
using System.Linq.Expressions;
|
||||
using System.ComponentModel;
|
||||
using DevExpress.Mvvm;
|
||||
|
||||
namespace DevExpress.DevAV.ViewModels {
|
||||
public abstract class FilterItemBase {
|
||||
protected FilterItemBase() { }
|
||||
public virtual string Name { get; set; }
|
||||
public virtual CriteriaOperator FilterCriteria { get; set; }
|
||||
}
|
||||
public interface IFilterTreeModelPageSpecificSettings {
|
||||
string StaticFiltersTitle { get; }
|
||||
FilterInfoList StaticFilters { get; set; }
|
||||
FilterInfoList CustomFilters { get; set; }
|
||||
FilterInfoList GroupFilters { get; set; }
|
||||
ApplicationSettingsBase Settings { get; }
|
||||
IEnumerable<string> HiddenFilterProperties { get; }
|
||||
IEnumerable<string> AdditionalFilterProperties { get; }
|
||||
}
|
||||
|
||||
public class FilterTreeModelPageSpecificSettings<TSettings> : IFilterTreeModelPageSpecificSettings where TSettings : ApplicationSettingsBase {
|
||||
readonly string staticFiltersTitle;
|
||||
readonly TSettings settings;
|
||||
readonly PropertyDescriptor customFiltersProperty;
|
||||
readonly PropertyDescriptor staticFiltersProperty;
|
||||
readonly PropertyDescriptor groupFiltersProperty;
|
||||
readonly IEnumerable<string> hiddenFilterProperties;
|
||||
readonly IEnumerable<string> additionalFilterProperties;
|
||||
|
||||
public FilterTreeModelPageSpecificSettings(TSettings settings, string staticFiltersTitle,
|
||||
Expression<Func<TSettings, FilterInfoList>> getStaticFiltersExpression, Expression<Func<TSettings, FilterInfoList>> getCustomFiltersExpression, Expression<Func<TSettings, FilterInfoList>> getGroupFiltersExpression,
|
||||
IEnumerable<string> hiddenFilterProperties = null, IEnumerable<string> additionalFilterProperties = null) {
|
||||
this.settings = settings;
|
||||
this.staticFiltersTitle = staticFiltersTitle;
|
||||
staticFiltersProperty = GetProperty(getStaticFiltersExpression);
|
||||
customFiltersProperty = GetProperty(getCustomFiltersExpression);
|
||||
groupFiltersProperty = GetProperty(getGroupFiltersExpression);
|
||||
this.hiddenFilterProperties = hiddenFilterProperties;
|
||||
this.additionalFilterProperties = additionalFilterProperties;
|
||||
}
|
||||
FilterInfoList IFilterTreeModelPageSpecificSettings.CustomFilters {
|
||||
get { return GetFilters(customFiltersProperty); }
|
||||
set { SetFilters(customFiltersProperty, value); }
|
||||
}
|
||||
FilterInfoList IFilterTreeModelPageSpecificSettings.StaticFilters {
|
||||
get { return GetFilters(staticFiltersProperty); }
|
||||
set { SetFilters(staticFiltersProperty, value); }
|
||||
}
|
||||
FilterInfoList IFilterTreeModelPageSpecificSettings.GroupFilters {
|
||||
get { return GetFilters(groupFiltersProperty); }
|
||||
set { SetFilters(groupFiltersProperty, value); }
|
||||
}
|
||||
ApplicationSettingsBase IFilterTreeModelPageSpecificSettings.Settings { get { return settings; } }
|
||||
string IFilterTreeModelPageSpecificSettings.StaticFiltersTitle { get { return staticFiltersTitle; } }
|
||||
IEnumerable<string> IFilterTreeModelPageSpecificSettings.HiddenFilterProperties { get { return hiddenFilterProperties; } }
|
||||
IEnumerable<string> IFilterTreeModelPageSpecificSettings.AdditionalFilterProperties { get { return additionalFilterProperties; } }
|
||||
|
||||
PropertyDescriptor GetProperty(Expression<Func<TSettings, FilterInfoList>> expression) {
|
||||
if(expression != null)
|
||||
return TypeDescriptor.GetProperties(settings)[GetPropertyName(expression)];
|
||||
return null;
|
||||
}
|
||||
FilterInfoList GetFilters(PropertyDescriptor property) {
|
||||
return property != null ? (FilterInfoList)property.GetValue(settings) : null;
|
||||
}
|
||||
void SetFilters(PropertyDescriptor property, FilterInfoList value) {
|
||||
if(property != null)
|
||||
property.SetValue(settings, value);
|
||||
}
|
||||
static string GetPropertyName(Expression<Func<TSettings, FilterInfoList>> expression) {
|
||||
MemberExpression memberExpression = expression.Body as MemberExpression;
|
||||
if(memberExpression == null) {
|
||||
throw new ArgumentException("expression");
|
||||
}
|
||||
return memberExpression.Member.Name;
|
||||
}
|
||||
}
|
||||
|
||||
public class FilterInfo {
|
||||
public string Name { get; set; }
|
||||
public string FilterCriteria { get; set; }
|
||||
public string ImageUri { get; set; }
|
||||
}
|
||||
public class FilterInfoList : List<FilterInfo> {
|
||||
public FilterInfoList() { }
|
||||
public FilterInfoList(IEnumerable<FilterInfo> filters)
|
||||
: base(filters) {
|
||||
}
|
||||
}
|
||||
public abstract class FilterTreeViewModelBase {
|
||||
static FilterTreeViewModelBase() {
|
||||
var enums = typeof(EmployeeStatus).Assembly.GetTypes().Where(t => t.IsEnum);
|
||||
foreach(Type e in enums)
|
||||
EnumProcessingHelper.RegisterEnum(e);
|
||||
}
|
||||
protected IFilterTreeModelPageSpecificSettings settings;
|
||||
public FilterTreeViewModelBase(IFilterTreeModelPageSpecificSettings settings) {
|
||||
this.settings = settings;
|
||||
}
|
||||
public virtual void Init() {
|
||||
StaticFilters = CreateFilterItems(settings.StaticFilters);
|
||||
CustomFilters = CreateFilterItems(settings.CustomFilters);
|
||||
SelectedItem = StaticFilters.FirstOrDefault();
|
||||
}
|
||||
|
||||
public virtual ObservableCollection<FilterItemBase> StaticFilters { get; protected set; }
|
||||
public virtual ObservableCollection<FilterItemBase> CustomFilters { get; protected set; }
|
||||
public virtual FilterItemBase SelectedItem { get; set; }
|
||||
|
||||
protected void AddNewCustomFilter(FilterItemBase filterItem) {
|
||||
var existing = CustomFilters.FirstOrDefault(fi => fi.Name == filterItem.Name);
|
||||
if(existing != null) {
|
||||
CustomFilters.Remove(existing);
|
||||
}
|
||||
CustomFilters.Add(filterItem);
|
||||
SaveCustomFilters();
|
||||
}
|
||||
|
||||
public virtual void DeleteCustomFilter(FilterItemBase filterItem) {
|
||||
CustomFilters.Remove(filterItem);
|
||||
SaveCustomFilters();
|
||||
}
|
||||
|
||||
public virtual void DuplicateFilter(FilterItemBase filterItem) {
|
||||
var newItem = CreateFilterItem("Copy of " + filterItem.Name, filterItem.FilterCriteria, null);
|
||||
CustomFilters.Add(newItem);
|
||||
SaveCustomFilters();
|
||||
}
|
||||
public virtual void ResetCustomFilters() {
|
||||
if(CustomFilters.Contains(SelectedItem))
|
||||
SelectedItem = null;
|
||||
settings.CustomFilters = new FilterInfoList();
|
||||
CustomFilters.Clear();
|
||||
settings.Settings.Save();
|
||||
}
|
||||
|
||||
protected ObservableCollection<FilterItemBase> CreateFilterItems(IEnumerable<FilterInfo> filters) {
|
||||
if(filters == null)
|
||||
return new ObservableCollection<FilterItemBase>();
|
||||
return new ObservableCollection<FilterItemBase>(filters.Select(x => CreateFilterItem(x.Name, CriteriaOperator.Parse(x.FilterCriteria), x.ImageUri)));
|
||||
}
|
||||
|
||||
protected abstract FilterItemBase CreateFilterItem(string name, CriteriaOperator filterCriteria, string imageUri);
|
||||
|
||||
protected void SaveCustomFilters() {
|
||||
settings.CustomFilters = SaveToSettings(CustomFilters);
|
||||
settings.Settings.Save();
|
||||
}
|
||||
protected FilterInfoList SaveToSettings(ObservableCollection<FilterItemBase> filters) {
|
||||
return new FilterInfoList(filters.Select(fi => new FilterInfo { Name = fi.Name, FilterCriteria = CriteriaOperator.ToString(fi.FilterCriteria) }));
|
||||
}
|
||||
protected object ViewModel { get; private set; }
|
||||
public virtual void SetViewModel(object viewModel) {
|
||||
ViewModel = viewModel;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
namespace DevExpress.DevAV {
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using DevExpress.DevAV;
|
||||
using DevExpress.Map;
|
||||
using DevExpress.Mvvm;
|
||||
using DevExpress.DevAV.Modules;
|
||||
using DevExpress.XtraMap;
|
||||
|
||||
public static class ViewModelHelper {
|
||||
public static TViewModel GetParentViewModel<TViewModel>(object viewModel) {
|
||||
ISupportParentViewModel parentViewModelSupport = viewModel as ISupportParentViewModel;
|
||||
if(parentViewModelSupport != null)
|
||||
return (TViewModel)parentViewModelSupport.ParentViewModel;
|
||||
return default(TViewModel);
|
||||
}
|
||||
public static void EnsureModuleViewModel(object module, object parentViewModel, object parameter = null) {
|
||||
ISupportViewModel vm = module as ISupportViewModel;
|
||||
if(vm != null) {
|
||||
object oldParentViewModel = null;
|
||||
ISupportParentViewModel parentViewModelSupport = vm.ViewModel as ISupportParentViewModel;
|
||||
if(parentViewModelSupport != null)
|
||||
oldParentViewModel = parentViewModelSupport.ParentViewModel;
|
||||
EnsureViewModel(vm.ViewModel, parentViewModel, parameter);
|
||||
if(oldParentViewModel != parentViewModel)
|
||||
vm.ParentViewModelAttached();
|
||||
}
|
||||
}
|
||||
public static void EnsureViewModel(object viewModel, object parentViewModel, object parameter = null) {
|
||||
ISupportParentViewModel parentViewModelSupport = viewModel as ISupportParentViewModel;
|
||||
if(parentViewModelSupport != null)
|
||||
parentViewModelSupport.ParentViewModel = parentViewModel;
|
||||
ISupportParameter parameterSupport = viewModel as ISupportParameter;
|
||||
if(parameterSupport != null && parameter != null)
|
||||
parameterSupport.Parameter = parameter;
|
||||
}
|
||||
}
|
||||
public static class AddressExtension {
|
||||
public static GeoPoint ToGeoPoint(this Address address) {
|
||||
return (address != null) ? new GeoPoint(address.Latitude, address.Longitude) : null;
|
||||
}
|
||||
public static void ZoomTo(this DevExpress.XtraMap.Services.IZoomToRegionService zoomService, IEnumerable<Address> addresses, double margin = 0.25) {
|
||||
GeoPoint ptA = null;
|
||||
GeoPoint ptB = null;
|
||||
foreach(var address in addresses) {
|
||||
if(ptA == null) {
|
||||
ptA = address.ToGeoPoint();
|
||||
ptB = address.ToGeoPoint();
|
||||
continue;
|
||||
}
|
||||
GeoPoint pt = address.ToGeoPoint();
|
||||
if(pt == null || object.Equals(pt, new GeoPoint(0,0)))
|
||||
continue;
|
||||
ptA.Latitude = Math.Min(ptA.Latitude, pt.Latitude);
|
||||
ptA.Longitude = Math.Min(ptA.Longitude, pt.Longitude);
|
||||
ptB.Latitude = Math.Max(ptB.Latitude, pt.Latitude);
|
||||
ptB.Longitude = Math.Max(ptB.Longitude, pt.Longitude);
|
||||
}
|
||||
ZoomCore(zoomService, ptA, ptB, margin);
|
||||
}
|
||||
public static void ZoomTo(this DevExpress.XtraMap.Services.IZoomToRegionService zoomService, Address pointA, Address pointB, double margin = 0.2) {
|
||||
ZoomCore(zoomService, pointA.ToGeoPoint(), pointB.ToGeoPoint(), margin);
|
||||
}
|
||||
static void ZoomCore(DevExpress.XtraMap.Services.IZoomToRegionService zoomService, GeoPoint ptA, GeoPoint ptB, double margin) {
|
||||
if(ptA == null || ptB == null || zoomService == null) return;
|
||||
double latPadding = CalculatePadding(ptB.Latitude - ptA.Latitude, margin);
|
||||
double longPadding = CalculatePadding(ptB.Longitude - ptA.Longitude, margin);
|
||||
zoomService.ZoomToRegion(
|
||||
new GeoPoint(ptA.Latitude - latPadding, ptA.Longitude - longPadding),
|
||||
new GeoPoint(ptB.Latitude + latPadding, ptB.Longitude + longPadding),
|
||||
new GeoPoint(0.5 * (ptA.Latitude + ptB.Latitude), 0.5 * (ptA.Longitude + ptB.Longitude)));
|
||||
}
|
||||
static double CalculatePadding(double delta, double margin) {
|
||||
if(delta > 0)
|
||||
return Math.Max(0.1, delta * margin);
|
||||
if(delta < 0)
|
||||
return Math.Min(-0.1, delta * margin);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
public static class MapControlExtension {
|
||||
public static void Export(this MapControl mapControl, string path) {
|
||||
mapControl.ExportToImage(path, System.Drawing.Imaging.ImageFormat.Png);
|
||||
AppHelper.ProcessStart(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,149 @@
|
||||
namespace DevExpress.DevAV {
|
||||
using System;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
public enum ModuleType {
|
||||
Unknown,
|
||||
[Display(Name = "Employees")]
|
||||
Employees,
|
||||
EmployeesFilterPane,
|
||||
EmployeesFilterPaneCollapsed,
|
||||
EmployeesPeek,
|
||||
EmployeeView,
|
||||
[Display(Name = "Edit Contact")]
|
||||
EmployeeEditView,
|
||||
[Display(Name = "Contact Map")]
|
||||
EmployeeMapView,
|
||||
EmployeesCustomFilter,
|
||||
EmployeesGroupFilter,
|
||||
EmployeesExport,
|
||||
EmployeesPrint,
|
||||
[Display(Name = "Contact Mail Merge")]
|
||||
EmployeeMailMerge,
|
||||
[Display(Name = "Customers")]
|
||||
Customers,
|
||||
CustomersFilterPane,
|
||||
CustomersFilterPaneCollapsed,
|
||||
CustomersPeek,
|
||||
CustomerView,
|
||||
CustomerEditView,
|
||||
[Display(Name = "Sales Map")]
|
||||
CustomerMapView,
|
||||
[Display(Name = "Sales Analysis")]
|
||||
CustomerAnalysis,
|
||||
CustomersCustomFilter,
|
||||
CustomersGroupFilter,
|
||||
CustomersExport,
|
||||
CustomersPrint,
|
||||
[Display(Name = "Products")]
|
||||
Products,
|
||||
ProductsFilterPane,
|
||||
ProductsFilterPaneCollapsed,
|
||||
ProductsPeek,
|
||||
ProductView,
|
||||
ProductEditView,
|
||||
[Display(Name = "Sales Map")]
|
||||
ProductMapView,
|
||||
[Display(Name = "Sales Analysis")]
|
||||
ProductAnalysis,
|
||||
ProductsCustomFilter,
|
||||
ProductsGroupFilter,
|
||||
ProductsExport,
|
||||
ProductsPrint,
|
||||
[Display(Name = "Sales")]
|
||||
Orders,
|
||||
OrdersFilterPane,
|
||||
OrdersFilterPaneCollapsed,
|
||||
OrdersCustomFilter,
|
||||
OrdersPeek,
|
||||
OrderView,
|
||||
[Display(Name = "Edit Order")]
|
||||
OrderEditView,
|
||||
[Display(Name = "Shipping Map")]
|
||||
OrderMapView,
|
||||
OrdersExport,
|
||||
OrdersPrint,
|
||||
[Display(Name = "Sales Mail Merge")]
|
||||
OrderMailMerge,
|
||||
[Display(Name = "Invoice (PDF)")]
|
||||
OrderPdfQuickReportView,
|
||||
[Display(Name = "Invoice (DOC)")]
|
||||
OrderDocQuickReportView,
|
||||
[Display(Name = "Invoice (XLS)")]
|
||||
OrderXlsQuickReportView,
|
||||
[Display(Name = "Sales Report")]
|
||||
OrderRevenueView,
|
||||
[Display(Name = "Opportunities")]
|
||||
Quotes,
|
||||
QuotesFilterPane,
|
||||
QuotesFilterPaneCollapsed,
|
||||
QuotesCustomFilter,
|
||||
QuotesPeek,
|
||||
QuoteView,
|
||||
QuoteEditView,
|
||||
[Display(Name = "Opportunities Map")]
|
||||
QuoteMapView,
|
||||
QuotesExport,
|
||||
QuotesPrint,
|
||||
}
|
||||
//
|
||||
public interface IMainModule : IPeekModulesHost,
|
||||
ISupportModuleLayout, ISupportTransitions {
|
||||
}
|
||||
public interface ISupportCompactLayout {
|
||||
bool Compact { get; set; }
|
||||
}
|
||||
public interface ISupportZoom {
|
||||
int ZoomLevel { get; set; }
|
||||
event EventHandler ZoomChanged;
|
||||
}
|
||||
public interface ISupportTransitions {
|
||||
void StartTransition(bool forward, object waitParameter);
|
||||
void EndTransition();
|
||||
}
|
||||
public interface ISupportModuleLayout {
|
||||
void SaveLayoutToStream(System.IO.MemoryStream ms);
|
||||
void RestoreLayoutFromStream(System.IO.MemoryStream ms);
|
||||
}
|
||||
public interface IPeekModulesHost {
|
||||
bool IsDocked(ModuleType type);
|
||||
void DockModule(ModuleType moduleType);
|
||||
void UndockModule(ModuleType moduleType);
|
||||
void ShowPeek(ModuleType moduleType);
|
||||
}
|
||||
public interface ISupportMap {
|
||||
void ShowMap();
|
||||
bool CanShowMap();
|
||||
}
|
||||
public interface ISupportAnalysis {
|
||||
void ShowAnalysis();
|
||||
}
|
||||
public interface IZoomViewModel {
|
||||
object ZoomModule { get; }
|
||||
event EventHandler ZoomModuleChanged;
|
||||
}
|
||||
public interface ISupportModifications {
|
||||
bool Modified { get; }
|
||||
void Save();
|
||||
}
|
||||
public interface ISupportCustomFilters {
|
||||
void ResetCustomFilters();
|
||||
event EventHandler CustomFiltersReset;
|
||||
}
|
||||
public interface IRouteMapViewModel {
|
||||
DevExpress.XtraMap.BingTravelMode TravelMode { get; set; }
|
||||
Address PointA { get; set; }
|
||||
Address PointB { get; set; }
|
||||
double RouteDistance { get; set; }
|
||||
TimeSpan RouteTime { get; set; }
|
||||
//
|
||||
event EventHandler TravelModeChanged;
|
||||
event EventHandler PointAChanged;
|
||||
event EventHandler PointBChanged;
|
||||
event EventHandler UpdateRoute;
|
||||
}
|
||||
public interface ISalesMapViewModel {
|
||||
Period Period { get; set; }
|
||||
event EventHandler PeriodChanged;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
namespace DevExpress.DevAV.ViewModels {
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using DevExpress.Utils;
|
||||
|
||||
public static class MailMergeTemplatesHelper {
|
||||
static string[] templateNames = new string[] {
|
||||
"Employee of the Month.rtf",
|
||||
"Employee Probation Notice.rtf",
|
||||
"Employee Service Excellence.rtf",
|
||||
"Employee Thank You Note.rtf",
|
||||
"Welcome to DevAV.rtf"
|
||||
};
|
||||
public static List<TemplateViewModel> GetAllTemplates() {
|
||||
List<TemplateViewModel> templates = new List<TemplateViewModel>();
|
||||
foreach(var name in templateNames) {
|
||||
Stream stream = GetTemplateStream(name);
|
||||
templates.Add(new TemplateViewModel() {
|
||||
Name = name.Replace(".rtf", "")
|
||||
});
|
||||
}
|
||||
return templates;
|
||||
}
|
||||
public static Stream GetTemplateStream(string templateName) {
|
||||
return AssemblyHelper.GetEmbeddedResourceStream(typeof(MailMergeTemplatesHelper).Assembly, templateName, false);
|
||||
}
|
||||
}
|
||||
//
|
||||
public class TemplateViewModel {
|
||||
public string Name {
|
||||
get;
|
||||
set;
|
||||
}
|
||||
public Stream Template {
|
||||
get { return MailMergeTemplatesHelper.GetTemplateStream(Name + ".rtf"); }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
namespace DevExpress.DevAV.ViewModels {
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using DevExpress.Mvvm;
|
||||
using DevExpress.Mvvm.POCO;
|
||||
|
||||
public abstract class MailMergeViewModelBase<TMailTemplate> : ISupportParameter, IDocumentContent
|
||||
where TMailTemplate : struct {
|
||||
public virtual TMailTemplate? MailTemplate { get; set; }
|
||||
protected virtual void OnMailTemplateChanged() {
|
||||
RaiseMailTemplateChanged();
|
||||
}
|
||||
public virtual bool IsMailTemplateSelected { get; set; }
|
||||
protected virtual void OnIsMailTemplateSelectedChanged() {
|
||||
RaiseMailTemplateSelectedChanged();
|
||||
}
|
||||
object ISupportParameter.Parameter {
|
||||
get { return MailTemplate; }
|
||||
set {
|
||||
IsMailTemplateSelected = value is TMailTemplate;
|
||||
if(IsMailTemplateSelected)
|
||||
MailTemplate = (TMailTemplate)value;
|
||||
else MailTemplate = null;
|
||||
}
|
||||
}
|
||||
public event EventHandler MailTemplateChanged;
|
||||
public event EventHandler MailTemplateSelectedChanged;
|
||||
void RaiseMailTemplateChanged() {
|
||||
EventHandler handler = MailTemplateChanged;
|
||||
if(handler != null)
|
||||
handler(this, EventArgs.Empty);
|
||||
}
|
||||
void RaiseMailTemplateSelectedChanged() {
|
||||
EventHandler handler = MailTemplateSelectedChanged;
|
||||
if(handler != null)
|
||||
handler(this, EventArgs.Empty);
|
||||
}
|
||||
protected IMessageBoxService MessageBoxService { get { return this.GetService<IMessageBoxService>(); } }
|
||||
public bool Modified { get; set; }
|
||||
[DevExpress.Mvvm.DataAnnotations.Command]
|
||||
public bool Close() {
|
||||
MessageResult result = MessageResult.Yes;
|
||||
if(Modified) {
|
||||
if(MessageBoxService != null) {
|
||||
result = MessageBoxService.Show("Do you want to save changes?", "Mail Merge",
|
||||
MessageButton.YesNoCancel,
|
||||
MessageIcon.Question,
|
||||
MessageResult.Yes);
|
||||
if(result == MessageResult.Yes)
|
||||
RaiseSave();
|
||||
}
|
||||
}
|
||||
if(result != MessageResult.Cancel && DocumentOwner != null)
|
||||
DocumentOwner.Close(this);
|
||||
return result != MessageResult.Cancel;
|
||||
}
|
||||
public event EventHandler Save;
|
||||
void RaiseSave() {
|
||||
EventHandler handler = Save;
|
||||
if(handler != null)
|
||||
handler(this, EventArgs.Empty);
|
||||
}
|
||||
protected IDocumentOwner DocumentOwner { get; private set; }
|
||||
#region IDocumentContent
|
||||
object IDocumentContent.Title {
|
||||
get { return "Mail Merge"; }
|
||||
}
|
||||
void IDocumentContent.OnClose(CancelEventArgs e) {
|
||||
e.Cancel = !Close();
|
||||
}
|
||||
void IDocumentContent.OnDestroy() { }
|
||||
IDocumentOwner IDocumentContent.DocumentOwner {
|
||||
get { return DocumentOwner; }
|
||||
set { DocumentOwner = value; }
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,334 @@
|
||||
namespace DevExpress.DevAV.ViewModels {
|
||||
using System;
|
||||
using DevExpress.DevAV.Services;
|
||||
using DevExpress.Mvvm;
|
||||
using DevExpress.Mvvm.DataAnnotations;
|
||||
using DevExpress.Mvvm.POCO;
|
||||
|
||||
public class MainViewModel : IZoomViewModel {
|
||||
#region static
|
||||
static MainViewModel() {
|
||||
DevExpress.Mvvm.ServiceContainer.Default.RegisterService(new Services.ModuleResourceProvider());
|
||||
DevExpress.Mvvm.ServiceContainer.Default.RegisterService(new Services.ModuleTypesResolver());
|
||||
}
|
||||
#endregion static
|
||||
protected MainViewModel(IMainModule mainModule) {
|
||||
RegisterServices(mainModule);
|
||||
}
|
||||
void RegisterServices(IMainModule mainModule) {
|
||||
var mainModuleType = mainModule.GetType();
|
||||
ISupportServices localServices = (ISupportServices)this;
|
||||
localServices.ServiceContainer.RegisterService(new Services.WaitingService());
|
||||
localServices.ServiceContainer.RegisterService(new Services.ModuleActivator(mainModuleType.Assembly, mainModuleType.Namespace + ".Modules"));
|
||||
localServices.ServiceContainer.RegisterService(new Services.ReportActivator());
|
||||
localServices.ServiceContainer.RegisterService(new Services.ModuleLocator(localServices.ServiceContainer));
|
||||
localServices.ServiceContainer.RegisterService(new Services.ReportLocator(localServices.ServiceContainer));
|
||||
localServices.ServiceContainer.RegisterService(new Services.TransitionService(mainModule));
|
||||
localServices.ServiceContainer.RegisterService(new Services.PeekModulesHostingService(mainModule));
|
||||
localServices.ServiceContainer.RegisterService(new Services.WorkspaceService(mainModule));
|
||||
}
|
||||
#region Properties
|
||||
public virtual ModuleType SelectedModuleType {
|
||||
get;
|
||||
set;
|
||||
}
|
||||
public virtual object SelectedModule {
|
||||
get;
|
||||
set;
|
||||
}
|
||||
public ModuleType SelectedNavPaneModuleType {
|
||||
get { return GetNavPaneModuleType(SelectedModuleType); }
|
||||
}
|
||||
public ModuleType SelectedPeekModuleType {
|
||||
get { return GetPeekModuleType(SelectedModuleType); }
|
||||
}
|
||||
public ModuleType SelectedNavPaneHeaderModuleType {
|
||||
get { return GetNavPaneModuleType(SelectedModuleType, true); }
|
||||
}
|
||||
public ModuleType SelectedExportModuleType {
|
||||
get { return GetExportModuleType(SelectedModuleType); }
|
||||
}
|
||||
public ModuleType SelectedPrintModuleType {
|
||||
get { return GetPrintModuleType(SelectedModuleType); }
|
||||
}
|
||||
public object SelectedModuleViewModel {
|
||||
get { return ((Modules.ISupportViewModel)SelectedModule).ViewModel; }
|
||||
}
|
||||
#endregion Properties
|
||||
#region Commands
|
||||
public bool CanSelectModule(ModuleType moduleType) {
|
||||
return SelectedModuleType != moduleType;
|
||||
}
|
||||
[Command]
|
||||
public void SelectModule(ModuleType moduleType) {
|
||||
SelectedModuleType = moduleType;
|
||||
}
|
||||
public bool CanDockPeekModule(ModuleType moduleType) {
|
||||
var peekModuleType = GetPeekModuleType(moduleType);
|
||||
return !this.GetService<IPeekModulesHostingService>().IsDocked(peekModuleType);
|
||||
}
|
||||
[Command]
|
||||
public void DockPeekModule(ModuleType moduleType) {
|
||||
var peekModuleType = GetPeekModuleType(moduleType);
|
||||
this.GetService<IPeekModulesHostingService>().DockModule(peekModuleType);
|
||||
}
|
||||
public bool CanUndockPeekModule(ModuleType moduleType) {
|
||||
var peekModuleType = GetPeekModuleType(moduleType);
|
||||
return this.GetService<IPeekModulesHostingService>().IsDocked(peekModuleType);
|
||||
}
|
||||
[Command]
|
||||
public void UndockPeekModule(ModuleType moduleType) {
|
||||
var peekModuleType = GetPeekModuleType(moduleType);
|
||||
this.GetService<IPeekModulesHostingService>().UndockModule(peekModuleType);
|
||||
}
|
||||
public bool CanShowPeekModule(ModuleType moduleType) {
|
||||
var peekModuleType = GetPeekModuleType(moduleType);
|
||||
return !this.GetService<IPeekModulesHostingService>().IsDocked(peekModuleType);
|
||||
}
|
||||
[Command]
|
||||
public void ShowPeekModule(ModuleType moduleType) {
|
||||
var peekModuleType = GetPeekModuleType(moduleType);
|
||||
this.GetService<IPeekModulesHostingService>().ShowModule(peekModuleType);
|
||||
}
|
||||
[Command]
|
||||
public void GetStarted() {
|
||||
AppHelper.ProcessStart(AssemblyInfo.DXLinkGetStarted);
|
||||
}
|
||||
[Command]
|
||||
public void GetSupport() {
|
||||
AppHelper.ProcessStart(AssemblyInfo.DXLinkGetSupport);
|
||||
}
|
||||
[Command]
|
||||
public void BuyNow() {
|
||||
AppHelper.ProcessStart(AssemblyInfo.DXLinkBuyNow);
|
||||
}
|
||||
[Command]
|
||||
public void About() {
|
||||
DevExpress.Utils.About.AboutHelper.Show(DevExpress.Utils.About.ProductKind.DXperienceWin,
|
||||
new DevExpress.Utils.About.ProductStringInfoWin("Outlook Inspired App"));
|
||||
}
|
||||
#endregion
|
||||
#region FiltersVisibility
|
||||
public virtual bool IsReadingMode { get; set; }
|
||||
[Command]
|
||||
public void TurnOnReadingMode() {
|
||||
IsReadingMode = true;
|
||||
}
|
||||
public bool CanTurnOnReadingMode() {
|
||||
return !IsReadingMode;
|
||||
}
|
||||
[Command]
|
||||
public void TurnOffReadingMode() {
|
||||
IsReadingMode = false;
|
||||
}
|
||||
public bool CanTurnOffReadingMode() {
|
||||
return IsReadingMode;
|
||||
}
|
||||
public virtual CollectionViewFiltersVisibility FiltersVisibility { get; set; }
|
||||
[Command]
|
||||
public void ShowFilters() {
|
||||
FiltersVisibility = CollectionViewFiltersVisibility.Visible;
|
||||
}
|
||||
public bool CanShowFilters() {
|
||||
return FiltersVisibility != CollectionViewFiltersVisibility.Visible;
|
||||
}
|
||||
[Command]
|
||||
public void MinimizeFilters() {
|
||||
FiltersVisibility = CollectionViewFiltersVisibility.Minimized;
|
||||
}
|
||||
public bool CanMinimizeFilters() {
|
||||
return FiltersVisibility != CollectionViewFiltersVisibility.Minimized;
|
||||
}
|
||||
[Command]
|
||||
public void HideFilters() {
|
||||
FiltersVisibility = CollectionViewFiltersVisibility.Hidden;
|
||||
}
|
||||
public bool CanHideFilters() {
|
||||
return FiltersVisibility != CollectionViewFiltersVisibility.Hidden;
|
||||
}
|
||||
public event EventHandler IsReadingModeChanged;
|
||||
protected virtual void OnIsReadingModeChanged() {
|
||||
this.RaiseCanExecuteChanged(x => x.TurnOnReadingMode());
|
||||
this.RaiseCanExecuteChanged(x => x.TurnOffReadingMode());
|
||||
RaiseIsReadingModeChanged();
|
||||
}
|
||||
void RaiseIsReadingModeChanged() {
|
||||
EventHandler handler = IsReadingModeChanged;
|
||||
if(handler != null)
|
||||
handler(this, EventArgs.Empty);
|
||||
}
|
||||
public event EventHandler ViewFiltersVisibilityChanged;
|
||||
protected virtual void OnFiltersVisibilityChanged() {
|
||||
this.RaiseCanExecuteChanged(x => x.ShowFilters());
|
||||
this.RaiseCanExecuteChanged(x => x.MinimizeFilters());
|
||||
this.RaiseCanExecuteChanged(x => x.HideFilters());
|
||||
RaiseFiltersVisibilityChanged();
|
||||
}
|
||||
void RaiseFiltersVisibilityChanged() {
|
||||
EventHandler handler = ViewFiltersVisibilityChanged;
|
||||
if(handler != null)
|
||||
handler(this, EventArgs.Empty);
|
||||
}
|
||||
#endregion
|
||||
bool IsModuleLoaded(ModuleType type) {
|
||||
return this.GetService<Services.IModuleLocator>().IsModuleLoaded(type);
|
||||
}
|
||||
public object GetModule(ModuleType type) {
|
||||
return this.GetService<Services.IModuleLocator>().GetModule(type);
|
||||
}
|
||||
public object GetModule(ModuleType type, object viewModel) {
|
||||
return this.GetService<Services.IModuleLocator>().GetModule(type, viewModel);
|
||||
}
|
||||
public string GetModuleName(ModuleType type) {
|
||||
return this.GetService<Services.IModuleTypesResolver>().GetName(type);
|
||||
}
|
||||
public System.Guid GetModuleID(ModuleType type) {
|
||||
return this.GetService<Services.IModuleTypesResolver>().GetId(type);
|
||||
}
|
||||
public string GetModuleCaption(ModuleType type) {
|
||||
return this.GetService<Services.IModuleResourceProvider>().GetCaption(type);
|
||||
}
|
||||
public string GetModuleSmallImageUri(ModuleType type) {
|
||||
return this.GetService<Services.IModuleResourceProvider>().GetModuleImageUri(type, true);
|
||||
}
|
||||
public string GetModuleImageUri(ModuleType type) {
|
||||
return this.GetService<Services.IModuleResourceProvider>().GetModuleImageUri(type);
|
||||
}
|
||||
public ModuleType GetMainModuleType(ModuleType type) {
|
||||
return this.GetService<Services.IModuleTypesResolver>().GetMainModuleType(type);
|
||||
}
|
||||
public ModuleType GetNavPaneModuleType(ModuleType type, bool collapsed = false) {
|
||||
var resolver = this.GetService<Services.IModuleTypesResolver>();
|
||||
return collapsed ? resolver.GetNavPaneHeaderModuleType(type) : resolver.GetNavPaneModuleType(type);
|
||||
}
|
||||
public ModuleType GetPeekModuleType(ModuleType type) {
|
||||
return this.GetService<Services.IModuleTypesResolver>().GetPeekModuleType(type);
|
||||
}
|
||||
public ModuleType GetExportModuleType(ModuleType type) {
|
||||
return this.GetService<Services.IModuleTypesResolver>().GetExportModuleType(type);
|
||||
}
|
||||
public ModuleType GetPrintModuleType(ModuleType type) {
|
||||
return this.GetService<Services.IModuleTypesResolver>().GetPrintModuleType(type);
|
||||
}
|
||||
#region Selected Module
|
||||
protected virtual void OnSelectedModuleTypeChanged(ModuleType oldType) {
|
||||
var transitionService = this.GetService<Services.ITransitionService>();
|
||||
bool effective = (SelectedModuleType != ModuleType.Unknown) && (oldType != ModuleType.Unknown);
|
||||
object waitParameter = !IsModuleLoaded(SelectedModuleType) ? (object)SelectedModuleType : null;
|
||||
using(transitionService.EnterTransition(effective, ((int)SelectedModuleType > (int)oldType), waitParameter)) {
|
||||
var workspaceService = this.GetService<Services.IWorkspaceService>();
|
||||
var resolver = this.GetService<IModuleTypesResolver>();
|
||||
if(oldType != ModuleType.Unknown)
|
||||
workspaceService.SaveWorkspace(resolver.GetName(oldType));
|
||||
else
|
||||
workspaceService.SetupDefaultWorkspace();
|
||||
try {
|
||||
SelectedModule = GetModule(SelectedModuleType);
|
||||
RaiseSelectedModuleTypeChanged();
|
||||
}
|
||||
catch(Exception e) {
|
||||
var entryAsm = System.Reflection.Assembly.GetEntryAssembly();
|
||||
string msg = "Navigation Error: [" + oldType.ToString() + "=>" + SelectedModuleType.ToString() + Environment.NewLine +
|
||||
(entryAsm != null ? "StartUp:" + entryAsm.Location : string.Empty);
|
||||
throw new ApplicationException(msg, e);
|
||||
}
|
||||
if(SelectedModuleType != ModuleType.Unknown)
|
||||
workspaceService.RestoreWorkspace(resolver.GetName(SelectedModuleType));
|
||||
}
|
||||
}
|
||||
protected virtual void OnSelectedModuleChanged(object oldModule) {
|
||||
if(oldModule != null) {
|
||||
if(ModuleRemoved != null)
|
||||
ModuleRemoved(oldModule, EventArgs.Empty);
|
||||
}
|
||||
if(SelectedModuleChanged != null)
|
||||
SelectedModuleChanged(this, EventArgs.Empty);
|
||||
if(SelectedModule != null) {
|
||||
ViewModelHelper.EnsureModuleViewModel(SelectedModule, this);
|
||||
if(ModuleAdded != null)
|
||||
ModuleAdded(SelectedModule, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
protected virtual void RaiseSelectedModuleTypeChanged() {
|
||||
this.RaiseCanExecuteChanged(x => x.SelectModule(ModuleType.Unknown));
|
||||
this.RaisePropertyChanged(x => SelectedNavPaneModuleType);
|
||||
this.RaisePropertyChanged(x => SelectedNavPaneHeaderModuleType);
|
||||
if(SelectedModuleTypeChanged != null)
|
||||
SelectedModuleTypeChanged(this, EventArgs.Empty);
|
||||
}
|
||||
public event EventHandler ModuleAdded;
|
||||
public event EventHandler ModuleRemoved;
|
||||
public event EventHandler SelectedModuleChanged;
|
||||
public event EventHandler SelectedModuleTypeChanged;
|
||||
#endregion Selected Module
|
||||
#region Print & Reports
|
||||
public event EventHandler<PrintEventArgs> Print;
|
||||
public object ReportParameter { get; private set; }
|
||||
ModuleType currentReportModule;
|
||||
internal void BeforeReportShown(ModuleType moduleType) {
|
||||
if(ReportParameter != null)
|
||||
return;
|
||||
switch(moduleType) {
|
||||
case ModuleType.EmployeesExport:
|
||||
case ModuleType.EmployeesPrint:
|
||||
ReportParameter = EmployeeReportType.Profile;
|
||||
break;
|
||||
case ModuleType.CustomersExport:
|
||||
case ModuleType.CustomersPrint:
|
||||
ReportParameter = CustomerReportType.Profile;
|
||||
break;
|
||||
case ModuleType.ProductsExport:
|
||||
case ModuleType.ProductsPrint:
|
||||
ReportParameter = ProductReportType.OrderDetail;
|
||||
break;
|
||||
case ModuleType.OrdersExport:
|
||||
case ModuleType.OrdersPrint:
|
||||
ReportParameter = SalesReportType.Invoice;
|
||||
break;
|
||||
}
|
||||
}
|
||||
internal void AfterReportShown(ModuleType moduleType) {
|
||||
if(currentReportModule != moduleType) {
|
||||
bool reportChanged = currentReportModule != ModuleType.Unknown;
|
||||
this.currentReportModule = moduleType;
|
||||
if(reportChanged && moduleType != ModuleType.Unknown) {
|
||||
var reportViewModel = ((Modules.ISupportViewModel)GetModule(moduleType)).ViewModel as ReportViewModelBase;
|
||||
if(reportViewModel != null)
|
||||
reportViewModel.OnReload();
|
||||
}
|
||||
}
|
||||
}
|
||||
internal void AfterReportHidden() {
|
||||
this.currentReportModule = ModuleType.Unknown;
|
||||
ReportParameter = null;
|
||||
}
|
||||
internal void RaisePrint(object parameter) {
|
||||
ReportParameter = parameter;
|
||||
EventHandler<PrintEventArgs> handler = Print;
|
||||
if(handler != null)
|
||||
handler(this, new PrintEventArgs(parameter));
|
||||
}
|
||||
#endregion Print & Reports
|
||||
public event EventHandler ShowAllFolders;
|
||||
internal void RaiseShowAllFolders() {
|
||||
EventHandler handler = ShowAllFolders;
|
||||
if(handler != null)
|
||||
handler(this, EventArgs.Empty);
|
||||
}
|
||||
#region ISupportZoomModule Members
|
||||
object IZoomViewModel.ZoomModule {
|
||||
get { return SelectedModule; }
|
||||
}
|
||||
event EventHandler IZoomViewModel.ZoomModuleChanged {
|
||||
add { SelectedModuleChanged += value; }
|
||||
remove { SelectedModuleChanged -= value; }
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
public class PrintEventArgs : EventArgs {
|
||||
public PrintEventArgs(object parameter) {
|
||||
this.Parameter = parameter;
|
||||
}
|
||||
public object Parameter { get; private set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace DevExpress.DevAV.ViewModels {
|
||||
public abstract partial class MapViewModelBase {
|
||||
public const string WinBingKey = DevExpress.Map.Native.DXBingKeyVerifier.BingKeyWinOutlookInspiredApp;
|
||||
public const string WpfBingKey = DevExpress.Map.Native.DXBingKeyVerifier.BingKeyWpfOutlookInspiredApp;
|
||||
public virtual Address Address { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using DevExpress.Mvvm.POCO;
|
||||
using DevExpress.DevAV.Common.Utils;
|
||||
using DevExpress.DevAV.DevAVDbDataModel;
|
||||
using DevExpress.Mvvm.DataModel;
|
||||
using DevExpress.DevAV;
|
||||
using DevExpress.DevAV.Common.ViewModel;
|
||||
|
||||
namespace DevExpress.DevAV.ViewModels {
|
||||
/// <summary>
|
||||
/// Represents the Orders collection view model.
|
||||
/// </summary>
|
||||
public partial class OrderCollectionViewModel : CollectionViewModel<Order, long, IDevAVDbUnitOfWork> {
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of OrderCollectionViewModel as a POCO view model.
|
||||
/// </summary>
|
||||
/// <param name="unitOfWorkFactory">A factory used to create a unit of work instance.</param>
|
||||
public static OrderCollectionViewModel Create(IUnitOfWorkFactory<IDevAVDbUnitOfWork> unitOfWorkFactory = null) {
|
||||
return ViewModelSource.Create(() => new OrderCollectionViewModel(unitOfWorkFactory));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the OrderCollectionViewModel class.
|
||||
/// This constructor is declared protected to avoid undesired instantiation of the OrderCollectionViewModel type without the POCO proxy factory.
|
||||
/// </summary>
|
||||
/// <param name="unitOfWorkFactory">A factory used to create a unit of work instance.</param>
|
||||
protected OrderCollectionViewModel(IUnitOfWorkFactory<IDevAVDbUnitOfWork> unitOfWorkFactory = null)
|
||||
: base(unitOfWorkFactory ?? UnitOfWorkSource.GetUnitOfWorkFactory(), x => x.Orders, query => query.Include(x => x.Store).Include(x => x.Customer).ActualOrders().OrderBy(x => x.InvoiceNumber)) {
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,220 @@
|
||||
namespace DevExpress.DevAV.ViewModels {
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using DevExpress.DevAV;
|
||||
using DevExpress.DevAV.Common.ViewModel;
|
||||
using DevExpress.DevAV.DevAVDbDataModel;
|
||||
using DevExpress.Mvvm;
|
||||
using DevExpress.Mvvm.DataAnnotations;
|
||||
using DevExpress.Mvvm.POCO;
|
||||
|
||||
partial class OrderCollectionViewModel : ISupportMap, ISupportCustomFilters {
|
||||
public override void Refresh() {
|
||||
base.Refresh();
|
||||
RaiseReload();
|
||||
}
|
||||
protected override void OnSelectedEntityChanged() {
|
||||
base.OnSelectedEntityChanged();
|
||||
this.RaiseCanExecuteChanged(x => x.ShowMap());
|
||||
this.RaiseCanExecuteChanged(x => x.PrintInvoice());
|
||||
this.RaiseCanExecuteChanged(x => x.QuickReport(SalesReportType.Invoice));
|
||||
this.RaiseCanExecuteChanged(x => x.QuickReportFormat(ReportFormat.Doc));
|
||||
}
|
||||
public event EventHandler Reload;
|
||||
public event EventHandler CustomFilter;
|
||||
public event EventHandler CustomFiltersReset;
|
||||
[Command]
|
||||
public void ShowMap() {
|
||||
ShowMapCore(SelectedEntity);
|
||||
}
|
||||
public bool CanShowMap() {
|
||||
return CanShowMapCore(SelectedEntity);
|
||||
}
|
||||
protected internal void ShowMapCore(Order order) {
|
||||
ShowDocument<OrderMapViewModel>("MapView", order.Id);
|
||||
}
|
||||
protected internal bool CanShowMapCore(Order order) {
|
||||
return order != null;
|
||||
}
|
||||
[Command]
|
||||
public void ShowViewSettings() {
|
||||
var dms = this.GetService<IDocumentManagerService>("View Settings");
|
||||
if(dms != null) {
|
||||
var document = dms.Documents.FirstOrDefault(d => d.Content is ViewSettingsViewModel);
|
||||
if(document == null)
|
||||
document = dms.CreateDocument("View Settings", null, null, this);
|
||||
document.Show();
|
||||
}
|
||||
}
|
||||
[Command]
|
||||
public void NewCustomFilter() {
|
||||
RaiseCustomFilter();
|
||||
}
|
||||
[Command]
|
||||
public void PrintSalesReport() {
|
||||
RaisePrint(SalesReportType.SalesReport);
|
||||
}
|
||||
[Command]
|
||||
public void PrintSalesByStore() {
|
||||
RaisePrint(SalesReportType.SalesByStore);
|
||||
}
|
||||
[Command(UseCommandManager = false, CanExecuteMethodName = "CanPrint")]
|
||||
public void PrintInvoice() {
|
||||
RaisePrint(SalesReportType.Invoice);
|
||||
}
|
||||
public bool CanPrint() {
|
||||
return SelectedEntity != null;
|
||||
}
|
||||
[Command]
|
||||
public void QuickReport(SalesReportType reportType) {
|
||||
QuickReportCore(SelectedEntity, reportType);
|
||||
}
|
||||
public bool CanQuickReport(SalesReportType reportType) {
|
||||
return CanQuickReportCore(SelectedEntity, reportType);
|
||||
}
|
||||
protected internal void QuickReportCore(Order order, SalesReportType reportTemplate) {
|
||||
ShowDocument<OrderMailMergeViewModel>("MailMerge", reportTemplate);
|
||||
}
|
||||
protected internal bool CanQuickReportCore(Order order, SalesReportType reportTemplate) {
|
||||
return order != null;
|
||||
}
|
||||
public override void New() {
|
||||
GetDocumentManagerService().ShowNewEntityDocument<Order>(this, newOrder => InitializeNewOrder(newOrder));
|
||||
}
|
||||
void InitializeNewOrder(Order order) {
|
||||
var unitOfWork = CreateUnitOfWork();
|
||||
order.InvoiceNumber = GetNewInvoiceNumber(unitOfWork);
|
||||
order.OrderDate = DateTime.Now;
|
||||
Customer customer = unitOfWork.Customers.FirstOrDefault();
|
||||
if(customer != null) {
|
||||
order.CustomerId = customer.Id;
|
||||
var store = customer.CustomerStores.FirstOrDefault();
|
||||
if(store != null)
|
||||
order.StoreId = store.Id;
|
||||
var employee = customer.Employees.FirstOrDefault();
|
||||
if(employee != null)
|
||||
order.EmployeeId = employee.Id;
|
||||
}
|
||||
}
|
||||
string GetNewInvoiceNumber(IDevAVDbUnitOfWork unitOfWork) {
|
||||
var numberStrings = unitOfWork.Orders.Select(x => x.InvoiceNumber).ToList();
|
||||
var invoiceNumbers = numberStrings.ConvertAll(x =>
|
||||
{
|
||||
int number;
|
||||
return int.TryParse(x, out number) ? number : 0;
|
||||
});
|
||||
return (invoiceNumbers.Max() + 1).ToString();
|
||||
}
|
||||
[Command]
|
||||
public void QuickReportFormat(ReportFormat reportFormatType) {
|
||||
QuickReportFormatCore(reportFormatType);
|
||||
}
|
||||
public bool CanQuickReportFormat(ReportFormat reportFormatType) {
|
||||
return CanQuickReportFormatCore(SelectedEntity, reportFormatType);
|
||||
}
|
||||
protected internal void QuickReportFormatCore(ReportFormat reportFormatTemplate) {
|
||||
switch(reportFormatTemplate) {
|
||||
case ReportFormat.Pdf:
|
||||
ShowDocument<OrderQuickReportsViewModel>("OrderPdfQuickReportView", new object[] { reportFormatTemplate, SelectedEntity });
|
||||
break;
|
||||
case ReportFormat.Xls:
|
||||
ShowDocument<OrderQuickReportsViewModel>("OrderXlsQuickReportView", new object[] { reportFormatTemplate, SelectedEntity });
|
||||
break;
|
||||
case ReportFormat.Doc:
|
||||
ShowDocument<OrderQuickReportsViewModel>("OrderDocQuickReportView", new object[] { reportFormatTemplate, SelectedEntity });
|
||||
break;
|
||||
}
|
||||
}
|
||||
protected internal bool CanQuickReportFormatCore(Order order, ReportFormat reportFormatTemplate) {
|
||||
return order != null;
|
||||
}
|
||||
IDevAVDbUnitOfWork orderItemsUnitOfWork;
|
||||
protected override void OnBeforeEntityDeleted(long primaryKey, Order entity) {
|
||||
base.OnBeforeEntityDeleted(primaryKey, entity);
|
||||
if(!entity.OrderItems.Any())
|
||||
return;
|
||||
var deletedItemKeys = entity.OrderItems.Select(x => x.Id).ToList();
|
||||
orderItemsUnitOfWork = CreateUnitOfWork();
|
||||
deletedItemKeys.ForEach(x =>
|
||||
{
|
||||
var item = orderItemsUnitOfWork.OrderItems.Find(x);
|
||||
if(item != null)
|
||||
orderItemsUnitOfWork.OrderItems.Remove(item);
|
||||
});
|
||||
}
|
||||
protected override void OnEntityDeleted(long primaryKey, Order entity) {
|
||||
base.OnEntityDeleted(primaryKey, entity);
|
||||
if(orderItemsUnitOfWork != null)
|
||||
orderItemsUnitOfWork.SaveChanges();
|
||||
orderItemsUnitOfWork = null;
|
||||
}
|
||||
[Command]
|
||||
public void ShowAllFolders() {
|
||||
RaiseShowAllFolders();
|
||||
}
|
||||
[Command]
|
||||
public void ResetCustomFilters() {
|
||||
RaiseCustomFiltersReset();
|
||||
}
|
||||
void RaisePrint(SalesReportType reportType) {
|
||||
MainViewModel mainViewModel = ViewModelHelper.GetParentViewModel<MainViewModel>(this);
|
||||
if(mainViewModel != null)
|
||||
mainViewModel.RaisePrint(reportType);
|
||||
}
|
||||
void RaiseShowAllFolders() {
|
||||
MainViewModel mainViewModel = ViewModelHelper.GetParentViewModel<MainViewModel>(this);
|
||||
if(mainViewModel != null)
|
||||
mainViewModel.RaiseShowAllFolders();
|
||||
}
|
||||
void RaiseReload() {
|
||||
EventHandler handler = Reload;
|
||||
if(handler != null)
|
||||
handler(this, EventArgs.Empty);
|
||||
}
|
||||
void RaiseCustomFilter() {
|
||||
EventHandler handler = CustomFilter;
|
||||
if(handler != null)
|
||||
handler(this, EventArgs.Empty);
|
||||
}
|
||||
void RaiseCustomFiltersReset() {
|
||||
EventHandler handler = CustomFiltersReset;
|
||||
if(handler != null)
|
||||
handler(this, EventArgs.Empty);
|
||||
}
|
||||
void ShowDocument<TViewModel>(string documentType, object parameter) {
|
||||
var document = FindDocument<TViewModel>();
|
||||
if(parameter is long)
|
||||
document = FindDocument<TViewModel>((long)parameter);
|
||||
if(document == null)
|
||||
document = DocumentManagerService.CreateDocument(documentType, null, parameter, this);
|
||||
else
|
||||
ViewModelHelper.EnsureViewModel(document.Content, this, parameter);
|
||||
document.Show();
|
||||
}
|
||||
public override IQueryable<Order> GetEntities(Expression<Func<Order, bool>> filter = null) {
|
||||
return base.GetEntities(filter).ActualOrders();
|
||||
}
|
||||
internal IEnumerable<SaleAnalisysInfo> GetSaleAnalisysInfos() {
|
||||
return QueriesHelper.GetSaleAnalysis(CreateUnitOfWork().OrderItems);
|
||||
}
|
||||
internal IEnumerable<SaleSummaryInfo> GetSaleSummaryInfos() {
|
||||
return QueriesHelper.GetSaleSummaries(CreateUnitOfWork().OrderItems);
|
||||
}
|
||||
internal IEnumerable<OrderItem> GetOrderItems() {
|
||||
return CreateUnitOfWork().OrderItems.Include(x => x.Order).ToList();
|
||||
}
|
||||
internal IEnumerable<OrderItem> GetOrderItems(long? storeId) {
|
||||
return CreateUnitOfWork().OrderItems.Include(x => x.Order).Where(x => Nullable.Equals(x.Order.StoreId, storeId)).ToList();
|
||||
}
|
||||
public void ShowRevenueReport() {
|
||||
ShowDocument<OrderRevenueViewModel>("OrderRevenueView", new object[] {
|
||||
QueriesHelper.GetRevenueReportItems(CreateUnitOfWork().OrderItems), RevenueReportFormat.Summary});
|
||||
}
|
||||
public virtual void ShowRevenueAnalysisReport() {
|
||||
ShowDocument<OrderRevenueViewModel>("OrderRevenueView", new object[] {
|
||||
QueriesHelper.GetRevenueAnalysisReportItems(CreateUnitOfWork().OrderItems, SelectedEntity.StoreId.Value), RevenueReportFormat.Analysis });
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
namespace DevExpress.DevAV.ViewModels {
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using DevExpress.DevAV;
|
||||
using DevExpress.DevAV.DevAVDbDataModel;
|
||||
using DevExpress.DevAV.ViewModels;
|
||||
using DevExpress.Mvvm.DataAnnotations;
|
||||
using DevExpress.Mvvm.POCO;
|
||||
|
||||
public class OrderMailMergeViewModel :
|
||||
MailMergeViewModelBase<SalesReportType> {
|
||||
IDevAVDbUnitOfWork unitOfWork;
|
||||
|
||||
public static OrderMailMergeViewModel Create() {
|
||||
return ViewModelSource.Create(() => new OrderMailMergeViewModel());
|
||||
}
|
||||
protected OrderMailMergeViewModel() {
|
||||
unitOfWork = UnitOfWorkSource.GetUnitOfWorkFactory().CreateUnitOfWork();
|
||||
}
|
||||
public virtual OrderMailMergePeriod? Period { get; set; }
|
||||
[Command]
|
||||
public void SetThisMonthPeriod() {
|
||||
Period = OrderMailMergePeriod.ThisMonth;
|
||||
}
|
||||
public bool CanSetThisMonthPeriod() {
|
||||
return Period != OrderMailMergePeriod.ThisMonth;
|
||||
}
|
||||
[Command]
|
||||
public void SetLastMonthPeriod() {
|
||||
Period = OrderMailMergePeriod.LastMonth;
|
||||
}
|
||||
public bool CanSetLastMonthPeriod() {
|
||||
return Period != OrderMailMergePeriod.LastMonth;
|
||||
}
|
||||
protected virtual void OnPeriodChanged() {
|
||||
this.RaiseCanExecuteChanged(x => x.SetThisMonthPeriod());
|
||||
this.RaiseCanExecuteChanged(x => x.SetLastMonthPeriod());
|
||||
RaisePeriodChanged();
|
||||
}
|
||||
public IList<OrderItem> GetOrderItems() {
|
||||
return unitOfWork.OrderItems.ToList();
|
||||
}
|
||||
public event EventHandler PeriodChanged;
|
||||
void RaisePeriodChanged() {
|
||||
EventHandler handler = PeriodChanged;
|
||||
if(handler != null)
|
||||
handler(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
public enum OrderMailMergePeriod {
|
||||
ThisMonth,
|
||||
LastMonth
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
namespace DevExpress.DevAV.ViewModels {
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using DevExpress.DevAV;
|
||||
using DevExpress.DevAV.ViewModels;
|
||||
using DevExpress.Mvvm.DataAnnotations;
|
||||
using DevExpress.Mvvm.POCO;
|
||||
using DevExpress.XtraMap;
|
||||
|
||||
public class OrderMapViewModel : OrderViewModel, IRouteMapViewModel {
|
||||
public virtual BingTravelMode TravelMode { get; set; }
|
||||
[Command]
|
||||
public void SetDrivingTravelMode() {
|
||||
TravelMode = BingTravelMode.Driving;
|
||||
}
|
||||
public bool CanSetDrivingTravelMode() {
|
||||
return TravelMode != BingTravelMode.Driving;
|
||||
}
|
||||
[Command]
|
||||
public void SetWalkingTravelMode() {
|
||||
TravelMode = BingTravelMode.Walking;
|
||||
}
|
||||
public bool CanSetWalkingTravelMode() {
|
||||
return TravelMode != BingTravelMode.Walking;
|
||||
}
|
||||
protected virtual void OnTravelModeChanged() {
|
||||
this.RaiseCanExecuteChanged(x => x.SetDrivingTravelMode());
|
||||
this.RaiseCanExecuteChanged(x => x.SetWalkingTravelMode());
|
||||
RaiseTravelModeChanged();
|
||||
}
|
||||
public event EventHandler TravelModeChanged;
|
||||
void RaiseTravelModeChanged() {
|
||||
EventHandler handler = TravelModeChanged;
|
||||
if(handler != null)
|
||||
handler(this, EventArgs.Empty);
|
||||
}
|
||||
[Command]
|
||||
public void SwapRoutePoints() {
|
||||
Address a = PointA;
|
||||
PointA = PointB;
|
||||
PointB = a;
|
||||
RaiseUpdateRoute();
|
||||
}
|
||||
public string Name {
|
||||
get { return (Entity != null) ? Entity.Customer.Name : null; }
|
||||
}
|
||||
public string AddressLine1 {
|
||||
get { return (Entity != null) ? Entity.Customer.HomeOffice.Line : null; }
|
||||
}
|
||||
public string AddressLine2 {
|
||||
get { return (Entity != null) ? Entity.Customer.HomeOffice.CityLine : null; }
|
||||
}
|
||||
public Image Logo {
|
||||
get { return (Entity != null) ? Entity.Customer.Image : null; }
|
||||
}
|
||||
public string PointAAddress {
|
||||
get { return (PointA != null) ? PointA.ToString() : null; }
|
||||
}
|
||||
public string PointBAddress {
|
||||
get { return (PointB != null) ? PointB.ToString() : null; }
|
||||
}
|
||||
public virtual string RouteResult {
|
||||
get {
|
||||
return string.Format("{0:F1} mi, {1:hh\\:mm} min ", RouteDistance, RouteTime) +
|
||||
((TravelMode == BingTravelMode.Walking) ? "walking" : "driving");
|
||||
}
|
||||
}
|
||||
public virtual double RouteDistance { get; set; }
|
||||
protected virtual void OnRouteDistanceChanged() {
|
||||
this.RaisePropertyChanged(x => x.RouteResult);
|
||||
}
|
||||
public virtual TimeSpan RouteTime { get; set; }
|
||||
protected virtual void OnRouteTimeChanged() {
|
||||
this.RaisePropertyChanged(x => x.RouteResult);
|
||||
}
|
||||
protected override void OnEntityChanged() {
|
||||
PointB = AddressHelper.DevAVHomeOffice;
|
||||
PointA = Entity.Store.Address;
|
||||
this.RaisePropertyChanged(x => x.Name);
|
||||
this.RaisePropertyChanged(x => x.Title);
|
||||
this.RaisePropertyChanged(x => x.PointA);
|
||||
this.RaisePropertyChanged(x => x.PointB);
|
||||
this.RaisePropertyChanged(x => x.AddressLine1);
|
||||
this.RaisePropertyChanged(x => x.AddressLine2);
|
||||
base.OnEntityChanged();
|
||||
}
|
||||
public virtual Address PointA { get; set; }
|
||||
protected virtual void OnPointAChanged() {
|
||||
this.RaisePropertyChanged(x => x.PointAAddress);
|
||||
RaisePointAChanged();
|
||||
}
|
||||
public virtual Address PointB { get; set; }
|
||||
protected virtual void OnPointBChanged() {
|
||||
this.RaisePropertyChanged(x => x.PointBAddress);
|
||||
RaisePointBChanged();
|
||||
}
|
||||
public event EventHandler PointAChanged;
|
||||
void RaisePointAChanged() {
|
||||
EventHandler handler = PointAChanged;
|
||||
if(handler != null)
|
||||
handler(this, EventArgs.Empty);
|
||||
}
|
||||
public event EventHandler PointBChanged;
|
||||
void RaisePointBChanged() {
|
||||
EventHandler handler = PointBChanged;
|
||||
if(handler != null)
|
||||
handler(this, EventArgs.Empty);
|
||||
}
|
||||
public event EventHandler UpdateRoute;
|
||||
void RaiseUpdateRoute() {
|
||||
EventHandler handler = UpdateRoute;
|
||||
if(handler != null)
|
||||
handler(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
namespace DevExpress.DevAV.ViewModels {
|
||||
using DevExpress.DevAV;
|
||||
using DevExpress.DevAV.DevAVDbDataModel;
|
||||
|
||||
using DevExpress.Mvvm;
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
public class OrderQuickReportsViewModel : IDocumentContent, ISupportParameter {
|
||||
object ISupportParameter.Parameter {
|
||||
get { return new object[] { Format, Order }; }
|
||||
set {
|
||||
Format = (ReportFormat)((object[])value)[0];
|
||||
Order = (Order)((object[])value)[1];
|
||||
LoadDocument(Order);
|
||||
}
|
||||
}
|
||||
|
||||
protected IDocumentOwner DocumentOwner { get; private set; }
|
||||
|
||||
public void Close() {
|
||||
if(DocumentOwner != null)
|
||||
DocumentOwner.Close(this);
|
||||
}
|
||||
public void LoadDocument(Order order) {
|
||||
var documentStream = new MemoryStream();
|
||||
//var report = ReportFactory.SalesInvoice(order, true, false, false, false);
|
||||
//switch(Format) {
|
||||
// case ReportFormat.Pdf:
|
||||
// report.ExportToPdf(documentStream);
|
||||
// break;
|
||||
// case ReportFormat.Xls:
|
||||
// report.ExportToXls(documentStream);
|
||||
// break;
|
||||
// case ReportFormat.Doc:
|
||||
// report.ExportToRtf(documentStream, new XtraPrinting.RtfExportOptions() { ExportMode = XtraPrinting.RtfExportMode.SingleFilePageByPage });
|
||||
// break;
|
||||
//}
|
||||
DocumentStream = documentStream;
|
||||
DocumentStream.Seek(0, SeekOrigin.Begin);
|
||||
}
|
||||
|
||||
public virtual Stream DocumentStream { get; set; }
|
||||
public ReportFormat? Format { get; set; }
|
||||
public Order Order { get; set; }
|
||||
|
||||
#region IDocumentContent
|
||||
void IDocumentContent.OnClose(CancelEventArgs e) {
|
||||
DocumentStream.Dispose();
|
||||
}
|
||||
void IDocumentContent.OnDestroy() { }
|
||||
IDocumentOwner IDocumentContent.DocumentOwner {
|
||||
get { return DocumentOwner; }
|
||||
set { DocumentOwner = value; }
|
||||
}
|
||||
object IDocumentContent.Title { get { return string.Format("Invoice# {0}", Order.InvoiceNumber); } }
|
||||
|
||||
#endregion
|
||||
}
|
||||
public enum ReportFormat {
|
||||
Pdf,
|
||||
Xls,
|
||||
Doc
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.IO;
|
||||
|
||||
using DevExpress.Mvvm;
|
||||
using DevExpress.Mvvm.POCO;
|
||||
using DevExpress.XtraReports.UI;
|
||||
|
||||
namespace DevExpress.DevAV.ViewModels {
|
||||
public class OrderRevenueViewModel : IDocumentContent, ISupportParameter {
|
||||
object ISupportParameter.Parameter {
|
||||
get { return new object[] { SelectedItems, Format }; }
|
||||
set {
|
||||
SelectedItems = (IEnumerable<OrderItem>)((object[])value)[0];
|
||||
Format = (RevenueReportFormat)((object[])value)[1];
|
||||
OnLoaded();
|
||||
}
|
||||
}
|
||||
public OrderRevenueViewModel() { }
|
||||
public void Close() {
|
||||
if(DocumentOwner != null)
|
||||
DocumentOwner.Close(this);
|
||||
}
|
||||
protected IDocumentManagerService DocumentManagerService { get { return this.GetService<IDocumentManagerService>(); } }
|
||||
|
||||
protected IDocumentOwner DocumentOwner { get; private set; }
|
||||
|
||||
public RevenueReportFormat Format { get; set; }
|
||||
public IEnumerable<OrderItem> SelectedItems { get; set; }
|
||||
public virtual XtraReport Report { get; set; }
|
||||
|
||||
public virtual void OnLoaded() {
|
||||
Report = CreateReport();
|
||||
Report.CreateDocument();
|
||||
}
|
||||
|
||||
public void ShowDesigner() {
|
||||
var viewModel = ReportDesignerViewModel.Create(CloneReport(Report));
|
||||
var doc = DocumentManagerService.CreateDocument("ReportDesignerView", viewModel, null, this);
|
||||
doc.Title = CreateTitle();
|
||||
doc.Show();
|
||||
|
||||
if(viewModel.IsReportSaved) {
|
||||
Report = CloneReport(viewModel.Report);
|
||||
Report.CreateDocument();
|
||||
viewModel.Report.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
XtraReport CloneReport(XtraReport report) {
|
||||
var clonedReport = CloneReportLayout(report);
|
||||
InitReport(clonedReport);
|
||||
return clonedReport;
|
||||
}
|
||||
void InitReport(XtraReport report) {
|
||||
report.DataSource = SelectedItems;
|
||||
report.Parameters["paramOrderDate"].Value = true;
|
||||
}
|
||||
XtraReport CreateReport() {
|
||||
return null;
|
||||
//return Format == RevenueReportFormat.Summary ? ReportFactory.SalesRevenueReport(SelectedItems, true) :
|
||||
// ReportFactory.SalesRevenueAnalysisReport(SelectedItems, true);
|
||||
}
|
||||
string CreateTitle() {
|
||||
return string.Format("{0}", Format == RevenueReportFormat.Analysis ? "Revenue Analysis" : "Revenue");
|
||||
}
|
||||
static XtraReport CloneReportLayout(XtraReport report) {
|
||||
using(var stream = new MemoryStream()) {
|
||||
report.SaveLayoutToXml(stream);
|
||||
stream.Position = 0;
|
||||
return XtraReport.FromStream(stream, true);
|
||||
}
|
||||
}
|
||||
#region IDocumentContent
|
||||
void IDocumentContent.OnClose(CancelEventArgs e) {
|
||||
Report.Dispose();
|
||||
}
|
||||
void IDocumentContent.OnDestroy() { }
|
||||
IDocumentOwner IDocumentContent.DocumentOwner {
|
||||
get { return DocumentOwner; }
|
||||
set { DocumentOwner = value; }
|
||||
}
|
||||
object IDocumentContent.Title { get { return CreateTitle(); } }
|
||||
#endregion
|
||||
}
|
||||
public enum RevenueReportFormat {
|
||||
Summary,
|
||||
Analysis
|
||||
}
|
||||
public class ReportDesignerViewModel {
|
||||
public static ReportDesignerViewModel Create(XtraReport report) {
|
||||
return ViewModelSource.Create(() => new ReportDesignerViewModel(report));
|
||||
}
|
||||
protected ReportDesignerViewModel(XtraReport report) {
|
||||
Report = report;
|
||||
}
|
||||
|
||||
public XtraReport Report { get; private set; }
|
||||
public bool IsReportSaved { get; private set; }
|
||||
|
||||
public virtual void Save() {
|
||||
IsReportSaved = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using DevExpress.Mvvm;
|
||||
using DevExpress.Mvvm.POCO;
|
||||
using DevExpress.DevAV.Common.Utils;
|
||||
using DevExpress.DevAV.DevAVDbDataModel;
|
||||
using DevExpress.Mvvm.DataModel;
|
||||
using DevExpress.DevAV;
|
||||
using DevExpress.DevAV.Common.ViewModel;
|
||||
|
||||
namespace DevExpress.DevAV.ViewModels {
|
||||
/// <summary>
|
||||
/// Represents the single Order object view model.
|
||||
/// </summary>
|
||||
public partial class OrderViewModel : SingleObjectViewModel<Order, long, IDevAVDbUnitOfWork> {
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of OrderViewModel as a POCO view model.
|
||||
/// </summary>
|
||||
/// <param name="unitOfWorkFactory">A factory used to create a unit of work instance.</param>
|
||||
public static OrderViewModel Create(IUnitOfWorkFactory<IDevAVDbUnitOfWork> unitOfWorkFactory = null) {
|
||||
return ViewModelSource.Create(() => new OrderViewModel(unitOfWorkFactory));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the OrderViewModel class.
|
||||
/// This constructor is declared protected to avoid undesired instantiation of the OrderViewModel type without the POCO proxy factory.
|
||||
/// </summary>
|
||||
/// <param name="unitOfWorkFactory">A factory used to create a unit of work instance.</param>
|
||||
protected OrderViewModel(IUnitOfWorkFactory<IDevAVDbUnitOfWork> unitOfWorkFactory = null)
|
||||
: base(unitOfWorkFactory ?? UnitOfWorkSource.GetUnitOfWorkFactory(), x => x.Orders, x => x.InvoiceNumber) {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The view model that contains a look-up collection of Customers for the corresponding navigation property in the view.
|
||||
/// </summary>
|
||||
public IEntitiesViewModel<Customer> LookUpCustomers {
|
||||
get { return GetLookUpEntitiesViewModel((OrderViewModel x) => x.LookUpCustomers, x => x.Customers); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The view model that contains a look-up collection of CustomerStores for the corresponding navigation property in the view.
|
||||
/// </summary>
|
||||
public IEntitiesViewModel<CustomerStore> LookUpCustomerStores {
|
||||
get { return GetLookUpEntitiesViewModel((OrderViewModel x) => x.LookUpCustomerStores, x => x.CustomerStores); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The view model that contains a look-up collection of Employees for the corresponding navigation property in the view.
|
||||
/// </summary>
|
||||
public IEntitiesViewModel<Employee> LookUpEmployees {
|
||||
get { return GetLookUpEntitiesViewModel((OrderViewModel x) => x.LookUpEmployees, x => x.Employees); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The view model for the OrderOrderItems detail collection.
|
||||
/// </summary>
|
||||
public CollectionViewModel<OrderItem, long, IDevAVDbUnitOfWork> OrderOrderItemsDetails {
|
||||
get { return GetDetailsCollectionViewModel((OrderViewModel x) => x.OrderOrderItemsDetails, x => x.OrderItems, x => x.OrderId, (x, key) => x.OrderId = key); }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
namespace DevExpress.DevAV.ViewModels {
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using DevExpress.Mvvm.DataAnnotations;
|
||||
using DevExpress.Mvvm.POCO;
|
||||
using System.Linq;
|
||||
|
||||
partial class OrderViewModel {
|
||||
public event EventHandler CustomizeFilter;
|
||||
public event EventHandler EntityChanged;
|
||||
void RaiseCustomizeFilter() {
|
||||
EventHandler handler = CustomizeFilter;
|
||||
if(handler != null) handler(this, EventArgs.Empty);
|
||||
}
|
||||
protected override string GetTitle() {
|
||||
return string.Format("Invoice# {0}", Entity.InvoiceNumber);
|
||||
}
|
||||
void RaiseEntityChanged() {
|
||||
EventHandler handler = EntityChanged;
|
||||
if(handler != null) handler(this, EventArgs.Empty);
|
||||
}
|
||||
//
|
||||
public OrderCollectionViewModel OrderCollectionViewModel {
|
||||
get { return this.GetParentViewModel<OrderCollectionViewModel>(); }
|
||||
}
|
||||
public Order MasterEntity {
|
||||
get { return (OrderCollectionViewModel != null) ? OrderCollectionViewModel.SelectedEntity : null; }
|
||||
}
|
||||
// Edit
|
||||
protected bool CanEdit() {
|
||||
return MasterEntity != null;
|
||||
}
|
||||
public void Edit() {
|
||||
OrderCollectionViewModel.Edit(MasterEntity);
|
||||
RaiseCustomizeFilter();
|
||||
}
|
||||
// Delete
|
||||
public override bool CanDelete() {
|
||||
return MasterEntity != null;
|
||||
}
|
||||
public override void Delete() {
|
||||
OrderCollectionViewModel.Delete(MasterEntity);
|
||||
}
|
||||
// Refund
|
||||
protected bool CanIssueFullRefund() {
|
||||
return (MasterEntity != null) && (MasterEntity.RefundTotal < MasterEntity.PaymentTotal);
|
||||
}
|
||||
public void IssueFullRefund() {
|
||||
MasterEntity.RefundTotal = MasterEntity.PaymentTotal;
|
||||
OrderCollectionViewModel.Save(MasterEntity);
|
||||
}
|
||||
public virtual string IssueFullRefundToolTip { get; set; }
|
||||
// Mark Paid
|
||||
protected bool CanMarkPaid() {
|
||||
return (MasterEntity != null) && (MasterEntity.PaymentTotal < MasterEntity.TotalAmount);
|
||||
}
|
||||
public void MarkPaid() {
|
||||
MasterEntity.PaymentTotal = MasterEntity.TotalAmount;
|
||||
OrderCollectionViewModel.Save(MasterEntity);
|
||||
}
|
||||
public virtual string MarkPaidToolTip { get; set; }
|
||||
// Mail To
|
||||
protected bool CanMailTo() {
|
||||
return Entity != null;
|
||||
}
|
||||
public void MailTo() {
|
||||
EmployeeContactsViewModel.ExecuteMailTo(MessageBoxService, Entity.Employee.Email);
|
||||
}
|
||||
// Print
|
||||
protected bool CanPrint() {
|
||||
return OrderCollectionViewModel != null;
|
||||
}
|
||||
public void Print() {
|
||||
OrderCollectionViewModel.PrintInvoice();
|
||||
}
|
||||
// Dependencies
|
||||
protected override void OnEntityChanged() {
|
||||
base.OnEntityChanged();
|
||||
RaiseEntityChanged();
|
||||
}
|
||||
protected override void UpdateCommands() {
|
||||
base.UpdateCommands();
|
||||
this.RaiseCanExecuteChanged(x => x.Edit());
|
||||
this.RaiseCanExecuteChanged(x => x.MailTo());
|
||||
this.RaiseCanExecuteChanged(x => x.Print());
|
||||
this.RaiseCanExecuteChanged(x => x.MarkPaid());
|
||||
this.RaiseCanExecuteChanged(x => x.IssueFullRefund());
|
||||
MarkPaidToolTip = CanMarkPaid() ? "Mark as Paid" : "Paid";
|
||||
IssueFullRefundToolTip = CanIssueFullRefund() ? "Issue Full Refund" : "Refund Issued";
|
||||
}
|
||||
// Custom Actions
|
||||
[Command(false)]
|
||||
public OrderItem CreateOrderItem() {
|
||||
return UnitOfWork.OrderItems.Create();
|
||||
}
|
||||
[Command(false)]
|
||||
public void AddOrderItem(OrderItem orderItem) {
|
||||
UnitOfWork.OrderItems.Add(orderItem);
|
||||
}
|
||||
[Command(false)]
|
||||
public void RemoveOrderItem(OrderItem orderItem) {
|
||||
UnitOfWork.OrderItems.Remove(orderItem);
|
||||
}
|
||||
[Command(false)]
|
||||
public IEnumerable<CustomerStore> GetCustomerStores(long? customerId) {
|
||||
return UnitOfWork.CustomerStores.Where(x => Nullable.Equals(x.CustomerId, customerId));
|
||||
}
|
||||
//[Command(false)]
|
||||
//public Tuple<OrderCollections, Order> CreateInvoiceDataSource() {
|
||||
// var collections = new OrderCollections();
|
||||
// collections.Customers = UnitOfWork.Customers;
|
||||
// collections.Products = UnitOfWork.Products;
|
||||
// collections.Employees = UnitOfWork.Employees;
|
||||
// collections.CustomerStores = GetCustomerStores(Entity.CustomerId);
|
||||
// return new Tuple<OrderCollections, Order>(collections, Entity);
|
||||
//}
|
||||
public override bool CanSave() {
|
||||
return base.CanSave() && Entity.OrderItems.Any();
|
||||
}
|
||||
}
|
||||
|
||||
public partial class SynchronizedOrderViewModel : OrderViewModel {
|
||||
protected override bool EnableEntityChangedSynchronization {
|
||||
get { return true; }
|
||||
}
|
||||
protected override bool EnableSelectedItemSynchronization {
|
||||
get { return true; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
namespace DevExpress.DevAV.ViewModels {
|
||||
using System;
|
||||
using DevExpress.DevAV;
|
||||
using DevExpress.DevAV.DevAVDbDataModel;
|
||||
using DevExpress.DevAV.ViewModels;
|
||||
using DevExpress.DevAV.Properties;
|
||||
using DevExpress.Mvvm.POCO;
|
||||
|
||||
public class OrdersFilterTreeViewModel : FilterTreeViewModel<Order, long, IDevAVDbUnitOfWork> {
|
||||
public static OrdersFilterTreeViewModel Create(OrderCollectionViewModel collectionViewModel) {
|
||||
return ViewModelSource.Create(() => new OrdersFilterTreeViewModel(collectionViewModel));
|
||||
}
|
||||
protected OrdersFilterTreeViewModel(OrderCollectionViewModel collectionViewModel)
|
||||
: base(collectionViewModel, new FilterTreeModelPageSpecificSettings<Settings>(Settings.Default, StaticFiltersName, x => x.OrdersStaticFilters, x => x.OrdersCustomFilters, x => x.OrdersGroupFilters)) {
|
||||
}
|
||||
protected new OrderCollectionViewModel CollectionViewModel {
|
||||
get { return base.CollectionViewModel as OrderCollectionViewModel; }
|
||||
}
|
||||
protected override bool EnableGroups {
|
||||
get { return false; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
namespace DevExpress.DevAV.ViewModels {
|
||||
using System;
|
||||
using System.Linq;
|
||||
using DevExpress.DevAV;
|
||||
using DevExpress.DevAV.ViewModels;
|
||||
using DevExpress.DevAV.DevAVDbDataModel;
|
||||
using System.Collections.Generic;
|
||||
using DevExpress.Mvvm.POCO;
|
||||
|
||||
public class OrdersReportViewModel :
|
||||
ReportViewModelBase<SalesReportType, Order, long, IDevAVDbUnitOfWork> {
|
||||
IDevAVDbUnitOfWork unitOfWork;
|
||||
|
||||
public static OrdersReportViewModel Create() {
|
||||
return ViewModelSource.Create(() => new OrdersReportViewModel());
|
||||
}
|
||||
protected OrdersReportViewModel() {
|
||||
unitOfWork = UnitOfWorkSource.GetUnitOfWorkFactory().CreateUnitOfWork();
|
||||
}
|
||||
public IList<OrderItem> GetOrderItems() {
|
||||
return unitOfWork.OrderItems.ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
namespace DevExpress.DevAV.ViewModels {
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using DevExpress.DevAV;
|
||||
using DevExpress.DevAV.DevAVDbDataModel;
|
||||
using DevExpress.DevAV.ViewModels;
|
||||
using DevExpress.Mvvm;
|
||||
using DevExpress.Mvvm.POCO;
|
||||
|
||||
public class ProductAnalysisViewModel : DocumentContentViewModelBase {
|
||||
IDevAVDbUnitOfWork unitOfWork;
|
||||
|
||||
public static ProductAnalysisViewModel Create() {
|
||||
return ViewModelSource.Create(() => new ProductAnalysisViewModel());
|
||||
}
|
||||
protected ProductAnalysisViewModel() {
|
||||
unitOfWork = UnitOfWorkSource.GetUnitOfWorkFactory().CreateUnitOfWork();
|
||||
}
|
||||
public IEnumerable<ProductsAnalysis.Item> GetFinancialReport() {
|
||||
return ProductsAnalysis.GetFinancialReport(unitOfWork);
|
||||
}
|
||||
public IEnumerable<ProductsAnalysis.Item> GetFinancialData() {
|
||||
return ProductsAnalysis.GetFinancialData(unitOfWork);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using DevExpress.Mvvm.POCO;
|
||||
using DevExpress.DevAV.Common.Utils;
|
||||
using DevExpress.DevAV.DevAVDbDataModel;
|
||||
using DevExpress.Mvvm.DataModel;
|
||||
using DevExpress.DevAV;
|
||||
using DevExpress.DevAV.Common.ViewModel;
|
||||
|
||||
namespace DevExpress.DevAV.ViewModels {
|
||||
/// <summary>
|
||||
/// Represents the Products collection view model.
|
||||
/// </summary>
|
||||
public partial class ProductCollectionViewModel : CollectionViewModel<Product, long, IDevAVDbUnitOfWork> {
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of ProductCollectionViewModel as a POCO view model.
|
||||
/// </summary>
|
||||
/// <param name="unitOfWorkFactory">A factory used to create a unit of work instance.</param>
|
||||
public static ProductCollectionViewModel Create(IUnitOfWorkFactory<IDevAVDbUnitOfWork> unitOfWorkFactory = null) {
|
||||
return ViewModelSource.Create(() => new ProductCollectionViewModel(unitOfWorkFactory));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the ProductCollectionViewModel class.
|
||||
/// This constructor is declared protected to avoid undesired instantiation of the ProductCollectionViewModel type without the POCO proxy factory.
|
||||
/// </summary>
|
||||
/// <param name="unitOfWorkFactory">A factory used to create a unit of work instance.</param>
|
||||
protected ProductCollectionViewModel(IUnitOfWorkFactory<IDevAVDbUnitOfWork> unitOfWorkFactory = null)
|
||||
: base(unitOfWorkFactory ?? UnitOfWorkSource.GetUnitOfWorkFactory(), x => x.Products, query => query.OrderBy(x => x.Category)) {
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,150 @@
|
||||
namespace DevExpress.DevAV.ViewModels {
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using DevExpress.DevAV;
|
||||
using DevExpress.DevAV.DevAVDbDataModel;
|
||||
using DevExpress.DevAV.ViewModels;
|
||||
using DevExpress.Mvvm;
|
||||
using DevExpress.Mvvm.DataAnnotations;
|
||||
using DevExpress.Mvvm.POCO;
|
||||
|
||||
partial class ProductCollectionViewModel : ISupportMap, ISupportAnalysis, ISupportCustomFilters {
|
||||
public override void Refresh() {
|
||||
base.Refresh();
|
||||
RaiseReload();
|
||||
}
|
||||
protected override void OnSelectedEntityChanged() {
|
||||
base.OnSelectedEntityChanged();
|
||||
this.RaiseCanExecuteChanged(x => x.ShowMap());
|
||||
this.RaiseCanExecuteChanged(x => x.PrintOrderDetail());
|
||||
this.RaiseCanExecuteChanged(x => x.PrintSalesSummary());
|
||||
this.RaiseCanExecuteChanged(x => x.PrintSpecificationSummary());
|
||||
this.RaiseCanExecuteChanged(x => x.QuickReport(ProductReportType.OrderDetail));
|
||||
}
|
||||
public virtual IEnumerable<Product> Selection { get; set; }
|
||||
protected virtual void OnSelectionChanged() {
|
||||
this.RaiseCanExecuteChanged(x => x.GroupSelection());
|
||||
}
|
||||
public event EventHandler Reload;
|
||||
public event EventHandler CustomFilter;
|
||||
public event EventHandler CustomFiltersReset;
|
||||
public event EventHandler CustomGroup;
|
||||
public event EventHandler<GroupEventArgs<Product>> CustomGroupFromSelection;
|
||||
[Command]
|
||||
public void ShowAnalysis() {
|
||||
ShowDocument<ProductAnalysisViewModel>("Analysis", null);
|
||||
}
|
||||
[Command]
|
||||
public void ShowMap() {
|
||||
if(SelectedEntity == null) return;
|
||||
ShowDocument<ProductMapViewModel>("MapView", SelectedEntity.Id);
|
||||
}
|
||||
public bool CanShowMap() {
|
||||
return SelectedEntity != null;
|
||||
}
|
||||
[Command]
|
||||
public void ShowViewSettings() {
|
||||
var dms = this.GetService<IDocumentManagerService>("View Settings");
|
||||
if(dms != null) {
|
||||
var document = dms.Documents.FirstOrDefault(d => d.Content is ViewSettingsViewModel);
|
||||
if(document == null)
|
||||
document = dms.CreateDocument("View Settings", null, null, this);
|
||||
document.Show();
|
||||
}
|
||||
}
|
||||
[Command]
|
||||
public void NewGroup() {
|
||||
RaiseCustomGroup();
|
||||
}
|
||||
[Command]
|
||||
public void GroupSelection() {
|
||||
RaiseCustomGroupFromSelection();
|
||||
}
|
||||
public bool CanGroupSelection() {
|
||||
return (Selection != null) && Selection.Any();
|
||||
}
|
||||
[Command]
|
||||
public void NewCustomFilter() {
|
||||
RaiseCustomFilter();
|
||||
}
|
||||
[Command(UseCommandManager = false, CanExecuteMethodName = "CanPrint")]
|
||||
public void PrintOrderDetail() {
|
||||
RaisePrint(ProductReportType.OrderDetail);
|
||||
}
|
||||
[Command(UseCommandManager = false, CanExecuteMethodName = "CanPrint")]
|
||||
public void PrintSalesSummary() {
|
||||
RaisePrint(ProductReportType.SalesSummary);
|
||||
}
|
||||
[Command(UseCommandManager = false, CanExecuteMethodName = "CanPrint")]
|
||||
public void PrintSpecificationSummary() {
|
||||
RaisePrint(ProductReportType.SpecificationSummary);
|
||||
}
|
||||
[Command]
|
||||
public void QuickReport(ProductReportType reportType) {
|
||||
RaisePrint(reportType);
|
||||
}
|
||||
public bool CanQuickReport(ProductReportType reportType) {
|
||||
return SelectedEntity != null;
|
||||
}
|
||||
public bool CanPrint() {
|
||||
return SelectedEntity != null;
|
||||
}
|
||||
[Command]
|
||||
public void ShowAllFolders() {
|
||||
RaiseShowAllFolders();
|
||||
}
|
||||
[Command]
|
||||
public void ResetCustomFilters() {
|
||||
RaiseCustomFiltersReset();
|
||||
}
|
||||
void RaisePrint(ProductReportType reportType) {
|
||||
MainViewModel mainViewModel = ViewModelHelper.GetParentViewModel<MainViewModel>(this);
|
||||
if(mainViewModel != null)
|
||||
mainViewModel.RaisePrint(reportType);
|
||||
}
|
||||
void RaiseShowAllFolders() {
|
||||
MainViewModel mainViewModel = ViewModelHelper.GetParentViewModel<MainViewModel>(this);
|
||||
if(mainViewModel != null)
|
||||
mainViewModel.RaiseShowAllFolders();
|
||||
}
|
||||
void RaiseReload() {
|
||||
EventHandler handler = Reload;
|
||||
if(handler != null)
|
||||
handler(this, EventArgs.Empty);
|
||||
}
|
||||
void RaiseCustomFilter() {
|
||||
EventHandler handler = CustomFilter;
|
||||
if(handler != null)
|
||||
handler(this, EventArgs.Empty);
|
||||
}
|
||||
void RaiseCustomFiltersReset() {
|
||||
EventHandler handler = CustomFiltersReset;
|
||||
if(handler != null)
|
||||
handler(this, EventArgs.Empty);
|
||||
}
|
||||
void RaiseCustomGroup() {
|
||||
EventHandler handler = CustomGroup;
|
||||
if(handler != null)
|
||||
handler(this, EventArgs.Empty);
|
||||
}
|
||||
void RaiseCustomGroupFromSelection() {
|
||||
EventHandler<GroupEventArgs<Product>> handler = CustomGroupFromSelection;
|
||||
if(handler != null)
|
||||
handler(this, new GroupEventArgs<Product>(Selection));
|
||||
}
|
||||
void ShowDocument<TViewModel>(string documentType, object parameter) {
|
||||
var document = FindDocument<TViewModel>();
|
||||
if(parameter is long)
|
||||
document = FindDocument<TViewModel>((long)parameter);
|
||||
if(document == null)
|
||||
document = DocumentManagerService.CreateDocument(documentType, null, parameter, this);
|
||||
else
|
||||
ViewModelHelper.EnsureViewModel(document.Content, this, parameter);
|
||||
document.Show();
|
||||
}
|
||||
public override void Delete(Product entity) {
|
||||
MessageBoxService.ShowMessage("To ensure data integrity, the Products module doesn't allow records to be deleted. Record deletion is supported by the Employees module.", "Delete Product", MessageButton.OK);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
namespace DevExpress.DevAV.ViewModels {
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using DevExpress.DevAV.ViewModels;
|
||||
using DevExpress.Mvvm.DataAnnotations;
|
||||
using DevExpress.Mvvm.POCO;
|
||||
|
||||
public class ProductMapViewModel : ProductViewModel, ISalesMapViewModel {
|
||||
public virtual Period Period { get; set; }
|
||||
[Command]
|
||||
public void SetLifetimePeriod() {
|
||||
Period = Period.Lifetime;
|
||||
}
|
||||
public bool CanSetLifetimePeriod() {
|
||||
return Period != Period.Lifetime;
|
||||
}
|
||||
[Command]
|
||||
public void SetThisYearPeriod() {
|
||||
Period = Period.ThisYear;
|
||||
}
|
||||
public bool CanSetThisYearPeriod() {
|
||||
return Period != Period.ThisYear;
|
||||
}
|
||||
[Command]
|
||||
public void SetThisMonthPeriod() {
|
||||
Period = Period.ThisMonth;
|
||||
}
|
||||
public bool CanSetThisMonthPeriod() {
|
||||
return Period != Period.ThisMonth;
|
||||
}
|
||||
protected virtual void OnPeriodChanged() {
|
||||
this.RaiseCanExecuteChanged(x => x.SetLifetimePeriod());
|
||||
this.RaiseCanExecuteChanged(x => x.SetThisYearPeriod());
|
||||
this.RaiseCanExecuteChanged(x => x.SetThisMonthPeriod());
|
||||
RaisePeriodChanged();
|
||||
}
|
||||
public event EventHandler PeriodChanged;
|
||||
void RaisePeriodChanged() {
|
||||
EventHandler handler = PeriodChanged;
|
||||
if(handler != null)
|
||||
handler(this, EventArgs.Empty);
|
||||
}
|
||||
#region Properties
|
||||
public string Name {
|
||||
get { return (Entity != null) ? Entity.Name : null; }
|
||||
}
|
||||
public string Description {
|
||||
get { return (Entity != null) ? Entity.Description : null; }
|
||||
}
|
||||
public Image Image {
|
||||
get { return (Entity != null) ? Entity.ProductImage : null; }
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using DevExpress.Mvvm;
|
||||
using DevExpress.Mvvm.POCO;
|
||||
using DevExpress.DevAV.Common.Utils;
|
||||
using DevExpress.DevAV.DevAVDbDataModel;
|
||||
using DevExpress.Mvvm.DataModel;
|
||||
using DevExpress.DevAV;
|
||||
using DevExpress.DevAV.Common.ViewModel;
|
||||
|
||||
namespace DevExpress.DevAV.ViewModels {
|
||||
/// <summary>
|
||||
/// Represents the single Product object view model.
|
||||
/// </summary>
|
||||
public partial class ProductViewModel : SingleObjectViewModel<Product, long, IDevAVDbUnitOfWork> {
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of ProductViewModel as a POCO view model.
|
||||
/// </summary>
|
||||
/// <param name="unitOfWorkFactory">A factory used to create a unit of work instance.</param>
|
||||
public static ProductViewModel Create(IUnitOfWorkFactory<IDevAVDbUnitOfWork> unitOfWorkFactory = null) {
|
||||
return ViewModelSource.Create(() => new ProductViewModel(unitOfWorkFactory));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the ProductViewModel class.
|
||||
/// This constructor is declared protected to avoid undesired instantiation of the ProductViewModel type without the POCO proxy factory.
|
||||
/// </summary>
|
||||
/// <param name="unitOfWorkFactory">A factory used to create a unit of work instance.</param>
|
||||
protected ProductViewModel(IUnitOfWorkFactory<IDevAVDbUnitOfWork> unitOfWorkFactory = null)
|
||||
: base(unitOfWorkFactory ?? UnitOfWorkSource.GetUnitOfWorkFactory(), x => x.Products, x => x.Name) {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The view model that contains a look-up collection of Employees for the corresponding navigation property in the view.
|
||||
/// </summary>
|
||||
public IEntitiesViewModel<Employee> LookUpEmployees {
|
||||
get { return GetLookUpEntitiesViewModel((ProductViewModel x) => x.LookUpEmployees, x => x.Employees); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The view model that contains a look-up collection of Pictures for the corresponding navigation property in the view.
|
||||
/// </summary>
|
||||
public IEntitiesViewModel<Picture> LookUpPictures {
|
||||
get { return GetLookUpEntitiesViewModel((ProductViewModel x) => x.LookUpPictures, x => x.Pictures); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The view model for the ProductCatalog detail collection.
|
||||
/// </summary>
|
||||
public CollectionViewModel<ProductCatalog, long, IDevAVDbUnitOfWork> ProductCatalogDetails {
|
||||
get { return GetDetailsCollectionViewModel((ProductViewModel x) => x.ProductCatalogDetails, x => x.ProductCatalogs, x => x.ProductId, (x, key) => x.ProductId = key); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The view model for the ProductOrderItems detail collection.
|
||||
/// </summary>
|
||||
public CollectionViewModel<OrderItem, long, IDevAVDbUnitOfWork> ProductOrderItemsDetails {
|
||||
get { return GetDetailsCollectionViewModel((ProductViewModel x) => x.ProductOrderItemsDetails, x => x.OrderItems, x => x.ProductId, (x, key) => x.ProductId = key); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The view model for the ProductImages detail collection.
|
||||
/// </summary>
|
||||
public CollectionViewModel<ProductImage, long, IDevAVDbUnitOfWork> ProductImagesDetails {
|
||||
get { return GetDetailsCollectionViewModel((ProductViewModel x) => x.ProductImagesDetails, x => x.ProductImages, x => x.ProductId, (x, key) => x.ProductId = key); }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
namespace DevExpress.DevAV.ViewModels {
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using DevExpress.DevAV;
|
||||
using DevExpress.DevAV.DevAVDbDataModel;
|
||||
using DevExpress.DevAV.ViewModels;
|
||||
using DevExpress.Mvvm;
|
||||
|
||||
partial class ProductViewModel {
|
||||
public event System.EventHandler EntityChanged;
|
||||
protected override void OnEntityChanged() {
|
||||
base.OnEntityChanged();
|
||||
System.EventHandler handler = EntityChanged;
|
||||
if(handler != null)
|
||||
handler(this, System.EventArgs.Empty);
|
||||
}
|
||||
public IEnumerable<CustomerStore> GetSalesStores(Period period = Period.Lifetime) {
|
||||
return QueriesHelper.GetSalesStoresForPeriod(UnitOfWork.Orders, period);
|
||||
}
|
||||
public IEnumerable<DevAV.MapItem> GetSales(Period period = Period.Lifetime) {
|
||||
return QueriesHelper.GetSaleMapItems(UnitOfWork.OrderItems, Entity.Id, period);
|
||||
}
|
||||
public IEnumerable<DevAV.MapItem> GetSalesByCity(string city, Period period = Period.Lifetime) {
|
||||
return QueriesHelper.GetSaleMapItemsByCity(UnitOfWork.OrderItems, Entity.Id, city, period);
|
||||
}
|
||||
public override void Delete() {
|
||||
MessageBoxService.ShowMessage("To ensure data integrity, the Products module doesn't allow records to be deleted. Record deletion is supported by the Employees module.", "Delete Product", MessageButton.OK);
|
||||
}
|
||||
}
|
||||
public partial class SynchronizedProductViewModel : ProductViewModel {
|
||||
protected override bool EnableSelectedItemSynchronization {
|
||||
get { return true; }
|
||||
}
|
||||
protected override bool EnableEntityChangedSynchronization {
|
||||
get { return true; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
namespace DevExpress.DevAV.ViewModels {
|
||||
using System;
|
||||
using DevExpress.DevAV;
|
||||
using DevExpress.DevAV.DevAVDbDataModel;
|
||||
using DevExpress.DevAV.ViewModels;
|
||||
using DevExpress.DevAV.Properties;
|
||||
using DevExpress.Mvvm.POCO;
|
||||
|
||||
public class ProductsFilterTreeViewModel : FilterTreeViewModel<Product, long, IDevAVDbUnitOfWork> {
|
||||
public static ProductsFilterTreeViewModel Create(ProductCollectionViewModel collectionViewModel) {
|
||||
return ViewModelSource.Create(() => new ProductsFilterTreeViewModel(collectionViewModel));
|
||||
}
|
||||
protected ProductsFilterTreeViewModel(ProductCollectionViewModel collectionViewModel)
|
||||
: base(collectionViewModel, new FilterTreeModelPageSpecificSettings<Settings>(Settings.Default, StaticFiltersName, x => x.ProductsStaticFilters, x => x.ProductsCustomFilters, x => x.ProductsGroupFilters)) {
|
||||
}
|
||||
protected new ProductCollectionViewModel CollectionViewModel {
|
||||
get { return base.CollectionViewModel as ProductCollectionViewModel; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
namespace DevExpress.DevAV.ViewModels {
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using DevExpress.DevAV;
|
||||
using DevExpress.DevAV.DevAVDbDataModel;
|
||||
using DevExpress.DevAV.ViewModels;
|
||||
using DevExpress.Mvvm.POCO;
|
||||
|
||||
public class ProductsReportViewModel :
|
||||
ReportViewModelBase<ProductReportType, Product, long, IDevAVDbUnitOfWork> {
|
||||
IDevAVDbUnitOfWork unitOfWork;
|
||||
|
||||
public static ProductsReportViewModel Create() {
|
||||
return ViewModelSource.Create(() => new ProductsReportViewModel());
|
||||
}
|
||||
protected ProductsReportViewModel() {
|
||||
unitOfWork = UnitOfWorkSource.GetUnitOfWorkFactory().CreateUnitOfWork();
|
||||
}
|
||||
public IList<OrderItem> GetOrderItems(long productId) {
|
||||
return GetOrderItems(unitOfWork, productId).ToList();
|
||||
}
|
||||
static IQueryable<OrderItem> GetOrderItems(IDevAVDbUnitOfWork unitOfWork, long productId) {
|
||||
return from oi in unitOfWork.OrderItems
|
||||
where oi.ProductId != null && oi.ProductId == productId
|
||||
select oi;
|
||||
}
|
||||
public IList<State> GetStates() {
|
||||
return unitOfWork.States.ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace DevExpress.DevAV.ViewModels {
|
||||
public enum ProductReportType {
|
||||
None,
|
||||
[Display(Name = "Order Detail")]
|
||||
OrderDetail,
|
||||
[Display(Name = "Sales Summary Report")]
|
||||
SalesSummary,
|
||||
[Display(Name = "Specification Summary Report")]
|
||||
SpecificationSummary,
|
||||
[Display(Name = "Top Salesperson Report")]
|
||||
TopSalesperson
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using DevExpress.Mvvm.POCO;
|
||||
using DevExpress.DevAV.Common.Utils;
|
||||
using DevExpress.DevAV.DevAVDbDataModel;
|
||||
using DevExpress.Mvvm.DataModel;
|
||||
using DevExpress.DevAV;
|
||||
using DevExpress.DevAV.Common.ViewModel;
|
||||
|
||||
namespace DevExpress.DevAV.ViewModels {
|
||||
/// <summary>
|
||||
/// Represents the Quotes collection view model.
|
||||
/// </summary>
|
||||
public partial class QuoteCollectionViewModel : CollectionViewModel<Quote, long, IDevAVDbUnitOfWork> {
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of QuoteCollectionViewModel as a POCO view model.
|
||||
/// </summary>
|
||||
/// <param name="unitOfWorkFactory">A factory used to create a unit of work instance.</param>
|
||||
public static QuoteCollectionViewModel Create(IUnitOfWorkFactory<IDevAVDbUnitOfWork> unitOfWorkFactory = null) {
|
||||
return ViewModelSource.Create(() => new QuoteCollectionViewModel(unitOfWorkFactory));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the QuoteCollectionViewModel class.
|
||||
/// This constructor is declared protected to avoid undesired instantiation of the QuoteCollectionViewModel type without the POCO proxy factory.
|
||||
/// </summary>
|
||||
/// <param name="unitOfWorkFactory">A factory used to create a unit of work instance.</param>
|
||||
protected QuoteCollectionViewModel(IUnitOfWorkFactory<IDevAVDbUnitOfWork> unitOfWorkFactory = null)
|
||||
: base(unitOfWorkFactory ?? UnitOfWorkSource.GetUnitOfWorkFactory(), x => x.Quotes, query => query.ActualQuotes()) {
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
namespace DevExpress.DevAV.ViewModels {
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using DevExpress.DevAV;
|
||||
using DevExpress.Mvvm.DataModel;
|
||||
using DevExpress.Mvvm;
|
||||
using DevExpress.Mvvm.DataAnnotations;
|
||||
using DevExpress.Mvvm.POCO;
|
||||
|
||||
partial class QuoteCollectionViewModel : ISupportMap, ISupportCustomFilters {
|
||||
public override void Refresh() {
|
||||
base.Refresh();
|
||||
RaiseReload();
|
||||
}
|
||||
public event EventHandler Reload;
|
||||
public event EventHandler CustomFilter;
|
||||
public event EventHandler CustomFiltersReset;
|
||||
[Command]
|
||||
public void ShowMap() {
|
||||
ShowDocument<QuoteMapViewModel>("MapView", null);
|
||||
}
|
||||
public bool CanShowMap() {
|
||||
return true;
|
||||
}
|
||||
[Command]
|
||||
public void ShowViewSettings() {
|
||||
var dms = this.GetService<DevExpress.Mvvm.IDocumentManagerService>("View Settings");
|
||||
if(dms != null) {
|
||||
var document = dms.Documents.FirstOrDefault(d => d.Content is ViewSettingsViewModel);
|
||||
if(document == null)
|
||||
document = dms.CreateDocument("View Settings", null, null, this);
|
||||
document.Show();
|
||||
}
|
||||
}
|
||||
[Command]
|
||||
public void NewCustomFilter() {
|
||||
RaiseCustomFilter();
|
||||
}
|
||||
[Command]
|
||||
public void ShowAllFolders() {
|
||||
RaiseShowAllFolders();
|
||||
}
|
||||
[Command]
|
||||
public void ResetCustomFilters() {
|
||||
RaiseCustomFiltersReset();
|
||||
}
|
||||
void RaiseShowAllFolders() {
|
||||
MainViewModel mainViewModel = ViewModelHelper.GetParentViewModel<MainViewModel>(this);
|
||||
if(mainViewModel != null)
|
||||
mainViewModel.RaiseShowAllFolders();
|
||||
}
|
||||
void RaisePrint(SalesReportType reportType) {
|
||||
MainViewModel mainViewModel = ViewModelHelper.GetParentViewModel<MainViewModel>(this);
|
||||
if(mainViewModel != null)
|
||||
mainViewModel.RaisePrint(reportType);
|
||||
}
|
||||
void RaiseReload() {
|
||||
EventHandler handler = Reload;
|
||||
if(handler != null)
|
||||
handler(this, EventArgs.Empty);
|
||||
}
|
||||
void RaiseCustomFilter() {
|
||||
EventHandler handler = CustomFilter;
|
||||
if(handler != null)
|
||||
handler(this, EventArgs.Empty);
|
||||
}
|
||||
void RaiseCustomFiltersReset() {
|
||||
EventHandler handler = CustomFiltersReset;
|
||||
if(handler != null)
|
||||
handler(this, EventArgs.Empty);
|
||||
}
|
||||
void ShowDocument<TViewModel>(string documentType, object parameter) {
|
||||
var document = FindDocument<TViewModel>();
|
||||
if(parameter is long)
|
||||
document = FindDocument<TViewModel>((long)parameter);
|
||||
if(document == null)
|
||||
document = DocumentManagerService.CreateDocument(documentType, null, parameter, this);
|
||||
else
|
||||
ViewModelHelper.EnsureViewModel(document.Content, this, parameter);
|
||||
document.Show();
|
||||
}
|
||||
protected virtual IQueryable<Quote> GetQuotes() {
|
||||
return CreateRepository().GetFilteredEntities(FilterExpression);
|
||||
}
|
||||
public IList<QuoteMapItem> GetOpportunities() {
|
||||
return QueriesHelper.GetOpportunities(GetQuotes()).ToList();
|
||||
}
|
||||
public IList<QuoteMapItem> GetOpportunities(Stage stage, Expression<Func<Quote, bool>> filterExpression = null) {
|
||||
var unitOfWork = CreateUnitOfWork();
|
||||
var quotes = unitOfWork.Quotes.GetFilteredEntities(filterExpression ?? FilterExpression);
|
||||
var customers = unitOfWork.Customers;
|
||||
return QueriesHelper.GetOpportunities(quotes, customers, stage).ToList();
|
||||
}
|
||||
public IEnumerable<Address> GetAddresses(Stage stage) {
|
||||
var unitOfWork = CreateUnitOfWork();
|
||||
return QueriesHelper.GetCustomerStore(unitOfWork.CustomerStores, unitOfWork.Quotes.GetFilteredEntities(FilterExpression).ActualQuotes(), stage).Distinct().Select(cs => cs.Address);
|
||||
}
|
||||
public decimal GetOpportunity(Stage stage, string city) {
|
||||
return QueriesHelper.GetOpportunity(GetQuotes(), stage, city);
|
||||
}
|
||||
public override void Delete(Quote entity) {
|
||||
MessageBoxService.ShowMessage("To ensure data integrity, the Opportunities module doesn't allow records to be deleted. Record deletion is supported by the Employees module.", "Delete Opportunity", MessageButton.OK);
|
||||
}
|
||||
public override IQueryable<Quote> GetEntities(Expression<Func<Quote, bool>> filter = null) {
|
||||
return base.GetEntities(filter).ActualQuotes();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
namespace DevExpress.DevAV.ViewModels {
|
||||
using System;
|
||||
using DevExpress.DevAV.ViewModels;
|
||||
using DevExpress.Mvvm.DataAnnotations;
|
||||
using DevExpress.Mvvm.POCO;
|
||||
|
||||
public class QuoteMapViewModel : QuoteViewModel {
|
||||
public virtual Stage Stage { get; set; }
|
||||
[Command]
|
||||
public void SetHighStage() {
|
||||
Stage = Stage.High;
|
||||
}
|
||||
public bool CanSetHighStage() {
|
||||
return Stage != Stage.High;
|
||||
}
|
||||
[Command]
|
||||
public void SetMediumStage() {
|
||||
Stage = Stage.Medium;
|
||||
}
|
||||
public bool CanSetMediumStage() {
|
||||
return Stage != Stage.Medium;
|
||||
}
|
||||
[Command]
|
||||
public void SetLowStage() {
|
||||
Stage = Stage.Low;
|
||||
}
|
||||
public bool CanSetLowStage() {
|
||||
return Stage != Stage.Low;
|
||||
}
|
||||
[Command]
|
||||
public void SetUnlikelyStage() {
|
||||
Stage = Stage.Unlikely;
|
||||
}
|
||||
public bool CanSetUnlikelyStage() {
|
||||
return Stage != Stage.Unlikely;
|
||||
}
|
||||
protected virtual void OnStageChanged() {
|
||||
this.RaiseCanExecuteChanged(x => x.SetHighStage());
|
||||
this.RaiseCanExecuteChanged(x => x.SetMediumStage());
|
||||
this.RaiseCanExecuteChanged(x => x.SetLowStage());
|
||||
this.RaiseCanExecuteChanged(x => x.SetUnlikelyStage());
|
||||
RaiseStageChanged();
|
||||
}
|
||||
public event EventHandler StageChanged;
|
||||
void RaiseStageChanged() {
|
||||
EventHandler handler = StageChanged;
|
||||
if(handler != null) handler(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using DevExpress.Mvvm;
|
||||
using DevExpress.Mvvm.POCO;
|
||||
using DevExpress.DevAV.Common.Utils;
|
||||
using DevExpress.DevAV.DevAVDbDataModel;
|
||||
using DevExpress.Mvvm.DataModel;
|
||||
using DevExpress.DevAV;
|
||||
using DevExpress.DevAV.Common.ViewModel;
|
||||
|
||||
namespace DevExpress.DevAV.ViewModels {
|
||||
/// <summary>
|
||||
/// Represents the single Quote object view model.
|
||||
/// </summary>
|
||||
public partial class QuoteViewModel : SingleObjectViewModel<Quote, long, IDevAVDbUnitOfWork> {
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of QuoteViewModel as a POCO view model.
|
||||
/// </summary>
|
||||
/// <param name="unitOfWorkFactory">A factory used to create a unit of work instance.</param>
|
||||
public static QuoteViewModel Create(IUnitOfWorkFactory<IDevAVDbUnitOfWork> unitOfWorkFactory = null) {
|
||||
return ViewModelSource.Create(() => new QuoteViewModel(unitOfWorkFactory));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the QuoteViewModel class.
|
||||
/// This constructor is declared protected to avoid undesired instantiation of the QuoteViewModel type without the POCO proxy factory.
|
||||
/// </summary>
|
||||
/// <param name="unitOfWorkFactory">A factory used to create a unit of work instance.</param>
|
||||
protected QuoteViewModel(IUnitOfWorkFactory<IDevAVDbUnitOfWork> unitOfWorkFactory = null)
|
||||
: base(unitOfWorkFactory ?? UnitOfWorkSource.GetUnitOfWorkFactory(), x => x.Quotes, x => x.Number) {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The view model that contains a look-up collection of Customers for the corresponding navigation property in the view.
|
||||
/// </summary>
|
||||
public IEntitiesViewModel<Customer> LookUpCustomers {
|
||||
get { return GetLookUpEntitiesViewModel((QuoteViewModel x) => x.LookUpCustomers, x => x.Customers); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The view model that contains a look-up collection of CustomerStores for the corresponding navigation property in the view.
|
||||
/// </summary>
|
||||
public IEntitiesViewModel<CustomerStore> LookUpCustomerStores {
|
||||
get { return GetLookUpEntitiesViewModel((QuoteViewModel x) => x.LookUpCustomerStores, x => x.CustomerStores); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The view model that contains a look-up collection of Employees for the corresponding navigation property in the view.
|
||||
/// </summary>
|
||||
public IEntitiesViewModel<Employee> LookUpEmployees {
|
||||
get { return GetLookUpEntitiesViewModel((QuoteViewModel x) => x.LookUpEmployees, x => x.Employees); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The view model for the QuoteQuoteItems detail collection.
|
||||
/// </summary>
|
||||
public CollectionViewModel<QuoteItem, long, IDevAVDbUnitOfWork> QuoteQuoteItemsDetails {
|
||||
get { return GetDetailsCollectionViewModel((QuoteViewModel x) => x.QuoteQuoteItemsDetails, x => x.QuoteItems, x => x.QuoteId, (x, key) => x.QuoteId = key); }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
namespace DevExpress.DevAV.ViewModels {
|
||||
partial class QuoteViewModel {
|
||||
}
|
||||
public partial class SynchronizedQuoteViewModel : QuoteViewModel {
|
||||
protected override bool EnableSelectedItemSynchronization {
|
||||
get { return true; }
|
||||
}
|
||||
protected override bool EnableEntityChangedSynchronization {
|
||||
get { return true; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
namespace DevExpress.DevAV.ViewModels {
|
||||
using System;
|
||||
using DevExpress.DevAV;
|
||||
using DevExpress.DevAV.DevAVDbDataModel;
|
||||
using DevExpress.DevAV.ViewModels;
|
||||
using DevExpress.DevAV.Properties;
|
||||
using DevExpress.Mvvm.POCO;
|
||||
|
||||
public class QuotesFilterTreeViewModel : FilterTreeViewModel<Quote, long, IDevAVDbUnitOfWork> {
|
||||
public static QuotesFilterTreeViewModel Create(QuoteCollectionViewModel collectionViewModel) {
|
||||
return ViewModelSource.Create(() => new QuotesFilterTreeViewModel(collectionViewModel));
|
||||
}
|
||||
protected QuotesFilterTreeViewModel(QuoteCollectionViewModel collectionViewModel)
|
||||
: base(collectionViewModel, new FilterTreeModelPageSpecificSettings<Settings>(Settings.Default, StaticFiltersName, x => x.QuotesStaticFilters, x => x.QuotesCustomFilters, x => x.QuotesGroupFilters)) {
|
||||
}
|
||||
protected new QuoteCollectionViewModel CollectionViewModel {
|
||||
get { return base.CollectionViewModel as QuoteCollectionViewModel; }
|
||||
}
|
||||
protected override bool EnableGroups {
|
||||
get { return false; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
namespace DevExpress.DevAV.ViewModels {
|
||||
using System;
|
||||
using DevExpress.Mvvm.DataModel;
|
||||
using DevExpress.DevAV.Common.ViewModel;
|
||||
using DevExpress.Mvvm;
|
||||
|
||||
public abstract class ReportViewModelBase {
|
||||
protected internal abstract bool IsLoaded { get; }
|
||||
protected internal abstract void OnReload();
|
||||
}
|
||||
public abstract class ReportViewModelBase<TReportType> : ReportViewModelBase, ISupportParameter
|
||||
where TReportType : struct {
|
||||
public virtual TReportType ReportType { get; set; }
|
||||
protected virtual void OnReportTypeChanged() {
|
||||
if(IsLoaded) RaiseReportTypeChanged();
|
||||
}
|
||||
public event EventHandler ReportTypeChanged;
|
||||
void RaiseReportTypeChanged() {
|
||||
EventHandler handler = ReportTypeChanged;
|
||||
if(handler != null)
|
||||
handler(this, EventArgs.Empty);
|
||||
}
|
||||
#region ISupportParameter
|
||||
object ISupportParameter.Parameter {
|
||||
get { return ReportType; }
|
||||
set {
|
||||
ReportType = (TReportType)value;
|
||||
OnParameterChanged();
|
||||
}
|
||||
}
|
||||
protected virtual void OnParameterChanged() { }
|
||||
#endregion
|
||||
}
|
||||
//
|
||||
public class ReportViewModelBase<TReportType, TEntity, TPrimaryKey, TUnitOfWork> : ReportViewModelBase<TReportType>
|
||||
where TReportType : struct
|
||||
where TEntity : class
|
||||
where TUnitOfWork : class, IUnitOfWork {
|
||||
protected override void OnParameterChanged() {
|
||||
base.OnParameterChanged();
|
||||
CheckReportEntityKey();
|
||||
}
|
||||
public virtual object ReportEntityKey { get; set; }
|
||||
protected virtual void OnReportEntityKeyChanged() {
|
||||
RaiseReportEntityKeyChanged();
|
||||
}
|
||||
public event EventHandler ReportEntityKeyChanged;
|
||||
protected internal override void OnReload() {
|
||||
if(!IsLoaded) return;
|
||||
CheckReportEntityKey();
|
||||
RaiseReload();
|
||||
}
|
||||
public event EventHandler Reload;
|
||||
bool isLoadedCore;
|
||||
protected internal override bool IsLoaded {
|
||||
get { return isLoadedCore; }
|
||||
}
|
||||
public void OnLoad() {
|
||||
CheckReportEntityKey();
|
||||
isLoadedCore = true;
|
||||
}
|
||||
void CheckReportEntityKey() {
|
||||
var collectionViewModel = GetCollectionViewModel();
|
||||
if(collectionViewModel != null)
|
||||
ReportEntityKey = collectionViewModel.SelectedEntityKey;
|
||||
}
|
||||
protected CollectionViewModel<TEntity, TPrimaryKey, TUnitOfWork> GetCollectionViewModel() {
|
||||
ISupportParentViewModel supportParent = this as ISupportParentViewModel;
|
||||
if(supportParent != null)
|
||||
return supportParent.ParentViewModel as CollectionViewModel<TEntity, TPrimaryKey, TUnitOfWork>;
|
||||
return null;
|
||||
}
|
||||
void RaiseReportEntityKeyChanged() {
|
||||
EventHandler handler = ReportEntityKeyChanged;
|
||||
if(handler != null)
|
||||
handler(this, EventArgs.Empty);
|
||||
}
|
||||
void RaiseReload() {
|
||||
EventHandler handler = Reload;
|
||||
if(handler != null)
|
||||
handler(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace DevExpress.DevAV.ViewModels {
|
||||
public enum SalesReportType {
|
||||
None,
|
||||
[Display(Name = "Sales Report")]
|
||||
SalesReport,
|
||||
[Display(Name = "Sales by store")]
|
||||
SalesByStore,
|
||||
[Display(Name = "Follow Up")]
|
||||
OrderFollowUp,
|
||||
[Display(Name = "Invoice")]
|
||||
Invoice,
|
||||
}
|
||||
public static class SalesReportTypeExtension {
|
||||
public static string ToFileName(this SalesReportType reportTemplate) {
|
||||
switch(reportTemplate) {
|
||||
case SalesReportType.SalesReport:
|
||||
return ("Sales Order Summary Report");
|
||||
case SalesReportType.SalesByStore:
|
||||
return ("Sales Analysys Report");
|
||||
case SalesReportType.OrderFollowUp:
|
||||
return ("SalesOrderFollowUp");
|
||||
default:
|
||||
return ("Sales Invoice");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user