Ejemplo n.º 1
0
        private void esportaGridPdf()
        {
            try
            {
                ultraGridDocumentExporter1 = new UltraGridDocumentExporter();
                var grids = getFormGrid(MainStandardForm_Fill_Panel.Controls);

                if (grids.Count > 0)
                {
                    var opzioni = new OpzioniStampa();
                    if (opzioni.ShowDialog() == DialogResult.OK)
                    {
                        var grid = findCurrentGrid(grids);
                        var pathTempFile = Utility.GetTempFolder(grid.DisplayLayout.Bands[0].Header.Caption + ".pdf", "pdf");

                        if (opzioni.StampaLogo)
                            ultraGridDocumentExporter1.ExportStarted += ultraGridDocumentExporter1ExportStarted;     

                        var style = grid.DisplayLayout.ViewStyle;
                        if (!opzioni.VisualizzaDettagli)
                            grid.DisplayLayout.ViewStyle = ViewStyle.SingleBand;

                        var restoreDeleteColumn = false;
                        if (grid.DisplayLayout.Bands[0].Columns.Exists("DeleteColumn"))
                        {
                            grid.DisplayLayout.Bands[0].Columns["DeleteColumn"].Hidden = true;
                            restoreDeleteColumn = true;
                        }

                        var rowSelectors = grid.DisplayLayout.Bands[0].Override.RowSelectors;
                        grid.DisplayLayout.Bands[0].Override.RowSelectors = DefaultableBoolean.False;

                        ultraGridDocumentExporter1.TargetPaperOrientation = PageOrientation.Portrait;
                        if (opzioni.GetOrientamento() == OrientamentoStampa.Orizzontale)
                            ultraGridDocumentExporter1.TargetPaperOrientation = PageOrientation.Landscape;

                        try
                        {
                            ultraGridDocumentExporter1.Export(grid, pathTempFile, GridExportFileFormat.PDF);
                        }
                        catch (Exception ex)
                        {
                            log.ErrorFormat("Errore l'esportazione della grid in pdf - EXPORT - {0} - grid:{1} - form text:{2} - path:{3} - azienda:{4}", ex, Utility.GetMethodDescription(), grid.Name, Text, pathTempFile, Login.Instance.CurrentLogin().Azienda);
                            throw;
                        }

                        try
                        {
                            System.Diagnostics.Process.Start(pathTempFile);
                        }
                        catch (System.ComponentModel.Win32Exception exWin)
                        {
                            log.DebugFormat("Non è stata trovata nessuna applicazione per visualizzare il file pdf generato - {0} - grid:{1} - form text:{2} - path:{3} - azienda:{4}", exWin, Utility.GetMethodDescription(), grid.Name, Text, pathTempFile, Login.Instance.CurrentLogin().Azienda);
                            MessageBox.Show("Non è stata trovata nessuna applicazione per visualizzare il file pdf generato.", "Apertura Documento", MessageBoxButtons.OK, MessageBoxIcon.Warning);    
                        }
                        catch (Exception ex)
                        {
                            log.ErrorFormat("Errore l'esportazione della grid in pdf - APERTURA PDF - {0} - grid:{1} - form text:{2} - path:{3} - azienda:{4}", ex, Utility.GetMethodDescription(), grid.Name, Text, pathTempFile, Login.Instance.CurrentLogin().Azienda);
                            throw;
                        }

                        grid.DisplayLayout.ViewStyle = style;
                        grid.DisplayLayout.Bands[0].Override.RowSelectors = rowSelectors;
                        if (restoreDeleteColumn)
                            grid.DisplayLayout.Bands[0].Columns["DeleteColumn"].Hidden = false;

                    }

                    opzioni.Dispose();
                }
            }
            catch (Exception ex)
            {
                
                log.Error("Errore durante l'esportazione della grid in pdf - " + Utility.GetMethodDescription() + " - azienda:" + Login.Instance.CurrentLogin().Azienda, ex);
            }
        }
