Add Outlook Inspired and Stock Market demos

This commit is contained in:
maxerokh
2018-12-13 18:49:44 +03:00
parent b5cab35919
commit 2e45b5d38f
833 changed files with 124450 additions and 47 deletions

View File

@@ -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);
}
}
}

View File

@@ -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)) {
}
}
}

View File

@@ -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;
}
}
}

View File

@@ -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
}
}

View File

@@ -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); }
}
}
}

View File

@@ -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; }
}
}
}

View File

@@ -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; }
}
}
}

View File

@@ -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(); }
}
}
}