private ObservableCollection <Arquivo> GetArquivos() { using (var context = new ColinfoContext()) { var Arqs = new ObservableCollection <Arquivo>(); var arqs = context.Arquivos .Include(vnd => vnd.Pedidos) .ThenInclude(cli => cli.Cliente) .ThenInclude(ret => ret.RetConsultaCadastro) .ThenInclude(inf => inf.infCons) .ThenInclude(inf2 => inf2.infCad); try { foreach (var item in arqs) { Arqs.Add(item); } return(Arqs); } catch (Exception) { return(Arqs); } } }
public static Arquivo getArquivo(string path, string nome) { using (var context = new ColinfoContext()) { decimal val = 0; var peds = new List <Pedido>(); var Lines = File.ReadLines(path).Select(a => a.Split('|')); # region Clientes var clientes = (from line in Lines where line[0] == "CCLI.TXT" select new Cliente { RegiaoCliente = int.Parse(line[1]), NumCliente = int.Parse(line[2]), Razao = line[3], Sigla = line[4], CNPJ = MascararCNPJ(line[15]), IE = line[17], Rota = int.Parse(line[41]), Situacao = CNPJVerif(line[15]) }).ToList(); #endregion # region Pedidos foreach (var line in Lines)
public async void Dialog_AddRomaneio() { var view = new Dialog_AddRomaneio { DataContext = this }; var result = await DialogHost.Show(view, "RootDialog", ClosingEventHandler); var path = @"F:\SOF\VDWIN\EXP\PEDIDOS.CSV"; if (Environment.MachineName == "ATAIDE-PC") { path = @"C:\Users\krekm\Desktop\PEDIDOS.CSV"; } using (var context = new ColinfoContext()) { var NumRom = ToRomaneio(); var rom = Coletor.GetRomaneio(path, NumRom); if (rom != null) { Application.Current.Dispatcher.Invoke(delegate { Arquivos.Add(rom); }); ConsultaCadastros(rom); } } }
public void LimparTudo() { using (var context = new ColinfoContext()) { try { context.Arquivos.RemoveRange(); var existingArqs = context.Arquivos.ToList(); context.Arquivos.RemoveRange(existingArqs); context.SaveChanges(); AtualizaArquivos(); } catch (Exception ex) { var msg = ""; if (!string.IsNullOrEmpty(ex.Message)) { msg = ex.InnerException?.Message ?? ex.Message; //ShowDialogErrorAsync(msg); } } } AtualizaArquivos(); }
public void AddArquivo(Arquivo arq) { using (var context = new ColinfoContext()) { context.Add(arq); context.SaveChanges(); } }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { var vnd = (Venda)value; var resumo = new List <Resumo>(); if (vnd?.Pedidos == null) { using (var context = new ColinfoContext()) { var arq = context.Arquivos .Include(x => x.Pedidos) .FirstOrDefault(x => x.CodVendedor == vnd.CodVendedor && x.Pedidos.Count > 4); if (arq != null) { resumo.Add ( new Resumo { QntCX = arq.Pedidos.Count(), Sigla = arq.ArquivoVendedor } ); return(resumo); //return $"{arq.ArquivoVendedor} ({arq.Pedidos.Count()})"; } return(null); } } ; var items = vnd?.Pedidos?.SelectMany(it => it.Items); var rankedItems = Tools.RankProd(items); var rank2 = "?"; if (rankedItems.Length > 1) { rank2 = $"{rankedItems[1]?.QntCX} {Tools.GetItemNickProd(rankedItems[1]?.Produto)}"; } foreach (var item in rankedItems) { resumo.Add ( new Resumo { QntCX = item.QntCX, Sigla = Tools.GetItemNickProd(item.Produto) } ); } return(resumo); //return $"{rankedItems[0].QntCX} {Tools.GetItemNickProd(rankedItems[0].Produto)} | {rank2}"; }
private void MigrationUpdate() { using (var context = new ColinfoContext()) { if (context.Database.EnsureCreated()) { context.Database.Migrate(); } context.Database.Migrate(); } }
public void EditarPedido(Pedido ped, Model.retConsCad consulta) { using (var context = new ColinfoContext()) { var vnd = context.Arquivos .Include(vd => vd.Pedidos) .ThenInclude(cli => cli.Cliente) .ThenInclude(cons => cons.RetConsultaCadastro) .ThenInclude(inf => inf.infCons) .ThenInclude(cad => cad.infCad) .FirstOrDefault(v => v.ArquivoID == ped.Arquivo.ArquivoID); var oldPed = vnd.Pedidos.FirstOrDefault(pd => pd.PedidoID == ped.PedidoID); var ctxPed = Arquivos.FirstOrDefault(v => v.ArquivoID == ped.Arquivo.ArquivoID).Pedidos.FirstOrDefault(p => p.PedidoID == ped.PedidoID); oldPed.Cliente.RetConsultaCadastro = consulta; oldPed.Cliente.Situacao = SituacaoCadastro(oldPed); context.Entry(oldPed).State = EntityState.Modified; context.SaveChanges(); ctxPed.Cliente.RetConsultaCadastro = consulta; } }
public void RemoverArquivo(Arquivo arq) { using (var context = new ColinfoContext()) { try { var a1 = context.Arquivos.Find(arq.ArquivoID); context.Arquivos.Remove(a1); context.Entry(a1).State = EntityState.Deleted; context.SaveChanges(); } catch (Exception ex) { var msg = ""; if (!string.IsNullOrEmpty(ex.Message)) { msg = ex.InnerException?.Message ?? ex.Message; //ShowDialogErrorAsync(msg); } } } AtualizaArquivos(); }
public void ConsultaCadastro(Pedido ped) { int NumOfRetries = 10; int trysExCom = 0; int trysExOthers = 0; var recRet = new Model.retConsCad(); Task.Run(() => { TryAgain: try { var servicoNFe = new ServicosNFe(Configuracoes.CfgServico); //var cert = DFe.Utils.Assinatura.CertificadoDigital.ListareObterDoRepositorio(); //Configuracoes.CfgServico.Certificado.Serial = cert.SerialNumber; //Configuracoes.CfgServico.Certificado.Serial = "00D424AA"; var retornoConsulta = servicoNFe.NfeConsultaCadastro("MG", (ConsultaCadastroTipoDocumento)1, ped.Cliente.CNPJ.Replace(".", "").Replace("/", "").Replace("-", "")); recRet = FuncoesXml.XmlStringParaClasse <Model.retConsCad>(retornoConsulta.RetornoCompletoStr); //ped.Cliente.RetConsultaCadastro = recRet; using (var context = new ColinfoContext()) { var vnd = context.Arquivos .Include(vd => vd.Pedidos) .ThenInclude(cli => cli.Cliente) .ThenInclude(cons => cons.RetConsultaCadastro) .ThenInclude(inf => inf.infCons) .ThenInclude(cad => cad.infCad) .FirstOrDefault(v => v.ArquivoID == ped.Arquivo.ArquivoID); var oldPed = vnd.Pedidos.FirstOrDefault(pd => pd.PedidoID == ped.PedidoID); var ctxPed = Arquivos.FirstOrDefault(v => v.ArquivoID == ped.Arquivo.ArquivoID).Pedidos.FirstOrDefault(p => p.PedidoID == ped.PedidoID); var ctxVnd = Arquivos.FirstOrDefault(v => v.ArquivoID == ped.Arquivo.ArquivoID); oldPed.Cliente.RetConsultaCadastro = recRet; oldPed.Cliente.Situacao = SituacaoCadastro(oldPed); context.Entry(oldPed).State = EntityState.Modified; context.SaveChanges(); ctxPed.Cliente.RetConsultaCadastro = recRet; Arquivo = ctxVnd; NotifyOfPropertyChange(() => ctxVnd.Pedidos); NotifyOfPropertyChange(() => Arquivo.Pedidos); Arquivo.ForcePropertyChanged("Pedidos"); ctxPed.Cliente.ForcePropertyChanged("RetConsultaCadastro"); } } catch (ComunicacaoException ex) { if (trysExCom < NumOfRetries) { trysExCom += 1; goto TryAgain; } var consulta = new Model.retConsCad() { ErrorCode = "err_dives", ErrorMessage = ex.Message }; EditarPedido(ped, consulta); } catch (ValidacaoSchemaException ex) { var consulta = new Model.retConsCad() { ErrorCode = "err_dives", ErrorMessage = ex.Message }; EditarPedido(ped, consulta); } catch (DbUpdateException) { throw; } catch (Exception ex) { if (trysExOthers < NumOfRetries) { trysExOthers += 1; goto TryAgain; } var consulta = new Model.retConsCad() { ErrorCode = "err_dives", ErrorMessage = ex.Message }; EditarPedido(ped, consulta); } }); }
private void GetClientes(string path) { var clis = new List <Cliente>(); var Lines = File.ReadLines(path).Select(a => a.Split(';')); CliAdded = 0; CliAtivos = 0; CliAtualizados = 0; using (var context = new ColinfoContext()) { var clientes = (from line in Lines where IsValidCliente(line) select new Cliente { RegiaoCliente = int.Parse(line[0]), NumCliente = int.Parse(line[1]), Sigla = line[3], Razao = line[4], CNPJ = ToCNPJ(line[2]), IE = line[25], Rota = int.Parse(line[31].Last().ToString()), Situacao = CNPJVerif(line[2]), Endereco = new Endereco { xTPLgr = line[45], xPrepLgr = line[46], xLgr = line[48], nro = line[49], xMun = line[51], xBairro = line[52], cMun = line[53], CEP = line[54] } }).ToList(); foreach (var cli in clientes) { CliAtivos = clientes.Count(); NotifyOfPropertyChange(() => CliAtivos); var cliOld = context.Clientes.FirstOrDefault(x => x.RegiaoCliente == cli.RegiaoCliente && x.NumCliente == cli.NumCliente); if (cliOld == null) { context.Clientes.Add(cli); context.SaveChanges(); CliAdded += 1; NotifyOfPropertyChange(() => CliAdded); } else { cliOld.RegiaoCliente = cli.RegiaoCliente; cliOld.NumCliente = cli.NumCliente; cliOld.Razao = cli.Razao; cliOld.CNPJ = cli.CNPJ; cliOld.IE = cli.IE; cliOld.Rota = cli.Rota; cliOld.Situacao = cli.Situacao; cliOld.Endereco = cli.Endereco; context.Entry(cliOld).State = EntityState.Modified; context.SaveChanges(); CliAtualizados += 1; NotifyOfPropertyChange(() => CliAtualizados); } } } }