Example #1
0
        public static void GerarDanfe(String xmlPath, String logoPath)
        {
            try
            {
                DanfeViewModel model = DanfeViewModel.CreateFromXmlFile(xmlPath);
                DanfeDocumento danfe = new DanfeDocumento(model);

                if (!String.IsNullOrWhiteSpace(logoPath))
                {
                    danfe.AdicionarLogo(logoPath);
                }

                danfe.Gerar();

                String outFile = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(xmlPath), model.ChaveAcesso + ".pdf");
                danfe.Salvar(outFile);

                var process = System.Diagnostics.Process.Start(outFile);

                if (process == null)
                {
                    MessageBox.Show(String.Format("Não foi possível abrir o DANFE gerado.\nEle foi gravado em: {0}", outFile), Strings.AppName, MessageBoxButton.OK, MessageBoxImage.Information);
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, "Erro ao gerar o DANFE", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Example #2
0
        public void XmlPasta()
        {
            var arquivos = Directory.EnumerateFiles("../../XmlTestes", "*.xml");

            foreach (var arquivo in arquivos)
            {
                try
                {
                    DanfeViewModel model = DanfeViewModel.CreateFromXmlFile(arquivo);
                    using (DanfeDocumento danfe = new DanfeDocumento(model))
                    {
                        danfe.Gerar();

                        using (MemoryStream ms = new MemoryStream())
                        {
                            danfe.Salvar(ms);
                        }
                    }
                }
                catch (Exception e)
                {
                    Debugger.Break();
                }
            }
        }
Example #3
0
        public static void GerarDanfe(String xmlPath, String logoPath)
        {
            try
            {
                DanfeViewModel model = DanfeViewModel.CreateFromXmlFile(xmlPath);
                DanfeDocumento danfe = new DanfeDocumento(model);

                if(!String.IsNullOrWhiteSpace(logoPath))
                {
                    danfe.AdicionarLogo(logoPath);
                }

                danfe.Gerar();

                String outFile = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(xmlPath), model.ChaveAcesso + ".pdf");
                danfe.Salvar(outFile);

                var process = System.Diagnostics.Process.Start(outFile);

                if(process == null)
                {
                    MessageBox.Show(String.Format("Não foi possível abrir o DANFE gerado.\nEle foi gravado em: {0}", outFile), Strings.AppName, MessageBoxButton.OK, MessageBoxImage.Information);
                }

            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, "Erro ao gerar o DANFE", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }