From 1f4e14b2e973ee7de337fd4866d9a5ceff5cb6d1 Mon Sep 17 00:00:00 2001 From: Lucas Faria Mendes Date: Mon, 30 Mar 2026 10:38:18 -0300 Subject: chore: location --- .../ViewModels/Ferramentas/EmpresaViewModel.cs | 512 --------------------- 1 file changed, 512 deletions(-) delete mode 100644 Gestor.Application/ViewModels/Ferramentas/EmpresaViewModel.cs (limited to 'Gestor.Application/ViewModels/Ferramentas/EmpresaViewModel.cs') diff --git a/Gestor.Application/ViewModels/Ferramentas/EmpresaViewModel.cs b/Gestor.Application/ViewModels/Ferramentas/EmpresaViewModel.cs deleted file mode 100644 index 6f528ac..0000000 --- a/Gestor.Application/ViewModels/Ferramentas/EmpresaViewModel.cs +++ /dev/null @@ -1,512 +0,0 @@ -using Gestor.Application.Helpers; -using Gestor.Application.Servicos.Ferramentas; -using Gestor.Application.Servicos.Generic; -using Gestor.Application.ViewModels.Command; -using Gestor.Application.ViewModels.Generic; -using Gestor.Common.Helpers; -using Gestor.Common.Validation; -using Gestor.Model.API; -using Gestor.Model.Common; -using Gestor.Model.Domain.Common; -using Gestor.Model.Domain.Generic; -using Gestor.Model.Domain.Seguros; -using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.Diagnostics; -using System.IO; -using System.Linq; -using System.Runtime.CompilerServices; -using System.Threading.Tasks; -using System.Windows; -using System.Windows.Forms; -using System.Windows.Input; - -namespace Gestor.Application.ViewModels.Ferramentas -{ - public class EmpresaViewModel : BaseSegurosViewModel - { - private readonly EmpresaServico _servico; - - public Empresa CancelEmpresa; - - private Empresa _selectedEmpresa = new Empresa(); - - private string _logoLabel = "ANEXAR LOGOTIPO"; - - private bool _passWordReadOnly; - - private bool _enableConsultaEspaco = true; - - private double _espaco; - - private string _senha; - - private string _confirmaSenha; - - private ObservableCollection _empresasFiltradas = new ObservableCollection(); - - private bool _isExpanded; - - private Visibility _confirmacaoSenha { get; set; } = Visibility.Collapsed; - - private Visibility _visualizacaoMatriz { get; set; } = Visibility.Collapsed; - - public Visibility ConfirmacaoSenha - { - get - { - return this._confirmacaoSenha; - } - set - { - this._confirmacaoSenha = value; - base.OnPropertyChanged("ConfirmacaoSenha"); - } - } - - public string ConfirmaSenha - { - get - { - return this._confirmaSenha; - } - set - { - this._confirmaSenha = value; - base.OnPropertyChanged("ConfirmaSenha"); - } - } - - public ICommand ConsultarEspacoCommand - { - get; - set; - } - - public List Empresas - { - get; - set; - } - - public ObservableCollection EmpresasFiltradas - { - get - { - return this._empresasFiltradas; - } - set - { - this._empresasFiltradas = value; - this.IsExpanded = (value != null ? value.Count > 0 : false); - base.OnPropertyChanged("EmpresasFiltradas"); - } - } - - public bool EnableConsultaEspaco - { - get - { - return this._enableConsultaEspaco; - } - set - { - this._enableConsultaEspaco = value; - base.OnPropertyChanged("EnableConsultaEspaco"); - } - } - - public double Espaco - { - get - { - return this._espaco; - } - set - { - this._espaco = value; - base.OnPropertyChanged("Espaco"); - } - } - - public bool IsExpanded - { - get - { - return this._isExpanded; - } - set - { - this._isExpanded = value; - base.OnPropertyChanged("IsExpanded"); - } - } - - public string LogoLabel - { - get - { - return this._logoLabel; - } - set - { - this._logoLabel = value; - base.OnPropertyChanged("LogoLabel"); - } - } - - public bool PassWordReadOnly - { - get - { - return this._passWordReadOnly; - } - set - { - bool flag; - if (!value) - { - flag = false; - } - else - { - flag = (Recursos.Usuario.get_Administrador() ? true : Recursos.Usuario.get_Id() == (long)0); - } - this._passWordReadOnly = flag; - base.OnPropertyChanged("PassWordReadOnly"); - } - } - - public Empresa SelectedEmpresa - { - get - { - return this._selectedEmpresa; - } - set - { - string str; - long? nullable; - this._selectedEmpresa = value; - if (value != null) - { - string senhaAdmin = value.get_SenhaAdmin(); - if (senhaAdmin != null) - { - str = EncryptionHelper.Decrypt(senhaAdmin); - } - else - { - str = null; - } - } - else - { - str = null; - } - this.Senha = str; - this.ConfirmaSenha = string.Empty; - this.WorkOnSelectedEmpresa(value, true); - if (value != null) - { - nullable = new long?(value.get_Id()); - } - else - { - nullable = null; - } - base.VerificarEnables(nullable); - base.OnPropertyChanged("SelectedEmpresa"); - } - } - - public string Senha - { - get - { - return this._senha; - } - set - { - this._senha = value; - base.OnPropertyChanged("Senha"); - } - } - - public Visibility VisualizacaoMatriz - { - get - { - return this._visualizacaoMatriz; - } - set - { - this._visualizacaoMatriz = value; - base.OnPropertyChanged("VisualizacaoMatriz"); - } - } - - public EmpresaViewModel() - { - this.ConsultarEspacoCommand = new RelayCommand(async () => await this.ConsultaEspacoUsadoClienteInGb()); - this._servico = new EmpresaServico(); - base.EnableMenu = true; - this.PassWordReadOnly = (!Recursos.Usuario.get_Administrador() ? false : base.EnableFields); - this.Seleciona(); - } - - public async Task AnexarLogo() - { - string fileName = ""; - using (OpenFileDialog openFileDialog = new OpenFileDialog()) - { - openFileDialog.Multiselect = false; - openFileDialog.Filter = "Imagens|*.jpg;*.jpeg;*.png;"; - openFileDialog.InitialDirectory = Environment.SpecialFolder.Desktop.ToString(); - if (DialogResult.OK == openFileDialog.ShowDialog()) - { - fileName = openFileDialog.FileName; - } - else - { - return; - } - } - int num = 0; - try - { - using (MemoryStream memoryStream = new MemoryStream(File.ReadAllBytes(fileName))) - { - byte[] numArray = new byte[checked((IntPtr)memoryStream.Length)]; - memoryStream.Position = (long)0; - memoryStream.Read(numArray, 0, (int)numArray.Length); - this.SelectedEmpresa.set_Logo(numArray); - } - } - catch (Exception exception) - { - num = 1; - } - if (num == 1) - { - string[] newLine = new string[] { "NÃO FOI POSSÍVEL CARREGAR O ARQUIVO ", fileName, ".", Environment.NewLine, "O ARQUIVO ESTÁ INACESSÍVEL OU SENDO UTILIZADO POR OUTRO PROCESSO." }; - await base.ShowMessage(string.Concat(newLine), "OK", "", false); - } - } - - public void CancelarAlteracao() - { - if (this.CancelEmpresa == null || !this.Empresas.Any((Empresa x) => x.get_Id() == this.CancelEmpresa.get_Id())) - { - this.Incluir(); - } - else - { - DomainBase.Copy(this.Empresas.First((Empresa x) => x.get_Id() == this.CancelEmpresa.get_Id()), this.CancelEmpresa); - if (this.EmpresasFiltradas.Count <= 0 || !this.EmpresasFiltradas.Any((Empresa x) => x.get_Id() == this.CancelEmpresa.get_Id())) - { - this.EmpresasFiltradas.Add(this.CancelEmpresa); - } - else - { - DomainBase.Copy(this.EmpresasFiltradas.First((Empresa x) => x.get_Id() == this.CancelEmpresa.get_Id()), this.CancelEmpresa); - } - this.EmpresasFiltradas = new ObservableCollection(this.EmpresasFiltradas); - this.SelectedEmpresa = this.EmpresasFiltradas.First((Empresa x) => x.get_Id() == this.CancelEmpresa.get_Id()); - } - base.Alterar(false); - } - - public async Task ConsultaEspacoUsadoClienteInGb() - { - this.EnableConsultaEspaco = false; - base.Loading(true); - double num = await this._servico.ConsultaEspacoBancoInGb(); - double num1 = 0; - if (Connection.ConnectionAddress.get_UsaAzureStorage()) - { - double num2 = await Connection.EspacoUsadoAzureInBytes(""); - if (num2 > 0) - { - num1 = num2 / 1024 / 1024 / 1024; - } - } - this.Espaco = num + num1; - if (this.Espaco == 0) - { - this.EnableConsultaEspaco = true; - } - base.Loading(false); - } - - internal async Task> Filtrar(string value) - { - List empresas = await Task.Run>(() => this.FiltrarEmpresa(value)); - return empresas; - } - - public List FiltrarEmpresa(string filter) - { - this.EmpresasFiltradas = (string.IsNullOrWhiteSpace(filter) ? new ObservableCollection(this.Empresas) : new ObservableCollection( - from x in this.Empresas - where ValidationHelper.RemoveDiacritics(x.get_Nome().Trim()).ToUpper().Contains(ValidationHelper.RemoveDiacritics(filter)) - orderby x.get_Nome() - select x)); - return this.EmpresasFiltradas.ToList(); - } - - public void Incluir() - { - this.SelectedEmpresa = new Empresa(); - base.Alterar(true); - } - - public async Task>> Salvar() - { - List> keyValuePairs; - string str; - string str1; - List> keyValuePairs1 = this.SelectedEmpresa.Validate(); - if (this.VisualizacaoMatriz != Visibility.Collapsed && this.ConfirmaSenha != this.Senha) - { - keyValuePairs1.Add(new KeyValuePair("SenhaAdmin|SENHA ADM", "A SENHA E A CONFIRMAÇÃO DA SENHA DEVEM SER IGUAIS.")); - } - if (keyValuePairs1.Count <= 0) - { - if (this.SelectedEmpresa.get_Id() == (long)1) - { - this.SelectedEmpresa.set_SenhaAdmin(EncryptionHelper.Encrypt(this.Senha)); - } - str = (this.SelectedEmpresa.get_Id() == 0 ? "INCLUIU" : "ALTEROU"); - str1 = str; - Empresa empresa = await this._servico.Save(this.SelectedEmpresa); - if (this._servico.Sucesso) - { - base.RegistrarAcao(string.Concat(str1, " EMPRESA \"", empresa.get_Nome(), "\""), empresa.get_Id(), new TipoTela?(18), string.Format("EMPRESA \"{0}\", ID: {1}", empresa.get_Nome(), empresa.get_Id())); - if (!this.Empresas.Any((Empresa x) => x.get_Id() == empresa.get_Id())) - { - this.Empresas.Add(empresa); - } - else - { - DomainBase.Copy(this.Empresas.First((Empresa x) => x.get_Id() == empresa.get_Id()), empresa); - } - if (!this.EmpresasFiltradas.Any((Empresa x) => x.get_Id() == empresa.get_Id())) - { - this.EmpresasFiltradas.Add(empresa); - } - else - { - DomainBase.Copy(this.EmpresasFiltradas.First((Empresa x) => x.get_Id() == empresa.get_Id()), empresa); - } - this.EmpresasFiltradas = new ObservableCollection(this.EmpresasFiltradas); - Recursos.Empresas = this.Empresas; - this.WorkOnSelectedEmpresa(empresa, false); - base.Alterar(false); - base.ToggleSnackBar("EMPRESA SALVA COM SUCESSO", true); - keyValuePairs = null; - } - else - { - keyValuePairs = null; - } - } - else - { - keyValuePairs = keyValuePairs1; - } - str1 = null; - return keyValuePairs; - } - - private async void Seleciona() - { - base.Loading(true); - await base.PermissaoTela(18); - await this.SelecionaEmpresas(); - base.Loading(false); - } - - public async void SelecionaEmpresa(Empresa empresa) - { - Empresa empresa1 = await this._servico.BuscarEmpresaPorId(empresa.get_Id()); - DomainBase.Copy(this.EmpresasFiltradas.First((Empresa x) => x.get_Id() == empresa.get_Id()), empresa1); - this.SelectedEmpresa = this.EmpresasFiltradas.First((Empresa x) => x.get_Id() == empresa.get_Id()); - } - - private async Task SelecionaEmpresas() - { - base.Loading(true); - List empresas = await (new BaseServico()).BuscarEmpresasAsync(); - EmpresaViewModel list = this; - List empresas1 = empresas; - IEnumerable empresas2 = empresas1.Where((Empresa x) => { - if (Recursos.Usuario.get_IdEmpresa() == (long)1) - { - return true; - } - return x.get_Id() == Recursos.Usuario.get_IdEmpresa(); - }); - list.Empresas = ( - from x in empresas2 - orderby x.get_Nome() - select x).ToList(); - this.EmpresasFiltradas = new ObservableCollection(this.Empresas); - if (this.EmpresasFiltradas.Count <= 0) - { - this.SelectedEmpresa = new Empresa(); - base.Alterar(false); - base.EnableMenu = false; - } - else - { - this.SelecionaEmpresa(this.EmpresasFiltradas.First()); - } - base.Loading(false); - } - - private void WorkOnSelectedEmpresa(Empresa value, bool registrar = true) - { - long? nullable; - bool logo; - this.CancelEmpresa = (value == null || value.get_Id() == 0 ? this.CancelEmpresa : (Empresa)value.Clone()); - if (value == null || value.get_Id() == 0 || this.LastAccessId == value.get_Id() && this.LastAccessTela == 18) - { - return; - } - if (registrar) - { - base.RegistrarAcao(string.Concat("ACESSOU EMPRESA \"", value.get_Nome(), "\""), value.get_Id(), new TipoTela?(18), string.Format("ID EMPRESA: {0}", value.get_Id())); - } - this.LastAccessId = value.get_Id(); - this.LastAccessTela = 18; - Empresa selectedEmpresa = this.SelectedEmpresa; - if (selectedEmpresa != null) - { - nullable = new long?(selectedEmpresa.get_Id()); - } - else - { - nullable = null; - } - long? nullable1 = nullable; - long id = value.get_Id(); - if (nullable1.GetValueOrDefault() != id | !nullable1.HasValue) - { - this.SelectedEmpresa = this.EmpresasFiltradas.FirstOrDefault((Empresa x) => x.get_Id() == value.get_Id()); - } - Empresa empresa = this.SelectedEmpresa; - if (empresa != null) - { - logo = empresa.get_Logo(); - } - else - { - logo = false; - } - this.LogoLabel = (!logo ? "ANEXAR LOGOTIPO" : "ALTERAR LOGOTIPO"); - this.VisualizacaoMatriz = (this.SelectedEmpresa.get_Id() == (long)1 ? Visibility.Visible : Visibility.Collapsed); - } - } -} \ No newline at end of file -- cgit v1.2.3