Esempio n. 1
0
        private void BtnGerarRelatorio_Click(object sender, EventArgs e)
        {
            var model = new RelatorioPessoaModel
            {
                Nome           = tbNome.Text,
                Sobrenome      = tbSobrenome.Text,
                Idade          = (int)tbIdade.Value,
                DataNascimento = dtNascimento.Value,
                DataAdmissao   = dtAdmissao.Value,
                DataPromocao   = dtPromocao.Value,
                Descricao      = rtbDescricao.Text
            };

            var result = RelatorioPessoa.GerarRelatorio(model);

            if (result)
            {
                MessageBox.Show("Relatório gerado com Sucesso!!!");
            }
            else
            {
                MessageBox.Show("Erro ao gerar o relatório");
            }
        }
Esempio n. 2
0
        public static bool GerarRelatorio(RelatorioPessoaModel model)
        {
            bool result = false;

            try
            {
                using (DocX document = DocX.Create("../../../GerarRelatorio.Business/Documento/" + @"Relatório.docx"))
                {
                    // Adicionado um titulo
                    document.InsertParagraph("Relatório de Pessoa").FontSize(15d).SpacingAfter(50d).Alignment = Alignment.center;

                    //inserindo um paragrafo no documento
                    var pTitle = document.InsertParagraph();

                    //dando append no texto e formatando (subtitulo).
                    pTitle.Append("Dados da Pessoa")
                    .Font(new Xceed.Words.NET.Font("Arial"))
                    .FontSize(18)
                    .Color(Color.Black)
                    .Bold()
                    .SpacingAfter(40);

                    ///Dados das pessoa
                    var array = model.PropriedadesPessoa();
                    foreach (var item in array)
                    {
                        var p = document.InsertParagraph();
                        if (!item.Key.Contains("Descricao"))
                        {
                            p.Append(item.Key + ":\t")
                            .Font(new Xceed.Words.NET.Font("Times New Roman"))
                            .Color(Color.Black)
                            .Bold()
                            .Append(item.Value)
                            .Font(new Xceed.Words.NET.Font("Times New Roman"))
                            .Color(Color.Black);
                        }
                        else
                        {
                            p.Append(item.Key + ":\n")
                            .Font(new Xceed.Words.NET.Font("Times New Roman"))
                            .Color(Color.Black)
                            .Bold()
                            .Append(item.Value)
                            .Font(new Xceed.Words.NET.Font("Times New Roman"))
                            .FontSize(10)
                            .CapsStyle(CapsStyle.caps)
                            .Color(Color.Black);
                        }
                    }

                    // Salvando o codumento no diretório.
                    document.Save();
                    result = true;
                }
            }
            catch (Exception ex)
            {
                result = false;
            }
            return(result);
        }