bruno-pere Posted January 18, 2013 Posted January 18, 2013 Not a component for UniGUI, but a good component to use in UniGUI. My current web application needs basic reporting features, so I use this instead of other reporting solutions. So, if anyone needs to export or print a dataset using basic commands, this can help. This component exports any linked dataset to HTML, in disk, then you can show a UniHTMLFrame of it and print. Working here for IE, Chrome and Firefox. The component is attached. Bye! Bruno Lovatti Use like this: procedure TUniFrameInv.CreateHTML(fname: string); begin ToHTML.HTML.Clear; ToHTML.PageOptions.Title := 'Produtos'; ToHTML.PageOptions.Header := 'Produtos da Extrafruti para Inventário <br>' + '<br> LOJA: ' + TrimRight(UniCBoxLoja.Text) + '<br> DATA: ' + FormatDateTime('dd/MMM/yyyy - hh:mm:ss',now) + '<br> ENCARREGADO: ' + UniMainModule.UsuarioLogado; if FileExists(fname) then try SysUtils.DeleteFile(fname); except // end; //ToHTML.PageOptions.Footer := FormatDateTime('dd/MMM/yyyy - hh:mm:ss',now); ToHTML.FileName := fname; // script - test (*ToHTML.Script.Add('<script type="text/javascript">'); ToHTML.Script.Add('$(function(){'); ToHTML.Script.Add(' printPage();'); ToHTML.Script.Add('});'); ToHTML.Script.Add(' function printPage() {'); ToHTML.Script.Add(' focus(); print(); }'); ToHTML.Script.Add('</script>');*) // accents for brazilian portuguese ToHTML.Meta.Clear; ToHTML.Meta.Add('<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" />'); ToHTML.Meta.Add('<meta http-equiv="cache-control" content="no-cache" />'); ToHTML.Meta.Add('<meta http-equiv="pragma" content="no-cache" />'); ToHTML.CreateHTML; //ToHTML.SaveHTML; end; Example of call: fname := AppPath + 'impressao\PROD_' + FormatDateTime('dd.mm.yyyy_hh.mm.ss',now)+'_'+ TrimRight(UniCBoxLoja.Text)+'.html'; CreateHTML(fname); And the events like this: procedure TUniFrameInv.ToHTMLAcceptColumn(Field: TField; var Accept: Boolean); var fn: string; begin fn := Field.FieldName; Accept := (fn='COD_PROD_SPALLA') or (fn='COD_PROD_EXT') or (fn='NOME') or (fn='UNIDADE') or (fn='QUANTIDADE') or (fn='QUANTIDADE_DEV') or (fn='DES_GRUPO') or (fn='DES_SUBGRUPO'); end; procedure TUniFrameInv.ToHTMLAcceptRow(Dataset: TDataSet; var Accept: Boolean); begin Accept := true; end; procedure TUniFrameInv.ToHTMLGetColumnWidth(Field: TField; var ColumnWidth: Integer; var ColumnTitle: string); begin if Field.FieldName='COD_PROD_SPALLA' then begin ColumnWidth := 50; ColumnTitle := 'Cód. Spalla'; end else if Field.FieldName='COD_PROD_EXT' then begin ColumnWidth := 50; ColumnTitle := 'Cód. na Loja'; end else if Field.FieldName='NOME' then begin ColumnWidth := 350; ColumnTitle := 'Nome'; end else if Field.FieldName='UNIDADE' then begin ColumnWidth := 10; ColumnTitle := 'Unid.'; end else if Field.FieldName='QUANTIDADE' then begin ColumnWidth := 150; ColumnTitle := 'Estoque'; end else if Field.FieldName='QUANTIDADE_DEV' then begin ColumnWidth := 150; ColumnTitle := 'Devolução'; end else if (Field.FieldName='DES_GRUPO') then begin ColumnWidth := 60; ColumnTitle := 'Grupo'; end else if (Field.FieldName='DES_SUBGRUPO') then begin ColumnWidth := 80; ColumnTitle := 'Subgrupo'; end; end; procedure TUniFrameInv.ToHTMLGetFieldValue(Field: TField; var FieldValue: string); begin if (Field.FieldName='QUANTIDADE') or (Field.FieldName='QUANTIDADE_DEV') then FieldValue := FormatFloat('0.##',Field.AsFloat) else if (Field.FieldName='DES_GRUPO') or (Field.FieldName='DES_SUBGRUPO') then FieldValue := copy(Field.AsString,1,13) else if (Field.FieldName='NOME') then FieldValue := copy(Field.AsString,1,100); end; procedure TUniFrameInv.ToHTMLSummaryRow(Field: TField); begin if Field.FieldName = 'COD_PROD_SPALLA' then Inc(Count); end; procedure TUniFrameInv.ToHTMLSummaryStart; begin Count := 0; end; procedure TUniFrameInv.ToHTMLSummaryText(Field: TField; var SummaryText: string); begin if Field.FieldName = 'COD_PROD_SPALLA' then SummaryText := IntToStr( Count ); end; To open in HTMLFrame (Form ShowLink attached): procedure TUniFrameInv.OpenHTML(fname: string); var url: string; begin url := 'http://' + UniSession.Host + '/impressao/' + ExtractFileName( fname ); UniFormShowLink.UniURL1.HTML.Assign(ToHTML.HTML); UniFormShowLink.ShowModal; end; In the print button ExtEvents of Form ShowLink: function OnClick(sender, e) { var frm = UniFormShowLink.UniURL1.iframe; if (frm) { //zPrint(frm.contentWindow); printIframe(frm); } } DatasetToHTML.zip UnitShowLink.zip 1 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.