summaryrefslogtreecommitdiff
path: root/Gestor.Application/Componentes/DialogTarefa.cs
blob: a9dc3095512f56a735c7bf1f45b6bcc7fa2da05c (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
using Gestor.Application;
using Gestor.Application.Helpers;
using Gestor.Application.ViewModels.Generic;
using Gestor.Application.Views.Generic;
using Gestor.Application.Views.Seguros;
using Gestor.Common.Validation;
using Gestor.Model.Common;
using Gestor.Model.Domain.Ferramentas;
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.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.Input;
using System.Windows.Markup;
using System.Windows.Threading;
using Xceed.Wpf.AvalonDock.Controls;

namespace Gestor.Application.Componentes
{
	public class DialogTarefa : UserControl, IComponentConnector, IStyleConnector
	{
		internal Button ClienteButton;

		internal Button ApoliceButton;

		internal Button SinistroButton;

		internal TextBox TituloBox;

		internal DatePicker AgendamentoBox;

		internal RadioButton AnotacoesButton;

		internal TextBox AnotacoesBox;

		internal ComboBox ResponsavelBox;

		internal DatePicker ConclusaoBox;

		internal MenuItem SalvarButton;

		internal MaterialDesignThemes.Wpf.Snackbar Snackbar;

		private bool _contentLoaded;

		private DialogTarefaViewModel ViewModel
		{
			get;
		}

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

		public DialogTarefa(Tarefa tarefa, List<TelefoneBase> telefones, bool nota = false, bool agendamento = false)
		{
			this.ViewModel = new DialogTarefaViewModel(tarefa, telefones, nota, agendamento);
			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 async void AcessarApolice_OnClick(object sender, RoutedEventArgs e)
		{
			Documento documento;
			documento = (this.ViewModel.Tarefa.get_Entidade() != 3 ? await this.ViewModel.CarregaApolice(this.ViewModel.Tarefa.get_IdEntidade()) : await this.ViewModel.CarregaApoliceParcela(this.ViewModel.Tarefa.get_IdEntidade()));
			double? nullable = null;
			double? nullable1 = nullable;
			nullable = null;
			(new HosterWindow(new ApoliceView(documento, true, false, 0, (long)0, false), string.Concat("CADASTRO DE APÓLICES - ", this.ViewModel.Tarefa.get_Cliente()), nullable1, nullable, false)).Show();
		}

		private async void AcessarCliente_OnClick(object sender, RoutedEventArgs e)
		{
			double? nullable = null;
			double? nullable1 = nullable;
			nullable = null;
			(new HosterWindow(new ClienteView(await this.ViewModel.CarregaCliente(this.ViewModel.Tarefa.get_IdCliente()), true, null), string.Concat("CADASTRO DE CLIENTE - ", this.ViewModel.Tarefa.get_Cliente()), nullable1, nullable, false)).Show();
		}

		private async void AcessarSinistro_OnClick(object sender, RoutedEventArgs e)
		{
			Sinistro sinistro = await this.ViewModel.CarregaSinistroApolice(this.ViewModel.Tarefa.get_IdEntidade());
			double? nullable = null;
			double? nullable1 = nullable;
			nullable = null;
			(new HosterWindow(new SinistroView(sinistro.get_ControleSinistro().get_Item(), false), string.Concat("CADASTRO DE SINISTRO - ", sinistro.get_ControleSinistro().get_Item().get_Descricao()), nullable1, nullable, false)).Show();
		}

		private void AdicionarResponsavel_OnClick(object sender, RoutedEventArgs e)
		{
			this.ViewModel.AdcionarResponsavel();
		}

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

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

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

		private void ContentLoad()
		{
			this.AgendamentoBox.LostKeyboardFocus += new KeyboardFocusChangedEventHandler(this.DatePicker_OnLostKeyboardFocus);
			this.AgendamentoBox.PreviewKeyDown += new KeyEventHandler(this.DatePicker_PreviewKeyDown);
			this.ViewModel.PermissaoWhatsapp = this.ViewModel.Restricao(32);
			switch (this.ViewModel.Tarefa.get_Entidade())
			{
				case 0:
				{
					this.ClienteButton.Visibility = System.Windows.Visibility.Visible;
					this.ApoliceButton.Visibility = System.Windows.Visibility.Visible;
					break;
				}
				case 2:
				{
					this.ClienteButton.Visibility = System.Windows.Visibility.Visible;
					break;
				}
				case 3:
				{
					this.ClienteButton.Visibility = System.Windows.Visibility.Visible;
					this.ApoliceButton.Visibility = System.Windows.Visibility.Visible;
					break;
				}
				case 4:
				{
					this.ClienteButton.Visibility = System.Windows.Visibility.Visible;
					this.SinistroButton.Visibility = System.Windows.Visibility.Visible;
					break;
				}
				default:
				{
					this.ClienteButton.Visibility = System.Windows.Visibility.Collapsed;
					this.ApoliceButton.Visibility = System.Windows.Visibility.Collapsed;
					break;
				}
			}
			this.AnotacoesButton.IsChecked = new bool?(this.ViewModel.IsAnotacoes);
			this.AnotacoesButton.Checked += new RoutedEventHandler(this.Anotacoes_OnChecked);
		}

		private void CopyTelefoneToClipBoard_Click(object sender, RoutedEventArgs e)
		{
			TelefoneBase dataContext = (TelefoneBase)((Button)sender).DataContext;
			string.Concat(dataContext.get_Prefixo(), dataContext.get_Numero()).CopyToClipboard();
			this.ToggleSnackBar("NÚMERO COPIADO COM SUCESSO", true);
		}

		private void DataAtual_OnDoubleClick(object sender, RoutedEventArgs e)
		{
			((DatePicker)sender).SelectedDate = new DateTime?(Funcoes.GetNetworkTime().Date);
		}

		private void DatePicker_OnLostKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)
		{
			DatePicker datePicker = (DatePicker)sender;
			datePicker.Text = ValidationHelper.FormatDate(datePicker.Text);
		}

		private void DatePicker_PreviewKeyDown(object sender, KeyEventArgs e)
		{
			if (e.Key != Key.Return)
			{
				return;
			}
			DatePicker str = (DatePicker)sender;
			DateTime date = Funcoes.GetNetworkTime().Date;
			str.Text = date.ToString("dd/MM/yyyy");
		}

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

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

		private void MenuItem_OnClick(object sender, RoutedEventArgs e)
		{
			if (this.ViewModel.Tarefa.get_UsuariosVinculados() == null)
			{
				this.ViewModel.Tarefa.set_UsuariosVinculados(new List<Usuario>());
			}
			DialogHost.CloseDialogCommand.Execute(this.ViewModel.Tarefa, this.SalvarButton);
		}

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

		[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.ClienteButton = (Button)target;
					this.ClienteButton.Click += new RoutedEventHandler(this.AcessarCliente_OnClick);
					return;
				}
				case 2:
				{
					this.ApoliceButton = (Button)target;
					this.ApoliceButton.Click += new RoutedEventHandler(this.AcessarApolice_OnClick);
					return;
				}
				case 3:
				{
					this.SinistroButton = (Button)target;
					this.SinistroButton.Click += new RoutedEventHandler(this.AcessarSinistro_OnClick);
					return;
				}
				case 4:
				case 5:
				case 12:
				{
					this._contentLoaded = true;
					return;
				}
				case 6:
				{
					this.TituloBox = (TextBox)target;
					return;
				}
				case 7:
				{
					this.AgendamentoBox = (DatePicker)target;
					this.AgendamentoBox.LostKeyboardFocus += new KeyboardFocusChangedEventHandler(this.DatePicker_OnLostKeyboardFocus);
					this.AgendamentoBox.MouseDoubleClick += new MouseButtonEventHandler(this.DataAtual_OnDoubleClick);
					return;
				}
				case 8:
				{
					this.AnotacoesButton = (RadioButton)target;
					return;
				}
				case 9:
				{
					this.AnotacoesBox = (TextBox)target;
					return;
				}
				case 10:
				{
					this.ResponsavelBox = (ComboBox)target;
					return;
				}
				case 11:
				{
					((Button)target).Click += new RoutedEventHandler(this.AdicionarResponsavel_OnClick);
					return;
				}
				case 13:
				{
					this.ConclusaoBox = (DatePicker)target;
					this.ConclusaoBox.LostKeyboardFocus += new KeyboardFocusChangedEventHandler(this.DatePicker_OnLostKeyboardFocus);
					this.ConclusaoBox.MouseDoubleClick += new MouseButtonEventHandler(this.DataAtual_OnDoubleClick);
					return;
				}
				case 14:
				{
					this.SalvarButton = (MenuItem)target;
					this.SalvarButton.Click += new RoutedEventHandler(this.MenuItem_OnClick);
					return;
				}
				case 15:
				{
					this.Snackbar = (MaterialDesignThemes.Wpf.Snackbar)target;
					return;
				}
				case 16:
				{
					((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)
		{
			if (connectionId == 4)
			{
				((Button)target).Click += new RoutedEventHandler(this.CopyTelefoneToClipBoard_Click);
				return;
			}
			if (connectionId == 5)
			{
				((Button)target).Click += new RoutedEventHandler(this.WhatsAppMessage_Click);
				return;
			}
			if (connectionId != 12)
			{
				return;
			}
			((Chip)target).add_DeleteClick(new RoutedEventHandler(this.ExcluirResponsavel_OnClick));
		}

		private void TimePicker_OnLostKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)
		{
			TimePicker timePicker = (TimePicker)sender;
			timePicker.TextBox.Text = ValidationHelper.FormatTime(timePicker.TextBox.Text);
		}

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

		private async void WhatsAppMessage_Click(object sender, RoutedEventArgs e)
		{
			string str;
			TelefoneBase dataContext = (TelefoneBase)((Button)sender).DataContext;
			str = (!dataContext.get_Tipo().HasValue || dataContext.get_Tipo().GetValueOrDefault() != 8 ? string.Concat("55", dataContext.get_Prefixo(), dataContext.get_Numero().Clear()) : string.Concat(dataContext.get_Prefixo(), dataContext.get_Numero()).Clear());
			if (!str.EnviarWhatsapp(null))
			{
				await this.ViewModel.ShowMessage("HOUVE UM PROBLEMA AO ABRIR LINK DO WHATSAPP, O LINK FOI COPIADO EM SUA MAQUINA, BASTA ABRIR O NAVEGADOR DE INTERNET E COLAR NA BARRA DE ENDEREÇOS", "OK", "", false);
			}
		}
	}
}