using Gestor.Application; using Gestor.Application.ViewModels.Generic; using Gestor.Application.ViewModels.Relatorios; using Gestor.Model.Domain.Relatorios; using MaterialDesignThemes.Wpf; using System; using System.CodeDom.Compiler; 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.Markup; using System.Windows.Threading; namespace Gestor.Application.Drawers.Relatorios { public class ConfiguracaoRelatorio : UserControl, IComponentConnector, IStyleConnector { internal System.Windows.Controls.ProgressBar ProgressBar; internal RadioButton CampoButton; internal RadioButton TotalizacaoButton; internal ComboBox CampoComboBox; internal ComboBox TotalizacaoComboBox; internal DataGrid ParametrosGrid; internal DataGrid TotalizacaoGrid; internal Snackbar SnackbarArquivoDigital; private bool _contentLoaded; public RelatorioViewModel ViewModel { get; set; } [DebuggerNonUserCode] [GeneratedCode("PresentationBuildTasks", "4.0.0.0")] internal Delegate _CreateDelegate(Type delegateType, string handler) { return Delegate.CreateDelegate(delegateType, this, handler); } public ConfiguracaoRelatorio(RelatorioViewModel viewModel) { this.ViewModel = viewModel; 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 AdicionarParametro_OnClick(object sender, RoutedEventArgs e) { object item; RelatorioViewModel viewModel = this.ViewModel; ComboBox campoComboBox = this.CampoComboBox; if (campoComboBox != null) { item = campoComboBox.Items[this.CampoComboBox.SelectedIndex]; } else { item = null; } viewModel.AdicionarParametro((ParametrosRelatorio)item); } private void AdicionarTotalizacao_OnClick(object sender, RoutedEventArgs e) { object item; RelatorioViewModel viewModel = this.ViewModel; ComboBox totalizacaoComboBox = this.TotalizacaoComboBox; if (totalizacaoComboBox != null) { item = totalizacaoComboBox.Items[this.TotalizacaoComboBox.SelectedIndex]; } else { item = null; } viewModel.AdicionarTotalizacao((ParametrosTotalizacao)item); } private void Campo_OnChecked(object sender, RoutedEventArgs e) { this.ViewModel.IsCampo = true; } private void CloseSlackBar() { Thread.Sleep(5000); System.Windows.Threading.Dispatcher dispatcher = App.ProgressRing.Dispatcher; if (dispatcher == null) { return; } dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() => this.Toggle("", false))); } private async void ContentLoad() { this.CampoButton.IsChecked = new bool?(this.ViewModel.IsCampo); this.TotalizacaoButton.IsChecked = new bool?(!this.ViewModel.IsCampo); this.CampoButton.Checked += new RoutedEventHandler(this.Campo_OnChecked); this.TotalizacaoButton.Checked += new RoutedEventHandler(this.Totalizacao_OnChecked); this.ViewModel.IsEnabled = false; await this.ViewModel.CarregarConfiguracoes(); this.ViewModel.IsEnabled = true; } private void DescerParametro_OnClick(object sender, RoutedEventArgs e) { bool selectedIndex; object item; DataGrid parametrosGrid = this.ParametrosGrid; if (parametrosGrid != null) { selectedIndex = parametrosGrid.SelectedIndex < 0; } else { selectedIndex = false; } if (selectedIndex) { return; } RelatorioViewModel viewModel = this.ViewModel; DataGrid dataGrid = this.ParametrosGrid; if (dataGrid != null) { item = dataGrid.Items[this.ParametrosGrid.SelectedIndex]; } else { item = null; } viewModel.DescerParametro((ParametrosRelatorio)item); } private void ExcluirParametro_OnClick(object sender, RoutedEventArgs e) { bool selectedIndex; object item; DataGrid parametrosGrid = this.ParametrosGrid; if (parametrosGrid != null) { selectedIndex = parametrosGrid.SelectedIndex < 0; } else { selectedIndex = false; } if (selectedIndex) { return; } RelatorioViewModel viewModel = this.ViewModel; DataGrid dataGrid = this.ParametrosGrid; if (dataGrid != null) { item = dataGrid.Items[this.ParametrosGrid.SelectedIndex]; } else { item = null; } viewModel.ExcluirParametro((ParametrosRelatorio)item); } private void ExcluirTotalizacao_OnClick(object sender, RoutedEventArgs e) { bool selectedIndex; object item; DataGrid totalizacaoGrid = this.TotalizacaoGrid; if (totalizacaoGrid != null) { selectedIndex = totalizacaoGrid.SelectedIndex < 0; } else { selectedIndex = false; } if (selectedIndex) { return; } RelatorioViewModel viewModel = this.ViewModel; DataGrid dataGrid = this.TotalizacaoGrid; if (dataGrid != null) { item = dataGrid.Items[this.TotalizacaoGrid.SelectedIndex]; } else { item = null; } viewModel.ExcluirTotalizacao((ParametrosTotalizacao)item); } private void Fechar_OnClick(object sender, RoutedEventArgs e) { this.ViewModel.CloseDrawer(); } [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/drawers/relatorios/configuracaorelatorio.xaml", UriKind.Relative)); } private async void Salvar_OnClick(object sender, RoutedEventArgs e) { this.ViewModel.IsEnabled = false; bool flag = await this.ViewModel.SalvarParametros(); this.ViewModel.IsEnabled = true; if (flag) { this.Toggle("CONFIGURAÇÕES SALVAS.", true); } } private void SnackbarMessage_ActionClick(object sender, RoutedEventArgs e) { this.SnackbarArquivoDigital.set_IsActive(false); } private void SubirParametro_OnClick(object sender, RoutedEventArgs e) { bool selectedIndex; object item; DataGrid parametrosGrid = this.ParametrosGrid; if (parametrosGrid != null) { selectedIndex = parametrosGrid.SelectedIndex < 0; } else { selectedIndex = false; } if (selectedIndex) { return; } RelatorioViewModel viewModel = this.ViewModel; DataGrid dataGrid = this.ParametrosGrid; if (dataGrid != null) { item = dataGrid.Items[this.ParametrosGrid.SelectedIndex]; } else { item = null; } viewModel.SubirParametro((ParametrosRelatorio)item); } [DebuggerNonUserCode] [EditorBrowsable(EditorBrowsableState.Never)] [GeneratedCode("PresentationBuildTasks", "4.0.0.0")] void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target) { switch (connectionId) { case 1: { ((Button)target).Click += new RoutedEventHandler(this.Fechar_OnClick); return; } case 2: { this.ProgressBar = (System.Windows.Controls.ProgressBar)target; return; } case 3: { this.CampoButton = (RadioButton)target; return; } case 4: { this.TotalizacaoButton = (RadioButton)target; return; } case 5: { this.CampoComboBox = (ComboBox)target; return; } case 6: { ((MenuItem)target).Click += new RoutedEventHandler(this.AdicionarParametro_OnClick); return; } case 7: { this.TotalizacaoComboBox = (ComboBox)target; return; } case 8: { ((MenuItem)target).Click += new RoutedEventHandler(this.AdicionarTotalizacao_OnClick); return; } case 9: { this.ParametrosGrid = (DataGrid)target; return; } case 10: case 11: case 12: case 14: { this._contentLoaded = true; return; } case 13: { this.TotalizacaoGrid = (DataGrid)target; return; } case 15: { ((MenuItem)target).Click += new RoutedEventHandler(this.Salvar_OnClick); return; } case 16: { this.SnackbarArquivoDigital = (Snackbar)target; return; } case 17: { ((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) { switch (connectionId) { case 10: { ((Button)target).Click += new RoutedEventHandler(this.SubirParametro_OnClick); return; } case 11: { ((Button)target).Click += new RoutedEventHandler(this.DescerParametro_OnClick); return; } case 12: { ((Button)target).Click += new RoutedEventHandler(this.ExcluirParametro_OnClick); return; } case 13: { return; } case 14: { ((Button)target).Click += new RoutedEventHandler(this.ExcluirTotalizacao_OnClick); return; } default: { return; } } } public void Toggle(string message, bool active = true) { this.SnackbarArquivoDigital.get_Message().Content = message; this.SnackbarArquivoDigital.set_IsActive(active); if (!active) { return; } Task.Factory.StartNew(new Action(this.CloseSlackBar)); } private void Totalizacao_OnChecked(object sender, RoutedEventArgs e) { this.ViewModel.IsCampo = false; } } }