/// <summary> /// Génère le rendu du contenu du contrôle serveur Web via le navigateur du client à l'aide de l'objet <see cref="T:System.Web.UI.HtmlTextWriter" /> spécifié. /// </summary> /// <param name="writer"><see cref="T:System.Web.UI.HtmlTextWriter" /> utilisé pour afficher le contenu du contrôle serveur sur le navigateur du client.</param> protected override void Render(System.Web.UI.HtmlTextWriter writer) { if (RenderWithNoTableTag) { System.IO.StringWriter sw = new System.IO.StringWriter(); System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(sw); base.Render(hw); hw.Flush(); hw.Close(); string origTag = sw.ToString(); if (origTag.IndexOf("<tr") < 0) { writer.Write(""); } else { string newTag = origTag.Substring(origTag.IndexOf("<tr"), origTag.LastIndexOf("</tr>") + 5 - origTag.IndexOf("<tr")); writer.Write(newTag); } } else { base.Render(writer); } }
internal string DrawHtml(string uniqueID, WebGridHtmlWriter writer, Grid grid, RowCell cell) { string theValueToShow = Value(cell); HtmlEditor e = new HtmlEditor { ID = uniqueID, ImagePath = Grid.ImagePath, UserBRonCarriageReturn = true, Width = (WidthEditableColumn != Unit.Empty ? WidthEditableColumn : 500), Height = (HeightEditableColumn != Unit.Empty ? HeightEditableColumn : 400), Text = theValueToShow }; e.ImagePath = GridConfig.Get("WGEditorImagePath", grid.ImagePath); StringBuilder sb = new StringBuilder(); StringWriter sw = new StringWriter(sb); System.Web.UI.HtmlTextWriter mywriter = new System.Web.UI.HtmlTextWriter(sw); e.RenderControl(mywriter); mywriter.Flush(); mywriter.Close(); return(sb.ToString()); }
private static string RenderTableToString(Table fullTable) { using (var ts = new StringWriter()) using (var html = new System.Web.UI.HtmlTextWriter(ts)) { // Not entirely sure about this part fullTable.RenderControl(html); html.Flush(); return(HttpUtility.HtmlDecode(ts.ToString().Replace("\t", "").Replace(Environment.NewLine, ""))); } }
public string Export(ref DataTable table) { string result = String.Empty; System.Web.UI.HtmlTextWriter _writer = GetWriter(); if (_writer != null) { string _document = ToString(); if (_document.Length > "</Workbook>".Length) { _document = _document.Remove(_document.Length - "</Workbook>".Length - 1, "</Workbook>".Length); } _writer.Write(_document); _writer.Flush(); CreateAssetSheet(ref table); _writer.Write("</Workbook>"); _writer.Flush(); } return(result); }
private void CreateAssetSheet(ref DataTable table) { System.Web.UI.HtmlTextWriter _writer = GetWriter(); if ((table != null) && (_writer != null)) { DataRow[] foundRows = table.Select(); if (foundRows != null) { if (foundRows.Length > 0) { Assets.ExcelColumns columns = null; columns = CreateColumns(ref columns, ref table); string _start_worksheet = "<Worksheet ss:Name=\"BulkAssets\">"; string _end_worksheet = "</Worksheet>"; _writer.Write(_start_worksheet); Assets.ExcelTable _table = this.CreateWorkSheet("BulkAssets", ref columns); if (_table != null) { AddHeader(ref _table, ref columns); _writer.Write(_table.ToHeader()); bool is_white = true; for (int row_index = 0; row_index < foundRows.Length; row_index++) { DataRow _row = foundRows[row_index]; if (_row != null) { Assets.ExcelRow excel_row = new Assets.ExcelRow(_table); if (excel_row != null) { UpdateRow(ref excel_row, ref table, ref _row, is_white); is_white = !is_white; _writer.Write(excel_row.ToString()); _writer.Flush(); } } } _writer.Write(_table.ToFooter()); } _writer.Write(_end_worksheet); } } } }
/// <summary> /// Gera o boleto /// </summary> /// <param name="codigoContaReceber"></param> /// <param name="codigoNotaFiscal"></param> /// <param name="codigoLiberacao"></param> /// <param name="codigoContaBanco"></param> /// <param name="carteira"></param> /// <param name="especieDocumento"></param> /// <param name="instrucoes"></param> /// <param name="ignorarNotificacaoBoletoImpresso"></param> /// <param name="conteudoBoleto"></param> /// <returns></returns> public Colosoft.Business.OperationResult <IEnumerable <uint> > GerarBoleto( int codigoContaReceber, int codigoNotaFiscal, int codigoLiberacao, int codigoCte, int codigoContaBanco, string carteira, int especieDocumento, string[] instrucoes, System.IO.Stream conteudoBoleto) { var idsContasR = new List <uint>() { (uint)codigoContaReceber }; if (codigoNotaFiscal > 0) { idsContasR = ContasReceberDAO.Instance.ObtemPelaNfe((uint)codigoNotaFiscal).ToList(); } if (codigoCte > 0) { idsContasR = ContasReceberDAO.Instance.ObterIdContaRPeloIdCte((uint)codigoCte).ToList(); } if ((idsContasR.Count == 0 || idsContasR.FirstOrDefault() == 0) && codigoLiberacao > 0) { var contasReceberLiberacao = ContasReceberDAO.Instance.GetByPedidoLiberacao(0, (uint)codigoLiberacao, null); if (contasReceberLiberacao != null && contasReceberLiberacao.Count > 0) { if (!Glass.Configuracoes.FinanceiroConfig.EmitirBoletoApenasContaTipoPagtoBoleto) { idsContasR = contasReceberLiberacao.Select(f => f.IdContaR).ToList(); } else { var idsContaRBoleto = new List <ContasReceber>(); var contasRecebimentoBoleto = UtilsPlanoConta.ContasRecebimentoBoleto().Split(','); foreach (var item in contasReceberLiberacao) { if (contasRecebimentoBoleto.Contains(Conversoes.UintParaStr(item.IdConta))) { idsContaRBoleto.Add(item); } } if (idsContaRBoleto.Count > 0) { idsContasR = idsContaRBoleto.Select(f => f.IdContaR).ToList(); } else { throw new Exception("Nenhuma conta encontrada para gerar o boleto"); } } } } using (var outPdf = new PdfSharp.Pdf.PdfDocument()) { foreach (var id in idsContasR) { var writer = new System.IO.StringWriter(); var htmlWriter = new System.Web.UI.HtmlTextWriter(writer); BoletoNet.BoletoBancario.HtmlOfflineHeader(writer.GetStringBuilder()); DadosBoleto.Instance.ObtemDadosBoleto(id, (uint)codigoContaBanco, carteira, especieDocumento, instrucoes, htmlWriter); BoletoNet.BoletoBancario.HtmlOfflineFooter(writer.GetStringBuilder()); htmlWriter.Flush(); var htmlStr = writer.GetStringBuilder().ToString(); var converter = new SelectPdf.HtmlToPdf(100); converter.Options.MarginTop = 30; converter.Options.MarginBottom = 10; converter.Options.MarginLeft = 30; converter.Options.MarginRight = 10; var doc = converter.ConvertHtmlString(htmlStr); using (var stream = new System.IO.MemoryStream()) { doc.Save(stream); using (var pdfBoleto = PdfSharp.Pdf.IO.PdfReader.Open(stream, PdfSharp.Pdf.IO.PdfDocumentOpenMode.Import)) CopyPages(pdfBoleto, outPdf); doc.Close(); } } outPdf.Save(conteudoBoleto, false); if (Configuracoes.FinanceiroConfig.EnviarEmailEmitirBoleto && !Impresso.Instance.VerificarPossuiBoletoImpresso(null, (int)idsContasR.FirstOrDefault())) { if (codigoNotaFiscal > 0) { var idLoja = NotaFiscalDAO.Instance.ObtemIdLoja((uint)codigoNotaFiscal); if (idLoja == 0) { throw new Exception("Não foi possível recuperar a loja da nota fiscal ao salvar o e-mail a ser enviado."); } var idCliente = NotaFiscalDAO.Instance.ObtemIdCliente((uint)codigoNotaFiscal); var email = ClienteDAO.Instance.GetEmail(null, idCliente.GetValueOrDefault(0)); if (!string.IsNullOrWhiteSpace(email)) { var numNfe = NotaFiscalDAO.Instance.ObtemNumeroNf(null, (uint)codigoNotaFiscal); var texto = string.Format("Prezado(a) cliente,\nSegue anexo boleto da sua NF-e: {0}.\n\nAtt.\n{1}", numNfe, LojaDAO.Instance.GetElement(null, idLoja).RazaoSocial); var assunto = string.Format("Boleto NF-e: {0}", numNfe); var caminho = string.Format("{0}", "BoletoNFe" + codigoNotaFiscal); var anexo = new Data.Model.AnexoEmail(caminho, string.Format("boletoNFe{0}.pdf", numNfe)); uint idEmail = 0; try { idEmail = Email.EnviaEmailAsyncComTransacao(idLoja, email, assunto, texto, Email.EmailEnvio.Comercial, false, anexo); //Salva o pdf em uma pasta local outPdf.Save(Armazenamento.ArmazenamentoIsolado.DiretorioBoletos + string.Format("\\anexo{0}.pdf", anexo.IdAnexoEmail)); } catch (System.Exception ex) { ErroDAO.Instance.InserirFromException("GerarBoletoAnexoEmail", ex); if (idEmail > 0) { FilaEmailDAO.Instance.DeleteByPrimaryKey(idEmail); } } } } else if (codigoCte > 0) { var idContaR = ContasReceberDAO.Instance.ObterIdContaRPeloIdCte((uint)codigoCte).FirstOrDefault(); var idLoja = ContasReceberDAO.Instance.ObtemIdLoja(null, idContaR); if (idLoja == 0) { throw new Exception("Não foi possível recuperar a loja da nota fiscal ao salvar o e-mail a ser enviado."); } var idCliente = ContasReceberDAO.Instance.ObtemIdCliente((uint)codigoCte); var email = ClienteDAO.Instance.GetEmail(null, idCliente); if (!string.IsNullOrWhiteSpace(email)) { var numCte = Data.DAL.CTe.ConhecimentoTransporteDAO.Instance.ObtemNumeroCte((uint)codigoCte); var texto = string.Format("Prezado(a) cliente,\nSegue anexo boleto do seu Ct-e: {0}.\n\nAtt.\n{1}", numCte, LojaDAO.Instance.GetElement(null, (uint)idLoja).RazaoSocial); var assunto = string.Format("Boleto CT-e: {0}", numCte); var caminho = string.Format("{0}", "BoletoCTe" + codigoCte); var anexo = new Data.Model.AnexoEmail(caminho, string.Format("boletoCTe{0}.pdf", numCte)); uint idEmail = 0; try { idEmail = Email.EnviaEmailAsyncComTransacao((uint)idLoja, email, assunto, texto, Email.EmailEnvio.Comercial, false, anexo); //Salva o pdf em uma pasta local outPdf.Save(Armazenamento.ArmazenamentoIsolado.DiretorioBoletos + string.Format("\\anexo{0}.pdf", anexo.IdAnexoEmail)); } catch (System.Exception ex) { ErroDAO.Instance.InserirFromException("GerarBoletoAnexoEmail", ex); if (idEmail > 0) { FilaEmailDAO.Instance.DeleteByPrimaryKey(idEmail); } } } } } foreach (var b in idsContasR) { Impresso.Instance.IndicarBoletoImpresso((int)b, codigoNotaFiscal, codigoLiberacao, codigoCte, codigoContaBanco, UserInfo.GetUserInfo); } } return(new Colosoft.Business.OperationResult <IEnumerable <uint> >(idsContasR)); }
internal string DrawHtml(string uniqueID, WebGridHtmlWriter writer, Grid grid,RowCell cell) { string theValueToShow = Value(cell); HtmlEditor e = new HtmlEditor { ID = uniqueID, ImagePath = Grid.ImagePath, UserBRonCarriageReturn = true, Width = (WidthEditableColumn != Unit.Empty ? WidthEditableColumn : 500), Height = (HeightEditableColumn != Unit.Empty ? HeightEditableColumn : 400), Text = theValueToShow }; e.ImagePath = GridConfig.Get("WGEditorImagePath", grid.ImagePath); StringBuilder sb = new StringBuilder(); StringWriter sw = new StringWriter(sb); System.Web.UI.HtmlTextWriter mywriter = new System.Web.UI.HtmlTextWriter(sw); e.RenderControl(mywriter); mywriter.Flush(); mywriter.Close(); return sb.ToString(); }