using Gestor.Application.Helpers; using Gestor.Application.ViewModels.BI; using Gestor.Application.ViewModels.Generic; using Gestor.Application.Views.Generic; using Gestor.Model.Domain.Ferramentas; using Gestor.Model.Domain.Generic; using Gestor.Model.Domain.Seguros; using System; using System.CodeDom.Compiler; using System.Collections.Generic; 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 System.Windows.Media; namespace Gestor.Application.Views.BI { public class NotasView : BaseUserControl, IComponentConnector, IStyleConnector { internal ProgressBar ProgressRing; private bool _contentLoaded; public NotasViewModel ViewModel { get; set; } [DebuggerNonUserCode] [GeneratedCode("PresentationBuildTasks", "4.0.0.0")] internal Delegate _CreateDelegate(Type delegateType, string handler) { return Delegate.CreateDelegate(delegateType, this, handler); } public NotasView() { this.ViewModel = new NotasViewModel(); base.DataContext = this.ViewModel; this.InitializeComponent(); } private async Task AbrirNota(Tarefa data, bool notaBool = false, bool agendamento = false) { while (true) { Tarefa tarefa = await this.ViewModel.ShowTarefaDialog(data, notaBool, agendamento); Tarefa tarefa1 = tarefa; if (tarefa1 == null) { return; } if (tarefa1.get_Usuario() == null) { tarefa1.set_Usuario(tarefa1.get_UsuariosVinculados().FirstOrDefault()); } List list = tarefa1.get_UsuariosVinculados().Select((Usuario x) => { ResponsavelTarefa responsavelTarefa = new ResponsavelTarefa(); responsavelTarefa.set_IdTarefa(tarefa1.get_Id()); responsavelTarefa.set_Usuario(x); return responsavelTarefa; }).ToList(); tarefa1.set_Responsaveis(list); this.ViewModel.Loading(true); List> keyValuePairs = await this.ViewModel.Salvar(tarefa1); this.ViewModel.Loading(false); if (keyValuePairs == null || keyValuePairs.Count == 0) { break; } await this.ViewModel.ShowMessage(keyValuePairs, this.ViewModel.ErroCamposInvalidos, "OK", ""); } this.ViewModel.ToggleSnackBar("NOTA SALVA COM SUCESSO.", true); await this.ViewModel.CarregarNotas(); return; } private async void AdicionarNota_OnClick(object sender, RoutedEventArgs e) { await this.ViewModel.AdicionarNota(); } private async void ExcluirNota_OnClick(object sender, RoutedEventArgs e) { Tarefa dataContext = ((Button)sender).DataContext as Tarefa; if (dataContext != null) { await this.ViewModel.ExcluirNota(dataContext); await this.ViewModel.CarregarNotas(); } } private static object GetDataFromListBox(ItemsControl source, Point point) { UIElement parent = source.InputHitTest(point) as UIElement; if (parent == null) { return null; } object unsetValue = DependencyProperty.UnsetValue; while (unsetValue == DependencyProperty.UnsetValue) { if (parent == null) { continue; } unsetValue = source.ItemContainerGenerator.ItemFromContainer(parent); if (unsetValue == DependencyProperty.UnsetValue) { parent = VisualTreeHelper.GetParent(parent) as UIElement; } if (parent != source) { continue; } return null; } if (unsetValue == DependencyProperty.UnsetValue) { return null; } return unsetValue; } [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/bi/notasview.xaml", UriKind.Relative)); } private async void ListBox_OnPreviewMouseDoubleClick(object sender, MouseButtonEventArgs e) { List list; ListBox listBox = (ListBox)sender; object dataFromListBox = NotasView.GetDataFromListBox(listBox, e.GetPosition(listBox)); if (dataFromListBox != null) { Tarefa tarefa = new Tarefa(); DomainBase.Copy(tarefa, (Tarefa)dataFromListBox); Tarefa tarefa1 = tarefa; List responsaveis = tarefa.get_Responsaveis(); if (responsaveis != null) { list = ( from x in responsaveis select x.get_Usuario()).ToList(); } else { list = null; } tarefa1.set_UsuariosVinculados(list); await this.AbrirNota(tarefa, tarefa.get_Entidade() == 1, tarefa.get_Entidade() == 1); } } private async void NotaConcluida_OnClick(object sender, RoutedEventArgs e) { Tarefa dataContext = ((Button)sender).DataContext as Tarefa; if (dataContext != null) { dataContext.set_Conclusao(new DateTime?(Funcoes.GetNetworkTime())); dataContext.set_Status(2); await this.ViewModel.SalvarNota(dataContext); await this.ViewModel.CarregarNotas(); } } private async void SarvarNota_OnClick(object sender, RoutedEventArgs e) { Tarefa dataContext = ((Button)sender).DataContext as Tarefa; if (dataContext != null) { this.ViewModel.Loading(true); List> keyValuePairs = await this.ViewModel.Salvar(dataContext); this.ViewModel.Loading(false); if (keyValuePairs == null || keyValuePairs.Count == 0) { this.ViewModel.ToggleSnackBar("NOTA SALVA COM SUCESSO.", true); } else { await this.ViewModel.CarregarNotas(); } } } [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: { ((ListBox)target).PreviewMouseDoubleClick += new MouseButtonEventHandler(this.ListBox_OnPreviewMouseDoubleClick); return; } case 3: case 4: case 5: { this._contentLoaded = true; return; } case 6: { ((Button)target).Click += new RoutedEventHandler(this.AdicionarNota_OnClick); return; } case 7: { ((Button)target).Click += new RoutedEventHandler(this.ToggleNotasConcluidas_OnClick); return; } case 8: { ((ListBox)target).PreviewMouseDoubleClick += new MouseButtonEventHandler(this.ListBox_OnPreviewMouseDoubleClick); 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 3: { ((Button)target).Click += new RoutedEventHandler(this.ExcluirNota_OnClick); return; } case 4: { ((Button)target).Click += new RoutedEventHandler(this.NotaConcluida_OnClick); return; } case 5: { ((Button)target).Click += new RoutedEventHandler(this.SarvarNota_OnClick); return; } case 6: case 7: case 8: { return; } case 9: { ((Button)target).Click += new RoutedEventHandler(this.ExcluirNota_OnClick); return; } case 10: { ((Button)target).Click += new RoutedEventHandler(this.SarvarNota_OnClick); return; } default: { return; } } } private void ToggleNotasConcluidas_OnClick(object sender, RoutedEventArgs e) { this.ViewModel.ToggleNotasConcluidas(); } } }