1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Forms;
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 Xceed.Wpf.AvalonDock.Controls;
namespace Gestor.Application.ViewModels.Generic;
public abstract class BaseFinanceiroViewModel : BaseViewModel
{
public AutoCompleteFilterPredicate<object> BancosContasItemFilter => (string searchText, object obj) => ((BancosContas)obj).Descricao.ToUpper().Contains(searchText.ToUpper());
public AutoCompleteFilterPredicate<object> FornecedorItemFilter => (string searchText, object obj) => (((Fornecedor)obj).Nome != null && ((Fornecedor)obj).Nome.ToUpper().Contains(searchText.ToUpper())) || (((Fornecedor)obj).Documento != null && ((Fornecedor)obj).Documento.ToString().Contains(searchText.ToUpper())) || (((Fornecedor)obj).Telefone1 != null && ((Fornecedor)obj).Telefone1.ToString().Contains(searchText.ToUpper())) || (((Fornecedor)obj).Telefone2 != null && ((Fornecedor)obj).Telefone2.ToString().Contains(searchText.ToUpper())) || (((Fornecedor)obj).Email != null && ((Fornecedor)obj).Email.ToString().Contains(searchText.ToUpper()));
public AutoCompleteFilterPredicate<object> LancamentoItemFilter => delegate(string searchText, object obj)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: Unknown result type (might be due to invalid IL or missing references)
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
//IL_0056: Unknown result type (might be due to invalid IL or missing references)
//IL_0099: Unknown result type (might be due to invalid IL or missing references)
//IL_006b: Unknown result type (might be due to invalid IL or missing references)
//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
//IL_0113: Unknown result type (might be due to invalid IL or missing references)
//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
//IL_0156: Unknown result type (might be due to invalid IL or missing references)
//IL_012c: Unknown result type (might be due to invalid IL or missing references)
//IL_019e: Unknown result type (might be due to invalid IL or missing references)
//IL_016f: Unknown result type (might be due to invalid IL or missing references)
//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
if ((((Lancamento)obj).Historico == null || !((Lancamento)obj).Historico.ToUpper().Contains(searchText.ToUpper())) && !((Lancamento)obj).Vencimento.ToString().ToUpper().Contains(searchText.ToUpper()) && (!((Lancamento)obj).Baixa.HasValue || !((Lancamento)obj).Baixa.ToString().ToUpper().Contains(searchText.ToUpper())) && (!((Lancamento)obj).Pagamento.HasValue || !((Lancamento)obj).Pagamento.ToString().ToUpper().Contains(searchText.ToUpper())) && (((Lancamento)obj).Conta == null || !((Lancamento)obj).Conta.Descricao.ToString().ToUpper().Contains(searchText.ToUpper())))
{
ControleFinanceiro controle = ((Lancamento)obj).Controle;
if (((controle != null) ? controle.Historico : null) == null || !((Lancamento)obj).Controle.Historico.ToString().ToUpper().Contains(searchText.ToUpper()))
{
ControleFinanceiro controle2 = ((Lancamento)obj).Controle;
if (((controle2 != null) ? controle2.Plano : null) == null || !((Lancamento)obj).Controle.Plano.Descricao.ToString().ToUpper().Contains(searchText.ToUpper()))
{
ControleFinanceiro controle3 = ((Lancamento)obj).Controle;
if (((controle3 != null) ? controle3.Centro : null) == null || !((Lancamento)obj).Controle.Centro.Descricao.ToString().ToUpper().Contains(searchText.ToUpper()))
{
ControleFinanceiro controle4 = ((Lancamento)obj).Controle;
if (((controle4 != null) ? controle4.Fornecedor : null) != null)
{
return ((Lancamento)obj).Controle.Fornecedor.Nome.ToString().ToUpper().Contains(searchText.ToUpper());
}
return false;
}
}
}
}
return true;
};
public AutoCompleteFilterPredicate<object> PlanoItemFilter => (string searchText, object obj) => ((Plano)obj).Descricao.ToUpper().Contains(searchText.ToUpper()) || ((Plano)obj).Descricao.ToString().Contains(searchText.ToUpper());
public AutoCompleteFilterPredicate<object> PlanosItemFilter => (string searchText, object obj) => ((Planos)obj).Descricao.ToUpper().Contains(searchText.ToUpper()) || ((Planos)obj).Descricao.ToString().Contains(searchText.ToUpper());
public AutoCompleteFilterPredicate<object> BancoItemFilter => (string searchText, object obj) => ((Banco)obj).Nome.ToUpper().Contains(searchText.ToUpper());
internal async Task<List<BancosContas>> BuscarBancosContas(string value)
{
return await Task.Run(() => new BaseServico().BuscarBancosContas(value));
}
internal async Task<List<Fornecedor>> BuscarFornecedor(string value)
{
return await Task.Run(() => new BaseServico().BuscarFornecedor(value));
}
internal async Task<List<Fornecedor>> BuscarFornecedorAtivo(string value)
{
return await Task.Run(() => new BaseServico().BuscarFornecedor(value, ativo: true));
}
internal async Task<Transferencia> ShowTransferencia(Transferencia transferencia)
{
DialogHost val = Extentions.FindVisualChildren<DialogHost>((DependencyObject)(object)((IEnumerable)Application.Current.Windows).OfType<Window>().SingleOrDefault((Func<Window, bool>)((Window x) => x.IsActive))).FirstOrDefault();
DialogTransferencia dialogControl = new DialogTransferencia(transferencia);
return await ExecuteRunExtendedDialogTransferencia((UserControl)(object)dialogControl, (val != null) ? val.Identifier.ToString() : "RootDialog");
}
public async Task<Transferencia> ExecuteRunExtendedDialogTransferencia(UserControl dialogControl, string hostName)
{
Extentions.FindVisualChildren<WebEditor>((DependencyObject)(object)((IEnumerable)Application.Current.Windows).OfType<Window>().SingleOrDefault((Func<Window, bool>)((Window x) => x.IsActive))).ToList().ForEach(delegate(WebEditor x)
{
((UIElement)x).Visibility = (Visibility)2;
});
object obj = await DialogHost.Show((object)dialogControl, (object)hostName, new DialogOpenedEventHandler(base.ExtendedOpenedEventHandler), new DialogClosingEventHandler(base.ExtendedClosingEventHandler));
if (obj is bool)
{
return null;
}
return (Transferencia)obj;
}
internal async Task<Lancamento> ShowVinculo(FinanceiroViewModel viewModel)
{
DialogHost val = Extentions.FindVisualChildren<DialogHost>((DependencyObject)(object)((IEnumerable)Application.Current.Windows).OfType<Window>().SingleOrDefault((Func<Window, bool>)((Window x) => x.IsActive))).FirstOrDefault();
VincularLancamentoDialog dialogControl = new VincularLancamentoDialog(viewModel);
return await ExecuteRunExtendedDialogVinculo((UserControl)(object)dialogControl, (val != null) ? val.Identifier.ToString() : "RootDialog");
}
public async Task<Lancamento> ExecuteRunExtendedDialogVinculo(UserControl dialogControl, string hostName)
{
Extentions.FindVisualChildren<WebEditor>((DependencyObject)(object)((IEnumerable)Application.Current.Windows).OfType<Window>().SingleOrDefault((Func<Window, bool>)((Window x) => x.IsActive))).ToList().ForEach(delegate(WebEditor x)
{
((UIElement)x).Visibility = (Visibility)2;
});
object obj = await DialogHost.Show((object)dialogControl, (object)hostName, new DialogOpenedEventHandler(base.ExtendedOpenedEventHandler), new DialogClosingEventHandler(base.ExtendedClosingEventHandler));
if (obj is bool)
{
return null;
}
return (Lancamento)obj;
}
internal async Task<BancosContas> ShowContas(List<BancosContas> contas)
{
DialogHost val = Extentions.FindVisualChildren<DialogHost>((DependencyObject)(object)((IEnumerable)Application.Current.Windows).OfType<Window>().SingleOrDefault((Func<Window, bool>)((Window x) => x.IsActive))).FirstOrDefault();
ContasDialog dialogControl = new ContasDialog(contas);
return await ExecuteRunExtendedDialogContas((UserControl)(object)dialogControl, (val != null) ? val.Identifier.ToString() : "RootDialog");
}
public async Task<BancosContas> ExecuteRunExtendedDialogContas(UserControl dialogControl, string hostName)
{
Extentions.FindVisualChildren<WebEditor>((DependencyObject)(object)((IEnumerable)Application.Current.Windows).OfType<Window>().SingleOrDefault((Func<Window, bool>)((Window x) => x.IsActive))).ToList().ForEach(delegate(WebEditor x)
{
((UIElement)x).Visibility = (Visibility)2;
});
object obj = await DialogHost.Show((object)dialogControl, (object)hostName, new DialogOpenedEventHandler(base.ExtendedOpenedEventHandler), new DialogClosingEventHandler(base.ExtendedClosingEventHandler));
if (obj is bool)
{
return null;
}
return (BancosContas)obj;
}
public Encoding GetEncoding(string filename)
{
byte[] array = new byte[4];
using (FileStream fileStream = new FileStream(filename, FileMode.Open, FileAccess.Read))
{
fileStream.Read(array, 0, 4);
}
if (array[0] == 43 && array[1] == 47 && array[2] == 118)
{
return Encoding.UTF7;
}
if (array[0] == 239 && array[1] == 187 && array[2] == 191)
{
return Encoding.UTF8;
}
if (array[0] == byte.MaxValue && array[1] == 254 && array[2] == 0 && array[3] == 0)
{
return Encoding.UTF32;
}
if (array[0] == byte.MaxValue && array[1] == 254)
{
return Encoding.Unicode;
}
if (array[0] == 254 && array[1] == byte.MaxValue)
{
return Encoding.BigEndianUnicode;
}
if (array[0] == 0 && array[1] == 0 && array[2] == 254 && array[3] == byte.MaxValue)
{
return new UTF32Encoding(bigEndian: true, byteOrderMark: true);
}
return Encoding.ASCII;
}
public async Task<List<OfxDocument>> ImportarOfx()
{
List<OfxDocument> ofxDocuments = new List<OfxDocument>();
bool error = false;
List<string> files = new List<string>();
OpenFileDialog val = new OpenFileDialog();
try
{
val.Multiselect = true;
((FileDialog)val).Filter = "Arquivos OFX|*.ofx";
((FileDialog)val).InitialDirectory = Environment.SpecialFolder.Desktop.ToString();
if (1 != (int)((CommonDialog)val).ShowDialog())
{
return null;
}
files.AddRange(((FileDialog)val).FileNames);
}
finally
{
((IDisposable)val)?.Dispose();
}
await Task.Run(delegate
{
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
//IL_0018: Expected O, but got Unknown
OfxDocumentParser parser = new OfxDocumentParser();
files.ForEach(delegate(string x)
{
try
{
string text = DateTime.Now.Date.ToString("yyyyMMddHHmmss");
string text2 = DetectEncodingAndRead(x).Replace("<DTASOF>00000000", "<DTASOF>" + text).Replace("<DTSERVER>00000000000000", "<DTSERVER>" + text).Replace(",", ".")
.Replace("<REFNUM> </REFNUM>", "<REFNUM>.</REFNUM>");
if (text2.Contains("<FID>336</FID>") && !text2.Contains("<LEDGERBAL>"))
{
text2 = text2.Replace("UTF - 8", "USASCII").Replace("</BANKTRANLIST>", "</BANKTRANLIST>\r\n<LEDGERBAL>\r\n<BALAMT>0\r\n<DTASOF>00000000\r\n</LEDGERBAL>").Replace("<DTASOF>00000000", "<DTASOF>" + text)
.Replace(": ", ":")
.Replace(" ", "")
.Replace("<REFNUM/>", "<REFNUM>0");
}
if (text2.Contains("<FID>0403</FID>") && !text2.Contains("CHARSET:1252") && text2.Contains("ENCODING:UTF-8"))
{
text2 = text2.Replace("UTF-8", "USASCII\nCHARSET:1252").Replace("<DTASOF>00000000", "<DTASOF>" + text).Replace("[0:GMT]", "")
.Replace(": ", ":")
.Replace(" ", "");
}
if (text2.Contains("<FID>260"))
{
text2 = text2.Replace("UTF-8", "USASCII").Replace("CHARSET:NONE", "CHARSET:1252");
}
if (text2.Contains("<MEMO></MEMO>"))
{
text2 = text2.Replace("<MEMO></MEMO>", "<MEMO>SEM INFORMAÇÃO</MEMO>");
}
if (Regex.IsMatch(text2, "<NAME>\\s*</NAME>"))
{
text2 = text2.Replace("<NAME>\n</NAME>", "<NAME>SEM NOME</NAME>").Replace("<NAME></NAME>", "<NAME>SEM NOME</NAME>");
}
OfxDocument item = parser.Import(text2);
ofxDocuments.Add(item);
}
catch (Exception)
{
error = true;
}
});
});
if (error)
{
await ShowMessage("HOUVE PROBLEMAS AO IMPORTAR O OFX, BAIXE-O NOVAMENTE COM UM PERÍODO MENOR.");
}
return ofxDocuments;
}
private string DetectEncodingAndRead(string arquivo)
{
return File.ReadAllText(arquivo, DetectTextFileEncoding(arquivo));
}
public static Encoding DetectTextFileEncoding(string filePath)
{
byte[] array;
using (FileStream fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read))
{
int num = (int)Math.Min(fileStream.Length, 4096L);
array = new byte[num];
fileStream.Read(array, 0, num);
}
if (array.Length >= 2)
{
if (array.Length >= 3 && array[0] == 239 && array[1] == 187 && array[2] == 191)
{
return Encoding.UTF8;
}
if (array[0] == byte.MaxValue && array[1] == 254)
{
return Encoding.Unicode;
}
if (array[0] == 254 && array[1] == byte.MaxValue)
{
return Encoding.BigEndianUnicode;
}
if (array.Length >= 4 && array[0] == byte.MaxValue && array[1] == 254 && array[2] == 0 && array[3] == 0)
{
return Encoding.UTF32;
}
if (array.Length >= 4 && array[0] == 0 && array[1] == 0 && array[2] == 254 && array[3] == byte.MaxValue)
{
return new UTF32Encoding(bigEndian: true, byteOrderMark: true);
}
}
bool flag = true;
int num2 = 0;
int num3 = 0;
for (int i = 0; i < array.Length; i++)
{
if (array[i] <= 127)
{
num3++;
continue;
}
if (array[i] >= 194 && array[i] <= 223 && i + 1 < array.Length && array[i + 1] >= 128 && array[i + 1] <= 191)
{
num2++;
i++;
continue;
}
if (array[i] >= 224 && array[i] <= 239 && i + 2 < array.Length && array[i + 1] >= 128 && array[i + 1] <= 191 && array[i + 2] >= 128 && array[i + 2] <= 191)
{
num2++;
i += 2;
continue;
}
if (array[i] >= 240 && array[i] <= 244 && i + 3 < array.Length && array[i + 1] >= 128 && array[i + 1] <= 191 && array[i + 2] >= 128 && array[i + 2] <= 191 && array[i + 3] >= 128 && array[i + 3] <= 191)
{
num2++;
i += 3;
continue;
}
flag = false;
break;
}
int num4 = 0;
for (int j = 0; j < array.Length - 1; j += 2)
{
if (array[j] == 0 || array[j + 1] == 0)
{
num4++;
}
}
if (flag && num2 > 0)
{
return Encoding.UTF8;
}
if ((double)num3 > (double)array.Length * 0.95)
{
return Encoding.ASCII;
}
if ((double)num4 > (double)array.Length * 0.4)
{
int num5 = 0;
int num6 = 0;
for (int k = 0; k < array.Length - 1; k += 2)
{
if (array[k] == 0 && array[k + 1] != 0)
{
num6++;
}
if (array[k] != 0 && array[k + 1] == 0)
{
num5++;
}
}
if (num5 > num6)
{
return Encoding.Unicode;
}
return Encoding.BigEndianUnicode;
}
return Encoding.GetEncoding(1252);
}
}
|