Ejemplo n.º 2
0
        private void esportaGridPreview()
        {
            try
            {
                
                
                var grids = getFormGrid(MainStandardForm_Fill_Panel.Controls);

                if (grids.Count > 0)
                {
                    var opzioni = new OpzioniStampa();
                    if (opzioni.ShowDialog() == DialogResult.OK)
                    {
                        var grid = findCurrentGrid(grids);
                        if (grid != null)
                        {
                            try
                            {
                                var style = grid.DisplayLayout.ViewStyle;
                                if (!opzioni.VisualizzaDettagli)
                                    grid.DisplayLayout.ViewStyle = ViewStyle.SingleBand;

                                var restoreDeleteColumn = false;
                                if (grid.DisplayLayout.Bands[0].Columns.Exists("DeleteColumn"))
                                {
                                    grid.DisplayLayout.Bands[0].Columns["DeleteColumn"].Hidden = true;
                                    restoreDeleteColumn = true;
                                }

                                var rowSelectors = grid.DisplayLayout.Bands[0].Override.RowSelectors;
                                grid.DisplayLayout.Bands[0].Override.RowSelectors = DefaultableBoolean.False;

                                ultraGridPrintDocument1.DefaultPageSettings.Margins.Left = 5;
                                ultraGridPrintDocument1.DefaultPageSettings.Margins.Right = 5;
                                ultraGridPrintDocument1.DefaultPageSettings.Margins.Bottom = 5;
                                ultraGridPrintDocument1.DefaultPageSettings.Landscape = opzioni.GetOrientamento() == OrientamentoStampa.Orizzontale;
                                ultraGridPrintDocument1.Grid = grid;
                                ultraGridPrintDocument1.Header.Height = 30;
                                if (opzioni.StampaLogo)
                                    ultraGridPrintDocument1.Header.Document.PrintPage += documentPrintPage;

                                //ultraGridPrintDocument1.Header.TextLeft = "Condominio: 005 - via Ghirardini 5, Bologna";
                                //ultraGridPrintDocument1.Header.Padding.Bottom = 10;
                                //ultraGridPrintDocument1.Header.Padding.Left = 10;
                                //ultraGridPrintDocument1.Header.Appearance.FontData.Name = @"Tahoma, Arial, SansSerif";
                                //ultraGridPrintDocument1.Header.Appearance.FontData.SizeInPoints = 12;
                                //ultraGridPrintDocument1.Header.Appearance.TextHAlign = HAlign.Left;
                                //ultraPrintPreviewDialog1.Close();
                                using (var ultraPrintPreviewDialog = new UltraPrintPreviewDialog())
                                {
                                    ultraPrintPreviewDialog.Document = ultraGridPrintDocument1;
                                    ultraPrintPreviewDialog.ShowDialog();
                                }

                                grid.DisplayLayout.ViewStyle = style;
                                grid.DisplayLayout.Bands[0].Override.RowSelectors = rowSelectors;
                                if (restoreDeleteColumn)
                                    grid.DisplayLayout.Bands[0].Columns["DeleteColumn"].Hidden = false;
                            }
                            catch (Exception ex)
                            {
                                var formName = string.Empty;
                                var form = FindForm();
                                if (form != null)
                                    formName = form.Name;
                                
                                _log.ErrorFormat("Errore durante la visualizzazione della preview della grid - {0} - grid:{1} - form:{2}", ex, Utility.GetMethodDescription(), grid.Name, formName);
                            }
                        }
                    }

                    opzioni.Dispose();
                }
            }
            catch (Exception ex)
            {
                var formName = string.Empty;
                var form = FindForm();
                if (form != null)
                    formName = form.Name;
                
                _log.ErrorFormat("Errore durante la visualizzazione della preview della grid - {0} - form:{1}", ex, Utility.GetMethodDescription(), formName);
            }
        }