-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainPage.xaml.cs
298 lines (277 loc) · 13 KB
/
MainPage.xaml.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
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
using CommunityToolkit.Maui.Markup;
using CommunityToolkit.Maui.Markup.LeftToRight;
using MauiApp2.Models;
using MauiApp2.ViewModels;
using Microsoft.Maui.Controls;
using Microsoft.Maui.Controls.Shapes;
using System.Collections.ObjectModel;
using System.Linq;
namespace MauiApp2;
public partial class MainPage : ContentPage
{
readonly MainViewModel sharedCollectionViewModel;
internal Polygon SortingIcon;
public MainPage()
{
InitializeComponent();
sharedCollectionViewModel = new MainViewModel();
BindingContext = sharedCollectionViewModel;
LoadFilters();
}
public void LoadFilters()
{
SortingIcon = new();
Grid DateTimeGrid = new()
{
Margin = new Thickness(50),
RowDefinitions =
{
new RowDefinition{Height=50},
},
ColumnDefinitions=
{
new ColumnDefinition(GridLength.Star),
new ColumnDefinition(GridLength.Star),
new ColumnDefinition(GridLength.Star),
}
};
Grid ListGrid = new()
{
Margin = new Thickness(10, 5, 10, 10),
RowDefinitions =
{
new RowDefinition(GridLength.Star),
},
ColumnDefinitions =
{
new ColumnDefinition(GridLength.Star),
new ColumnDefinition(GridLength.Star),
new ColumnDefinition(GridLength.Star),
new ColumnDefinition(GridLength.Star),
}
};
DateTimeGrid.Children.Add(new DateLabel("From Date").Row(0).Column(0));
DateTimeGrid.Children.Add(new FromDatetime(sharedCollectionViewModel).Bind(DatePicker.DateProperty, nameof(sharedCollectionViewModel.UserEntryFromDate)).Row(0).Column(0));
DateTimeGrid.Children.Add(new DateLabel("To Date").Row(0).Column(1));
DateTimeGrid.Children.Add(new ToDatetime(sharedCollectionViewModel).Bind(DatePicker.DateProperty, nameof(sharedCollectionViewModel.UserEntryToDate)).Row(0).Column(1));
DateTimeGrid.Children.Add(new MyEntry(sharedCollectionViewModel).Bind(Entry.TextProperty, nameof(sharedCollectionViewModel.UserEntryText)).Row(0).Column(2));
//ListGrid.Children.Add(new MyPickerView(sharedCollectionViewModel).Bind(Picker.BindingContextProperty, nameof(sharedCollectionViewModel.UserItems), BindingMode.TwoWay).Row(0).Column(0));
ListGrid.Children.Add(new MyCollectionView(sharedCollectionViewModel).Bind(ItemsView.ItemsSourceProperty, nameof(sharedCollectionViewModel.Products), BindingMode.TwoWay).Row(0).Column(0));
ListGrid.Children.Add(new MyEventsCollectionView(sharedCollectionViewModel).Bind(ItemsView.ItemsSourceProperty, nameof(sharedCollectionViewModel.Events), BindingMode.TwoWay).Row(0).Column(1));
ListGrid.Children.Add(new MyCardCollectionView(sharedCollectionViewModel).Bind(ItemsView.ItemsSourceProperty, nameof(sharedCollectionViewModel.Cards), BindingMode.TwoWay).Row(0).Column(2));
ListGrid.Children.Add(new ClearButtion(sharedCollectionViewModel).Bind(ItemsView.ItemsSourceProperty, nameof(sharedCollectionViewModel.UserItems), BindingMode.TwoWay).Row(0).Column(3));
Grid MainGrid = new()
{
RowDefinitions =
{
new RowDefinition(GridLength.Star),
new RowDefinition(GridLength.Star),
new RowDefinition(GridLength.Star),
},
};
MainGrid.Children.Add(DateTimeGrid.Column(0));
MainGrid.Children.Add(ListGrid.Row(1));
MainGrid.Children.Add(_dataGrid1.Row(2));
Content = new Grid
{
Children = {
MainGrid
}
};
}
class MyEntry : Entry
{
readonly MainViewModel _sharedCollectionViewModel;
public MyEntry(MainViewModel sharedCollectionViewModel)
{
WidthRequest = 250;
Placeholder = "Search Product";
_sharedCollectionViewModel = sharedCollectionViewModel;
TextChanged += OnMyEditTextChanged;
Margin = 10;
BackgroundColor = Colors.LightBlue;
}
private void OnMyEditTextChanged(object sender, TextChangedEventArgs e)
{
if (string.IsNullOrWhiteSpace(e.NewTextValue))
{
_sharedCollectionViewModel.Teams = new ObservableCollection<Team>(_sharedCollectionViewModel.SaveHistoryUserItems);
}
else
{
_sharedCollectionViewModel.Teams = new ObservableCollection<Team>(_sharedCollectionViewModel.SaveHistoryUserItems.Where(i => i.Name.ToLower().Contains(e.NewTextValue.ToLower())));
}
}
}
class FromDatetime : DatePicker
{
readonly MainViewModel _sharedCollectionViewModel;
public FromDatetime(MainViewModel sharedCollectionViewModel)
{
_sharedCollectionViewModel = sharedCollectionViewModel;
DateSelected += OnMyEditTextChanged;
}
private void OnMyEditTextChanged(object sender, DateChangedEventArgs e)
{
_sharedCollectionViewModel.Teams = new ObservableCollection<Team>(_sharedCollectionViewModel.SaveHistoryUserItems.Where(i => i.CreatedDate >= DateOnly.FromDateTime(e.NewDate.Date)));
}
}
class DateLabel: Label
{
public DateLabel(string name)
{
Margin = 10;
Text = name;
WidthRequest = 100;
BackgroundColor = Colors.LightBlue;
HorizontalTextAlignment = TextAlignment.Center;
VerticalTextAlignment= TextAlignment.Center;
}
}
class ToDatetime : DatePicker
{
readonly MainViewModel _sharedCollectionViewModel;
public ToDatetime(MainViewModel sharedCollectionViewModel)
{
_sharedCollectionViewModel = sharedCollectionViewModel;
DateSelected += OnDateSelected;
}
private void OnDateSelected(object sender, DateChangedEventArgs e)
{
_sharedCollectionViewModel.Teams = new ObservableCollection<Team>(_sharedCollectionViewModel.SaveHistoryUserItems.Where(i => i.CreatedDate <= DateOnly.FromDateTime(e.NewDate.Date)));
}
}
class MyCollectionView : CollectionView
{
readonly MainViewModel _sharedCollectionViewModel;
public MyCollectionView(MainViewModel sharedCollectionViewModel)
{
_sharedCollectionViewModel = sharedCollectionViewModel;
SelectionMode = SelectionMode.Multiple;
BackgroundColor = Colors.LightBlue;
Header = "Select Product";
SelectionChanged += HandleCollectionViewSelectionChanged;
ItemsLayout = new GridItemsLayout(orientation: ItemsLayoutOrientation.Vertical);
ItemTemplate = new DataTemplate(() =>
{
VerticalStackLayout VerticalView = new VerticalStackLayout { Spacing = 50, Padding = new Thickness(0, 0, 0,0) ,IsVisible=true}.BackgroundColor(Colors.LightGray);
Label nameLabel = new Label { }.Left().TextColor(Colors.Black);
nameLabel.SetBinding(Label.TextProperty, "Name");
VerticalView.Children.Add(nameLabel);
return VerticalView;
});
}
void HandleCollectionViewSelectionChanged(object sender, SelectionChangedEventArgs e)
{
var list = (Product)e.CurrentSelection.FirstOrDefault();
if (list != null) _sharedCollectionViewModel.Teams = new ObservableCollection<Team>(_sharedCollectionViewModel.SaveHistoryUserItems.Where(i => i.Name == list.Name));
}
}
class MyEventsCollectionView : CollectionView
{
readonly MainViewModel _sharedCollectionViewModel;
public MyEventsCollectionView(MainViewModel sharedCollectionViewModel)
{
_sharedCollectionViewModel = sharedCollectionViewModel;
SelectionMode = SelectionMode.Multiple;
BackgroundColor = Colors.LightBlue;
Header = "Select Event";
SelectionChanged += HandleCollectionViewSelectionChanged;
ItemsLayout = new GridItemsLayout(orientation: ItemsLayoutOrientation.Vertical);
ItemTemplate = new DataTemplate(() =>
{
VerticalStackLayout VerticalView = new VerticalStackLayout { Spacing = 0, Padding = new Thickness(0, 0, 0, 0) }.BackgroundColor(Colors.LightGray);
Label nameLabel = new Label { }.Left().TextColor(Colors.Black);
nameLabel.SetBinding(Label.TextProperty, "Name");
VerticalView.Children.Add(nameLabel);
return VerticalView;
});
}
void HandleCollectionViewSelectionChanged(object sender, SelectionChangedEventArgs e)
{
var list = (Event)e.CurrentSelection.FirstOrDefault();
if (list != null) _sharedCollectionViewModel.Teams = new ObservableCollection<Team>(_sharedCollectionViewModel.SaveHistoryUserItems.Where(i => i.Event == list.Name));
}
}
class MyCardCollectionView : CollectionView
{
readonly MainViewModel _sharedCollectionViewModel;
internal Polygon SortingIcon;
internal View SortingIconContainer { get; }
public MyCardCollectionView(MainViewModel sharedCollectionViewModel)
{
SortingIcon = new();
SortingIconContainer = new ContentView
{
IsVisible = false,
Content = SortingIcon,
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.Center,
InputTransparent = true,
};
_sharedCollectionViewModel = sharedCollectionViewModel;
SelectionMode = SelectionMode.Multiple;
BackgroundColor = Colors.LightBlue;
Header = "Select Card";
SelectionChanged += HandleCollectionViewSelectionChanged;
ItemsLayout = new GridItemsLayout(orientation: ItemsLayoutOrientation.Vertical);
ItemTemplate = new DataTemplate(() =>
{
VerticalStackLayout VerticalView = new VerticalStackLayout { Spacing = 0, Padding = new Thickness(0, 0, 0, 0) }.BackgroundColor(Colors.LightGray);
Label nameLabel = new Label { }.Left().TextColor(Colors.Black);
nameLabel.SetBinding(Label.TextProperty, "Name");
VerticalView.Children.Add(nameLabel);
return VerticalView;
});
}
void HandleCollectionViewSelectionChanged(object sender, SelectionChangedEventArgs e)
{
Card list = (Card) e.CurrentSelection.FirstOrDefault();
if (list!=null) _sharedCollectionViewModel.Teams = new ObservableCollection<Team>(_sharedCollectionViewModel.SaveHistoryUserItems.Where(i => i.CardNo == list.Name));
;
}
}
class ClearButtion: Button
{
readonly MainViewModel _sharedCollectionViewModel;
public ClearButtion(MainViewModel sharedCollectionViewModel)
{
Text = "Clear All";
TextColor = Colors.Red;
_sharedCollectionViewModel = sharedCollectionViewModel;
Clicked += ButtonClicked;
}
void ButtonClicked(object sender, EventArgs e)
{
_sharedCollectionViewModel.Teams = _sharedCollectionViewModel.SaveHistoryUserItems;
}
}
class MyPickerView : Picker
{
readonly MainViewModel _sharedCollectionViewModel;
public MyPickerView(MainViewModel sharedCollectionViewModel)
{
_sharedCollectionViewModel = sharedCollectionViewModel;
//= SelectionMode.Multiple;
BackgroundColor = Colors.LightBlue;
Title = "Select Product";
SelectedIndexChanged += OnPickerSelectedIndexChanged;
ItemDisplayBinding = new Binding("Name");
//ItemsLayout = new GridItemsLayout(orientation: ItemsLayoutOrientation.Vertical);
//ItemTemplate = new DataTemplate(() =>
//{
// VerticalStackLayout VerticalView = new VerticalStackLayout { Spacing = 50, Padding = new Thickness(10, 10, 10, 10) }.BackgroundColor(Colors.LightGray);
// Label nameLabel = new Label { }.Left().TextColor(Colors.Black);
// nameLabel.SetBinding(Label.TextProperty, "Name");
// VerticalView.Children.Add(nameLabel);
// return VerticalView;
//});
}
void OnPickerSelectedIndexChanged(object sender, EventArgs e)
{
Team list = (Team)sender;
if (list != null) _sharedCollectionViewModel.Teams = new ObservableCollection<Team>(_sharedCollectionViewModel.SaveHistoryUserItems.Where(i => i.Name == list.Name));
;
}
}
}