summaryrefslogtreecommitdiff
path: root/Codemerx/Gestor.Application/Views/Financeiro/Relatorios/FechamentoFinanceiroView.cs
blob: 3c04339da780bf82a30566d4c997ff4ab0731f52 (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
using Gestor.Application.Componentes;
using Gestor.Application.ViewModels.Financeiro.Relatorios;
using Gestor.Application.ViewModels.Generic;
using Gestor.Application.Views.Generic;
using Gestor.Common.Validation;
using Gestor.Model.Domain.Financeiro;
using Gestor.Model.Domain.Financeiro.Relatorios;
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.Input;
using System.Windows.Markup;
using System.Windows.Threading;

namespace Gestor.Application.Views.Financeiro.Relatorios
{
	public class FechamentoFinanceiroView : BaseUserControl, IComponentConnector, IStyleConnector
	{
		public FechamentoFinanceiroViewModel ViewModel;

		internal ProgressBar ProgressRing;

		internal DatePicker InicioBox;

		internal DatePicker FimBox;

		internal Gestor.Application.Componentes.WebEditor WebEditor;

		internal TextBlock NaoHaDados;

		private bool _contentLoaded;

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

		public FechamentoFinanceiroView()
		{
			this.ViewModel = new FechamentoFinanceiroViewModel();
			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 CheckBox_Checked(object sender, RoutedEventArgs e)
		{
			string name = ((CheckBox)sender).Name;
			if (name == "GridPlanos")
			{
				this.ViewModel.Planos.ForEach((Planos x) => x.set_Selecionado(!x.get_Selecionado()));
				this.ViewModel.Planos = new List<Planos>(this.ViewModel.Planos);
				return;
			}
			if (name == "GridCentro")
			{
				this.ViewModel.Centro.ForEach((Centro x) => x.set_Selecionado(!x.get_Selecionado()));
				this.ViewModel.Centro = new List<Centro>(this.ViewModel.Centro);
				return;
			}
			if (name != "GridConta")
			{
				this.ViewModel.Plano.ForEach((Plano x) => x.set_Selecionado(!x.get_Selecionado()));
				this.ViewModel.Plano = new List<Plano>(this.ViewModel.Plano);
				return;
			}
			this.ViewModel.Conta.ForEach((BancosContas x) => x.set_Selecionado(!x.get_Selecionado()));
			this.ViewModel.Conta = new List<BancosContas>(this.ViewModel.Conta);
		}

		private void ContentLoad()
		{
			this.InicioBox.LostKeyboardFocus += new KeyboardFocusChangedEventHandler(this.DatePicker_OnLostKeyboardFocus);
			this.InicioBox.PreviewKeyDown += new KeyEventHandler(this.DatePicker_PreviewKeyDown);
			this.InicioBox.SelectedDateChanged += new EventHandler<SelectionChangedEventArgs>(this.Periodo_OnSelectedDateChanged);
			this.FimBox.LostKeyboardFocus += new KeyboardFocusChangedEventHandler(this.DatePicker_OnLostKeyboardFocus);
			this.FimBox.PreviewKeyDown += new KeyEventHandler(this.DatePicker_PreviewKeyDown);
			this.FimBox.SelectedDateChanged += new EventHandler<SelectionChangedEventArgs>(this.Periodo_OnSelectedDateChanged);
		}

		private async void ExportarExcel_OnClick(object sender, RoutedEventArgs e)
		{
			this.ProgressRing.Visibility = System.Windows.Visibility.Visible;
			this.ViewModel.IsEnabled = false;
			await this.ViewModel.GerarExcel();
			this.ProgressRing.Visibility = System.Windows.Visibility.Collapsed;
			this.ViewModel.IsEnabled = true;
		}

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

		private void Filtros_OnClick(object sender, RoutedEventArgs e)
		{
			this.ViewModel.IsExpanded = !this.ViewModel.IsExpanded;
		}

		private async void GerarResultados_OnClick(object sender, RoutedEventArgs e)
		{
			bool flag;
			this.InicioBox.Text = ValidationHelper.FormatDate(this.InicioBox.Text);
			this.FimBox.Text = ValidationHelper.FormatDate(this.FimBox.Text);
			try
			{
				this.ViewModel.Inicio = new DateTime?(Convert.ToDateTime(this.InicioBox.Text));
				this.ViewModel.Fim = new DateTime?(Convert.ToDateTime(this.FimBox.Text));
			}
			catch (Exception exception)
			{
				return;
			}
			DateTime? inicio = this.ViewModel.Inicio;
			DateTime? fim = this.ViewModel.Fim;
			flag = (inicio.HasValue & fim.HasValue ? inicio.GetValueOrDefault() > fim.GetValueOrDefault() : false);
			if (!flag)
			{
				this.ProgressRing.Visibility = System.Windows.Visibility.Visible;
				this.ViewModel.IsEnabled = false;
				this.ViewModel.HtmlContent = string.Empty;
				this.ViewModel.Fechamento = new List<FechamentoFinanceiro>();
				await this.ViewModel.GerarRelatorio();
				if (this.ViewModel.HtmlContent == string.Empty)
				{
					this.NaoHaDados.Visibility = System.Windows.Visibility.Visible;
					this.ViewModel.IsEnabled = true;
					this.ProgressRing.Visibility = System.Windows.Visibility.Collapsed;
				}
				this.WebEditor.Initialize(this.ViewModel.HtmlContent);
				this.NaoHaDados.Visibility = System.Windows.Visibility.Collapsed;
				this.ViewModel.IsEnabled = true;
				this.ProgressRing.Visibility = System.Windows.Visibility.Collapsed;
			}
			else
			{
				await this.ViewModel.ShowMessage("A DATA FINAL NÃO PODE SER MENOR QUE A DATA INICIAL DO FILTRO.", "OK", "", false);
			}
		}

		private async void Imprimir_OnClick(object sender, RoutedEventArgs e)
		{
			this.ProgressRing.Visibility = System.Windows.Visibility.Visible;
			this.ViewModel.IsEnabled = false;
			await this.ViewModel.Print();
			this.ProgressRing.Visibility = System.Windows.Visibility.Collapsed;
			this.ViewModel.IsEnabled = true;
		}

		[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/relatorios/fechamentofinanceiroview.xaml", UriKind.Relative));
		}

		private void Periodo_OnSelectedDateChanged(object sender, SelectionChangedEventArgs e)
		{
			this.ViewModel.Fechamento = new List<FechamentoFinanceiro>();
			this.ViewModel.HtmlContent = string.Empty;
			this.WebEditor.Initialize("");
		}

		[DebuggerNonUserCode]
		[EditorBrowsable(EditorBrowsableState.Never)]
		[GeneratedCode("PresentationBuildTasks", "4.0.0.0")]
		void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target)
		{
			switch (connectionId)
			{
				case 1:
				{
					this.ProgressRing = (ProgressBar)target;
					return;
				}
				case 2:
				{
					this.InicioBox = (DatePicker)target;
					this.InicioBox.LostKeyboardFocus += new KeyboardFocusChangedEventHandler(this.DatePicker_OnLostKeyboardFocus);
					this.InicioBox.MouseDoubleClick += new MouseButtonEventHandler(this.DataAtual_OnDoubleClick);
					return;
				}
				case 3:
				{
					this.FimBox = (DatePicker)target;
					this.FimBox.LostKeyboardFocus += new KeyboardFocusChangedEventHandler(this.DatePicker_OnLostKeyboardFocus);
					this.FimBox.MouseDoubleClick += new MouseButtonEventHandler(this.DataAtual_OnDoubleClick);
					return;
				}
				case 4:
				{
					((MenuItem)target).Click += new RoutedEventHandler(this.GerarResultados_OnClick);
					return;
				}
				case 5:
				{
					((MenuItem)target).Click += new RoutedEventHandler(this.Filtros_OnClick);
					return;
				}
				case 6:
				{
					((MenuItem)target).Click += new RoutedEventHandler(this.Imprimir_OnClick);
					return;
				}
				case 7:
				{
					((MenuItem)target).Click += new RoutedEventHandler(this.ExportarExcel_OnClick);
					return;
				}
				case 8:
				{
					this.WebEditor = (Gestor.Application.Componentes.WebEditor)target;
					return;
				}
				case 9:
				{
					this.NaoHaDados = (TextBlock)target;
					return;
				}
				case 10:
				{
					((Button)target).Click += new RoutedEventHandler(this.Fechar_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)
		{
			switch (connectionId)
			{
				case 11:
				{
					((CheckBox)target).Checked += new RoutedEventHandler(this.CheckBox_Checked);
					((CheckBox)target).Unchecked += new RoutedEventHandler(this.CheckBox_Checked);
					return;
				}
				case 12:
				{
					((CheckBox)target).Checked += new RoutedEventHandler(this.CheckBox_Checked);
					((CheckBox)target).Unchecked += new RoutedEventHandler(this.CheckBox_Checked);
					return;
				}
				case 13:
				{
					((CheckBox)target).Checked += new RoutedEventHandler(this.CheckBox_Checked);
					((CheckBox)target).Unchecked += new RoutedEventHandler(this.CheckBox_Checked);
					return;
				}
				case 14:
				{
					((CheckBox)target).Checked += new RoutedEventHandler(this.CheckBox_Checked);
					((CheckBox)target).Unchecked += new RoutedEventHandler(this.CheckBox_Checked);
					return;
				}
				default:
				{
					return;
				}
			}
		}
	}
}