using Gestor.Application.Helpers; using Gestor.Application.Servicos; using Gestor.Application.Servicos.Generic; using Gestor.Application.Servicos.Seguros; using Gestor.Application.ViewModels.Generic; using Gestor.Model.Common; using Gestor.Model.Domain.Generic; using Gestor.Model.Domain.Seguros; using System; using System.CodeDom.Compiler; using System.ComponentModel; using System.Diagnostics; using System.Runtime.CompilerServices; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Markup; using System.Windows.Threading; namespace Gestor.Application.Drawers { public class ObservacoesDrawer : UserControl, IComponentConnector { private readonly BaseSegurosViewModel _viewModel; private readonly long _id; private TipoTela _tipo; private ApoliceServico _apoliceServico; private ParcelaServico _parcelaServico; private ClienteServico _clienteServico; internal Grid GridMainObservacao; internal TextBlock Observacaotxt; internal TextBox ObservacaoBox; private bool _contentLoaded; [DebuggerNonUserCode] [GeneratedCode("PresentationBuildTasks", "4.0.0.0")] internal Delegate _CreateDelegate(Type delegateType, string handler) { return Delegate.CreateDelegate(delegateType, this, handler); } public ObservacoesDrawer(long id, TipoTela tipo) { this._apoliceServico = new ApoliceServico(); this._parcelaServico = new ParcelaServico(); this._clienteServico = new ClienteServico(); this._viewModel = new BaseSegurosViewModel(); base.DataContext = this._viewModel; this.InitializeComponent(); this._id = id; this._tipo = tipo; double windowHeight = this._viewModel.GetWindowHeight(); this.GridMainObservacao.Height = windowHeight; System.Windows.Threading.Dispatcher dispatcher = base.Dispatcher; if (dispatcher == null) { return; } dispatcher.BeginInvoke(DispatcherPriority.Render, new Action(this.ContentLoad)); } private void Alterar_OnClick(object sender, RoutedEventArgs e) { this._viewModel.Alterar(true); } private void Cancelar_OnClick(object sender, RoutedEventArgs e) { this._viewModel.Alterar(false); this._viewModel.Anotacoes = string.Empty; } private async void ContentLoad() { await this.LoadObservacao(this._id, this._tipo, false); } 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/observacoesdrawer.xaml", UriKind.Relative)); } private async Task LoadObservacao(long id, TipoTela tipo, bool salvar) { string str; TextBox observacaoBox; object[] nome = new object[] { Recursos.Usuario.get_Nome(), Recursos.Usuario.get_Id(), Funcoes.GetNetworkTime(), Environment.NewLine, this._viewModel.Anotacoes, Environment.NewLine, Environment.NewLine, this.ObservacaoBox.Text }; string str1 = string.Format("{0}, ID: {1}, {2:g}{3}{4}{5}{6}{7}", nome); this._viewModel.VerificarEnables(new long?(id)); switch (tipo) { case 1: { this.Observacaotxt.Text = "OBSERVAÇÃO CLIENTE"; if (salvar) { observacaoBox = this.ObservacaoBox; str = await this._clienteServico.SalvarObservacoes(this._id, str1); observacaoBox.Text = str; observacaoBox = null; if (!this._clienteServico.Sucesso) { goto case 4; } this.ObservacaoBox.Text = str1; goto case 4; } else { observacaoBox = this.ObservacaoBox; Cliente cliente = await this._clienteServico.BuscarClienteAsync(id); observacaoBox.Text = cliente.get_Observacao(); observacaoBox = null; goto case 4; } } case 2: { this.Observacaotxt.Text = "OBSERVAÇÃO APÓLICE"; if (salvar) { str1 = await this._apoliceServico.Save(this._id, str1); if (!this._apoliceServico.Sucesso) { goto case 4; } this.ObservacaoBox.Text = str1; goto case 4; } else { observacaoBox = this.ObservacaoBox; Documento documento = await this._apoliceServico.BuscarApoliceAsync(id, false, false); observacaoBox.Text = documento.get_Observacao(); observacaoBox = null; goto case 4; } } case 3: case 4: { break; } case 5: { this.Observacaotxt.Text = "OBSERVAÇÃO PARCELA"; if (salvar) { observacaoBox = this.ObservacaoBox; str = await this._parcelaServico.SalvarObservacoes(this._id, str1); observacaoBox.Text = str; observacaoBox = null; if (!this._parcelaServico.Sucesso) { goto case 4; } this.ObservacaoBox.Text = str1; goto case 4; } else { observacaoBox = this.ObservacaoBox; Parcela parcela = await this._parcelaServico.BuscarParcela(id); observacaoBox.Text = parcela.get_Observacao(); observacaoBox = null; goto case 4; } } default: { goto case 4; } } str1 = null; } private async void ObservacoesDrawer_OnLoaded(object sender, RoutedEventArgs e) { await this._viewModel.PermissaoTela(2); this._viewModel.Alterar(false); } private async void Salvar_OnClick(object sender, RoutedEventArgs e) { if (!string.IsNullOrWhiteSpace(this._viewModel.Anotacoes)) { await this.LoadObservacao(this._id, this._tipo, true); this._viewModel.Anotacoes = string.Empty; this._viewModel.Alterar(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: { ((ObservacoesDrawer)target).Loaded += new RoutedEventHandler(this.ObservacoesDrawer_OnLoaded); return; } case 2: { this.GridMainObservacao = (Grid)target; return; } case 3: { ((Button)target).Click += new RoutedEventHandler(this.Fechar_OnClick); return; } case 4: { this.Observacaotxt = (TextBlock)target; return; } case 5: { ((MenuItem)target).Click += new RoutedEventHandler(this.Alterar_OnClick); return; } case 6: { ((MenuItem)target).Click += new RoutedEventHandler(this.Salvar_OnClick); return; } case 7: { ((MenuItem)target).Click += new RoutedEventHandler(this.Cancelar_OnClick); return; } case 8: { this.ObservacaoBox = (TextBox)target; return; } } this._contentLoaded = true; } } }