diff options
Diffstat (limited to 'Codemerx/Gestor.Application/ViewModels/Generic/BaseViewModel.cs')
| -rw-r--r-- | Codemerx/Gestor.Application/ViewModels/Generic/BaseViewModel.cs | 3140 |
1 files changed, 3140 insertions, 0 deletions
diff --git a/Codemerx/Gestor.Application/ViewModels/Generic/BaseViewModel.cs b/Codemerx/Gestor.Application/ViewModels/Generic/BaseViewModel.cs new file mode 100644 index 0000000..e680922 --- /dev/null +++ b/Codemerx/Gestor.Application/ViewModels/Generic/BaseViewModel.cs @@ -0,0 +1,3140 @@ +using Agger.Registro;
+using Gestor.Application;
+using Gestor.Application.Actions;
+using Gestor.Application.Componentes;
+using Gestor.Application.Drawers;
+using Gestor.Application.Helpers;
+using Gestor.Application.Model;
+using Gestor.Application.Properties;
+using Gestor.Application.Servicos;
+using Gestor.Application.Servicos.Ferramentas;
+using Gestor.Application.Servicos.Generic;
+using Gestor.Application.Servicos.Seguros;
+using Gestor.Application.Servicos.Seguros.Itens;
+using Gestor.Common.Helpers;
+using Gestor.Common.Validation;
+using Gestor.Model.Common;
+using Gestor.Model.Domain.Aggilizador;
+using Gestor.Model.Domain.Common;
+using Gestor.Model.Domain.Ferramentas;
+using Gestor.Model.Domain.Financeiro;
+using Gestor.Model.Domain.Generic;
+using Gestor.Model.Domain.MalaDireta;
+using Gestor.Model.Domain.Seguros;
+using Gestor.Model.License;
+using MaterialDesignThemes.Wpf;
+using Newtonsoft.Json;
+using Newtonsoft.Json.Linq;
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.ComponentModel;
+using System.Diagnostics;
+using System.IO;
+using System.Linq;
+using System.Net;
+using System.Net.Http;
+using System.Runtime.CompilerServices;
+using System.Text;
+using System.Threading;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Forms;
+using System.Windows.Input;
+using System.Windows.Threading;
+using Xceed.Wpf.AvalonDock.Controls;
+
+namespace Gestor.Application.ViewModels.Generic
+{
+ public abstract class BaseViewModel : INotifyPropertyChanged
+ {
+ public Gestor.Application.Servicos.ArquivoDigitalServico ArquivoDigitalServico;
+
+ public PermissaoArquivoDigitalServico ServicoPermissArquivoDigital;
+
+ public PermissaoUsuarioServico ServicoPermissUsuario;
+
+ public RestricaoUsuarioServico ServicoRestriUsuario;
+
+ public VendedorUsuarioServico ServicoVendedorUsuario;
+
+ public bool _incluirPermissEnabled;
+
+ public bool _alterarPermissEnabled;
+
+ public bool _excluirPermissEnabled;
+
+ public long LastAccessId;
+
+ public TipoTela LastAccessTela;
+
+ private bool _enableButtons = true;
+
+ private bool _enableIncluir = true;
+
+ private bool _isVisibleEmpresa;
+
+ private bool _enableAlterar;
+
+ private bool _enableExcluir;
+
+ private long? _lastId;
+
+ private bool _incluirParcelaEnabled;
+
+ private bool _alterarParcelaEnabled;
+
+ private bool _excluirParcelaEnabled;
+
+ private bool _permissaoWhatsapp;
+
+ public bool Initialized;
+
+ private bool _enableFields;
+
+ private bool _allowEditParcela;
+
+ private bool _isEnableEdit;
+
+ private bool _isEnabledEditEndosso;
+
+ private bool _enableMenu;
+
+ private bool _enableMainMenu;
+
+ private bool _isEnabled;
+
+ private Visibility _isVisible;
+
+ private object _popupContent;
+
+ public bool AllowEditParcela
+ {
+ get
+ {
+ return this._allowEditParcela;
+ }
+ set
+ {
+ this._allowEditParcela = value;
+ this.OnPropertyChanged("AllowEditParcela");
+ }
+ }
+
+ public bool AlterarParcelaEnabled
+ {
+ get
+ {
+ return this._alterarParcelaEnabled;
+ }
+ set
+ {
+ this._alterarParcelaEnabled = value;
+ this.OnPropertyChanged("AlterarParcelaEnabled");
+ }
+ }
+
+ public AutoCompleteFilterPredicate<object> CoberturaItemFilter
+ {
+ get
+ {
+ AutoCompleteFilterPredicate<object> u003cu003e9_1610 = BaseViewModel.u003cu003ec.u003cu003e9__161_0;
+ if (u003cu003e9_1610 == null)
+ {
+ u003cu003e9_1610 = new AutoCompleteFilterPredicate<object>(BaseViewModel.u003cu003ec.u003cu003e9, (string searchText, object obj) => ((CoberturaPadrao)obj).get_Descricao().ToUpper().Contains(searchText.ToUpper()));
+ BaseViewModel.u003cu003ec.u003cu003e9__161_0 = u003cu003e9_1610;
+ }
+ return u003cu003e9_1610;
+ }
+ }
+
+ public bool EnableAlterar
+ {
+ get
+ {
+ return this._enableAlterar;
+ }
+ set
+ {
+ this._enableAlterar = this._alterarPermissEnabled & value;
+ this.OnPropertyChanged("EnableAlterar");
+ }
+ }
+
+ public bool EnableButtons
+ {
+ get
+ {
+ return this._enableButtons;
+ }
+ set
+ {
+ this._enableButtons = value;
+ this.OnPropertyChanged("EnableButtons");
+ }
+ }
+
+ public bool EnableExcluir
+ {
+ get
+ {
+ return this._enableExcluir;
+ }
+ set
+ {
+ this._enableExcluir = this._excluirPermissEnabled & value;
+ this.OnPropertyChanged("EnableExcluir");
+ }
+ }
+
+ public bool EnableFields
+ {
+ get
+ {
+ return this._enableFields;
+ }
+ set
+ {
+ this._enableFields = value;
+ this.OnPropertyChanged("EnableFields");
+ }
+ }
+
+ public bool EnableIncluir
+ {
+ get
+ {
+ return this._enableIncluir;
+ }
+ set
+ {
+ this._enableIncluir = this._incluirPermissEnabled & value;
+ this.OnPropertyChanged("EnableIncluir");
+ }
+ }
+
+ public bool EnableMainMenu
+ {
+ get
+ {
+ return this._enableMainMenu;
+ }
+ set
+ {
+ this._enableMainMenu = value;
+ this.OnPropertyChanged("EnableMainMenu");
+ }
+ }
+
+ public bool EnableMenu
+ {
+ get
+ {
+ return this._enableMenu;
+ }
+ set
+ {
+ this._enableMenu = value;
+ this.OnPropertyChanged("EnableMenu");
+ }
+ }
+
+ public string ErroCamposInvalidos
+ {
+ get;
+ }
+
+ public bool ExcluirParcelaEnabled
+ {
+ get
+ {
+ return this._excluirParcelaEnabled;
+ }
+ set
+ {
+ this._excluirParcelaEnabled = value;
+ this.OnPropertyChanged("ExcluirParcelaEnabled");
+ }
+ }
+
+ public bool IncluirParcelaEnabled
+ {
+ get
+ {
+ return this._incluirParcelaEnabled;
+ }
+ set
+ {
+ this._incluirParcelaEnabled = value;
+ this.OnPropertyChanged("IncluirParcelaEnabled");
+ }
+ }
+
+ public bool IsEnabled
+ {
+ get
+ {
+ return this._isEnabled;
+ }
+ set
+ {
+ this._isEnabled = value;
+ this.OnPropertyChanged("IsEnabled");
+ }
+ }
+
+ public bool IsEnabledEdit
+ {
+ get
+ {
+ return this._isEnableEdit;
+ }
+ set
+ {
+ this._isEnableEdit = value;
+ this.OnPropertyChanged("IsEnabledEdit");
+ }
+ }
+
+ public bool IsEnabledEditEndosso
+ {
+ get
+ {
+ return this._isEnabledEditEndosso;
+ }
+ set
+ {
+ this._isEnabledEditEndosso = value;
+ this.OnPropertyChanged("IsEnabledEditEndosso");
+ }
+ }
+
+ public Visibility IsVisible
+ {
+ get
+ {
+ return this._isVisible;
+ }
+ set
+ {
+ this._isVisible = value;
+ this.OnPropertyChanged("IsVisible");
+ }
+ }
+
+ public bool IsVisibleEmpresa
+ {
+ get
+ {
+ return this._isVisibleEmpresa;
+ }
+ set
+ {
+ this._isVisibleEmpresa = value;
+ this.OnPropertyChanged("IsVisibleEmpresa");
+ }
+ }
+
+ public bool PermissaoWhatsapp
+ {
+ get
+ {
+ return this._permissaoWhatsapp;
+ }
+ set
+ {
+ this._permissaoWhatsapp = value;
+ this.OnPropertyChanged("PermissaoWhatsapp");
+ }
+ }
+
+ public object PopupContent
+ {
+ get
+ {
+ return this._popupContent;
+ }
+ set
+ {
+ this._popupContent = value;
+ this.OnPropertyChanged("PopupContent");
+ }
+ }
+
+ protected BaseViewModel()
+ {
+ this._enableButtons = true;
+ this._enableIncluir = true;
+ if (LicenseHelper.Produtos != null)
+ {
+ if (!LicenseHelper.Produtos.Any<Licenca>((Licenca x) => {
+ if (x.get_Produto() != 2)
+ {
+ return false;
+ }
+ return x.get_Status() == 1;
+ }))
+ {
+ goto Label1;
+ }
+ Empresa empresa = Recursos.Empresa;
+ if (empresa != null)
+ {
+ id = empresa.get_Id() == (long)1;
+ goto Label0;
+ }
+ else
+ {
+ id = false;
+ goto Label0;
+ }
+ }
+ Label1:
+ id = false;
+ Label0:
+ this._isVisibleEmpresa = id;
+ this._enableAlterar = true;
+ this._enableExcluir = true;
+ this._permissaoWhatsapp = true;
+ this._allowEditParcela = true;
+ this._isEnableEdit = true;
+ this._isEnabledEditEndosso = true;
+ Usuario usuario = Recursos.Usuario;
+ if (usuario != null)
+ {
+ flag = usuario.get_Id() > (long)0;
+ }
+ else
+ {
+ flag = false;
+ }
+ this._enableMenu = flag;
+ this._enableMainMenu = true;
+ this._isEnabled = true;
+ this._isVisible = Visibility.Collapsed;
+ this.ErroCamposInvalidos = string.Concat("HÁ CAMPOS DESTACADOS QUE DEVEM SER PREENCHIDOS CORRETAMENTE.", Environment.NewLine, "REALIZE A CORREÇÃO E TENTE NOVAMENTE.");
+ base();
+ bool id;
+ bool flag;
+ this.ArquivoDigitalServico = new Gestor.Application.Servicos.ArquivoDigitalServico();
+ Gestor.Application.Actions.Actions.EnableMainMenu = (Action<bool>)Delegate.Combine(Gestor.Application.Actions.Actions.EnableMainMenu, new Action<bool>(this.HabilitarMenu));
+ Gestor.Application.Actions.Actions.EnableMenu = (Action<bool>)Delegate.Combine(Gestor.Application.Actions.Actions.EnableMenu, new Action<bool>(this.HabilitarMenuSecundario));
+ this.ServicoPermissArquivoDigital = new PermissaoArquivoDigitalServico();
+ this.ServicoPermissUsuario = new PermissaoUsuarioServico();
+ this.ServicoRestriUsuario = new RestricaoUsuarioServico();
+ this.ServicoVendedorUsuario = new VendedorUsuarioServico();
+ }
+
+ public bool Abrir(IndiceArquivoDigital indice, Gestor.Model.Domain.Common.ArquivoDigital arquivo)
+ {
+ bool flag;
+ string tempPath = Path.GetTempPath();
+ Guid? azureGuid = arquivo.get_AzureGuid();
+ string str = string.Format("{0}{1}{2}", tempPath, (azureGuid.HasValue ? azureGuid.GetValueOrDefault() : Guid.NewGuid()), Gestor.Common.Validation.ValidationHelper.GetDefaultExtension(arquivo.get_Extensao()));
+ try
+ {
+ using (BinaryWriter binaryWriter = new BinaryWriter(File.Open(str, FileMode.Create)))
+ {
+ binaryWriter.Write(arquivo.get_Arquivo());
+ }
+ Process.Start(str);
+ return true;
+ }
+ catch (Exception exception)
+ {
+ flag = false;
+ }
+ return flag;
+ }
+
+ public async void AbrirLog(TipoTela tipoTela, long id)
+ {
+ if (Recursos.Usuario.get_Id() != 0)
+ {
+ RestricaoUsuario restricaoUsuario = this.ServicoRestriUsuario.BuscarRestricao(Recursos.Usuario, 109);
+ if (restricaoUsuario == null || !restricaoUsuario.get_Restricao())
+ {
+ this.ShowDrawer(new LogDrawer(tipoTela, id, null, 0), 0, false);
+ }
+ else
+ {
+ await this.ShowMessage("VOCÊ NÃO POSSUI PERMISSÃO PARA ACESSAR OS LOGS", "OK", "", false);
+ }
+ }
+ else
+ {
+ this.ShowDrawer(new LogDrawer(tipoTela, id, null, 0), 0, false);
+ }
+ }
+
+ public async void AbrirLogEmail(TipoTela tela, long id)
+ {
+ if (Recursos.Usuario.get_Id() != 0)
+ {
+ RestricaoUsuario restricaoUsuario = this.ServicoRestriUsuario.BuscarRestricao(Recursos.Usuario, 109);
+ if (restricaoUsuario == null || !restricaoUsuario.get_Restricao())
+ {
+ this.ShowDrawer(new LogEmailDrawer(tela, id, false), 0, false);
+ }
+ else
+ {
+ await this.ShowMessage("VOCÊ NÃO POSSUI PERMISSÃO PARA ACESSAR OS LOGS", "OK", "", false);
+ }
+ }
+ else
+ {
+ this.ShowDrawer(new LogEmailDrawer(tela, id, false), 0, false);
+ }
+ }
+
+ public async void AbrirLogParcela(List<long> parcelas, long documento, int numparcela = 0)
+ {
+ if (Recursos.Usuario.get_Id() != 0)
+ {
+ RestricaoUsuario restricaoUsuario = this.ServicoRestriUsuario.BuscarRestricao(Recursos.Usuario, 109);
+ if (restricaoUsuario == null || !restricaoUsuario.get_Restricao())
+ {
+ this.ShowDrawer(new LogDrawer(5, documento, parcelas, numparcela), 0, false);
+ }
+ else
+ {
+ await this.ShowMessage("VOCÊ NÃO POSSUI PERMISSÃO PARA ACESSAR OS LOGS", "OK", "", false);
+ }
+ }
+ else
+ {
+ this.ShowDrawer(new LogDrawer(5, documento, parcelas, numparcela), 0, false);
+ }
+ }
+
+ public async Task<List<Gestor.Model.Domain.Common.ArquivoDigital>> AddAttachments(List<Gestor.Model.Domain.Common.ArquivoDigital> attachments, List<Gestor.Model.Domain.Common.ArquivoDigital> attacheds)
+ {
+ List<Gestor.Model.Domain.Common.ArquivoDigital> arquivoDigitals;
+ List<Gestor.Model.Domain.Common.ArquivoDigital> arquivoDigitals1;
+ List<string> strs = new List<string>();
+ using (OpenFileDialog openFileDialog = new OpenFileDialog())
+ {
+ openFileDialog.Multiselect = true;
+ openFileDialog.Filter = "Todos os Arquivos|*.pdf;*.jpg;*.jpeg;*.png;*.bmp;*.doc;*.docx;*.xls;*.xlsx;*.json;*.rar;*.zip;*.msg;*.eml;*.txt|Arquivos PDF|*.pdf|Imagens|*.jpg;*.jpeg;*.png;*.bmp|Documentos|*.doc;*.docx;*.msg|Planilhas|*.xls;*.xlsx|Arquivos do Aggilizador|*.json|Arquivos de Áudio|*.amr;*.ogg";
+ openFileDialog.InitialDirectory = Environment.SpecialFolder.Desktop.ToString();
+ if (DialogResult.OK == openFileDialog.ShowDialog())
+ {
+ strs.AddRange(openFileDialog.FileNames);
+ }
+ else
+ {
+ arquivoDigitals = null;
+ return arquivoDigitals;
+ }
+ }
+ strs = await this.ValidateAttachment(attachments, strs);
+ strs = await this.ValidateAttachment(attacheds, strs);
+ attachments = new List<Gestor.Model.Domain.Common.ArquivoDigital>();
+ foreach (string str in strs)
+ {
+ int num = 0;
+ try
+ {
+ string extension = Path.GetExtension(str);
+ using (MemoryStream memoryStream = new MemoryStream(File.ReadAllBytes(str)))
+ {
+ byte[] numArray = new byte[checked((IntPtr)memoryStream.Length)];
+ memoryStream.Position = (long)0;
+ memoryStream.Read(numArray, 0, (int)numArray.Length);
+ Gestor.Model.Domain.Common.ArquivoDigital arquivoDigital = new Gestor.Model.Domain.Common.ArquivoDigital();
+ arquivoDigital.set_Arquivo(numArray);
+ arquivoDigital.set_Descricao(Path.GetFileNameWithoutExtension(str));
+ arquivoDigital.set_Extensao(extension);
+ attachments.Add(arquivoDigital);
+ }
+ }
+ catch (Exception exception)
+ {
+ num = 1;
+ }
+ if (num != 1)
+ {
+ continue;
+ }
+ string[] newLine = new string[] { "NÃO FOI POSSÍVEL CARREGAR O ARQUIVO ", str, ".", Environment.NewLine, "O ARQUIVO ESTÁ INACESSÍVEL OU SENDO UTILIZADO POR OUTRO PROCESSO." };
+ await this.ShowMessage(string.Concat(newLine), "OK", "", false);
+ }
+ if (attachments.Count == 0)
+ {
+ arquivoDigitals1 = null;
+ }
+ else
+ {
+ arquivoDigitals1 = attachments;
+ }
+ arquivoDigitals = arquivoDigitals1;
+ return arquivoDigitals;
+ }
+
+ public async void Alterar(bool alterar)
+ {
+ Action<bool> enablePesquisarClientes = Gestor.Application.Actions.Actions.EnablePesquisarClientes;
+ if (enablePesquisarClientes != null)
+ {
+ enablePesquisarClientes(!alterar);
+ }
+ else
+ {
+ }
+ Action<bool> enableMenu = Gestor.Application.Actions.Actions.EnableMenu;
+ if (enableMenu != null)
+ {
+ enableMenu(!alterar);
+ }
+ else
+ {
+ }
+ Action<bool> enableMainMenu = Gestor.Application.Actions.Actions.EnableMainMenu;
+ if (enableMainMenu != null)
+ {
+ enableMainMenu(!alterar);
+ }
+ else
+ {
+ }
+ this.EnableFields = alterar;
+ this.EnableMenu = !alterar;
+ if (alterar)
+ {
+ this.EnableIncluir = false;
+ this.EnableAlterar = false;
+ this.EnableExcluir = false;
+ this.EnableButtons = false;
+ }
+ else
+ {
+ this.VerificarEnables(this._lastId);
+ }
+ this.AllowEditParcela = !alterar;
+ this.IsEnabledEdit = !alterar;
+ this.IsEnabledEditEndosso = !alterar;
+ if ((Funcoes.GetNetworkTime() - ApplicationHelper.ChecagemVersao).TotalMinutes > 10)
+ {
+ await this.VerificarVersao();
+ }
+ }
+
+ public async Task<EnderecoBase> BuscaCep(string cep)
+ {
+ return await (new CepService()).SearchDirect(cep);
+ }
+
+ internal async Task<List<Banco>> BuscarBanco(string value)
+ {
+ List<Banco> bancos = await Task.Run<List<Banco>>(() => (new BaseServico()).BuscarBanco(value));
+ return bancos;
+ }
+
+ internal void CloseDrawer()
+ {
+ Window window = System.Windows.Application.Current.Windows.OfType<Window>().SingleOrDefault<Window>((Window x) => x.IsActive);
+ DrawerHost drawerHost = Extentions.FindVisualChildren<DrawerHost>(window).FirstOrDefault<DrawerHost>();
+ Extentions.FindVisualChildren<WebEditor>(window).ToList<WebEditor>().ForEach((WebEditor x) => x.Visibility = Visibility.Visible);
+ if (drawerHost == null)
+ {
+ return;
+ }
+ drawerHost.set_IsBottomDrawerOpen(false);
+ drawerHost.set_IsTopDrawerOpen(false);
+ if (drawerHost.get_IsLeftDrawerOpen())
+ {
+ drawerHost.set_IsLeftDrawerOpen(false);
+ return;
+ }
+ drawerHost.set_IsRightDrawerOpen(false);
+ }
+
+ private void CloseSlackBar()
+ {
+ Thread.Sleep(5000);
+ Dispatcher dispatcher = App.ProgressRing.Dispatcher;
+ if (dispatcher == null)
+ {
+ return;
+ }
+ dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() => this.ToggleSnackBar("", false)));
+ }
+
+ private async Task<DialogAdvertising> CreateDialogAdvertising()
+ {
+ DialogAdvertising dialogAdvertising;
+ DateTime? nullable;
+ DialogAdvertising dialogAdvertising1;
+ DateTime? nullable1;
+ DateTime? nullable2;
+ string str;
+ bool flag;
+ bool flag1;
+ object empty;
+ JObject jObject = await this.LoadJsonAdvertising(Address.get_SurveyJson());
+ if (jObject != null)
+ {
+ JToken item = jObject.get_Item("Inicio");
+ if (item != null)
+ {
+ nullable1 = new DateTime?(Extensions.Value<DateTime>(item));
+ }
+ else
+ {
+ nullable = null;
+ nullable1 = nullable;
+ }
+ DateTime? nullable3 = nullable1;
+ JToken jToken = jObject.get_Item("Fim");
+ if (jToken != null)
+ {
+ nullable2 = new DateTime?(Extensions.Value<DateTime>(jToken));
+ }
+ else
+ {
+ nullable = null;
+ nullable2 = nullable;
+ }
+ DateTime? nullable4 = nullable2;
+ DateTime networkTime = Funcoes.GetNetworkTime();
+ Gestor.Application.Model.Configuracoes configuraco = this.LoadConfiguracoes();
+ JToken item1 = jObject.get_Item("UrlPost");
+ if (item1 != null)
+ {
+ str = Extensions.Value<string>(item1);
+ }
+ else
+ {
+ str = null;
+ }
+ string str1 = str;
+ if (Gestor.Common.Validation.ValidationHelper.IsNullOrEmpty(str1))
+ {
+ JToken jToken1 = jObject.get_Item("UrlFixa");
+ if (jToken1 != null)
+ {
+ empty = Extensions.Value<string>(jToken1);
+ }
+ else
+ {
+ empty = null;
+ }
+ if (empty == null)
+ {
+ empty = string.Empty;
+ }
+ str1 = (string)empty;
+ }
+ if (configuraco.LinkPromo == str1 || configuraco.NaoverPromo)
+ {
+ dialogAdvertising = null;
+ }
+ else
+ {
+ nullable = nullable4;
+ DateTime dateTime = networkTime;
+ flag = (nullable.HasValue ? nullable.GetValueOrDefault() >= dateTime : false);
+ if (flag)
+ {
+ nullable = nullable3;
+ dateTime = networkTime;
+ flag1 = (nullable.HasValue ? nullable.GetValueOrDefault() <= dateTime : false);
+ if (!flag1)
+ {
+ goto Label1;
+ }
+ dialogAdvertising1 = new DialogAdvertising(jObject, false);
+ goto Label0;
+ }
+ Label1:
+ dialogAdvertising1 = await this.LoadDialogAdertisingPromo();
+ Label0:
+ dialogAdvertising = dialogAdvertising1;
+ }
+ }
+ else
+ {
+ dialogAdvertising = await this.LoadDialogAdertisingPromo();
+ }
+ return dialogAdvertising;
+ }
+
+ private void CriarConfiguracaoPadrao(string configFile)
+ {
+ if (File.Exists(configFile))
+ {
+ return;
+ }
+ File.WriteAllText(configFile, JsonConvert.SerializeObject(new Gestor.Application.Model.Configuracoes()
+ {
+ LinkPromo = "",
+ NaoverPromo = false
+ }, 1));
+ }
+
+ public async void Download(IndiceArquivoDigital indice, bool open = true)
+ {
+ DateTime valueOrDefault;
+ bool arquivo;
+ int? nullable;
+ bool flag;
+ Gestor.Model.Domain.Common.ArquivoDigital arquivoDigital;
+ if (indice.get_Id() != 0)
+ {
+ arquivoDigital = null;
+ if (indice.get_Assinado())
+ {
+ Gestor.Model.Domain.Common.ArquivoDigital arquivoDigital1 = await this.ArquivoDigitalServico.BuscarPorId(indice.get_Id());
+ if (arquivoDigital1 != null)
+ {
+ flag = arquivoDigital1.get_Arquivo();
+ }
+ else
+ {
+ flag = false;
+ }
+ if (flag)
+ {
+ if (!arquivoDigital1.get_Extensao().Contains("."))
+ {
+ arquivoDigital1.set_Extensao(string.Concat(".", arquivoDigital1.get_Extensao()));
+ }
+ arquivoDigital = arquivoDigital1;
+ }
+ }
+ if (arquivoDigital == null)
+ {
+ arquivoDigital = await this.ArquivoDigitalServico.BuscarPorId(indice.get_IdArquivoDigital(), indice.get_Bd());
+ }
+ Gestor.Model.Domain.Common.ArquivoDigital arquivoDigital2 = arquivoDigital;
+ if (arquivoDigital2 != null)
+ {
+ arquivo = arquivoDigital2.get_Arquivo();
+ }
+ else
+ {
+ arquivo = false;
+ }
+ if (!arquivo || arquivoDigital.get_Extensao() == null)
+ {
+ string str = "DOCUMENTO NÃO POSSUI PDF";
+ DateTime? dataCriacao = indice.get_DataCriacao();
+ if (dataCriacao.HasValue)
+ {
+ valueOrDefault = dataCriacao.GetValueOrDefault();
+ nullable = new int?(valueOrDefault.Year);
+ }
+ else
+ {
+ nullable = null;
+ }
+ int? nullable1 = nullable;
+ valueOrDefault = DateTime.Now;
+ if (nullable1.GetValueOrDefault() <= valueOrDefault.Year - 5 & nullable1.HasValue)
+ {
+ str = string.Concat(str, " OU POR SER UM ARQUIVO ANTIGO, TENTE NOVAMENTE EM ALGUNS MINUTOS");
+ }
+ await this.ShowMessage(string.Concat(str, "."), "OK", "", false);
+ }
+ else
+ {
+ if (open)
+ {
+ if (!this.Abrir(indice, arquivoDigital))
+ {
+ await this.ShowMessage("NÃO FOI POSSÍVEL ABRIR O ARQUIVO. ESCOLHA UM LOCAL PARA SALVAR O ARQUIVO.", "OK", "", false);
+ }
+ else
+ {
+ arquivoDigital = null;
+ return;
+ }
+ }
+ using (SaveFileDialog saveFileDialog = new SaveFileDialog())
+ {
+ saveFileDialog.Filter = "All Files|*.*";
+ saveFileDialog.FileName = indice.get_Descricao();
+ if (DialogResult.OK != saveFileDialog.ShowDialog())
+ {
+ arquivoDigital = null;
+ return;
+ }
+ else if (!File.Exists(string.Concat(saveFileDialog.FileName, Gestor.Common.Validation.ValidationHelper.GetDefaultExtension(arquivoDigital.get_Extensao()))))
+ {
+ using (BinaryWriter binaryWriter = new BinaryWriter(File.Open(string.Concat(saveFileDialog.FileName, Gestor.Common.Validation.ValidationHelper.GetDefaultExtension(arquivoDigital.get_Extensao())), FileMode.Create)))
+ {
+ binaryWriter.Write(arquivoDigital.get_Arquivo());
+ }
+ }
+ else
+ {
+ string[] descricao = new string[] { "JÁ EXISTE UM ARQUIVO COM O NOME DE ", arquivoDigital.get_Descricao(), Gestor.Common.Validation.ValidationHelper.GetDefaultExtension(arquivoDigital.get_Extensao()), " NA PASTA SELECIONADA. ", Environment.NewLine, "TENTE NOVAMENTE EM OUTRA PASTA." };
+ await this.ShowMessage(string.Concat(descricao), "OK", "", false);
+ arquivoDigital = null;
+ return;
+ }
+ }
+ saveFileDialog = null;
+ }
+ }
+ arquivoDigital = null;
+ }
+
+ public async Task<bool> DownloadAll(List<IndiceArquivoDigital> indices, long id)
+ {
+ bool flag;
+ bool arquivo;
+ bool arquivo1;
+ string str;
+ using (FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog())
+ {
+ if (DialogResult.OK == folderBrowserDialog.ShowDialog())
+ {
+ str = string.Format("{0}\\{1}", folderBrowserDialog.SelectedPath, id);
+ Directory.CreateDirectory(str);
+ }
+ else
+ {
+ flag = false;
+ str = null;
+ return flag;
+ }
+ }
+ int num = 1;
+ foreach (IndiceArquivoDigital index in indices)
+ {
+ Gestor.Model.Domain.Common.ArquivoDigital arquivoDigital = null;
+ if (index.get_Assinado())
+ {
+ Gestor.Model.Domain.Common.ArquivoDigital arquivoDigital1 = await this.ArquivoDigitalServico.BuscarPorId(index.get_Id());
+ if (arquivoDigital1 != null)
+ {
+ arquivo1 = arquivoDigital1.get_Arquivo();
+ }
+ else
+ {
+ arquivo1 = false;
+ }
+ if (arquivo1)
+ {
+ arquivoDigital = arquivoDigital1;
+ }
+ }
+ if (arquivoDigital == null)
+ {
+ arquivoDigital = await this.ArquivoDigitalServico.BuscarPorId(index.get_IdArquivoDigital(), index.get_Bd());
+ }
+ Gestor.Model.Domain.Common.ArquivoDigital arquivoDigital2 = arquivoDigital;
+ if (arquivoDigital2 != null)
+ {
+ arquivo = arquivoDigital2.get_Arquivo();
+ }
+ else
+ {
+ arquivo = false;
+ }
+ if (!arquivo || arquivoDigital.get_Extensao() == null)
+ {
+ flag = false;
+ str = null;
+ return flag;
+ }
+ else
+ {
+ if (File.Exists(Gestor.Common.Validation.ValidationHelper.NormalizePath(string.Concat(str, "\\", index.get_Descricao(), Gestor.Common.Validation.ValidationHelper.GetDefaultExtension(arquivoDigital.get_Extensao())))))
+ {
+ index.set_Descricao(string.Format("{0}_{1}", index.get_Descricao(), num));
+ num++;
+ }
+ using (BinaryWriter binaryWriter = new BinaryWriter(File.Open(Gestor.Common.Validation.ValidationHelper.NormalizePath(string.Concat(str, "\\", index.get_Descricao(), Gestor.Common.Validation.ValidationHelper.GetDefaultExtension(arquivoDigital.get_Extensao()))), FileMode.Create)))
+ {
+ binaryWriter.Write(arquivoDigital.get_Arquivo());
+ }
+ arquivoDigital = null;
+ index = null;
+ }
+ }
+ Process.Start(str);
+ flag = true;
+ str = null;
+ return flag;
+ }
+
+ public async Task DownloadAll(List<long> ids, TipoArquivoVinculo type)
+ {
+ bool arquivo;
+ string str;
+ Gestor.Application.Servicos.ArquivoDigitalServico arquivoDigitalServico;
+ if (ids != null && ids.Count != 0)
+ {
+ str = string.Format("{0}{1}", Path.GetTempPath(), Guid.NewGuid());
+ BaseServico baseServico = new BaseServico();
+ arquivoDigitalServico = new Gestor.Application.Servicos.ArquivoDigitalServico();
+ List<ArquivoVinculo> arquivoVinculos = await baseServico.ArquivoVinculo(ids, type);
+ int num = 1;
+ if (!Directory.Exists(str))
+ {
+ Directory.CreateDirectory(str);
+ }
+ foreach (ArquivoVinculo arquivoVinculo in await arquivoDigitalServico.BaixarArquivosPendentes(arquivoVinculos))
+ {
+ if (arquivoVinculo != null)
+ {
+ arquivo = arquivoVinculo.get_Arquivo();
+ }
+ else
+ {
+ arquivo = false;
+ }
+ if (!arquivo)
+ {
+ continue;
+ }
+ string str1 = Guid.NewGuid().ToString();
+ if (File.Exists(string.Concat(str, "\\", str1, ".pdf")))
+ {
+ str1 = string.Format("{0}_{1}", str1, num);
+ num++;
+ }
+ using (BinaryWriter binaryWriter = new BinaryWriter(File.Open(string.Concat(str, "\\", str1, ".pdf"), FileMode.Create)))
+ {
+ binaryWriter.Write(arquivoVinculo.get_Arquivo());
+ }
+ }
+ Process.Start(str);
+ }
+ str = null;
+ arquivoDigitalServico = null;
+ }
+
+ public async Task EmitirCheckList(List<Documento> documentos)
+ {
+ DateTime vencimento;
+ string str;
+ string str1;
+ string str2;
+ string str3;
+ string str4;
+ string str5;
+ string str6;
+ string str7;
+ string nome;
+ ParcelaServico parcelaServico = new ParcelaServico();
+ string str8 = "<html><head><title>CHECK LIST DE PROTOCOLOS</title></head><body style='font-size: 12px; font-family: Arial, Helvetica, sans-serif; margin-left: 50px; margin-right: 50px; line-height: 30px;' onload='self.print();'>";
+ str8 = string.Concat(str8, "<div align='center' style='font-size: 20px;'><strong>CHECK LIST DE PROTOCOLOS</strong></div> <br>");
+ str8 = string.Concat(str8, "<div class='table-responsive'>");
+ str8 = string.Concat(str8, "<table align='center' class='table table-bordered' border='1px' style='border-collapse:collapse;' style='width:100%;' style='margin:auto;'>");
+ int num = 1;
+ str8 = string.Concat(str8, "<tr bgcolor=LightBlue>");
+ str8 = string.Concat(str8, "<td><strong>CLIENTE</strong></td>");
+ str8 = string.Concat(str8, "<td><strong>APÓLICE</strong></td>");
+ str8 = string.Concat(str8, "<td><strong>1ª PARCELA</strong></td>");
+ str8 = string.Concat(str8, "<td><strong>2ª PARCELA</strong></td>");
+ str8 = string.Concat(str8, "<td><strong>RECEBIDA POR</strong></td>");
+ str8 = string.Concat(str8, "<td><strong>VENDEDOR</strong></td>");
+ str8 = string.Concat(str8, "</tr>");
+ List<Documento> documentos1 = documentos;
+ documentos = (
+ from x in documentos1
+ orderby x.get_Controle().get_Cliente().get_Nome()
+ select x).ToList<Documento>();
+ foreach (Documento documento in documentos)
+ {
+ Documento documento1 = documento;
+ ObservableCollection<Parcela> observableCollection = await parcelaServico.BuscarParcelasAsync(documento.get_Id());
+ documento1.set_Parcelas(observableCollection);
+ documento1 = null;
+ string[] strArrays = new string[] { str8, "<tr> <td style='padding:10px' bgcolor='", null, null, null, null };
+ str = (num % 2 == 0 ? "WhiteSmoke" : "White");
+ strArrays[2] = str;
+ strArrays[3] = "'>";
+ strArrays[4] = documento.get_Controle().get_Cliente().get_Nome();
+ strArrays[5] = "</td>";
+ str8 = string.Concat(strArrays);
+ string[] apolice = new string[] { str8, "<td style='padding:10px' bgcolor='", null, null, null, null };
+ str1 = (num % 2 == 0 ? "WhiteSmoke" : "White");
+ apolice[2] = str1;
+ apolice[3] = "'>";
+ apolice[4] = documento.get_Apolice();
+ apolice[5] = "</td>";
+ str8 = string.Concat(apolice);
+ if (documento.get_Parcelas() != null)
+ {
+ ObservableCollection<Parcela> parcelas = documento.get_Parcelas();
+ if ((
+ from x in parcelas
+ where x.get_SubTipo() == 1
+ select x).ToList<Parcela>().Count <= 0)
+ {
+ goto Label1;
+ }
+ ObservableCollection<Parcela> parcelas1 = documento.get_Parcelas();
+ vencimento = (
+ from x in parcelas1
+ where x.get_NumeroParcela() == 1
+ select x).First<Parcela>().get_Vencimento();
+ vencimento = vencimento.Date;
+ str2 = vencimento.ToString("dd/MM/yyyy");
+ goto Label0;
+ }
+ Label1:
+ str2 = "";
+ Label0:
+ string str9 = str2;
+ string[] strArrays1 = new string[] { str8, "<td style='padding:10px' bgcolor='", null, null, null, null };
+ str3 = (num % 2 == 0 ? "WhiteSmoke" : "White");
+ strArrays1[2] = str3;
+ strArrays1[3] = "'>";
+ strArrays1[4] = str9;
+ strArrays1[5] = "</td>";
+ str8 = string.Concat(strArrays1);
+ if (documento.get_Parcelas() != null)
+ {
+ ObservableCollection<Parcela> observableCollection1 = documento.get_Parcelas();
+ if ((
+ from x in observableCollection1
+ where x.get_SubTipo() == 1
+ select x).ToList<Parcela>().Count <= 1)
+ {
+ goto Label3;
+ }
+ ObservableCollection<Parcela> parcelas2 = documento.get_Parcelas();
+ vencimento = (
+ from x in parcelas2
+ where x.get_NumeroParcela() == 2
+ select x).First<Parcela>().get_Vencimento();
+ vencimento = vencimento.Date;
+ str4 = vencimento.ToString("dd/MM/yyyy");
+ goto Label2;
+ }
+ Label3:
+ str4 = "";
+ Label2:
+ str9 = str4;
+ string[] strArrays2 = new string[] { str8, "<td style='padding:10px' bgcolor='", null, null, null, null };
+ str5 = (num % 2 == 0 ? "WhiteSmoke" : "White");
+ strArrays2[2] = str5;
+ strArrays2[3] = "'>";
+ strArrays2[4] = str9;
+ strArrays2[5] = "</td>";
+ str8 = string.Concat(strArrays2);
+ string str10 = str8;
+ str6 = (num % 2 == 0 ? "WhiteSmoke" : "White");
+ str8 = string.Concat(str10, "<td style='padding:10px' bgcolor='", str6, "'>____________/____/___</td>");
+ string[] strArrays3 = new string[] { str8, "<td style='padding:10px' bgcolor='", null, null, null, null };
+ str7 = (num % 2 == 0 ? "WhiteSmoke" : "White");
+ strArrays3[2] = str7;
+ strArrays3[3] = "'>";
+ Vendedor vendedorPrincipal = documento.get_VendedorPrincipal();
+ if (vendedorPrincipal != null)
+ {
+ nome = vendedorPrincipal.get_Nome();
+ }
+ else
+ {
+ nome = null;
+ }
+ strArrays3[4] = nome;
+ strArrays3[5] = "</td></tr>";
+ str8 = string.Concat(strArrays3);
+ if (num != 1)
+ {
+ num++;
+ }
+ else
+ {
+ num = 0;
+ }
+ }
+ DateTime networkTime = Funcoes.GetNetworkTime();
+ string nome1 = Recursos.Usuario.get_Nome();
+ str8 = string.Concat(str8, "</table></div>");
+ string str11 = str8;
+ int count = documentos.Count;
+ str8 = string.Concat(str11, "<div align='center'><strong>TOTAL DE PROTOCOLOS: ", count.ToString(), "</strong></div>");
+ str8 = string.Concat(str8, string.Format("Emitido pelo usuário: {0}, data e hora: {1}.", nome1, networkTime));
+ str8 = string.Concat(str8, "</body>");
+ string tempPath = Path.GetTempPath();
+ string str12 = string.Format("{0}{1}CheckList_{2:ddMMyyyyhhmmss}.html", tempPath, (TipoExtrato)0, networkTime);
+ StreamWriter streamWriter = new StreamWriter(str12, true, Encoding.UTF8);
+ streamWriter.Write(str8);
+ streamWriter.Close();
+ Process.Start(str12);
+ parcelaServico = null;
+ str8 = null;
+ }
+
+ public async Task EmitirProtocolos(List<Tuple<long, string>> lista, bool doisPorPagina, List<Documento> protocolo)
+ {
+ DateTime vigencia1;
+ string str;
+ ClienteEndereco clienteEndereco;
+ string str1;
+ string str2;
+ string str3;
+ string str4;
+ string str5;
+ string str6;
+ string str7;
+ string str8;
+ bool flag;
+ string email;
+ string str9;
+ string str10;
+ string shortDateString;
+ string shortDateString1;
+ string shortDateString2;
+ string str11;
+ string obsProtocolo;
+ string str12;
+ string pasta;
+ string nome;
+ string str13;
+ string str14;
+ string str15;
+ object obj;
+ string shortDateString3;
+ string shortDateString4;
+ string str16;
+ object obj1;
+ int num = 0;
+ DateTime networkTime = Funcoes.GetNetworkTime();
+ int num1 = 0;
+ StringBuilder stringBuilder = new StringBuilder();
+ StringBuilder stringBuilder1 = new StringBuilder();
+ foreach (Tuple<long, string> listum in lista)
+ {
+ num1++;
+ ApoliceServico apoliceServico = new ApoliceServico();
+ ItemServico itemServico = new ItemServico();
+ ClienteServico clienteServico = new ClienteServico();
+ ParcelaServico parcelaServico = new ParcelaServico();
+ Documento documento = await apoliceServico.BuscarApoliceAsync(listum.Item1, false, false);
+ Documento documento1 = documento;
+ documento1.get_Controle().get_Cliente().set_Telefones(clienteServico.BuscarTelefones(documento1.get_Controle().get_Cliente().get_Id()));
+ Cliente cliente = documento1.get_Controle().get_Cliente();
+ ObservableCollection<ClienteEmail> observableCollection = await clienteServico.BuscarEmailsAsync(documento1.get_Controle().get_Cliente().get_Id());
+ cliente.set_Emails(observableCollection);
+ cliente = null;
+ cliente = documento1.get_Controle().get_Cliente();
+ ObservableCollection<ClienteEndereco> observableCollection1 = await clienteServico.BuscarEnderecosAsync(documento1.get_Controle().get_Cliente().get_Id());
+ cliente.set_Enderecos(observableCollection1);
+ cliente = null;
+ if (documento1.get_VendedorPrincipal() == null)
+ {
+ Documento documento2 = documento1;
+ Vendedor vendedor = await apoliceServico.BuscarVendedorPrincipal(documento1.get_Controle().get_Id());
+ documento2.set_VendedorPrincipal(vendedor);
+ documento2 = null;
+ }
+ ObservableCollection<Item> observableCollection2 = await itemServico.BuscarItems(documento1.get_Id(), 2, false);
+ if (observableCollection2 == null || observableCollection2.Count == 0)
+ {
+ observableCollection2 = await itemServico.BuscarItens(documento1.get_Controle().get_Id(), 3);
+ }
+ ObservableCollection<Parcela> observableCollection3 = await parcelaServico.BuscarParcelasAsync(documento1.get_Id());
+ documento1.set_ProtocoloEmail(protocolo.Find((Documento x) => x.get_Id() == documento1.get_Id()).get_ProtocoloEmail());
+ documento1.set_ProtocoloTelefone(protocolo.Find((Documento x) => x.get_Id() == documento1.get_Id()).get_ProtocoloTelefone());
+ documento1.set_ProtocoloParcela(protocolo.Find((Documento x) => x.get_Id() == documento1.get_Id()).get_ProtocoloParcela());
+ documento1.set_ProtocoloEndereco(protocolo.Find((Documento x) => x.get_Id() == documento1.get_Id()).get_ProtocoloEndereco());
+ documento1.set_ProtocoloVendedor(protocolo.Find((Documento x) => x.get_Id() == documento1.get_Id()).get_ProtocoloVendedor());
+ ObservableCollection<ClienteTelefone> telefones = documento1.get_Controle().get_Cliente().get_Telefones();
+ if (documento1.get_ProtocoloTelefone() && telefones != null)
+ {
+ ObservableCollection<ClienteTelefone> observableCollection4 = telefones;
+ if (!(
+ from t in observableCollection4
+ where !string.IsNullOrEmpty(t.get_Numero())
+ select t).Any<ClienteTelefone>())
+ {
+ goto Label1;
+ }
+ ObservableCollection<ClienteTelefone> observableCollection5 = telefones;
+ IEnumerable<ClienteTelefone> clienteTelefones =
+ from t in observableCollection5
+ where !string.IsNullOrEmpty(t.get_Numero())
+ select t;
+ str = string.Join(" | ", (
+ from t in clienteTelefones
+ select string.Concat(t.get_Prefixo(), " ", t.get_Numero())).ToList<string>());
+ goto Label0;
+ }
+ Label1:
+ str = null;
+ Label0:
+ string str17 = string.Concat("Telefone: <b>", str, "</b>");
+ ObservableCollection<ClienteEndereco> enderecos = documento1.get_Controle().get_Cliente().get_Enderecos();
+ if (enderecos != null)
+ {
+ clienteEndereco = enderecos.FirstOrDefault<ClienteEndereco>();
+ }
+ else
+ {
+ clienteEndereco = null;
+ }
+ ClienteEndereco clienteEndereco1 = clienteEndereco;
+ if (protocolo.Find((Documento x) => x.get_Id() == documento1.get_Id()).get_ProtocoloEndereco())
+ {
+ string[] strArrays = new string[12];
+ str1 = (string.IsNullOrWhiteSpace(clienteEndereco1.get_Endereco()) ? "" : clienteEndereco1.get_Endereco());
+ strArrays[0] = str1;
+ strArrays[1] = ", ";
+ str2 = (string.IsNullOrWhiteSpace(clienteEndereco1.get_Numero()) ? "" : clienteEndereco1.get_Numero());
+ strArrays[2] = str2;
+ str3 = (string.IsNullOrWhiteSpace(clienteEndereco1.get_Complemento()) ? "" : string.Concat(" - ", clienteEndereco1.get_Complemento()));
+ strArrays[3] = str3;
+ strArrays[4] = " - ";
+ str4 = (string.IsNullOrWhiteSpace(clienteEndereco1.get_Bairro()) ? "" : clienteEndereco1.get_Bairro());
+ strArrays[5] = str4;
+ strArrays[6] = " - ";
+ str5 = (string.IsNullOrWhiteSpace(clienteEndereco1.get_Cidade()) ? "" : clienteEndereco1.get_Cidade());
+ strArrays[7] = str5;
+ strArrays[8] = " - ";
+ str6 = (string.IsNullOrWhiteSpace(clienteEndereco1.get_Estado()) ? "" : clienteEndereco1.get_Estado());
+ strArrays[9] = str6;
+ strArrays[10] = ", ";
+ str7 = (string.IsNullOrWhiteSpace(clienteEndereco1.get_Cep()) ? "" : clienteEndereco1.get_Cep());
+ strArrays[11] = str7;
+ str8 = string.Concat(strArrays);
+ }
+ else
+ {
+ str8 = null;
+ }
+ string str18 = str8;
+ ObservableCollection<ClienteEmail> emails = documento1.get_Controle().get_Cliente().get_Emails();
+ flag = (!documento1.get_ProtocoloEmail() || emails == null || emails.Count <= 0 ? false : !string.IsNullOrEmpty(emails.First<ClienteEmail>().get_Email()));
+ if (flag)
+ {
+ email = emails.First<ClienteEmail>().get_Email();
+ }
+ else
+ {
+ email = null;
+ }
+ string str19 = string.Concat(" Email: <b>", email, "</b>");
+ str9 = (telefones != null || clienteEndereco1 != null || emails != null ? "" : "style='display:none;'");
+ string str20 = str9;
+ str10 = (string.IsNullOrWhiteSpace(documento1.get_Endosso()) ? ", " : string.Concat(" e<br>endosso de n° <b>", documento1.get_Endosso(), "</b>, "));
+ string str21 = str10;
+ string[] strArrays1 = new string[] { "iniciado em <b>", null, null, null, null };
+ if (string.IsNullOrWhiteSpace(documento1.get_Vigencia1().ToShortDateString()))
+ {
+ shortDateString = "";
+ }
+ else
+ {
+ vigencia1 = documento1.get_Vigencia1();
+ shortDateString = vigencia1.ToShortDateString();
+ }
+ strArrays1[1] = shortDateString;
+ strArrays1[2] = "</b> até <b>";
+ DateTime? vigencia2 = documento1.get_Vigencia2();
+ if (vigencia2.HasValue)
+ {
+ shortDateString1 = vigencia2.GetValueOrDefault().ToShortDateString();
+ }
+ else
+ {
+ shortDateString1 = null;
+ }
+ if (string.IsNullOrWhiteSpace(shortDateString1))
+ {
+ shortDateString2 = "";
+ }
+ else
+ {
+ vigencia2 = documento1.get_Vigencia2();
+ if (vigencia2.HasValue)
+ {
+ shortDateString2 = vigencia2.GetValueOrDefault().ToShortDateString();
+ }
+ else
+ {
+ shortDateString2 = null;
+ }
+ }
+ strArrays1[3] = shortDateString2;
+ strArrays1[4] = "</b>";
+ string str22 = string.Concat(strArrays1);
+ if (observableCollection2 == null || observableCollection2.Count <= 0)
+ {
+ str11 = "";
+ }
+ else
+ {
+ str16 = (string.IsNullOrWhiteSpace(observableCollection2[0].get_Descricao()) ? "" : observableCollection2[0].get_Descricao());
+ str11 = string.Concat("<b>", str16, "</b>");
+ }
+ string str23 = str11;
+ string str24 = "";
+ Documento documento3 = protocolo.FirstOrDefault<Documento>((Documento x) => x.get_Id() == documento1.get_Id());
+ if (documento3 != null)
+ {
+ obsProtocolo = documento3.get_ObsProtocolo();
+ }
+ else
+ {
+ obsProtocolo = null;
+ }
+ string str25 = obsProtocolo;
+ str12 = (string.IsNullOrEmpty(str25) ? "" : string.Concat("OBSERVAÇÃO: ", str25));
+ string str26 = str12;
+ if (documento1.get_ProtocoloParcela() && observableCollection3 != null && observableCollection3.Count > 0)
+ {
+ if (observableCollection3.Count != 1)
+ {
+ object count = observableCollection3.Count;
+ if (string.IsNullOrWhiteSpace(observableCollection3[0].get_Vencimento().ToShortDateString()))
+ {
+ obj = "";
+ }
+ else
+ {
+ vigencia1 = observableCollection3[0].get_Vencimento();
+ obj = vigencia1.ToShortDateString();
+ }
+ string str27 = string.Format("{0} parcelas: vencimento 1ª parcela: <strong>{1}</strong>, ", count, obj);
+ if (string.IsNullOrWhiteSpace(observableCollection3[1].get_Vencimento().ToShortDateString()))
+ {
+ shortDateString3 = "";
+ }
+ else
+ {
+ vigencia1 = observableCollection3[1].get_Vencimento();
+ shortDateString3 = vigencia1.ToShortDateString();
+ }
+ str24 = string.Concat(str27, "vencimento 2ª parcela: <strong>", shortDateString3, "</strong>, demais parcelas, vide apólice.");
+ }
+ else
+ {
+ string str28 = str24;
+ if (string.IsNullOrWhiteSpace(observableCollection3[0].get_Vencimento().ToShortDateString()))
+ {
+ shortDateString4 = "";
+ }
+ else
+ {
+ vigencia1 = observableCollection3[0].get_Vencimento();
+ shortDateString4 = vigencia1.ToShortDateString();
+ }
+ str24 = string.Concat(str28, "1 parcela: vencimento <strong>", shortDateString4, "</strong> ");
+ }
+ }
+ if (documento1.get_ProtocoloVendedor())
+ {
+ pasta = documento1.get_Pasta();
+ }
+ else
+ {
+ pasta = null;
+ }
+ string str29 = pasta;
+ if (documento1.get_ProtocoloVendedor())
+ {
+ Vendedor vendedorPrincipal = documento1.get_VendedorPrincipal();
+ if (vendedorPrincipal != null)
+ {
+ nome = vendedorPrincipal.get_Nome();
+ }
+ else
+ {
+ nome = null;
+ }
+ }
+ else
+ {
+ nome = null;
+ }
+ string str30 = nome;
+ str13 = (str29 != null || str30 != null ? "" : "style = 'display:none;'");
+ string str31 = str13;
+ StringBuilder stringBuilder2 = stringBuilder1;
+ string protocoloTemplate = Resources.ProtocoloTemplate;
+ str14 = (doisPorPagina ? "12.2cm" : "24.4cm");
+ string str32 = protocoloTemplate.Replace("{Tamanho}", str14).Replace("{Observacao}", str26).Replace("{Nome}", documento1.get_Controle().get_Cliente().get_Nome()).Replace("{Email}", str19).Replace("{DisplayTelefones}", str20);
+ str15 = (telefones != null ? str17 : "");
+ stringBuilder2.Append(str32.Replace("{Telefones}", str15).Replace("{Endereço}", str18).Replace("{Ramo}", documento1.get_Controle().get_Ramo().get_Nome()).Replace("{Apolice}", documento1.get_Apolice()).Replace("{Endosso}", str21).Replace("{Seguradora}", documento1.get_Controle().get_Seguradora().get_Nome()).Replace("{Vigencias}", str22).Replace("{Item}", str23).Replace("{Parcelas}", str24).Replace("{Pasta}", str29).Replace("{Vendedor}", str30).Replace("{DisplayVendedor}", str31).Replace("{NomeCorretora}", Recursos.Empresa.get_Nome()).Replace("{Usuario}", Recursos.Usuario.get_Nome()).Replace("{Emissao}", string.Format("{0}", networkTime)));
+ num++;
+ if (!doisPorPagina || num1 == 2)
+ {
+ stringBuilder1.Append("<div style='page-break-after: always'></div>");
+ num1 = 0;
+ }
+ apoliceServico = null;
+ itemServico = null;
+ clienteServico = null;
+ parcelaServico = null;
+ observableCollection2 = null;
+ }
+ stringBuilder.Append(Resources.ProtocoloPageTemplate.Replace("{Protocolos}", stringBuilder1.ToString()));
+ string tempPath = Path.GetTempPath();
+ string str33 = string.Format("{0}{1}_{2:ddMMyyyyhhmmss}.html", tempPath, (TipoExtrato)0, networkTime);
+ StreamWriter streamWriter = new StreamWriter(str33, true, Encoding.UTF8);
+ streamWriter.Write(stringBuilder);
+ streamWriter.Close();
+ Process.Start(str33);
+ BaseViewModel baseViewModel = this;
+ object count1 = lista.Count;
+ obj1 = (lista.Count == 1 ? "" : "S");
+ string str34 = string.Format("EMITIU PROTOCOLO DE {0} DOCUMENTO{1}", count1, obj1);
+ long num2 = (long)0;
+ TipoTela? nullable = new TipoTela?(59);
+ List<Tuple<long, string>> tuples = lista;
+ baseViewModel.RegistrarAcao(str34, num2, nullable, string.Concat("IDS DOS DOCUMENTOS E SUAS RESPECTIVAS OBSERVAÇÕES:\n", string.Join("\n",
+ from x in tuples
+ select string.Concat(x.Item1.ToString(), ": \"", x.Item2, "\""))));
+ stringBuilder = null;
+ stringBuilder1 = null;
+ }
+
+ public async Task<bool> ExecuteRunExtendedDialog(System.Windows.Controls.UserControl dialogControl, string hostName)
+ {
+ object obj = await DialogHost.Show(dialogControl, hostName, new DialogOpenedEventHandler(this, BaseViewModel.ExtendedOpenedEventHandler), new DialogClosingEventHandler(this, BaseViewModel.ExtendedClosingEventHandler));
+ DialogHost.CloseDialogCommand.Execute(null, null);
+ return (obj == null ? false : (bool)obj);
+ }
+
+ public async Task ExecuteRunExtendedDialogAdvertising(System.Windows.Controls.UserControl dialogControl, string hostName)
+ {
+ IEnumerable<Window> windows = System.Windows.Application.Current.Windows.OfType<Window>();
+ List<WebEditor> list = Extentions.FindVisualChildren<WebEditor>(windows.SingleOrDefault<Window>((Window x) => x.IsActive)).ToList<WebEditor>();
+ list.ForEach((WebEditor x) => x.Visibility = Visibility.Collapsed);
+ await DialogHost.Show(dialogControl, hostName, new DialogOpenedEventHandler(this, BaseViewModel.ExtendedOpenedEventHandler), new DialogClosingEventHandler(this, BaseViewModel.ExtendedClosingEventHandlerArquivo));
+ }
+
+ public async Task<List<Gestor.Model.Domain.Common.ArquivoDigital>> ExecuteRunExtendedDialogAnexar(System.Windows.Controls.UserControl dialogControl, string hostName)
+ {
+ IEnumerable<Window> windows = System.Windows.Application.Current.Windows.OfType<Window>();
+ List<WebEditor> list = Extentions.FindVisualChildren<WebEditor>(windows.SingleOrDefault<Window>((Window x) => x.IsActive)).ToList<WebEditor>();
+ list.ForEach((WebEditor x) => x.Visibility = Visibility.Collapsed);
+ List<Gestor.Model.Domain.Common.ArquivoDigital> arquivoDigitals = (List<Gestor.Model.Domain.Common.ArquivoDigital>)await DialogHost.Show(dialogControl, hostName, new DialogOpenedEventHandler(this, BaseViewModel.ExtendedOpenedEventHandler), new DialogClosingEventHandler(this, BaseViewModel.ExtendedClosingEventHandlerArquivo));
+ return arquivoDigitals;
+ }
+
+ public async Task<Copia> ExecuteRunExtendedDialogCopia(System.Windows.Controls.UserControl dialogControl, string hostName)
+ {
+ Copia copium;
+ IEnumerable<Window> windows = System.Windows.Application.Current.Windows.OfType<Window>();
+ List<WebEditor> list = Extentions.FindVisualChildren<WebEditor>(windows.SingleOrDefault<Window>((Window x) => x.IsActive)).ToList<WebEditor>();
+ list.ForEach((WebEditor x) => x.Visibility = Visibility.Collapsed);
+ object obj = await DialogHost.Show(dialogControl, hostName, new DialogOpenedEventHandler(this, BaseViewModel.ExtendedOpenedEventHandler), new DialogClosingEventHandler(this, BaseViewModel.ExtendedClosingEventHandler));
+ if (!(obj is bool))
+ {
+ copium = (Copia)obj;
+ }
+ else
+ {
+ copium = null;
+ }
+ return copium;
+ }
+
+ public async Task<Cliente> ExecuteRunExtendedDialogCopiarCliente(System.Windows.Controls.UserControl dialogControl, string hostName)
+ {
+ Cliente cliente;
+ IEnumerable<Window> windows = System.Windows.Application.Current.Windows.OfType<Window>();
+ List<WebEditor> list = Extentions.FindVisualChildren<WebEditor>(windows.SingleOrDefault<Window>((Window x) => x.IsActive)).ToList<WebEditor>();
+ list.ForEach((WebEditor x) => x.Visibility = Visibility.Collapsed);
+ object obj = await DialogHost.Show(dialogControl, hostName, new DialogOpenedEventHandler(this, BaseViewModel.ExtendedOpenedEventHandler), new DialogClosingEventHandler(this, BaseViewModel.ExtendedClosingEventHandler));
+ if (!(obj is bool))
+ {
+ cliente = (Cliente)obj;
+ }
+ else
+ {
+ cliente = null;
+ }
+ return cliente;
+ }
+
+ public async Task<List<NotaFiscal>> ExecuteRunExtendedDialogExtratoComissao(System.Windows.Controls.UserControl dialogControl, string hostName)
+ {
+ List<NotaFiscal> notaFiscals;
+ IEnumerable<Window> windows = System.Windows.Application.Current.Windows.OfType<Window>();
+ List<WebEditor> list = Extentions.FindVisualChildren<WebEditor>(windows.SingleOrDefault<Window>((Window x) => x.IsActive)).ToList<WebEditor>();
+ list.ForEach((WebEditor x) => x.Visibility = Visibility.Collapsed);
+ object obj = await DialogHost.Show(dialogControl, hostName, new DialogOpenedEventHandler(this, BaseViewModel.ExtendedOpenedEventHandler), new DialogClosingEventHandler(this, BaseViewModel.ExtendedClosingEventHandler));
+ if (!(obj is bool))
+ {
+ notaFiscals = (List<NotaFiscal>)obj;
+ }
+ else
+ {
+ notaFiscals = null;
+ }
+ return notaFiscals;
+ }
+
+ public async Task<Instalacao> ExecuteRunExtendedDialogInstalacoes(System.Windows.Controls.UserControl dialogControl, string hostName)
+ {
+ Instalacao instalacao;
+ IEnumerable<Window> windows = System.Windows.Application.Current.Windows.OfType<Window>();
+ List<WebEditor> list = Extentions.FindVisualChildren<WebEditor>(windows.SingleOrDefault<Window>((Window x) => x.IsActive)).ToList<WebEditor>();
+ list.ForEach((WebEditor x) => x.Visibility = Visibility.Collapsed);
+ object obj = await DialogHost.Show(dialogControl, hostName, new DialogOpenedEventHandler(this, BaseViewModel.ExtendedOpenedEventHandler), new DialogClosingEventHandler(this, BaseViewModel.ExtendedClosingEventHandler));
+ object obj1 = obj;
+ if (obj1 == null || obj1 is bool && !(bool)obj1)
+ {
+ instalacao = null;
+ }
+ else
+ {
+ instalacao = (Instalacao)obj;
+ }
+ return instalacao;
+ }
+
+ public async Task<ConfiguracaoImpressao> ExecuteRunExtendedDialogPrint(System.Windows.Controls.UserControl dialogControl, string hostName)
+ {
+ IEnumerable<Window> windows = System.Windows.Application.Current.Windows.OfType<Window>();
+ List<WebEditor> list = Extentions.FindVisualChildren<WebEditor>(windows.SingleOrDefault<Window>((Window x) => x.IsActive)).ToList<WebEditor>();
+ list.ForEach((WebEditor x) => x.Visibility = Visibility.Collapsed);
+ ConfiguracaoImpressao configuracaoImpressao = (ConfiguracaoImpressao)await DialogHost.Show(dialogControl, hostName, new DialogOpenedEventHandler(this, BaseViewModel.ExtendedOpenedEventHandler), new DialogClosingEventHandler(this, BaseViewModel.ExtendedClosingEventHandler));
+ return configuracaoImpressao;
+ }
+
+ public async Task<Prospeccao> ExecuteRunExtendedDialogProspeccao(System.Windows.Controls.UserControl dialogControl, string hostName)
+ {
+ Prospeccao prospeccao;
+ IEnumerable<Window> windows = System.Windows.Application.Current.Windows.OfType<Window>();
+ List<WebEditor> list = Extentions.FindVisualChildren<WebEditor>(windows.SingleOrDefault<Window>((Window x) => x.IsActive)).ToList<WebEditor>();
+ list.ForEach((WebEditor x) => x.Visibility = Visibility.Collapsed);
+ object obj = await DialogHost.Show(dialogControl, hostName, new DialogOpenedEventHandler(this, BaseViewModel.ExtendedOpenedEventHandler), new DialogClosingEventHandler(this, BaseViewModel.ExtendedClosingEventHandler));
+ if (!(obj is bool))
+ {
+ prospeccao = (Prospeccao)obj;
+ }
+ else
+ {
+ prospeccao = null;
+ }
+ return prospeccao;
+ }
+
+ public async Task<bool?> ExecuteRunExtendedDialogSenha(System.Windows.Controls.UserControl dialogControl, string hostName)
+ {
+ IEnumerable<Window> windows = System.Windows.Application.Current.Windows.OfType<Window>();
+ List<WebEditor> list = Extentions.FindVisualChildren<WebEditor>(windows.SingleOrDefault<Window>((Window x) => x.IsActive)).ToList<WebEditor>();
+ list.ForEach((WebEditor x) => x.Visibility = Visibility.Collapsed);
+ bool? nullable = (bool?)await DialogHost.Show(dialogControl, hostName, new DialogOpenedEventHandler(this, BaseViewModel.ExtendedOpenedEventHandler), new DialogClosingEventHandler(this, BaseViewModel.ExtendedClosingEventHandler));
+ return nullable;
+ }
+
+ public void ExtendedClosingEventHandler(object sender, DialogClosingEventArgs eventArgs)
+ {
+ this.IsEnabled = true;
+ Window window = System.Windows.Application.Current.Windows.OfType<Window>().SingleOrDefault<Window>((Window x) => x.IsActive);
+ Extentions.FindVisualChildren<WebEditor>(window).ToList<WebEditor>().ForEach((WebEditor x) => {
+ if (!x.IsReadOnly)
+ {
+ x.Visibility = Visibility.Visible;
+ }
+ });
+ Extentions.FindVisualChildren<DrawerHost>(window).Any<DrawerHost>((DrawerHost x) => {
+ if (x.get_IsLeftDrawerOpen() || x.get_IsBottomDrawerOpen() || x.get_IsRightDrawerOpen())
+ {
+ return true;
+ }
+ return x.get_IsTopDrawerOpen();
+ });
+ }
+
+ public void ExtendedClosingEventHandlerArquivo(object sender, DialogClosingEventArgs eventArgs)
+ {
+ this.IsEnabled = true;
+ Extentions.FindVisualChildren<DrawerHost>(System.Windows.Application.Current.Windows.OfType<Window>().SingleOrDefault<Window>((Window x) => x.IsActive)).Any<DrawerHost>((DrawerHost x) => {
+ if (x.get_IsLeftDrawerOpen() || x.get_IsBottomDrawerOpen() || x.get_IsRightDrawerOpen())
+ {
+ return true;
+ }
+ return x.get_IsTopDrawerOpen();
+ });
+ }
+
+ public void ExtendedOpenedEventHandler(object sender, DialogOpenedEventArgs eventargs)
+ {
+ this.IsEnabled = false;
+ }
+
+ internal DialogHost GetHost()
+ {
+ DialogHost dialogHost = Extentions.FindVisualChildren<DialogHost>(System.Windows.Application.Current.Windows.OfType<Window>().SingleOrDefault<Window>((Window x) => x.IsActive)).FirstOrDefault<DialogHost>();
+ if (dialogHost == null)
+ {
+ foreach (Window window in System.Windows.Application.Current.Windows.OfType<Window>())
+ {
+ dialogHost = Extentions.FindVisualChildren<DialogHost>(window).FirstOrDefault<DialogHost>();
+ if (dialogHost == null || dialogHost.get_IsOpen())
+ {
+ continue;
+ }
+ if (dialogHost != null && dialogHost.get_IsOpen())
+ {
+ return null;
+ }
+ return dialogHost;
+ }
+ }
+ if (dialogHost != null && dialogHost.get_IsOpen())
+ {
+ return null;
+ }
+ return dialogHost;
+ }
+
+ public double GetWindowHeight()
+ {
+ return System.Windows.Application.Current.Windows.OfType<Window>().SingleOrDefault<Window>((Window x) => x.IsActive).ActualHeight;
+ }
+
+ private void HabilitarMenu(bool enable)
+ {
+ this.EnableMainMenu = enable;
+ }
+
+ private void HabilitarMenuSecundario(bool enable)
+ {
+ this.EnableMenu = enable;
+ }
+
+ public async Task ImprimirFornecedor(List<Fornecedor> fornecedores)
+ {
+ string str;
+ string str1;
+ string str2;
+ string str3;
+ string str4;
+ string str5;
+ ParcelaServico parcelaServico = new ParcelaServico();
+ string str6 = "<html><head><title>RELATÓRIO DE FORNECEDORES</title></head><body style='font-size: 12px; font-family: Arial, Helvetica, sans-serif; margin-left: 50px; margin-right: 50px; line-height: 30px;' onload='self.print();'>";
+ str6 = string.Concat(str6, "<div align='center' style='font-size: 20px;'><strong>RELATÓRIO DE FORNECEDORES</strong></div> <br>");
+ str6 = string.Concat(str6, "<div class='table-responsive'>");
+ str6 = string.Concat(str6, "<table align='center' class='table table-bordered' border='1px' style='border-collapse:collapse;' style='width:100%;' style='margin:auto;'>");
+ int num = 1;
+ str6 = string.Concat(str6, "<tr bgcolor=LightBlue>");
+ str6 = string.Concat(str6, "<td><strong>NOME</strong></td>");
+ str6 = string.Concat(str6, "<td><strong>CPF/CNPJ</strong></td>");
+ str6 = string.Concat(str6, "<td><strong>ENDEREÇO</strong></td>");
+ str6 = string.Concat(str6, "<td><strong>E-MAIL</strong></td>");
+ str6 = string.Concat(str6, "<td><strong>TIPO PESSOA</strong></td>");
+ str6 = string.Concat(str6, "</tr>");
+ foreach (Fornecedor fornecedore in fornecedores)
+ {
+ string[] nome = new string[] { str6, "<tr> <td style='padding:10px' bgcolor='", null, null, null, null };
+ str = (num % 2 == 0 ? "WhiteSmoke" : "White");
+ nome[2] = str;
+ nome[3] = "'>";
+ nome[4] = fornecedore.get_Nome();
+ nome[5] = "</td>";
+ str6 = string.Concat(nome);
+ string[] documento = new string[] { str6, "<td style='padding:10px' bgcolor='", null, null, null, null };
+ str1 = (num % 2 == 0 ? "WhiteSmoke" : "White");
+ documento[2] = str1;
+ documento[3] = "'>";
+ documento[4] = fornecedore.get_Documento();
+ documento[5] = "</td>";
+ str6 = string.Concat(documento);
+ string[] endereco = new string[] { str6, "<td style='padding:10px' bgcolor='", null, null, null, null };
+ str2 = (num % 2 == 0 ? "WhiteSmoke" : "White");
+ endereco[2] = str2;
+ endereco[3] = "'>";
+ endereco[4] = fornecedore.get_Endereco();
+ endereco[5] = "</td>";
+ str6 = string.Concat(endereco);
+ string[] email = new string[] { str6, "<td style='padding:10px' bgcolor='", null, null, null, null };
+ str3 = (num % 2 == 0 ? "WhiteSmoke" : "White");
+ email[2] = str3;
+ email[3] = "'>";
+ email[4] = fornecedore.get_Email();
+ email[5] = "</td>";
+ str6 = string.Concat(email);
+ if (fornecedore.get_Documento() == null)
+ {
+ str4 = "";
+ }
+ else
+ {
+ str4 = (Gestor.Common.Validation.ValidationHelper.OnlyNumber(fornecedore.get_Documento()).Length > 11 ? "JURÍDICA" : "FÍSICA");
+ }
+ string str7 = str4;
+ string[] strArrays = new string[] { str6, "<td style='padding:10px' bgcolor='", null, null, null, null };
+ str5 = (num % 2 == 0 ? "WhiteSmoke" : "White");
+ strArrays[2] = str5;
+ strArrays[3] = "'>";
+ strArrays[4] = str7;
+ strArrays[5] = "</td></tr>";
+ str6 = string.Concat(strArrays);
+ if (num != 1)
+ {
+ num++;
+ }
+ else
+ {
+ num = 0;
+ }
+ }
+ DateTime networkTime = Funcoes.GetNetworkTime();
+ string nome1 = Recursos.Usuario.get_Nome();
+ str6 = string.Concat(str6, "</table></div>");
+ str6 = string.Concat(str6, string.Format("Emitido pelo usuário: {0}, data e hora: {1}.", nome1, networkTime));
+ str6 = string.Concat(str6, "</body>");
+ string tempPath = Path.GetTempPath();
+ string str8 = string.Format("{0}FORNECEDORES_{1:ddMMyyyyhhmmss}.html", tempPath, networkTime);
+ StreamWriter streamWriter = new StreamWriter(str8, true, Encoding.UTF8);
+ streamWriter.Write(str6);
+ streamWriter.Close();
+ Process.Start(str8);
+ }
+
+ private Gestor.Application.Model.Configuracoes LoadConfiguracoes()
+ {
+ this.CriarConfiguracaoPadrao("config.json");
+ return JsonConvert.DeserializeObject<Gestor.Application.Model.Configuracoes>(File.ReadAllText("config.json"));
+ }
+
+ private async Task<DialogAdvertising> LoadDialogAdertisingPromo()
+ {
+ DialogAdvertising dialogAdvertising;
+ object empty;
+ Gestor.Application.Model.Configuracoes configuraco = this.LoadConfiguracoes();
+ JObject jObject = await this.LoadJsonAdvertising(Address.JsonPromo());
+ if (jObject != null)
+ {
+ JToken item = jObject.get_Item("Imagem");
+ if (item != null)
+ {
+ empty = Extensions.Value<string>(item);
+ }
+ else
+ {
+ empty = null;
+ }
+ if (empty == null)
+ {
+ empty = string.Empty;
+ }
+ string str = (string)empty;
+ if (configuraco.LinkPromo == str || configuraco.NaoverPromo)
+ {
+ dialogAdvertising = null;
+ }
+ else
+ {
+ dialogAdvertising = new DialogAdvertising(jObject, true);
+ }
+ }
+ else
+ {
+ dialogAdvertising = null;
+ }
+ configuraco = null;
+ return dialogAdvertising;
+ }
+
+ public void Loading(bool isLoading)
+ {
+ Grid progressRing = App.ProgressRing;
+ if (progressRing == null)
+ {
+ return;
+ }
+ Dispatcher dispatcher = progressRing.Dispatcher;
+ if (dispatcher == null)
+ {
+ return;
+ }
+ dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() => this.LoadingThread(isLoading)));
+ }
+
+ public void LoadingThread(bool isLoading)
+ {
+ this.IsVisible = (isLoading ? Visibility.Collapsed : Visibility.Visible);
+ App.ProgressRing.Visibility = (isLoading ? Visibility.Visible : Visibility.Collapsed);
+ this.IsEnabled = !isLoading;
+ }
+
+ private async Task<JObject> LoadJsonAdvertising(Uri location)
+ {
+ JObject jObject;
+ JObject jObject1;
+ using (HttpClient httpClient = new HttpClient())
+ {
+ ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
+ httpClient.set_Timeout(TimeSpan.FromSeconds(20));
+ HttpResponseMessage async = await httpClient.GetAsync(location);
+ if (!async.get_IsSuccessStatusCode())
+ {
+ jObject1 = null;
+ }
+ else
+ {
+ jObject1 = JObject.Parse(await async.get_Content().ReadAsStringAsync());
+ }
+ jObject = jObject1;
+ }
+ return jObject;
+ }
+
+ public void OnPropertyChanged([CallerMemberName] string name = "")
+ {
+ PropertyChangedEventHandler propertyChangedEventHandler = this.PropertyChanged;
+ if (propertyChangedEventHandler == null)
+ {
+ return;
+ }
+ propertyChangedEventHandler(this, new PropertyChangedEventArgs(name));
+ }
+
+ public bool Permissao(TipoTela tipoTela)
+ {
+ if (Recursos.Usuario.get_Id() == 0)
+ {
+ return false;
+ }
+ PermissaoUsuario permissaoUsuario = this.ServicoPermissUsuario.BuscarPermissao(Recursos.Usuario, tipoTela);
+ if (permissaoUsuario == null)
+ {
+ return true;
+ }
+ return permissaoUsuario.get_Consultar();
+ }
+
+ public async Task PermissaoArquivoDigital(TipoArquivoDigital tela)
+ {
+ bool flag;
+ bool flag1;
+ this.EnableIncluir = false;
+ this.EnableExcluir = false;
+ if (Recursos.Usuario.get_Id() != 0)
+ {
+ PermissaoArquivoDigital permissaoArquivoDigital = await this.ServicoPermissArquivoDigital.VerificarPermissao(Recursos.Usuario, tela);
+ BaseViewModel baseViewModel = this;
+ flag = (permissaoArquivoDigital != null ? permissaoArquivoDigital.get_Incluir() : true);
+ baseViewModel._incluirPermissEnabled = flag;
+ BaseViewModel baseViewModel1 = this;
+ flag1 = (permissaoArquivoDigital != null ? permissaoArquivoDigital.get_Excluir() : true);
+ baseViewModel1._excluirPermissEnabled = flag1;
+ }
+ }
+
+ public async Task<bool> PermissaoConsultar(TipoTela tela)
+ {
+ bool flag;
+ bool consultar;
+ if (Recursos.Usuario.get_Id() != 0)
+ {
+ PermissaoUsuario permissaoUsuario = await this.ServicoPermissUsuario.VerificarPermissao(Recursos.Usuario, tela);
+ if (permissaoUsuario != null)
+ {
+ consultar = permissaoUsuario.get_Consultar();
+ }
+ else
+ {
+ consultar = true;
+ }
+ flag = consultar;
+ }
+ else
+ {
+ flag = true;
+ }
+ return flag;
+ }
+
+ public async Task PermissaoTela(TipoTela tela)
+ {
+ bool flag;
+ bool flag1;
+ bool flag2;
+ bool flag3;
+ bool flag4;
+ bool flag5;
+ this.EnableIncluir = false;
+ this.EnableAlterar = false;
+ this.EnableExcluir = false;
+ if (Recursos.Usuario.get_Id() != 0)
+ {
+ PermissaoUsuario permissaoUsuario = await this.ServicoPermissUsuario.VerificarPermissao(Recursos.Usuario, tela);
+ if (tela == 5)
+ {
+ BaseViewModel baseViewModel = this;
+ flag3 = (permissaoUsuario != null ? permissaoUsuario.get_Incluir() : true);
+ baseViewModel.IncluirParcelaEnabled = flag3;
+ BaseViewModel baseViewModel1 = this;
+ flag4 = (permissaoUsuario != null ? permissaoUsuario.get_Alterar() : true);
+ baseViewModel1.AlterarParcelaEnabled = flag4;
+ BaseViewModel baseViewModel2 = this;
+ flag5 = (permissaoUsuario != null ? permissaoUsuario.get_Excluir() : true);
+ baseViewModel2.ExcluirParcelaEnabled = flag5;
+ }
+ else if (tela == 24 || tela == 26 || tela == 29 || tela == 28 || tela == 27)
+ {
+ this._incluirPermissEnabled = true;
+ this._alterarPermissEnabled = true;
+ this._excluirPermissEnabled = true;
+ }
+ else
+ {
+ BaseViewModel baseViewModel3 = this;
+ flag = (permissaoUsuario != null ? permissaoUsuario.get_Incluir() : true);
+ baseViewModel3._incluirPermissEnabled = flag;
+ BaseViewModel baseViewModel4 = this;
+ flag1 = (permissaoUsuario != null ? permissaoUsuario.get_Alterar() : true);
+ baseViewModel4._alterarPermissEnabled = flag1;
+ BaseViewModel baseViewModel5 = this;
+ flag2 = (permissaoUsuario != null ? permissaoUsuario.get_Excluir() : true);
+ baseViewModel5._excluirPermissEnabled = flag2;
+ }
+ }
+ }
+
+ public void RegistrarAcao(string descricao, long entidadeId, TipoTela? tela = null, object obs = null)
+ {
+ RegistroAcao registroAcao = new RegistroAcao();
+ registroAcao.set_Descricao(descricao);
+ registroAcao.set_EntidadeId(entidadeId);
+ registroAcao.set_Tela(tela);
+ (new ApoliceServico()).SalvarAcao(registroAcao, obs);
+ }
+
+ public void RegistrarAcao(string descricao, Relatorio? relatorio, object obs = null)
+ {
+ RegistroAcao registroAcao = new RegistroAcao();
+ registroAcao.set_Relatorio(relatorio);
+ registroAcao.set_Descricao(descricao);
+ (new ApoliceServico()).SalvarAcao(registroAcao, obs);
+ }
+
+ public bool Restricao(TipoRestricao tipoRestricao)
+ {
+ if (Recursos.Usuario.get_Id() == 0)
+ {
+ return false;
+ }
+ RestricaoUsuario restricaoUsuario = this.ServicoRestriUsuario.BuscarRestricao(Recursos.Usuario, tipoRestricao);
+ if (restricaoUsuario == null)
+ {
+ return false;
+ }
+ return restricaoUsuario.get_Restricao();
+ }
+
+ public async Task<string> Salvar(IndiceArquivoDigital indice)
+ {
+ string str;
+ bool arquivo;
+ Guid guid;
+ if (indice.get_Id() != 0)
+ {
+ Gestor.Model.Domain.Common.ArquivoDigital arquivoDigital = await this.ArquivoDigitalServico.BuscarPorId(indice.get_IdArquivoDigital(), indice.get_Bd());
+ if (arquivoDigital != null)
+ {
+ arquivo = arquivoDigital.get_Arquivo();
+ }
+ else
+ {
+ arquivo = false;
+ }
+ if (!arquivo || arquivoDigital.get_Extensao() == null)
+ {
+ str = null;
+ }
+ else
+ {
+ string tempPath = Path.GetTempPath();
+ Guid? azureGuid = arquivoDigital.get_AzureGuid();
+ guid = (azureGuid.HasValue ? azureGuid.GetValueOrDefault() : Guid.NewGuid());
+ string str1 = string.Format("{0}{1}{2}", tempPath, guid, Gestor.Common.Validation.ValidationHelper.GetDefaultExtension(arquivoDigital.get_Extensao()));
+ using (BinaryWriter binaryWriter = new BinaryWriter(File.Open(str1, FileMode.Create)))
+ {
+ binaryWriter.Write(arquivoDigital.get_Arquivo());
+ }
+ str = str1;
+ }
+ }
+ else
+ {
+ str = null;
+ }
+ return str;
+ }
+
+ public async Task<bool> SalvarAttachments(List<Gestor.Model.Domain.Common.ArquivoDigital> arquivos, TipoArquivoDigital tipoAd, long id)
+ {
+ bool flag;
+ if (arquivos == null || arquivos.Count == 0)
+ {
+ flag = false;
+ }
+ else
+ {
+ arquivos.ForEach((Gestor.Model.Domain.Common.ArquivoDigital x) => {
+ x.set_IdCliente((tipoAd == 1 ? id : (long)0));
+ x.set_IdDocumento((tipoAd == 2 ? id : (long)0));
+ x.set_IdParcela((tipoAd == 3 ? id : (long)0));
+ x.set_IdItem((tipoAd == 4 ? id : (long)0));
+ x.set_IdSinistro((tipoAd == 5 ? id : (long)0));
+ x.set_IdVendedor((tipoAd == 6 ? id : (long)0));
+ x.set_IdUsuario((tipoAd == 12 ? id : (long)0));
+ x.set_IdSeguradora((tipoAd == 8 ? id : (long)0));
+ x.set_IdExtrato((tipoAd == 7 ? id : (long)0));
+ x.set_IdLancamento((tipoAd == 9 ? id : (long)0));
+ x.set_IdFornecedor((tipoAd == 10 ? id : (long)0));
+ x.set_IdProspeccao((tipoAd == 11 ? id : (long)0));
+ x.set_IdSocio((tipoAd == 14 ? id : (long)0));
+ x.set_IdTarefa((tipoAd == 15 ? id : (long)0));
+ x.set_IdNotaFiscal((tipoAd == 16 ? id : (long)0));
+ x.set_IdEstipulante((tipoAd == 17 ? id : (long)0));
+ x.set_IdEmpresa(Recursos.Usuario.get_IdEmpresa());
+ });
+ switch (tipoAd)
+ {
+ default:
+ {
+ break;
+ }
+ }
+ await this.ArquivoDigitalServico.Insert(arquivos);
+ flag = (this.ArquivoDigitalServico.Sucesso ? true : false);
+ }
+ return flag;
+ }
+
+ public async Task<List<KeyValuePair<string, string>>> SalvarProspeccao(Prospeccao prospecao)
+ {
+ List<KeyValuePair<string, string>> keyValuePairs;
+ bool count;
+ string str;
+ List<Gestor.Model.Domain.Common.ArquivoDigital> anexos;
+ Prospeccao prospeccao;
+ List<KeyValuePair<string, string>> keyValuePairs1 = prospecao.Validate();
+ if (keyValuePairs1.Count <= 0)
+ {
+ anexos = prospecao.get_Anexos();
+ if (prospecao.get_Tarefa().get_Id() == 0)
+ {
+ prospecao.get_Tarefa().set_Cliente(prospecao.get_Nome());
+ Tarefa tarefa = prospecao.get_Tarefa();
+ DateTime? vigenciaFinal = prospecao.get_VigenciaFinal();
+ if (vigenciaFinal.HasValue)
+ {
+ str = vigenciaFinal.GetValueOrDefault().ToString("d");
+ }
+ else
+ {
+ str = null;
+ }
+ tarefa.set_Titulo(string.Concat("PROSPECÇÃO ", str));
+ prospecao.get_Tarefa().set_Referencia(prospecao.get_Item());
+ Tarefa tarefa1 = prospecao.get_Tarefa();
+ object[] nome = new object[] { Recursos.Usuario.get_Nome(), Funcoes.GetNetworkTime(), Environment.NewLine, prospecao.get_Observacao() };
+ tarefa1.set_Descricao(string.Format("{0} {1:g} {2}{3}", nome));
+ }
+ prospeccao = await (new ProspeccaoServico()).Salvar(prospecao);
+ List<Gestor.Model.Domain.Common.ArquivoDigital> arquivoDigitals = anexos;
+ if (arquivoDigitals != null)
+ {
+ count = arquivoDigitals.Count > 0;
+ }
+ else
+ {
+ count = false;
+ }
+ if (count)
+ {
+ await this.SalvarAttachments(anexos, 11, prospeccao.get_Id());
+ }
+ if (prospeccao.get_Tarefa() != null && prospecao.get_AbrirTarefa() && prospeccao != null && prospeccao.get_Id() > (long)0)
+ {
+ Tarefa tarefa2 = prospeccao.get_Tarefa();
+ this.ShowDrawer(new TarefaDrawer(tarefa2, true), 0, false);
+ }
+ keyValuePairs = null;
+ }
+ else
+ {
+ keyValuePairs = keyValuePairs1;
+ }
+ anexos = null;
+ prospeccao = null;
+ return keyValuePairs;
+ }
+
+ internal async Task<Copia> ShowCopiaDialog(Copia copia)
+ {
+ Copia copium;
+ string str;
+ DialogHost host = this.GetHost();
+ if (host == null || !host.get_IsOpen())
+ {
+ DialogCopia dialogCopium = new DialogCopia(copia);
+ BaseViewModel baseViewModel = this;
+ DialogCopia dialogCopium1 = dialogCopium;
+ str = (host != null ? host.get_Identifier().ToString() : "RootDialog");
+ copium = await baseViewModel.ExecuteRunExtendedDialogCopia(dialogCopium1, str);
+ }
+ else
+ {
+ copium = null;
+ }
+ return copium;
+ }
+
+ internal async Task<Cliente> ShowCopiarCliente()
+ {
+ Cliente cliente;
+ string str;
+ DialogHost host = this.GetHost();
+ if (host == null || !host.get_IsOpen())
+ {
+ DialogCopiarCliente dialogCopiarCliente = new DialogCopiarCliente();
+ BaseViewModel baseViewModel = this;
+ DialogCopiarCliente dialogCopiarCliente1 = dialogCopiarCliente;
+ str = (host != null ? host.get_Identifier().ToString() : "RootDialog");
+ cliente = await baseViewModel.ExecuteRunExtendedDialogCopiarCliente(dialogCopiarCliente1, str);
+ }
+ else
+ {
+ cliente = null;
+ }
+ return cliente;
+ }
+
+ internal async Task ShowDialogAdvertising(bool root = false)
+ {
+ string str;
+ try
+ {
+ DialogHost host = null;
+ if (!root)
+ {
+ host = this.GetHost();
+ if (host != null && host.get_IsOpen())
+ {
+ return;
+ }
+ }
+ DialogAdvertising dialogAdvertising = await this.CreateDialogAdvertising();
+ if (dialogAdvertising != null)
+ {
+ BaseViewModel baseViewModel = this;
+ DialogAdvertising dialogAdvertising1 = dialogAdvertising;
+ str = (host != null ? host.get_Identifier().ToString() : "RootDialog");
+ await baseViewModel.ExecuteRunExtendedDialogAdvertising(dialogAdvertising1, str);
+ host = null;
+ }
+ else
+ {
+ return;
+ }
+ }
+ catch
+ {
+ }
+ }
+
+ internal async Task<List<Gestor.Model.Domain.Common.ArquivoDigital>> ShowDialogAnexar(List<Gestor.Model.Domain.Common.ArquivoDigital> arquivos, bool root = false)
+ {
+ List<Gestor.Model.Domain.Common.ArquivoDigital> arquivoDigitals;
+ string str;
+ DialogHost host = null;
+ if (!root)
+ {
+ host = this.GetHost();
+ if (host != null && host.get_IsOpen())
+ {
+ arquivoDigitals = arquivos;
+ return arquivoDigitals;
+ }
+ }
+ DialogAnexar dialogAnexar = new DialogAnexar(arquivos);
+ BaseViewModel baseViewModel = this;
+ DialogAnexar dialogAnexar1 = dialogAnexar;
+ str = (host != null ? host.get_Identifier().ToString() : "RootDialog");
+ arquivoDigitals = await baseViewModel.ExecuteRunExtendedDialogAnexar(dialogAnexar1, str);
+ return arquivoDigitals;
+ }
+
+ internal async Task<ConfiguracaoImpressao> ShowDialogPrint(Relatorio relatorio, Type tipo)
+ {
+ ConfiguracaoImpressao configuracaoImpressao;
+ string str;
+ DialogHost host = this.GetHost();
+ if (host == null || !host.get_IsOpen())
+ {
+ DialogPrint dialogPrint = new DialogPrint(relatorio, tipo);
+ BaseViewModel baseViewModel = this;
+ DialogPrint dialogPrint1 = dialogPrint;
+ str = (host != null ? host.get_Identifier().ToString() : "RootDialog");
+ configuracaoImpressao = await baseViewModel.ExecuteRunExtendedDialogPrint(dialogPrint1, str);
+ }
+ else
+ {
+ configuracaoImpressao = null;
+ }
+ return configuracaoImpressao;
+ }
+
+ internal void ShowDrawer(object content, int position, bool close = true)
+ {
+ Window window = System.Windows.Application.Current.Windows.OfType<Window>().SingleOrDefault<Window>((Window x) => x.IsActive);
+ DrawerHost drawerHost = Extentions.FindVisualChildren<DrawerHost>(window).FirstOrDefault<DrawerHost>();
+ Extentions.FindVisualChildren<WebEditor>(window).ToList<WebEditor>().ForEach((WebEditor x) => x.Visibility = Visibility.Collapsed);
+ if (drawerHost == null)
+ {
+ return;
+ }
+ switch (position)
+ {
+ case 1:
+ {
+ drawerHost.set_TopDrawerContent(content);
+ drawerHost.set_IsTopDrawerOpen(true);
+ drawerHost.set_TopDrawerCloseOnClickAway(close);
+ return;
+ }
+ case 2:
+ {
+ drawerHost.set_LeftDrawerContent(content);
+ drawerHost.set_IsLeftDrawerOpen(true);
+ drawerHost.set_LeftDrawerCloseOnClickAway(close);
+ return;
+ }
+ case 3:
+ {
+ drawerHost.set_BottomDrawerContent(content);
+ drawerHost.set_IsBottomDrawerOpen(true);
+ drawerHost.set_BottomDrawerCloseOnClickAway(close);
+ return;
+ }
+ default:
+ {
+ if (!drawerHost.get_IsRightDrawerOpen() || drawerHost.get_RightDrawerContent() != null && !(drawerHost.get_RightDrawerContent().GetType() != content.GetType()))
+ {
+ break;
+ }
+ else
+ {
+ drawerHost.set_LeftDrawerContent(content);
+ drawerHost.set_IsLeftDrawerOpen(true);
+ drawerHost.set_LeftDrawerCloseOnClickAway(close);
+ return;
+ }
+ }
+ }
+ drawerHost.set_IsRightDrawerOpen(true);
+ drawerHost.set_RightDrawerContent(content);
+ drawerHost.set_RightDrawerCloseOnClickAway(close);
+ }
+
+ internal async Task<List<NotaFiscal>> ShowExtratoComissaoDialog(List<Seguradora> seguradoras)
+ {
+ List<NotaFiscal> notaFiscals;
+ string str;
+ DialogHost host = this.GetHost();
+ if (host == null || !host.get_IsOpen())
+ {
+ DialogExtratoComissao dialogExtratoComissao = new DialogExtratoComissao(seguradoras);
+ BaseViewModel baseViewModel = this;
+ DialogExtratoComissao dialogExtratoComissao1 = dialogExtratoComissao;
+ str = (host != null ? host.get_Identifier().ToString() : "RootDialog");
+ notaFiscals = await baseViewModel.ExecuteRunExtendedDialogExtratoComissao(dialogExtratoComissao1, str);
+ }
+ else
+ {
+ notaFiscals = null;
+ }
+ return notaFiscals;
+ }
+
+ internal async Task<Instalacao> ShowInstalacoes(List<Instalacao> instalacoes)
+ {
+ Instalacao instalacao;
+ string str;
+ DialogHost host = this.GetHost();
+ if (host == null || !host.get_IsOpen())
+ {
+ DialogInstalacoes dialogInstalaco = new DialogInstalacoes(instalacoes);
+ BaseViewModel baseViewModel = this;
+ DialogInstalacoes dialogInstalaco1 = dialogInstalaco;
+ str = (host != null ? host.get_Identifier().ToString() : "RootDialog");
+ instalacao = await baseViewModel.ExecuteRunExtendedDialogInstalacoes(dialogInstalaco1, str);
+ }
+ else
+ {
+ instalacao = null;
+ }
+ return instalacao;
+ }
+
+ internal async Task ShowMedalha(int liquido, int comissao, int resultado, int media)
+ {
+ string str;
+ DialogHost host = this.GetHost();
+ if (host == null || !host.get_IsOpen())
+ {
+ DialogMedalha dialogMedalha = new DialogMedalha(liquido, comissao, resultado, media);
+ BaseViewModel baseViewModel = this;
+ DialogMedalha dialogMedalha1 = dialogMedalha;
+ str = (host != null ? host.get_Identifier().ToString() : "RootDialog");
+ await baseViewModel.ExecuteRunExtendedDialog(dialogMedalha1, str);
+ }
+ }
+
+ internal async Task<bool> ShowMessage(string message, string accept = "OK", string cancel = "", bool root = false)
+ {
+ bool flag;
+ string str;
+ DialogHost host = null;
+ if (!root)
+ {
+ host = this.GetHost();
+ if (host == null)
+ {
+ flag = false;
+ return flag;
+ }
+ }
+ DefaultDialog defaultDialog = new DefaultDialog();
+ DialogViewModel dialogViewModel = new DialogViewModel()
+ {
+ AcceptContent = accept,
+ CancelContent = cancel,
+ Message = message
+ };
+ defaultDialog.DataContext = dialogViewModel;
+ DefaultDialog defaultDialog1 = defaultDialog;
+ BaseViewModel baseViewModel = this;
+ DefaultDialog defaultDialog2 = defaultDialog1;
+ str = (host != null ? host.get_Identifier().ToString() : "RootDialog");
+ flag = await baseViewModel.ExecuteRunExtendedDialog(defaultDialog2, str);
+ return flag;
+ }
+
+ internal async Task<bool> ShowMessage(List<KeyValuePair<string, string>> pairs, string message, string accept, string cancel = "")
+ {
+ bool flag;
+ string str;
+ DialogHost host = this.GetHost();
+ if (host == null || !host.get_IsOpen())
+ {
+ ErrorDialog errorDialog = new ErrorDialog();
+ ErrorDialogViewModel errorDialogViewModel = new ErrorDialogViewModel();
+ List<KeyValuePair<string, string>> keyValuePairs = pairs;
+ errorDialogViewModel.Erros = (
+ from pair in keyValuePairs
+ select new KeyValuePair<string, string>((pair.Key.Contains("|") ? pair.Key.Substring(pair.Key.IndexOf("|", StringComparison.Ordinal) + 1) : pair.Key), pair.Value)).ToList<KeyValuePair<string, string>>();
+ errorDialogViewModel.AcceptContent = accept;
+ errorDialogViewModel.CancelContent = cancel;
+ errorDialogViewModel.Message = message;
+ errorDialog.DataContext = errorDialogViewModel;
+ ErrorDialog errorDialog1 = errorDialog;
+ BaseViewModel baseViewModel = this;
+ ErrorDialog errorDialog2 = errorDialog1;
+ str = (host != null ? host.get_Identifier().ToString() : "RootDialog");
+ flag = await baseViewModel.ExecuteRunExtendedDialog(errorDialog2, str);
+ }
+ else
+ {
+ flag = false;
+ }
+ return flag;
+ }
+
+ internal async Task<Prospeccao> ShowProspeccaoDialog(Prospeccao prospecao)
+ {
+ Prospeccao prospeccao;
+ string str;
+ DialogHost host = this.GetHost();
+ if (host == null || !host.get_IsOpen())
+ {
+ ProspeccaoDialog prospeccaoDialog = new ProspeccaoDialog(prospecao);
+ BaseViewModel baseViewModel = this;
+ ProspeccaoDialog prospeccaoDialog1 = prospeccaoDialog;
+ str = (host != null ? host.get_Identifier().ToString() : "RootDialog");
+ prospeccao = await baseViewModel.ExecuteRunExtendedDialogProspeccao(prospeccaoDialog1, str);
+ }
+ else
+ {
+ prospeccao = null;
+ }
+ return prospeccao;
+ }
+
+ internal async Task<bool?> ShowSenha(string mensagem)
+ {
+ bool? nullable;
+ string str;
+ DialogHost host = this.GetHost();
+ if (host == null || !host.get_IsOpen())
+ {
+ DialogSenhaAdm dialogSenhaAdm = new DialogSenhaAdm(mensagem);
+ BaseViewModel baseViewModel = this;
+ DialogSenhaAdm dialogSenhaAdm1 = dialogSenhaAdm;
+ str = (host != null ? host.get_Identifier().ToString() : "RootDialog");
+ nullable = await baseViewModel.ExecuteRunExtendedDialogSenha(dialogSenhaAdm1, str);
+ }
+ else
+ {
+ nullable = new bool?(false);
+ }
+ return nullable;
+ }
+
+ public void ToggleSnackBar(string message, bool active = true)
+ {
+ Snackbar snackbar = Extentions.FindVisualChildren<Snackbar>(System.Windows.Application.Current.Windows.OfType<Window>().SingleOrDefault<Window>((Window x) => x.IsActive)).FirstOrDefault<Snackbar>();
+ if (snackbar == null)
+ {
+ return;
+ }
+ snackbar.get_Message().Content = message;
+ snackbar.set_IsActive(active);
+ if (!active)
+ {
+ return;
+ }
+ Task.Factory.StartNew(new Action(this.CloseSlackBar));
+ }
+
+ public async Task<List<string>> ValidateAttachment(List<Gestor.Model.Domain.Common.ArquivoDigital> attachments, List<string> files)
+ {
+ char chr;
+ bool flag;
+ string lower;
+ object obj;
+ string upper = string.Concat("Os Arquivos Abaixo não podem ser anexados pois não possuem Formatos válidos, são maiores que o permitido ou já foram anexados!", Environment.NewLine, Environment.NewLine).ToUpper();
+ List<string> strs = new List<string>();
+ bool flag1 = false;
+ foreach (string file in files)
+ {
+ int num = 0;
+ try
+ {
+ flag = (attachments == null ? false : attachments.Exists((Gestor.Model.Domain.Common.ArquivoDigital a) => {
+ string str;
+ string str1 = Gestor.Common.Validation.ValidationHelper.RemoveDiacritics(a.get_Descricao().ToUpper());
+ string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(file);
+ if (fileNameWithoutExtension != null)
+ {
+ str = Gestor.Common.Validation.ValidationHelper.RemoveDiacritics(fileNameWithoutExtension.ToUpper());
+ }
+ else
+ {
+ str = null;
+ }
+ return str1 == str;
+ }));
+ if (!flag)
+ {
+ FileInfo fileInfo = new FileInfo(file);
+ if (fileInfo.Length > (long)1024)
+ {
+ long length = fileInfo.Length / (long)1024;
+ obj = (Recursos.Empresa.get_MaxFileSize() > 0 ? Recursos.Empresa.get_MaxFileSize() : 14336);
+ if (length > (long)obj)
+ {
+ upper = string.Concat(upper, Path.GetFileName(file));
+ flag1 = true;
+ continue;
+ }
+ }
+ string extension = Path.GetExtension(file);
+ if (extension != null)
+ {
+ lower = extension.ToLower();
+ }
+ else
+ {
+ lower = null;
+ }
+ string str2 = lower;
+ if (str2 != null)
+ {
+ int length1 = str2.Length;
+ if (length1 == 4)
+ {
+ chr = str2[1];
+ if (chr <= 't')
+ {
+ switch (chr)
+ {
+ case 'a':
+ {
+ if (str2 == ".amr")
+ {
+ break;
+ }
+ goto Label1;
+ }
+ case 'b':
+ {
+ if (str2 == ".bmp")
+ {
+ break;
+ }
+ goto Label1;
+ }
+ case 'c':
+ {
+ goto Label1;
+ }
+ case 'd':
+ {
+ if (str2 == ".doc")
+ {
+ break;
+ }
+ goto Label1;
+ }
+ case 'e':
+ {
+ if (str2 == ".eml")
+ {
+ break;
+ }
+ goto Label1;
+ }
+ default:
+ {
+ switch (chr)
+ {
+ case 'j':
+ {
+ if (str2 == ".jpg")
+ {
+ goto Label2;
+ }
+ goto Label1;
+ }
+ case 'm':
+ {
+ if (str2 == ".msg")
+ {
+ goto Label2;
+ }
+ goto Label1;
+ }
+ case 'o':
+ {
+ if (str2 == ".ogg")
+ {
+ goto Label2;
+ }
+ goto Label1;
+ }
+ case 'p':
+ {
+ if (str2 == ".png" || str2 == ".pdf")
+ {
+ goto Label2;
+ }
+ goto Label1;
+ }
+ case 'r':
+ {
+ if (str2 == ".rar")
+ {
+ goto Label2;
+ }
+ goto Label1;
+ }
+ case 't':
+ {
+ if (str2 == ".txt")
+ {
+ goto Label2;
+ }
+ goto Label1;
+ }
+ default:
+ {
+ goto Label1;
+ }
+ }
+ break;
+ }
+ }
+ }
+ else if (chr == 'x')
+ {
+ if (str2 == ".xls")
+ {
+ goto Label2;
+ }
+ goto Label1;
+ }
+ else if (chr == 'z')
+ {
+ if (str2 == ".zip")
+ {
+ goto Label2;
+ }
+ goto Label1;
+ }
+ else
+ {
+ goto Label1;
+ }
+ }
+ else if (length1 == 5)
+ {
+ chr = str2[2];
+ switch (chr)
+ {
+ case 'l':
+ {
+ if (str2 == ".xlsx")
+ {
+ break;
+ }
+ goto Label1;
+ }
+ case 'm':
+ case 'n':
+ {
+ goto Label1;
+ }
+ case 'o':
+ {
+ if (str2 == ".docx")
+ {
+ break;
+ }
+ goto Label1;
+ }
+ case 'p':
+ {
+ if (str2 == ".jpeg")
+ {
+ break;
+ }
+ goto Label1;
+ }
+ default:
+ {
+ if (chr != 's')
+ {
+ goto Label1;
+ }
+ else if (str2 == ".json")
+ {
+ break;
+ }
+ else
+ {
+ goto Label1;
+ }
+ }
+ }
+ }
+ else
+ {
+ goto Label1;
+ }
+ Label2:
+ strs.Add(file);
+ goto Label0;
+ }
+ Label1:
+ upper = string.Concat(upper, Path.GetFileName(file));
+ Label0:
+ }
+ else
+ {
+ upper = string.Concat(upper, Path.GetFileName(file));
+ flag1 = true;
+ continue;
+ }
+ }
+ catch (Exception exception)
+ {
+ num = 1;
+ }
+ if (num != 1)
+ {
+ continue;
+ }
+ string[] newLine = new string[] { "NÃO FOI POSSÍVEL CARREGAR O ARQUIVO ", file, ".", Environment.NewLine, "O ARQUIVO ESTÁ INACESSÍVEL OU SENDO UTILIZADO POR OUTRO PROCESSO." };
+ await this.ShowMessage(string.Concat(newLine), "OK", "", false);
+ }
+ if (flag1)
+ {
+ await this.ShowMessage(string.Concat(upper, Environment.NewLine, Environment.NewLine, "Favor Corrija antes de tentar novamente.").ToUpper(), "OK", "", false);
+ }
+ return strs;
+ }
+
+ public async Task<string> VerificarAcesso(long id)
+ {
+ string str;
+ string str1;
+ string str2 = null;
+ Usuario usuario = await (new UsuarioServico()).BuscarUsuarioPorId(id);
+ if (usuario != null)
+ {
+ List<string> strs = new List<string>();
+ List<string> strs1 = new List<string>()
+ {
+ "SEGUNDAS-FEIRAS",
+ "TERÇAS-FEIRAS",
+ "QUARTAS-FEIRAS",
+ "QUINTAS-FEIRAS",
+ "SEXTAS-FEIRAS",
+ "SÁBADOS",
+ "DOMINGOS"
+ };
+ List<string> strs2 = strs1;
+ bool? segunda = usuario.get_Segunda();
+ if (!segunda.GetValueOrDefault() & segunda.HasValue)
+ {
+ strs.Add("SEGUNDAS-FEIRAS");
+ strs2.Remove("SEGUNDAS-FEIRAS");
+ }
+ segunda = usuario.get_Terca();
+ if (!segunda.GetValueOrDefault() & segunda.HasValue)
+ {
+ strs.Add("TERÇAS-FEIRAS");
+ strs2.Remove("TERÇAS-FEIRAS");
+ }
+ segunda = usuario.get_Quarta();
+ if (!segunda.GetValueOrDefault() & segunda.HasValue)
+ {
+ strs.Add("QUARTAS-FEIRAS");
+ strs2.Remove("QUARTAS-FEIRAS");
+ }
+ segunda = usuario.get_Quinta();
+ if (!segunda.GetValueOrDefault() & segunda.HasValue)
+ {
+ strs.Add("QUINTAS-FEIRAS");
+ strs2.Remove("QUINTAS-FEIRAS");
+ }
+ segunda = usuario.get_Sexta();
+ if (!segunda.GetValueOrDefault() & segunda.HasValue)
+ {
+ strs.Add("SEXTAS-FEIRAS");
+ strs2.Remove("SEXTAS-FEIRAS");
+ }
+ segunda = usuario.get_Sabado();
+ if (!segunda.GetValueOrDefault() & segunda.HasValue)
+ {
+ strs.Add("SÁBADOS");
+ strs2.Remove("SÁBADOS");
+ }
+ segunda = usuario.get_Domingo();
+ if (!segunda.GetValueOrDefault() & segunda.HasValue)
+ {
+ strs.Add("DOMINGOS");
+ strs2.Remove("DOMINGOS");
+ }
+ if (strs.Count == 7)
+ {
+ str1 = "RESTRITO TODOS OS DIAS";
+ }
+ else if (strs.Count > 3)
+ {
+ str1 = "APENAS PERMITIDO ";
+ for (int i = 0; i < strs2.Count; i++)
+ {
+ if (i >= strs2.Count - 2)
+ {
+ str1 = (i != strs2.Count - 2 ? string.Concat(str1, strs2[i]) : string.Concat(str1, strs2[i], " E "));
+ }
+ else
+ {
+ str1 = string.Concat(str1, strs2[i], ", ");
+ }
+ }
+ }
+ else
+ {
+ str1 = "RESTRITO ";
+ for (int j = 0; j < strs.Count; j++)
+ {
+ if (j >= strs.Count - 2)
+ {
+ str1 = (j != strs.Count - 2 ? string.Concat(str1, strs[j]) : string.Concat(str1, strs[j], " E "));
+ }
+ else
+ {
+ str1 = string.Concat(str1, strs[j], ", ");
+ }
+ }
+ }
+ DateTime networkTime = Funcoes.GetNetworkTime();
+ switch (networkTime.DayOfWeek)
+ {
+ case DayOfWeek.Sunday:
+ {
+ segunda = usuario.get_Domingo();
+ if (!(!segunda.GetValueOrDefault() & segunda.HasValue))
+ {
+ break;
+ }
+ str = string.Concat("ACESSO ", str1, ". CONTATE O ADMINISTRADOR DO SISTEMA");
+ str2 = null;
+ return str;
+ }
+ case DayOfWeek.Monday:
+ {
+ segunda = usuario.get_Segunda();
+ if (!(!segunda.GetValueOrDefault() & segunda.HasValue))
+ {
+ break;
+ }
+ str = string.Concat("ACESSO ", str1, ". CONTATE O ADMINISTRADOR DO SISTEMA");
+ str2 = null;
+ return str;
+ }
+ case DayOfWeek.Tuesday:
+ {
+ segunda = usuario.get_Terca();
+ if (!(!segunda.GetValueOrDefault() & segunda.HasValue))
+ {
+ break;
+ }
+ str = string.Concat("ACESSO ", str1, ". CONTATE O ADMINISTRADOR DO SISTEMA");
+ str2 = null;
+ return str;
+ }
+ case DayOfWeek.Wednesday:
+ {
+ segunda = usuario.get_Quarta();
+ if (!(!segunda.GetValueOrDefault() & segunda.HasValue))
+ {
+ break;
+ }
+ str = string.Concat("ACESSO ", str1, ". CONTATE O ADMINISTRADOR DO SISTEMA");
+ str2 = null;
+ return str;
+ }
+ case DayOfWeek.Thursday:
+ {
+ segunda = usuario.get_Quinta();
+ if (!(!segunda.GetValueOrDefault() & segunda.HasValue))
+ {
+ break;
+ }
+ str = string.Concat("ACESSO ", str1, ". CONTATE O ADMINISTRADOR DO SISTEMA");
+ str2 = null;
+ return str;
+ }
+ case DayOfWeek.Friday:
+ {
+ segunda = usuario.get_Sexta();
+ if (!(!segunda.GetValueOrDefault() & segunda.HasValue))
+ {
+ break;
+ }
+ str = string.Concat("ACESSO ", str1, ". CONTATE O ADMINISTRADOR DO SISTEMA");
+ str2 = null;
+ return str;
+ }
+ case DayOfWeek.Saturday:
+ {
+ segunda = usuario.get_Sabado();
+ if (!(!segunda.GetValueOrDefault() & segunda.HasValue))
+ {
+ break;
+ }
+ str = string.Concat("ACESSO ", str1, ". CONTATE O ADMINISTRADOR DO SISTEMA");
+ str2 = null;
+ return str;
+ }
+ }
+ if (usuario.get_InicioAcesso().HasValue && usuario.get_FimAcesso().HasValue && (networkTime.TimeOfDay <= usuario.get_InicioAcesso().Value.TimeOfDay || networkTime.TimeOfDay >= usuario.get_FimAcesso().Value.TimeOfDay))
+ {
+ DateTime value = usuario.get_InicioAcesso().Value;
+ string shortTimeString = value.ToShortTimeString();
+ value = usuario.get_FimAcesso().Value;
+ str2 = string.Concat("USUÁRIO COM PERMISSÃO DE ACESSO ENTRE ", shortTimeString, " E ", value.ToShortTimeString());
+ }
+ str = str2;
+ }
+ else
+ {
+ str = "DADOS DE ACESSO INVÁLIDOS";
+ }
+ str2 = null;
+ return str;
+ }
+
+ public async Task<bool> VerificarContrato(Gestor.Model.License.Produto produto, bool message = true, bool root = false)
+ {
+ bool flag;
+ Licenca licenca;
+ string str;
+ if (produto == 79)
+ {
+ List<Licenca> produtos = LicenseHelper.Produtos;
+ if (!produtos.Exists((Licenca x) => {
+ if (x.get_Produto() != 91)
+ {
+ return false;
+ }
+ return x.get_AcessoLiberado();
+ }))
+ {
+ List<Licenca> licencas = LicenseHelper.Produtos;
+ if (!licencas.Exists((Licenca x) => {
+ if (x.get_Produto() != 81)
+ {
+ return false;
+ }
+ return x.get_AcessoLiberado();
+ }))
+ {
+ List<Licenca> produtos1 = LicenseHelper.Produtos;
+ if (produtos1.Exists((Licenca x) => {
+ if (x.get_Produto() != 77)
+ {
+ return false;
+ }
+ return x.get_AcessoLiberado();
+ }))
+ {
+ flag = true;
+ return flag;
+ }
+ }
+ else
+ {
+ flag = true;
+ return flag;
+ }
+ }
+ else
+ {
+ flag = true;
+ return flag;
+ }
+ }
+ if (LicenseHelper.Produtos == null || !LicenseHelper.Produtos.Exists((Licenca x) => {
+ if (x.get_Produto() != produto)
+ {
+ return false;
+ }
+ return x.get_AcessoLiberado();
+ }))
+ {
+ if (message)
+ {
+ List<Licenca> licencas1 = LicenseHelper.Produtos;
+ if (licencas1 != null)
+ {
+ licenca = licencas1.FirstOrDefault<Licenca>((Licenca x) => x.get_Produto() == produto);
+ }
+ else
+ {
+ licenca = null;
+ }
+ Licenca licenca1 = licenca;
+ BaseViewModel baseViewModel = this;
+ str = (licenca1 == null ? string.Concat("VOCÊ NÃO POSSUI O MÓDULO ", EnumHelper.GetDescription<Gestor.Model.License.Produto>(produto), " CONTRATADO") : string.Concat("ACESSO AO MÓDULO ", EnumHelper.GetDescription<Gestor.Model.License.Produto>(produto), " INTERROMPIDO"));
+ await baseViewModel.ShowMessage(str, "OK", "", root);
+ }
+ flag = false;
+ }
+ else
+ {
+ flag = true;
+ }
+ return flag;
+ }
+
+ public void VerificarEnables(long? id)
+ {
+ this._lastId = id;
+ this.EnableIncluir = (!id.HasValue ? true : id.Value >= (long)0);
+ this.EnableAlterar = (!id.HasValue ? false : id.Value > (long)0);
+ this.EnableExcluir = (!id.HasValue ? false : id.Value > (long)0);
+ this.EnableButtons = (!id.HasValue ? false : id.Value > (long)0);
+ }
+
+ public async Task<bool> VerificarPermissao(TipoTela tela, bool root = false)
+ {
+ bool flag;
+ if (!await this.PermissaoConsultar(tela))
+ {
+ await this.ShowMessage("VOCÊ NÃO POSSUI PERMISSÃO PARA ACESSAR ESSA TELA. CONTATE O ADIMINSTRADOR DO SISTEMA.", "OK", "", root);
+ flag = false;
+ }
+ else
+ {
+ flag = true;
+ }
+ return flag;
+ }
+
+ public async Task<bool> VerificarRestricao(TipoRestricao tipoRestricao, bool root = false, bool showmessage = true)
+ {
+ bool flag;
+ if (Recursos.Usuario.get_Id() != 0)
+ {
+ RestricaoUsuario restricaoUsuario = this.ServicoRestriUsuario.BuscarRestricao(Recursos.Usuario, tipoRestricao);
+ if (restricaoUsuario == null || !restricaoUsuario.get_Restricao())
+ {
+ flag = true;
+ }
+ else
+ {
+ if (showmessage)
+ {
+ await this.ShowMessage("VOCÊ NÃO POSSUI PERMISSÃO PARA ACESSAR ESSA TELA. CONTATE O ADMINISTRADOR DO SISTEMA.", "OK", "", root);
+ }
+ flag = false;
+ }
+ }
+ else
+ {
+ flag = true;
+ }
+ return flag;
+ }
+
+ public async Task VerificarVersao()
+ {
+ bool flag;
+ bool flag1;
+ try
+ {
+ string str = await Gestor.Application.Helpers.Connection.Get<string>(string.Format("Update/Stable?versao={0}", ApplicationHelper.Versao), true, false);
+ flag1 = (str == null ? false : bool.Parse(str));
+ flag = flag1;
+ }
+ catch (Exception exception1)
+ {
+ Exception exception = exception1;
+ (new BaseServico()).Registrar(exception, 287, 3, ApplicationHelper.Versao.ToString(), false);
+ flag = false;
+ }
+ if (flag)
+ {
+ await this.ShowMessage("HÁ UMA ATUALIZAÇÃO OBRIGATÓRIA A SER FEITA. O PROCESSO SERÁ CANCELADO PARA A ATUALIZAÇÃO", "OK", "", false);
+ System.Windows.Application.Current.Shutdown();
+ }
+ else
+ {
+ ApplicationHelper.ChecagemVersao = Funcoes.GetNetworkTime();
+ }
+ }
+
+ public async Task<List<VendedorUsuario>> VerificaVinculoVendedor(Usuario usuario)
+ {
+ List<VendedorUsuario> vendedorUsuarios;
+ if (usuario == null || usuario.get_Id() == 0)
+ {
+ vendedorUsuarios = new List<VendedorUsuario>();
+ }
+ else
+ {
+ vendedorUsuarios = await this.ServicoVendedorUsuario.FindByVinculo(usuario);
+ }
+ return vendedorUsuarios;
+ }
+
+ public event PropertyChangedEventHandler PropertyChanged;
+ }
+}
\ No newline at end of file |