-
Notifications
You must be signed in to change notification settings - Fork 1
/
ProductView.cs
80 lines (74 loc) · 2.56 KB
/
ProductView.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DevExpress.Data.Filtering;
using DevExpress.ExpressApp;
using DevExpress.Persistent.Base;
namespace NonPersistentObjectsDemo.Module.BusinessObjects {
[DefaultClassOptions]
[DevExpress.ExpressApp.DC.DomainComponent]
public class ProductView : NonPersistentObjectBase {
private IList<Product> _AllProducts;
public IList<Product> AllProducts {
get {
if(_AllProducts == null) {
_AllProducts = ObjectSpace.GetObjects<Product>();
}
return _AllProducts;
}
}
private Category _Category;
[ImmediatePostData]
public Category Category {
get { return _Category; }
set {
if(value != Category) {
_Category = value;
OnPropertyChanged(nameof(Category));
UpdateProducts();
}
}
}
private void UpdateProducts() {
if(_Products != null) {
ObjectSpace.ApplyCriteria(_Products, CriteriaOperator.Parse("? is null or Category = ?", Category, Category));
}
}
private IList<Product> _Products;
public IList<Product> Products {
get {
if(_Products == null) {
_Products = ObjectSpace.GetObjects<Product>();
UpdateProducts();
}
return _Products;
}
}
}
class ProductViewAdapter {
private NonPersistentObjectSpace objectSpace;
private bool isDirty = true;
public ProductViewAdapter(NonPersistentObjectSpace npos) {
this.objectSpace = npos;
objectSpace.ObjectGetting += ObjectSpace_ObjectGetting;
objectSpace.Reloaded += ObjectSpace_Reloaded;
}
private void ObjectSpace_Reloaded(object sender, EventArgs e) {
isDirty = true;
}
private void ObjectSpace_ObjectGetting(object sender, ObjectGettingEventArgs e) {
if(e.SourceObject is ProductView) {
var obj = (ProductView)e.SourceObject;
if(isDirty) {
var clone = new ProductView();
clone.Category = objectSpace.GetObject<Category>(obj.Category);
e.TargetObject = clone;
isDirty = false;
}
}
}
}
}