summaryrefslogtreecommitdiff
path: root/Codemerx/Gestor.Application/Componentes/ProspeccaoDialog.cs
blob: 151bc2a95c19fb5bebbe03f9a1224076187b242f (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
using Gestor.Application.ViewModels.Generic;
using Gestor.Application.Views.Generic;
using Gestor.Common.Validation;
using Gestor.Model.Domain.Common;
using Gestor.Model.Domain.Generic;
using Gestor.Model.Domain.Seguros;
using MaterialDesignThemes.Wpf;
using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Markup;
using Xceed.Wpf.AvalonDock.Controls;

namespace Gestor.Application.Componentes
{
	public class ProspeccaoDialog : BaseUserControl, IComponentConnector, IStyleConnector
	{
		public DialogProspeccaoViewModel ViewModel;

		internal TextBox DocumentoBox;

		internal DatePicker NascimentoBox;

		internal TextBox Prefixo1Box;

		internal TextBox Telefone1Box;

		internal TextBox Prefixo2Box;

		internal TextBox Telefone2Box;

		internal TextBox EmailBox;

		internal MenuItem SalvarButton;

		private bool _contentLoaded;

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

		public ProspeccaoDialog(Prospeccao prospeccao)
		{
			this.ViewModel = new DialogProspeccaoViewModel(prospeccao);
			base.DataContext = this.ViewModel;
			this.InitializeComponent();
		}

		private void AnexarArquivos_OnClick(object sender, RoutedEventArgs e)
		{
			this.ViewModel.Anexar();
		}

		private async void AutoCompleteBox_LostFocus(object sender, RoutedEventArgs e)
		{
			bool count;
			ClienteTelefone item;
			bool flag;
			ClienteTelefone clienteTelefone;
			bool email;
			string str;
			string numero;
			string prefixo;
			string numero1;
			string prefixo1;
			AutoCompleteBox autoCompleteBox = (AutoCompleteBox)sender;
			if (autoCompleteBox.get_SelectedItem() != null)
			{
				Cliente cliente = await this.ViewModel.BuscarInfoCliente((Cliente)autoCompleteBox.get_SelectedItem());
				this.DocumentoBox.Text = cliente.get_Documento();
				this.NascimentoBox.SelectedDate = cliente.get_Nascimento();
				ObservableCollection<ClienteTelefone> telefones = cliente.get_Telefones();
				if (telefones != null)
				{
					count = telefones.Count > 0;
				}
				else
				{
					count = false;
				}
				if (count)
				{
					item = cliente.get_Telefones()[0];
				}
				else
				{
					item = null;
				}
				ClienteTelefone clienteTelefone1 = item;
				if (clienteTelefone1 != null && clienteTelefone1.get_Prefixo() != null)
				{
					TextBox prefixo1Box = this.Prefixo1Box;
					if (clienteTelefone1 != null)
					{
						prefixo1 = clienteTelefone1.get_Prefixo();
					}
					else
					{
						prefixo1 = null;
					}
					prefixo1Box.Text = prefixo1;
				}
				if (clienteTelefone1 != null && clienteTelefone1.get_Numero() != null)
				{
					TextBox telefone1Box = this.Telefone1Box;
					if (clienteTelefone1 != null)
					{
						numero1 = clienteTelefone1.get_Numero();
					}
					else
					{
						numero1 = null;
					}
					telefone1Box.Text = numero1;
				}
				ObservableCollection<ClienteTelefone> observableCollection = cliente.get_Telefones();
				if (observableCollection != null)
				{
					flag = observableCollection.Count > 1;
				}
				else
				{
					flag = false;
				}
				if (flag)
				{
					clienteTelefone = cliente.get_Telefones()[1];
				}
				else
				{
					clienteTelefone = null;
				}
				ClienteTelefone clienteTelefone2 = clienteTelefone;
				if (clienteTelefone2 != null && clienteTelefone2.get_Prefixo() != null)
				{
					TextBox prefixo2Box = this.Prefixo2Box;
					if (clienteTelefone2 != null)
					{
						prefixo = clienteTelefone2.get_Prefixo();
					}
					else
					{
						prefixo = null;
					}
					prefixo2Box.Text = prefixo;
				}
				if (clienteTelefone2 != null && clienteTelefone2.get_Numero() != null)
				{
					TextBox telefone2Box = this.Telefone2Box;
					if (clienteTelefone2 != null)
					{
						numero = clienteTelefone2.get_Numero();
					}
					else
					{
						numero = null;
					}
					telefone2Box.Text = numero;
				}
				ObservableCollection<ClienteEmail> emails = cliente.get_Emails();
				if (emails != null)
				{
					ClienteEmail clienteEmail = emails.FirstOrDefault<ClienteEmail>();
					if (clienteEmail != null)
					{
						email = clienteEmail.get_Email();
					}
					else
					{
						email = false;
					}
				}
				else
				{
					email = false;
				}
				if (email)
				{
					TextBox emailBox = this.EmailBox;
					ObservableCollection<ClienteEmail> emails1 = cliente.get_Emails();
					if (emails1 != null)
					{
						ClienteEmail clienteEmail1 = emails1.FirstOrDefault<ClienteEmail>();
						if (clienteEmail1 != null)
						{
							str = clienteEmail1.get_Email();
						}
						else
						{
							str = null;
						}
					}
					else
					{
						str = null;
					}
					emailBox.Text = str;
				}
			}
		}

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

		private void DeleteArquivo_OnDeleteClick(object sender, RoutedEventArgs e)
		{
			Chip chip = sender as Chip;
			if (chip == null)
			{
				return;
			}
			ListBox listBox = Extentions.FindVisualAncestor<ListBox>(chip);
			ArquivoDigital item = (ArquivoDigital)listBox.Items[listBox.Items.IndexOf(chip.DataContext)];
			if (item == null)
			{
				return;
			}
			this.ViewModel.Delete(item);
		}

		private void DocumentoBox_OnLostFocus(object sender, RoutedEventArgs e)
		{
			TextBox textBox = (TextBox)sender;
			textBox.Text = ValidationHelper.FormatDocument(textBox.Text);
		}

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

		private void SalvarButton_OnClick(object sender, RoutedEventArgs e)
		{
			List<ArquivoDigital> list;
			Prospeccao selectedProspeccao = this.ViewModel.SelectedProspeccao;
			ObservableCollection<ArquivoDigital> arquivosAnexados = this.ViewModel.ArquivosAnexados;
			if (arquivosAnexados != null)
			{
				list = arquivosAnexados.ToList<ArquivoDigital>();
			}
			else
			{
				list = null;
			}
			selectedProspeccao.set_Anexos(list);
			DialogHost.CloseDialogCommand.Execute(this.ViewModel.SelectedProspeccao, this.SalvarButton);
		}

		[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, ProspeccaoDialog.AutoCompleteBox_Populating));
					((AutoCompleteBox)target).LostFocus += new RoutedEventHandler(this.AutoCompleteBox_LostFocus);
					return;
				}
				case 2:
				{
					this.DocumentoBox = (TextBox)target;
					ProspeccaoDialog prospeccaoDialog = this;
					this.DocumentoBox.PreviewTextInput += new TextCompositionEventHandler(prospeccaoDialog.SomenteNumeros);
					this.DocumentoBox.LostFocus += new RoutedEventHandler(this.DocumentoBox_OnLostFocus);
					return;
				}
				case 3:
				{
					this.NascimentoBox = (DatePicker)target;
					this.NascimentoBox.LostKeyboardFocus += new KeyboardFocusChangedEventHandler(this.DatePicker_OnLostKeyboardFocus);
					this.NascimentoBox.MouseDoubleClick += new MouseButtonEventHandler(this.DataAtual_OnDoubleClick);
					this.NascimentoBox.PreviewKeyDown += new KeyEventHandler(this.DatePicker_PreviewKeyDown);
					return;
				}
				case 4:
				{
					this.Prefixo1Box = (TextBox)target;
					ProspeccaoDialog prospeccaoDialog1 = this;
					this.Prefixo1Box.PreviewTextInput += new TextCompositionEventHandler(prospeccaoDialog1.SomenteNumeros);
					return;
				}
				case 5:
				{
					this.Telefone1Box = (TextBox)target;
					ProspeccaoDialog prospeccaoDialog2 = this;
					this.Telefone1Box.LostFocus += new RoutedEventHandler(prospeccaoDialog2.FormatarTelefone);
					ProspeccaoDialog prospeccaoDialog3 = this;
					this.Telefone1Box.PreviewTextInput += new TextCompositionEventHandler(prospeccaoDialog3.SomenteNumeros);
					return;
				}
				case 6:
				{
					this.Prefixo2Box = (TextBox)target;
					ProspeccaoDialog prospeccaoDialog4 = this;
					this.Prefixo2Box.PreviewTextInput += new TextCompositionEventHandler(prospeccaoDialog4.SomenteNumeros);
					return;
				}
				case 7:
				{
					this.Telefone2Box = (TextBox)target;
					ProspeccaoDialog prospeccaoDialog5 = this;
					this.Telefone2Box.LostFocus += new RoutedEventHandler(prospeccaoDialog5.FormatarTelefone);
					ProspeccaoDialog prospeccaoDialog6 = this;
					this.Telefone2Box.PreviewTextInput += new TextCompositionEventHandler(prospeccaoDialog6.SomenteNumeros);
					return;
				}
				case 8:
				{
					this.EmailBox = (TextBox)target;
					return;
				}
				case 9:
				{
					((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 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:
				{
					this._contentLoaded = true;
					return;
				}
				case 12:
				{
					((MenuItem)target).Click += new RoutedEventHandler(this.AnexarArquivos_OnClick);
					return;
				}
				case 13:
				{
					this.SalvarButton = (MenuItem)target;
					this.SalvarButton.Click += new RoutedEventHandler(this.SalvarButton_OnClick);
					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)
		{
			if (connectionId == 11)
			{
				((Chip)target).add_DeleteClick(new RoutedEventHandler(this.DeleteArquivo_OnDeleteClick));
			}
		}
	}
}