summaryrefslogtreecommitdiff
path: root/Gestor.Application/Views/Financeiro/BancosContasView.cs
blob: fa40fe760f26cbfa56228b1af92c35bd76d55377 (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
using CurrencyTextBoxControl;
using Gestor.Application.Helpers;
using Gestor.Application.ViewModels.Financeiro;
using Gestor.Application.ViewModels.Generic;
using Gestor.Application.Views.Generic;
using Gestor.Common.Validation;
using Gestor.Model.Domain.Common;
using Gestor.Model.Domain.Financeiro;
using Gestor.Model.Domain.Generic;
using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Input;
using System.Windows.Markup;
using System.Windows.Threading;

namespace Gestor.Application.Views.Financeiro
{
	public class BancosContasView : BaseUserControl, IComponentConnector, IStyleConnector
	{
		internal DataGrid BancosContasGrid;

		internal AutoCompleteBox AutoCompleteBanco;

		internal CurrencyTextBox ValorSaldoBox;

		private bool _contentLoaded;

		public BancosContasViewModel ViewModel
		{
			get;
			set;
		}

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

		public BancosContasView()
		{
			base.Tag = "BANCOS E CONTAS";
			this.ViewModel = new BancosContasViewModel();
			base.DataContext = this.ViewModel;
			this.ViewModel.Alterar(false);
			this.InitializeComponent();
			System.Windows.Threading.Dispatcher dispatcher = base.Dispatcher;
			if (dispatcher == null)
			{
				return;
			}
			dispatcher.BeginInvoke(DispatcherPriority.Render, new Action(this.ContentLoad));
		}

		private void AbrirLog_OnClick(object sender, RoutedEventArgs e)
		{
			this.ViewModel.AbrirLog(26, this.ViewModel.SelectedBancosContas.get_Id());
		}

		private void Alterar_OnClick(object sender, RoutedEventArgs e)
		{
			this.ViewModel.CancelBancosContas = (BancosContas)this.ViewModel.SelectedBancosContas.Clone();
			this.ViewModel.Alterar(true);
			this.ViewModel.SelectedBancosContas.Initialize();
		}

		private void AutoCompleteBancoBox_Populating(object sender, PopulatingEventArgs e)
		{
			if (e.get_Parameter().Length < 3)
			{
				return;
			}
			e.set_Cancel(true);
			this.ViewModel.BuscarBanco(ValidationHelper.RemoveDiacritics(e.get_Parameter().Trim())).ContinueWith((Task<List<Banco>> searchResult) => {
				if (searchResult.Result == null)
				{
					return;
				}
				AutoCompleteBox autoCompleteBox = (AutoCompleteBox)sender;
				autoCompleteBox.set_ItemsSource(searchResult.Result);
				autoCompleteBox.PopulateComplete();
			}, TaskScheduler.FromCurrentSynchronizationContext());
		}

		private void AutoCompleteBancosContasBox_Populating(object sender, PopulatingEventArgs e)
		{
			if (e.get_Parameter().Length < 3)
			{
				return;
			}
			e.set_Cancel(true);
			this.ViewModel.Filtrar(ValidationHelper.RemoveDiacritics(e.get_Parameter().Trim())).ContinueWith((Task<List<BancosContas>> searchResult) => {
				if (searchResult.Result == null)
				{
					return;
				}
				AutoCompleteBox autoCompleteBox = (AutoCompleteBox)sender;
				autoCompleteBox.set_ItemsSource(searchResult.Result);
				autoCompleteBox.PopulateComplete();
			}, TaskScheduler.FromCurrentSynchronizationContext());
		}

		private void AutoCompleteBox_OnTextChanged(object sender, RoutedEventArgs e)
		{
			if (!string.IsNullOrWhiteSpace(((AutoCompleteBox)sender).get_Text()))
			{
				return;
			}
			this.ViewModel.FiltrarBancosContas("");
		}

		private void BancosContasGrid_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
		{
			DataGrid dataGrid = (DataGrid)sender;
			if (dataGrid != null && dataGrid.SelectedIndex < 0)
			{
				return;
			}
			this.ViewModel.SelectedBancosContas = (BancosContas)((dataGrid != null ? dataGrid.Items[dataGrid.SelectedIndex] : null));
		}

		private void Cancelar_OnClick(object sender, RoutedEventArgs e)
		{
			this.ViewModel.CancelarAlteracao();
		}

		private void ContentLoad()
		{
			this.BancosContasGrid.SelectedIndex = 0;
			this.BancosContasGrid.SelectionChanged += new SelectionChangedEventHandler(this.BancosContasGrid_OnSelectionChanged);
			this.BancosContasGrid.MouseDoubleClick += new MouseButtonEventHandler((object sender, MouseButtonEventArgs args) => {
			});
		}

		private void Excluir_OnClick(object sender, RoutedEventArgs e)
		{
			this.ViewModel.Excluir();
		}

		private void ExcluirSaldo_OnClick(object sender, RoutedEventArgs e)
		{
			((MenuItem)sender).Click -= new RoutedEventHandler(this.ExcluirSaldo_OnClick);
			this.ViewModel.ExcluirSaldo();
			((MenuItem)sender).Click += new RoutedEventHandler(this.ExcluirSaldo_OnClick);
		}

		private async void FechamentoBox_OnLostKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)
		{
			DateTime dateTime;
			DatePicker datePicker = (DatePicker)sender;
			datePicker.Text = ValidationHelper.FormatDate(datePicker.Text);
			if (DateTime.TryParse(datePicker.Text, out dateTime))
			{
				CurrencyTextBox valorSaldoBox = this.ValorSaldoBox;
				valorSaldoBox.set_Number(await this.ViewModel.CalcularValor());
				valorSaldoBox = null;
			}
		}

		private async void FecharSaldo_OnClick(object sender, RoutedEventArgs e)
		{
			bool flag;
			TimeSpan? nullable;
			bool flag1;
			DateTime? dataFinal = this.ViewModel.SelectedSaldo.get_DataFinal();
			if (dataFinal.HasValue)
			{
				dataFinal = this.ViewModel.SelectedSaldo.get_DataInicio();
				DateTime? dataFinal1 = this.ViewModel.SelectedSaldo.get_DataFinal();
				DateTime value = dataFinal1.Value;
				flag = (dataFinal.HasValue ? dataFinal.GetValueOrDefault() >= value : false);
				if (!flag)
				{
					dataFinal1 = this.ViewModel.SelectedSaldo.get_DataFinal();
					value = dataFinal1.Value;
					dataFinal = this.ViewModel.SelectedSaldo.get_DataInicio();
					if (dataFinal.HasValue)
					{
						nullable = new TimeSpan?(value - dataFinal.GetValueOrDefault());
					}
					else
					{
						nullable = null;
					}
					TimeSpan? nullable1 = nullable;
					if (!nullable1.HasValue)
					{
						flag1 = false;
					}
					else
					{
						flag1 = (nullable1.Value.TotalDays < 28 ? true : nullable1.Value.TotalDays > 31);
					}
					bool flag2 = flag1;
					if (flag2)
					{
						flag2 = !await this.ViewModel.ShowMessage("O INTERVALO DE FECHAMENTO É RECOMENDADO 1 MÊS. DESEJA CONTINUAR?", "SIM", "NÃO", false);
					}
					if (!flag2)
					{
						this.ViewModel.Loading(true);
						await this.ViewModel.FecharSaldo();
						this.ViewModel.Loading(false);
					}
				}
				else
				{
					await this.ViewModel.ShowMessage("A DATA DE FECHAMENTO DEVE SER MAIOR QUE A DATA DE ABERTURA DO SALDO.", "OK", "", false);
				}
			}
			else
			{
				await this.ViewModel.ShowMessage("NECESSÁRIO PREENCHER A DATA DE FECHAMENTO.", "OK", "", false);
			}
		}

		private void Incluir_OnClick(object sender, RoutedEventArgs e)
		{
			this.ViewModel.Incluir();
			this.AutoCompleteBanco.set_Text("");
			List<KeyValuePair<string, string>> keyValuePairs = this.ViewModel.SelectedBancosContas.Validate();
			this.ValidateFields(keyValuePairs, true);
		}

		private void InfoExtrato_OnClick(object sender, RoutedEventArgs e)
		{
			Button button = (Button)sender;
			if (button == null || button.DataContext == null)
			{
				return;
			}
			(new HosterWindow(new InfoExtratoView((Saldo)button.DataContext, true), "INFORMAÇÕES DO EXTRATO", new double?((double)800), new double?((double)450), false)).ShowDialog();
			this.ViewModel.Loading(true);
			this.ViewModel.CarregarSaldos(this.ViewModel.SelectedBancosContas);
			this.ViewModel.Loading(false);
		}

		[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/views/financeiro/bancoscontasview.xaml", UriKind.Relative));
		}

		private async void Salvar_OnClick(object sender, RoutedEventArgs e)
		{
			bool flag;
			this.ViewModel.Loading(true);
			List<KeyValuePair<string, string>> keyValuePairs = await this.ViewModel.Salvar();
			this.ValidateFields(keyValuePairs, true);
			flag = (keyValuePairs == null ? true : keyValuePairs.Count == 0);
			this.ViewModel.Loading(false);
			if (!flag)
			{
				await this.ViewModel.ShowMessage(keyValuePairs, this.ViewModel.ErroCamposInvalidos, "OK", "");
			}
		}

		[DebuggerNonUserCode]
		[EditorBrowsable(EditorBrowsableState.Never)]
		[GeneratedCode("PresentationBuildTasks", "4.0.0.0")]
		void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target)
		{
			switch (connectionId)
			{
				case 1:
				{
					((AutoCompleteBox)target).add_Populating(new PopulatingEventHandler(this, BancosContasView.AutoCompleteBancosContasBox_Populating));
					((AutoCompleteBox)target).add_TextChanged(new RoutedEventHandler(this.AutoCompleteBox_OnTextChanged));
					return;
				}
				case 2:
				{
					this.BancosContasGrid = (DataGrid)target;
					return;
				}
				case 3:
				{
					((MenuItem)target).Click += new RoutedEventHandler(this.Incluir_OnClick);
					return;
				}
				case 4:
				{
					((MenuItem)target).Click += new RoutedEventHandler(this.Alterar_OnClick);
					return;
				}
				case 5:
				{
					((MenuItem)target).Click += new RoutedEventHandler(this.Salvar_OnClick);
					return;
				}
				case 6:
				{
					((MenuItem)target).Click += new RoutedEventHandler(this.Cancelar_OnClick);
					return;
				}
				case 7:
				{
					((MenuItem)target).Click += new RoutedEventHandler(this.Excluir_OnClick);
					return;
				}
				case 8:
				{
					((MenuItem)target).Click += new RoutedEventHandler(this.AbrirLog_OnClick);
					return;
				}
				case 9:
				{
					this.AutoCompleteBanco = (AutoCompleteBox)target;
					this.AutoCompleteBanco.add_Populating(new PopulatingEventHandler(this, BancosContasView.AutoCompleteBancoBox_Populating));
					return;
				}
				case 10:
				{
					((DatePicker)target).LostKeyboardFocus += new KeyboardFocusChangedEventHandler(this.DatePicker_OnLostKeyboardFocus);
					((DatePicker)target).MouseDoubleClick += new MouseButtonEventHandler(this.DataAtual_OnDoubleClick);
					((DatePicker)target).PreviewKeyDown += new KeyEventHandler(this.DatePicker_PreviewKeyDown);
					return;
				}
				case 11:
				{
					((DatePicker)target).LostKeyboardFocus += new KeyboardFocusChangedEventHandler(this.FechamentoBox_OnLostKeyboardFocus);
					((DatePicker)target).MouseDoubleClick += new MouseButtonEventHandler(this.DataAtual_OnDoubleClick);
					((DatePicker)target).PreviewKeyDown += new KeyEventHandler(this.DatePicker_PreviewKeyDown);
					return;
				}
				case 12:
				{
					this.ValorSaldoBox = (CurrencyTextBox)target;
					return;
				}
				case 13:
				{
					((MenuItem)target).Click += new RoutedEventHandler(this.FecharSaldo_OnClick);
					return;
				}
				case 14:
				{
					((MenuItem)target).Click += new RoutedEventHandler(this.ExcluirSaldo_OnClick);
					return;
				}
			}
			this._contentLoaded = true;
		}

		[DebuggerNonUserCode]
		[EditorBrowsable(EditorBrowsableState.Never)]
		[GeneratedCode("PresentationBuildTasks", "4.0.0.0")]
		void System.Windows.Markup.IStyleConnector.Connect(int connectionId, object target)
		{
			if (connectionId == 15)
			{
				((Button)target).Click += new RoutedEventHandler(this.InfoExtrato_OnClick);
			}
		}
	}
}