blob: 937c235881fbec14b2fcd414510e9413c7d48103 (
plain)
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tango.BL;
using Tango.BL.Entities;
using Tango.Core.Commands;
using Tango.PPC.Common;
using Tango.PPC.Common.Navigation;
using Tango.PPC.Jobs.NavigationObjects;
using Tango.Settings;
namespace Tango.PPC.Jobs.ViewModels
{
/// <summary>
/// Represents the twine catalog view model.
/// </summary>
/// <seealso cref="PPCViewModel" />
/// <seealso cref="INavigationResultProvider{CatalogItem, TwineCatalogNavigationObject}" />
public class TwineCatalogViewVM : PPCViewModel, INavigationResultProvider<ColorCatalogsItem, TwineCatalogNavigationObject>
{
private bool _confirmed;
private ObservablesContext _db;
private ColorCatalog _catalog;
/// <summary>
/// Gets or sets the catalog.
/// </summary>
public ColorCatalog Catalog
{
get { return _catalog; }
set { _catalog = value; RaisePropertyChangedAuto(); }
}
private ColorCatalog _recent;
/// <summary>
/// Gets or sets the recent catalog items as a complete catalog.
/// </summary>
public ColorCatalog Recent
{
get { return _recent; }
set { _recent = value; RaisePropertyChangedAuto(); }
}
private String _filter;
/// <summary>
/// Gets or sets the filter.
/// </summary>
/// <value>
/// The filter.
/// </value>
public String Filter
{
get { return _filter; }
set { _filter = value; RaisePropertyChangedAuto(); }
}
private ColorCatalogsItem _selectedItem;
/// <summary>
/// Gets or sets the selected item.
/// </summary>
public ColorCatalogsItem SelectedItem
{
get { return _selectedItem; }
set
{
_selectedItem = value; RaisePropertyChangedAuto();
}
}
/// <summary>
/// Gets or sets the OK command.
/// </summary>
public RelayCommand OKCommand { get; set; }
/// <summary>
/// Initializes a new instance of the <see cref="TwineCatalogViewVM"/> class.
/// </summary>
public TwineCatalogViewVM()
{
OKCommand = new RelayCommand(Confirm);
}
/// <summary>
/// Called when the application has been started.
/// </summary>
public override void OnApplicationStarted()
{
_db = ObservablesContext.CreateDefault();
}
/// <summary>
/// Called when the navigation system has navigated to this VM view.
/// </summary>
public override void OnNavigatedTo()
{
base.OnNavigatedTo();
_confirmed = false;
Filter = "CATALOG";
}
/// <summary>
/// Confirms this instance.
/// </summary>
private void Confirm()
{
if (SelectedItem != null)
{
var settings = SettingsManager.Default.GetOrCreate<JobsModuleSettings>();
settings.AddRecentCatalogItem(Catalog, SelectedItem);
SettingsManager.Default.Save();
}
_confirmed = true;
NavigationManager.NavigateBack();
}
/// <summary>
/// Called when the navigation system requests a result when it is navigating away from this instance.
/// </summary>
/// <returns></returns>
public ColorCatalogsItem GetNavigationResult()
{
if (_confirmed)
{
return SelectedItem;
}
else
{
return null;
}
}
/// <summary>
/// Called when the navigation object has been received
/// </summary>
/// <param name="brushStop">The brush stop.</param>
public virtual void OnNavigationObjectReceived(TwineCatalogNavigationObject obj)
{
IsFree = false;
Filter = "CATALOG";
Catalog = obj.Catalog;
ColorCatalog recentCatalog = new ColorCatalog();
recentCatalog.Name = Catalog.Name;
var settings = SettingsManager.Default.GetOrCreate<JobsModuleSettings>();
var settingsCatalog = settings.RecentCatalogsItems.SingleOrDefault(x => x.Guid == Catalog.Guid);
if (settingsCatalog != null)
{
var allItems = Catalog.ColorCatalogsGroups.SelectMany(x => x.ColorCatalogsItems).ToList();
foreach (var itemGuid in settingsCatalog.RecentItems)
{
var realItem = allItems.SingleOrDefault(x => x.Guid == itemGuid);
if (realItem != null)
{
var group = recentCatalog.ColorCatalogsGroups.SingleOrDefault(x => x.Guid == realItem.ColorCatalogsGroup.Guid);
if (group == null)
{
group = new ColorCatalogsGroup();
group.Guid = realItem.ColorCatalogsGroup.Guid;
group.Name = realItem.ColorCatalogsGroup.Name;
group.GroupIndex = realItem.ColorCatalogsGroup.GroupIndex;
recentCatalog.ColorCatalogsGroups.Add(group);
}
group.ColorCatalogsItems.Add(realItem);
}
}
}
Recent = recentCatalog;
SelectedItem = obj.SelectedItem;
IsFree = true;
}
}
}
|