summaryrefslogtreecommitdiff
path: root/Codemerx/Gestor.Application/Drawers/Relatorios/ConfiguracaoRelatorio.cs
blob: acd3f1fe2c46c650f334053a256a3ff4334c059f (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
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
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
using Gestor.Application;
using Gestor.Application.ViewModels.Generic;
using Gestor.Application.ViewModels.Relatorios;
using Gestor.Model.Domain.Relatorios;
using MaterialDesignThemes.Wpf;
using System;
using System.CodeDom.Compiler;
using System.ComponentModel;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Markup;
using System.Windows.Threading;

namespace Gestor.Application.Drawers.Relatorios
{
	public class ConfiguracaoRelatorio : UserControl, IComponentConnector, IStyleConnector
	{
		internal System.Windows.Controls.ProgressBar ProgressBar;

		internal RadioButton CampoButton;

		internal RadioButton TotalizacaoButton;

		internal ComboBox CampoComboBox;

		internal ComboBox TotalizacaoComboBox;

		internal DataGrid ParametrosGrid;

		internal DataGrid TotalizacaoGrid;

		internal Snackbar SnackbarArquivoDigital;

		private bool _contentLoaded;

		public RelatorioViewModel ViewModel
		{
			get;
			set;
		}

		[DebuggerNonUserCode]
		[GeneratedCode("PresentationBuildTasks", "4.0.0.0")]
		internal Delegate _CreateDelegate(Type delegateType, string handler)
		{
			return Delegate.CreateDelegate(delegateType, this, handler);
		}

		public ConfiguracaoRelatorio(RelatorioViewModel viewModel)
		{
			this.ViewModel = viewModel;
			base.DataContext = this.ViewModel;
			this.InitializeComponent();
			System.Windows.Threading.Dispatcher dispatcher = base.Dispatcher;
			if (dispatcher == null)
			{
				return;
			}
			dispatcher.BeginInvoke(DispatcherPriority.Render, new Action(this.ContentLoad));
		}

		private void AdicionarParametro_OnClick(object sender, RoutedEventArgs e)
		{
			object item;
			RelatorioViewModel viewModel = this.ViewModel;
			ComboBox campoComboBox = this.CampoComboBox;
			if (campoComboBox != null)
			{
				item = campoComboBox.Items[this.CampoComboBox.SelectedIndex];
			}
			else
			{
				item = null;
			}
			viewModel.AdicionarParametro((ParametrosRelatorio)item);
		}

		private void AdicionarTotalizacao_OnClick(object sender, RoutedEventArgs e)
		{
			object item;
			RelatorioViewModel viewModel = this.ViewModel;
			ComboBox totalizacaoComboBox = this.TotalizacaoComboBox;
			if (totalizacaoComboBox != null)
			{
				item = totalizacaoComboBox.Items[this.TotalizacaoComboBox.SelectedIndex];
			}
			else
			{
				item = null;
			}
			viewModel.AdicionarTotalizacao((ParametrosTotalizacao)item);
		}

		private void Campo_OnChecked(object sender, RoutedEventArgs e)
		{
			this.ViewModel.IsCampo = true;
		}

		private void CloseSlackBar()
		{
			Thread.Sleep(5000);
			System.Windows.Threading.Dispatcher dispatcher = App.ProgressRing.Dispatcher;
			if (dispatcher == null)
			{
				return;
			}
			dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() => this.Toggle("", false)));
		}

		private async void ContentLoad()
		{
			this.CampoButton.IsChecked = new bool?(this.ViewModel.IsCampo);
			this.TotalizacaoButton.IsChecked = new bool?(!this.ViewModel.IsCampo);
			this.CampoButton.Checked += new RoutedEventHandler(this.Campo_OnChecked);
			this.TotalizacaoButton.Checked += new RoutedEventHandler(this.Totalizacao_OnChecked);
			this.ViewModel.IsEnabled = false;
			await this.ViewModel.CarregarConfiguracoes();
			this.ViewModel.IsEnabled = true;
		}

		private void DescerParametro_OnClick(object sender, RoutedEventArgs e)
		{
			bool selectedIndex;
			object item;
			DataGrid parametrosGrid = this.ParametrosGrid;
			if (parametrosGrid != null)
			{
				selectedIndex = parametrosGrid.SelectedIndex < 0;
			}
			else
			{
				selectedIndex = false;
			}
			if (selectedIndex)
			{
				return;
			}
			RelatorioViewModel viewModel = this.ViewModel;
			DataGrid dataGrid = this.ParametrosGrid;
			if (dataGrid != null)
			{
				item = dataGrid.Items[this.ParametrosGrid.SelectedIndex];
			}
			else
			{
				item = null;
			}
			viewModel.DescerParametro((ParametrosRelatorio)item);
		}

		private void ExcluirParametro_OnClick(object sender, RoutedEventArgs e)
		{
			bool selectedIndex;
			object item;
			DataGrid parametrosGrid = this.ParametrosGrid;
			if (parametrosGrid != null)
			{
				selectedIndex = parametrosGrid.SelectedIndex < 0;
			}
			else
			{
				selectedIndex = false;
			}
			if (selectedIndex)
			{
				return;
			}
			RelatorioViewModel viewModel = this.ViewModel;
			DataGrid dataGrid = this.ParametrosGrid;
			if (dataGrid != null)
			{
				item = dataGrid.Items[this.ParametrosGrid.SelectedIndex];
			}
			else
			{
				item = null;
			}
			viewModel.ExcluirParametro((ParametrosRelatorio)item);
		}

		private void ExcluirTotalizacao_OnClick(object sender, RoutedEventArgs e)
		{
			bool selectedIndex;
			object item;
			DataGrid totalizacaoGrid = this.TotalizacaoGrid;
			if (totalizacaoGrid != null)
			{
				selectedIndex = totalizacaoGrid.SelectedIndex < 0;
			}
			else
			{
				selectedIndex = false;
			}
			if (selectedIndex)
			{
				return;
			}
			RelatorioViewModel viewModel = this.ViewModel;
			DataGrid dataGrid = this.TotalizacaoGrid;
			if (dataGrid != null)
			{
				item = dataGrid.Items[this.TotalizacaoGrid.SelectedIndex];
			}
			else
			{
				item = null;
			}
			viewModel.ExcluirTotalizacao((ParametrosTotalizacao)item);
		}

		private void Fechar_OnClick(object sender, RoutedEventArgs e)
		{
			this.ViewModel.CloseDrawer();
		}

		[DebuggerNonUserCode]
		[GeneratedCode("PresentationBuildTasks", "4.0.0.0")]
		public void InitializeComponent()
		{
			if (this._contentLoaded)
			{
				return;
			}
			this._contentLoaded = true;
			System.Windows.Application.LoadComponent(this, new Uri("/Gestor.Application;component/drawers/relatorios/configuracaorelatorio.xaml", UriKind.Relative));
		}

		private async void Salvar_OnClick(object sender, RoutedEventArgs e)
		{
			this.ViewModel.IsEnabled = false;
			bool flag = await this.ViewModel.SalvarParametros();
			this.ViewModel.IsEnabled = true;
			if (flag)
			{
				this.Toggle("CONFIGURAÇÕES SALVAS.", true);
			}
		}

		private void SnackbarMessage_ActionClick(object sender, RoutedEventArgs e)
		{
			this.SnackbarArquivoDigital.set_IsActive(false);
		}

		private void SubirParametro_OnClick(object sender, RoutedEventArgs e)
		{
			bool selectedIndex;
			object item;
			DataGrid parametrosGrid = this.ParametrosGrid;
			if (parametrosGrid != null)
			{
				selectedIndex = parametrosGrid.SelectedIndex < 0;
			}
			else
			{
				selectedIndex = false;
			}
			if (selectedIndex)
			{
				return;
			}
			RelatorioViewModel viewModel = this.ViewModel;
			DataGrid dataGrid = this.ParametrosGrid;
			if (dataGrid != null)
			{
				item = dataGrid.Items[this.ParametrosGrid.SelectedIndex];
			}
			else
			{
				item = null;
			}
			viewModel.SubirParametro((ParametrosRelatorio)item);
		}

		[DebuggerNonUserCode]
		[EditorBrowsable(EditorBrowsableState.Never)]
		[GeneratedCode("PresentationBuildTasks", "4.0.0.0")]
		void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target)
		{
			switch (connectionId)
			{
				case 1:
				{
					((Button)target).Click += new RoutedEventHandler(this.Fechar_OnClick);
					return;
				}
				case 2:
				{
					this.ProgressBar = (System.Windows.Controls.ProgressBar)target;
					return;
				}
				case 3:
				{
					this.CampoButton = (RadioButton)target;
					return;
				}
				case 4:
				{
					this.TotalizacaoButton = (RadioButton)target;
					return;
				}
				case 5:
				{
					this.CampoComboBox = (ComboBox)target;
					return;
				}
				case 6:
				{
					((MenuItem)target).Click += new RoutedEventHandler(this.AdicionarParametro_OnClick);
					return;
				}
				case 7:
				{
					this.TotalizacaoComboBox = (ComboBox)target;
					return;
				}
				case 8:
				{
					((MenuItem)target).Click += new RoutedEventHandler(this.AdicionarTotalizacao_OnClick);
					return;
				}
				case 9:
				{
					this.ParametrosGrid = (DataGrid)target;
					return;
				}
				case 10:
				case 11:
				case 12:
				case 14:
				{
					this._contentLoaded = true;
					return;
				}
				case 13:
				{
					this.TotalizacaoGrid = (DataGrid)target;
					return;
				}
				case 15:
				{
					((MenuItem)target).Click += new RoutedEventHandler(this.Salvar_OnClick);
					return;
				}
				case 16:
				{
					this.SnackbarArquivoDigital = (Snackbar)target;
					return;
				}
				case 17:
				{
					((SnackbarMessage)target).add_ActionClick(new RoutedEventHandler(this.SnackbarMessage_ActionClick));
					return;
				}
				default:
				{
					this._contentLoaded = true;
					return;
				}
			}
		}

		[DebuggerNonUserCode]
		[EditorBrowsable(EditorBrowsableState.Never)]
		[GeneratedCode("PresentationBuildTasks", "4.0.0.0")]
		void System.Windows.Markup.IStyleConnector.Connect(int connectionId, object target)
		{
			switch (connectionId)
			{
				case 10:
				{
					((Button)target).Click += new RoutedEventHandler(this.SubirParametro_OnClick);
					return;
				}
				case 11:
				{
					((Button)target).Click += new RoutedEventHandler(this.DescerParametro_OnClick);
					return;
				}
				case 12:
				{
					((Button)target).Click += new RoutedEventHandler(this.ExcluirParametro_OnClick);
					return;
				}
				case 13:
				{
					return;
				}
				case 14:
				{
					((Button)target).Click += new RoutedEventHandler(this.ExcluirTotalizacao_OnClick);
					return;
				}
				default:
				{
					return;
				}
			}
		}

		public void Toggle(string message, bool active = true)
		{
			this.SnackbarArquivoDigital.get_Message().Content = message;
			this.SnackbarArquivoDigital.set_IsActive(active);
			if (!active)
			{
				return;
			}
			Task.Factory.StartNew(new Action(this.CloseSlackBar));
		}

		private void Totalizacao_OnChecked(object sender, RoutedEventArgs e)
		{
			this.ViewModel.IsCampo = false;
		}
	}
}