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,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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user