diff options
| author | Lucas Faria Mendes <lucas.fariamo08@gmail.com> | 2026-03-30 13:38:18 +0000 |
|---|---|---|
| committer | Lucas Faria Mendes <lucas.fariamo08@gmail.com> | 2026-03-30 13:38:18 +0000 |
| commit | 1f4e14b2e973ee7de337fd4866d9a5ceff5cb6d1 (patch) | |
| tree | e1c3b20ea08f0cf71122a1e73f0d395f8fd83874 /Gestor.Application/ViewModels/Generic/BaseFinanceiroViewModel.cs | |
| parent | 674ca83ba9243a9e95a7568c797668dab6aee26a (diff) | |
| download | gestor-1f4e14b2e973ee7de337fd4866d9a5ceff5cb6d1.tar.gz gestor-1f4e14b2e973ee7de337fd4866d9a5ceff5cb6d1.zip | |
chore: location
Diffstat (limited to 'Gestor.Application/ViewModels/Generic/BaseFinanceiroViewModel.cs')
| -rw-r--r-- | Gestor.Application/ViewModels/Generic/BaseFinanceiroViewModel.cs | 512 |
1 files changed, 0 insertions, 512 deletions
diff --git a/Gestor.Application/ViewModels/Generic/BaseFinanceiroViewModel.cs b/Gestor.Application/ViewModels/Generic/BaseFinanceiroViewModel.cs deleted file mode 100644 index 3e5561d..0000000 --- a/Gestor.Application/ViewModels/Generic/BaseFinanceiroViewModel.cs +++ /dev/null @@ -1,512 +0,0 @@ -using Gestor.Application.Componentes;
-using Gestor.Application.Servicos.Generic;
-using Gestor.Application.ViewModels.Financeiro;
-using Gestor.Model.Domain.Common;
-using Gestor.Model.Domain.Financeiro;
-using MaterialDesignThemes.Wpf;
-using OfxSharpLib;
-using System;
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.IO;
-using System.Linq;
-using System.Runtime.CompilerServices;
-using System.Text;
-using System.Text.RegularExpressions;
-using System.Threading.Tasks;
-using System.Windows;
-using System.Windows.Controls;
-using System.Windows.Forms;
-using Xceed.Wpf.AvalonDock.Controls;
-
-namespace Gestor.Application.ViewModels.Generic
-{
- public abstract class BaseFinanceiroViewModel : BaseViewModel
- {
- public AutoCompleteFilterPredicate<object> BancoItemFilter
- {
- get
- {
- AutoCompleteFilterPredicate<object> u003cu003e9_140 = BaseFinanceiroViewModel.u003cu003ec.u003cu003e9__14_0;
- if (u003cu003e9_140 == null)
- {
- u003cu003e9_140 = new AutoCompleteFilterPredicate<object>(BaseFinanceiroViewModel.u003cu003ec.u003cu003e9, (string searchText, object obj) => ((Banco)obj).get_Nome().ToUpper().Contains(searchText.ToUpper()));
- BaseFinanceiroViewModel.u003cu003ec.u003cu003e9__14_0 = u003cu003e9_140;
- }
- return u003cu003e9_140;
- }
- }
-
- public AutoCompleteFilterPredicate<object> BancosContasItemFilter
- {
- get
- {
- AutoCompleteFilterPredicate<object> u003cu003e9_20 = BaseFinanceiroViewModel.u003cu003ec.u003cu003e9__2_0;
- if (u003cu003e9_20 == null)
- {
- u003cu003e9_20 = new AutoCompleteFilterPredicate<object>(BaseFinanceiroViewModel.u003cu003ec.u003cu003e9, (string searchText, object obj) => ((BancosContas)obj).get_Descricao().ToUpper().Contains(searchText.ToUpper()));
- BaseFinanceiroViewModel.u003cu003ec.u003cu003e9__2_0 = u003cu003e9_20;
- }
- return u003cu003e9_20;
- }
- }
-
- public AutoCompleteFilterPredicate<object> FornecedorItemFilter
- {
- get
- {
- AutoCompleteFilterPredicate<object> u003cu003e9_60 = BaseFinanceiroViewModel.u003cu003ec.u003cu003e9__6_0;
- if (u003cu003e9_60 == null)
- {
- u003cu003e9_60 = new AutoCompleteFilterPredicate<object>(BaseFinanceiroViewModel.u003cu003ec.u003cu003e9, (string searchText, object obj) => {
- if (((Fornecedor)obj).get_Nome() != null && ((Fornecedor)obj).get_Nome().ToUpper().Contains(searchText.ToUpper()) || ((Fornecedor)obj).get_Documento() != null && ((Fornecedor)obj).get_Documento().ToString().Contains(searchText.ToUpper()) || ((Fornecedor)obj).get_Telefone1() != null && ((Fornecedor)obj).get_Telefone1().ToString().Contains(searchText.ToUpper()) || ((Fornecedor)obj).get_Telefone2() != null && ((Fornecedor)obj).get_Telefone2().ToString().Contains(searchText.ToUpper()))
- {
- return true;
- }
- if (((Fornecedor)obj).get_Email() == null)
- {
- return false;
- }
- return ((Fornecedor)obj).get_Email().ToString().Contains(searchText.ToUpper());
- });
- BaseFinanceiroViewModel.u003cu003ec.u003cu003e9__6_0 = u003cu003e9_60;
- }
- return u003cu003e9_60;
- }
- }
-
- public AutoCompleteFilterPredicate<object> LancamentoItemFilter
- {
- get
- {
- AutoCompleteFilterPredicate<object> u003cu003e9_80 = BaseFinanceiroViewModel.u003cu003ec.u003cu003e9__8_0;
- if (u003cu003e9_80 == null)
- {
- u003cu003e9_80 = new AutoCompleteFilterPredicate<object>(BaseFinanceiroViewModel.u003cu003ec.u003cu003e9, (string searchText, object obj) => {
- bool historico;
- bool plano;
- bool centro;
- bool fornecedor;
- if ((((Lancamento)obj).get_Historico() == null || !((Lancamento)obj).get_Historico().ToUpper().Contains(searchText.ToUpper())) && !((Lancamento)obj).get_Vencimento().ToString().ToUpper().Contains(searchText.ToUpper()) && (!((Lancamento)obj).get_Baixa().HasValue || !((Lancamento)obj).get_Baixa().ToString().ToUpper().Contains(searchText.ToUpper())) && (!((Lancamento)obj).get_Pagamento().HasValue || !((Lancamento)obj).get_Pagamento().ToString().ToUpper().Contains(searchText.ToUpper())) && (((Lancamento)obj).get_Conta() == null || !((Lancamento)obj).get_Conta().get_Descricao().ToString().ToUpper().Contains(searchText.ToUpper())))
- {
- ControleFinanceiro controle = ((Lancamento)obj).get_Controle();
- if (controle != null)
- {
- historico = controle.get_Historico();
- }
- else
- {
- historico = false;
- }
- if (!historico || !((Lancamento)obj).get_Controle().get_Historico().ToString().ToUpper().Contains(searchText.ToUpper()))
- {
- ControleFinanceiro controleFinanceiro = ((Lancamento)obj).get_Controle();
- if (controleFinanceiro != null)
- {
- plano = controleFinanceiro.get_Plano();
- }
- else
- {
- plano = false;
- }
- if (!plano || !((Lancamento)obj).get_Controle().get_Plano().get_Descricao().ToString().ToUpper().Contains(searchText.ToUpper()))
- {
- ControleFinanceiro controle1 = ((Lancamento)obj).get_Controle();
- if (controle1 != null)
- {
- centro = controle1.get_Centro();
- }
- else
- {
- centro = false;
- }
- if (!centro || !((Lancamento)obj).get_Controle().get_Centro().get_Descricao().ToString().ToUpper().Contains(searchText.ToUpper()))
- {
- ControleFinanceiro controleFinanceiro1 = ((Lancamento)obj).get_Controle();
- if (controleFinanceiro1 != null)
- {
- fornecedor = controleFinanceiro1.get_Fornecedor();
- }
- else
- {
- fornecedor = false;
- }
- if (!fornecedor)
- {
- return false;
- }
- return ((Lancamento)obj).get_Controle().get_Fornecedor().get_Nome().ToString().ToUpper().Contains(searchText.ToUpper());
- }
- }
- }
- }
- return true;
- });
- BaseFinanceiroViewModel.u003cu003ec.u003cu003e9__8_0 = u003cu003e9_80;
- }
- return u003cu003e9_80;
- }
- }
-
- public AutoCompleteFilterPredicate<object> PlanoItemFilter
- {
- get
- {
- AutoCompleteFilterPredicate<object> u003cu003e9_100 = BaseFinanceiroViewModel.u003cu003ec.u003cu003e9__10_0;
- if (u003cu003e9_100 == null)
- {
- u003cu003e9_100 = new AutoCompleteFilterPredicate<object>(BaseFinanceiroViewModel.u003cu003ec.u003cu003e9, (string searchText, object obj) => {
- if (((Plano)obj).get_Descricao().ToUpper().Contains(searchText.ToUpper()))
- {
- return true;
- }
- return ((Plano)obj).get_Descricao().ToString().Contains(searchText.ToUpper());
- });
- BaseFinanceiroViewModel.u003cu003ec.u003cu003e9__10_0 = u003cu003e9_100;
- }
- return u003cu003e9_100;
- }
- }
-
- public AutoCompleteFilterPredicate<object> PlanosItemFilter
- {
- get
- {
- AutoCompleteFilterPredicate<object> u003cu003e9_120 = BaseFinanceiroViewModel.u003cu003ec.u003cu003e9__12_0;
- if (u003cu003e9_120 == null)
- {
- u003cu003e9_120 = new AutoCompleteFilterPredicate<object>(BaseFinanceiroViewModel.u003cu003ec.u003cu003e9, (string searchText, object obj) => {
- if (((Planos)obj).get_Descricao().ToUpper().Contains(searchText.ToUpper()))
- {
- return true;
- }
- return ((Planos)obj).get_Descricao().ToString().Contains(searchText.ToUpper());
- });
- BaseFinanceiroViewModel.u003cu003ec.u003cu003e9__12_0 = u003cu003e9_120;
- }
- return u003cu003e9_120;
- }
- }
-
- protected BaseFinanceiroViewModel()
- {
- }
-
- internal async Task<List<BancosContas>> BuscarBancosContas(string value)
- {
- List<BancosContas> bancosContas = await Task.Run<List<BancosContas>>(() => (new BaseServico()).BuscarBancosContas(value));
- return bancosContas;
- }
-
- internal async Task<List<Fornecedor>> BuscarFornecedor(string value)
- {
- List<Fornecedor> fornecedors = await Task.Run<List<Fornecedor>>(() => (new BaseServico()).BuscarFornecedor(value, false));
- return fornecedors;
- }
-
- internal async Task<List<Fornecedor>> BuscarFornecedorAtivo(string value)
- {
- List<Fornecedor> fornecedors = await Task.Run<List<Fornecedor>>(() => (new BaseServico()).BuscarFornecedor(value, true));
- return fornecedors;
- }
-
- private string DetectEncodingAndRead(string arquivo)
- {
- return File.ReadAllText(arquivo, BaseFinanceiroViewModel.DetectTextFileEncoding(arquivo));
- }
-
- public static Encoding DetectTextFileEncoding(string filePath)
- {
- byte[] numArray;
- using (FileStream fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read))
- {
- int num = (int)Math.Min(fileStream.Length, (long)4096);
- numArray = new byte[num];
- fileStream.Read(numArray, 0, num);
- }
- if ((int)numArray.Length >= 2)
- {
- if ((int)numArray.Length >= 3 && numArray[0] == 239 && numArray[1] == 187 && numArray[2] == 191)
- {
- return Encoding.UTF8;
- }
- if (numArray[0] == 255 && numArray[1] == 254)
- {
- return Encoding.Unicode;
- }
- if (numArray[0] == 254 && numArray[1] == 255)
- {
- return Encoding.BigEndianUnicode;
- }
- if ((int)numArray.Length >= 4 && numArray[0] == 255 && numArray[1] == 254 && numArray[2] == 0 && numArray[3] == 0)
- {
- return Encoding.UTF32;
- }
- if ((int)numArray.Length >= 4 && numArray[0] == 0 && numArray[1] == 0 && numArray[2] == 254 && numArray[3] == 255)
- {
- return new UTF32Encoding(true, true);
- }
- }
- bool flag = true;
- int num1 = 0;
- int num2 = 0;
- for (int i = 0; i < (int)numArray.Length; i++)
- {
- if (numArray[i] <= 127)
- {
- num2++;
- }
- else if (numArray[i] >= 194 && numArray[i] <= 223 && i + 1 < (int)numArray.Length && numArray[i + 1] >= 128 && numArray[i + 1] <= 191)
- {
- num1++;
- i++;
- }
- else if (numArray[i] >= 224 && numArray[i] <= 239 && i + 2 < (int)numArray.Length && numArray[i + 1] >= 128 && numArray[i + 1] <= 191 && numArray[i + 2] >= 128 && numArray[i + 2] <= 191)
- {
- num1++;
- i += 2;
- }
- else if (numArray[i] < 240 || numArray[i] > 244 || i + 3 >= (int)numArray.Length || numArray[i + 1] < 128 || numArray[i + 1] > 191 || numArray[i + 2] < 128 || numArray[i + 2] > 191 || numArray[i + 3] < 128 || numArray[i + 3] > 191)
- {
- flag = false;
- break;
- }
- else
- {
- num1++;
- i += 3;
- }
- }
- int num3 = 0;
- for (int j = 0; j < (int)numArray.Length - 1; j += 2)
- {
- if (numArray[j] == 0 || numArray[j + 1] == 0)
- {
- num3++;
- }
- }
- if (flag && num1 > 0)
- {
- return Encoding.UTF8;
- }
- if ((double)num2 > (double)((int)numArray.Length) * 0.95)
- {
- return Encoding.ASCII;
- }
- if ((double)num3 <= (double)((int)numArray.Length) * 0.4)
- {
- return Encoding.GetEncoding(1252);
- }
- int num4 = 0;
- int num5 = 0;
- for (int k = 0; k < (int)numArray.Length - 1; k += 2)
- {
- if (numArray[k] == 0 && numArray[k + 1] != 0)
- {
- num5++;
- }
- if (numArray[k] != 0 && numArray[k + 1] == 0)
- {
- num4++;
- }
- }
- if (num4 > num5)
- {
- return Encoding.Unicode;
- }
- return Encoding.BigEndianUnicode;
- }
-
- public async Task<BancosContas> ExecuteRunExtendedDialogContas(System.Windows.Controls.UserControl dialogControl, string hostName)
- {
- BancosContas bancosConta;
- 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))
- {
- bancosConta = (BancosContas)obj;
- }
- else
- {
- bancosConta = null;
- }
- return bancosConta;
- }
-
- public async Task<Transferencia> ExecuteRunExtendedDialogTransferencia(System.Windows.Controls.UserControl dialogControl, string hostName)
- {
- Transferencia transferencium;
- 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))
- {
- transferencium = (Transferencia)obj;
- }
- else
- {
- transferencium = null;
- }
- return transferencium;
- }
-
- public async Task<Lancamento> ExecuteRunExtendedDialogVinculo(System.Windows.Controls.UserControl dialogControl, string hostName)
- {
- Lancamento lancamento;
- 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))
- {
- lancamento = (Lancamento)obj;
- }
- else
- {
- lancamento = null;
- }
- return lancamento;
- }
-
- public Encoding GetEncoding(string filename)
- {
- byte[] numArray = new byte[4];
- using (FileStream fileStream = new FileStream(filename, FileMode.Open, FileAccess.Read))
- {
- fileStream.Read(numArray, 0, 4);
- }
- if (numArray[0] == 43 && numArray[1] == 47 && numArray[2] == 118)
- {
- return Encoding.UTF7;
- }
- if (numArray[0] == 239 && numArray[1] == 187 && numArray[2] == 191)
- {
- return Encoding.UTF8;
- }
- if (numArray[0] == 255 && numArray[1] == 254 && numArray[2] == 0 && numArray[3] == 0)
- {
- return Encoding.UTF32;
- }
- if (numArray[0] == 255 && numArray[1] == 254)
- {
- return Encoding.Unicode;
- }
- if (numArray[0] == 254 && numArray[1] == 255)
- {
- return Encoding.BigEndianUnicode;
- }
- if (numArray[0] != 0 || numArray[1] != 0 || numArray[2] != 254 || numArray[3] != 255)
- {
- return Encoding.ASCII;
- }
- return new UTF32Encoding(true, true);
- }
-
- public async Task<List<OfxDocument>> ImportarOfx()
- {
- List<OfxDocument> ofxDocuments;
- BaseFinanceiroViewModel.u003cu003ec__DisplayClass22_0 variable;
- List<OfxDocument> ofxDocuments1 = new List<OfxDocument>();
- bool flag = false;
- List<string> strs = new List<string>();
- using (OpenFileDialog openFileDialog = new OpenFileDialog())
- {
- openFileDialog.Multiselect = true;
- openFileDialog.Filter = "Arquivos OFX|*.ofx";
- openFileDialog.InitialDirectory = Environment.SpecialFolder.Desktop.ToString();
- if (DialogResult.OK == openFileDialog.ShowDialog())
- {
- strs.AddRange(openFileDialog.FileNames);
- }
- else
- {
- ofxDocuments = null;
- variable = null;
- return ofxDocuments;
- }
- }
- await Task.Run(() => {
- OfxDocumentParser ofxDocumentParser = new OfxDocumentParser();
- strs.ForEach((string x) => {
- try
- {
- string str = DateTime.Now.Date.ToString("yyyyMMddHHmmss");
- string str1 = this.DetectEncodingAndRead(x).Replace("<DTASOF>00000000", string.Concat("<DTASOF>", str)).Replace("<DTSERVER>00000000000000", string.Concat("<DTSERVER>", str)).Replace(",", ".").Replace("<REFNUM> </REFNUM>", "<REFNUM>.</REFNUM>");
- if (str1.Contains("<FID>336</FID>") && !str1.Contains("<LEDGERBAL>"))
- {
- str1 = str1.Replace("UTF - 8", "USASCII").Replace("</BANKTRANLIST>", "</BANKTRANLIST>\r\n<LEDGERBAL>\r\n<BALAMT>0\r\n<DTASOF>00000000\r\n</LEDGERBAL>").Replace("<DTASOF>00000000", string.Concat("<DTASOF>", str)).Replace(": ", ":").Replace(" ", "").Replace("<REFNUM/>", "<REFNUM>0");
- }
- if (str1.Contains("<FID>0403</FID>") && !str1.Contains("CHARSET:1252") && str1.Contains("ENCODING:UTF-8"))
- {
- str1 = str1.Replace("UTF-8", "USASCII\nCHARSET:1252").Replace("<DTASOF>00000000", string.Concat("<DTASOF>", str)).Replace("[0:GMT]", "").Replace(": ", ":").Replace(" ", "");
- }
- if (str1.Contains("<FID>260"))
- {
- str1 = str1.Replace("UTF-8", "USASCII").Replace("CHARSET:NONE", "CHARSET:1252");
- }
- if (str1.Contains("<MEMO></MEMO>"))
- {
- str1 = str1.Replace("<MEMO></MEMO>", "<MEMO>SEM INFORMAÇÃO</MEMO>");
- }
- if (Regex.IsMatch(str1, "<NAME>\\s*</NAME>"))
- {
- str1 = str1.Replace("<NAME>\n</NAME>", "<NAME>SEM NOME</NAME>").Replace("<NAME></NAME>", "<NAME>SEM NOME</NAME>");
- }
- OfxDocument ofxDocument = ofxDocumentParser.Import(str1);
- ofxDocuments1.Add(ofxDocument);
- }
- catch (Exception exception)
- {
- flag = true;
- }
- });
- });
- if (flag)
- {
- await base.ShowMessage("HOUVE PROBLEMAS AO IMPORTAR O OFX, BAIXE-O NOVAMENTE COM UM PERÍODO MENOR.", "OK", "", false);
- }
- ofxDocuments = ofxDocuments1;
- variable = null;
- return ofxDocuments;
- }
-
- internal async Task<BancosContas> ShowContas(List<BancosContas> contas)
- {
- string str;
- IEnumerable<Window> windows = System.Windows.Application.Current.Windows.OfType<Window>();
- DialogHost dialogHost = Extentions.FindVisualChildren<DialogHost>(windows.SingleOrDefault<Window>((Window x) => x.IsActive)).FirstOrDefault<DialogHost>();
- ContasDialog contasDialog = new ContasDialog(contas);
- BaseFinanceiroViewModel baseFinanceiroViewModel = this;
- ContasDialog contasDialog1 = contasDialog;
- str = (dialogHost != null ? dialogHost.get_Identifier().ToString() : "RootDialog");
- return await baseFinanceiroViewModel.ExecuteRunExtendedDialogContas(contasDialog1, str);
- }
-
- internal async Task<Transferencia> ShowTransferencia(Transferencia transferencia)
- {
- string str;
- IEnumerable<Window> windows = System.Windows.Application.Current.Windows.OfType<Window>();
- DialogHost dialogHost = Extentions.FindVisualChildren<DialogHost>(windows.SingleOrDefault<Window>((Window x) => x.IsActive)).FirstOrDefault<DialogHost>();
- DialogTransferencia dialogTransferencium = new DialogTransferencia(transferencia);
- BaseFinanceiroViewModel baseFinanceiroViewModel = this;
- DialogTransferencia dialogTransferencium1 = dialogTransferencium;
- str = (dialogHost != null ? dialogHost.get_Identifier().ToString() : "RootDialog");
- return await baseFinanceiroViewModel.ExecuteRunExtendedDialogTransferencia(dialogTransferencium1, str);
- }
-
- internal async Task<Lancamento> ShowVinculo(FinanceiroViewModel viewModel)
- {
- string str;
- IEnumerable<Window> windows = System.Windows.Application.Current.Windows.OfType<Window>();
- DialogHost dialogHost = Extentions.FindVisualChildren<DialogHost>(windows.SingleOrDefault<Window>((Window x) => x.IsActive)).FirstOrDefault<DialogHost>();
- VincularLancamentoDialog vincularLancamentoDialog = new VincularLancamentoDialog(viewModel);
- BaseFinanceiroViewModel baseFinanceiroViewModel = this;
- VincularLancamentoDialog vincularLancamentoDialog1 = vincularLancamentoDialog;
- str = (dialogHost != null ? dialogHost.get_Identifier().ToString() : "RootDialog");
- return await baseFinanceiroViewModel.ExecuteRunExtendedDialogVinculo(vincularLancamentoDialog1, str);
- }
- }
-}
\ No newline at end of file |