private void FrmViewReport_Load(object sender, System.EventArgs e) { try { ReportPages = 0; ReportPageRequestContext oPageContext = new ReportPageRequestContext(); ReportPages = ReportDoc.FormatEngine.GetLastPageNumber(oPageContext); AbilitaPageNavigator(ReportPages > 1); } catch (Exception E) { meta.LogError("Errore nel calcolo della stampa con i parametri:\r\n" + elencoparametri, E); QueryCreator.ShowException("Errore nel calcolo della stampa", E); AbilitaPageNavigator(false); errore = true; } isInited = true; }
/// <summary> /// Manda in stampa il documento /// </summary> /// <param name="ShowPrintDialog">True vuol dire che sono in anteprima, ricompare /// il PrintDialog</param> public bool StampaReport() { if (errore) { return(false); } if (printerName == null) { return(false); } if (ReportDoc == null) { return(false); } if (oneprint && printed) { MessageBox.Show("Una sola copia della stampa è ammessa."); return(false); } //se in anteprima mostro il printDialog con tutte le proprietà impostate //in precedenza PrintDialog pd = new PrintDialog(); pd.PrinterSettings = new PrinterSettings(); pd.PrinterSettings.PrinterName = printerName; string papersize = ModuleReport["papersize"].ToString(); //pd.Document = pdoc; //pd.PrinterSettings = pdoc.PrinterSettings; ReportPages = 1; ReportPageRequestContext oPageContext = new ReportPageRequestContext(); operating = true; try { ReportPages = ReportDoc.FormatEngine.GetLastPageNumber(oPageContext); } catch (Exception E) { QueryCreator.ShowException("Errore nel calcolo del numero totale delle pagine", E); errore = true; operating = false; return(false); } if (ReportPages < 1) { ReportPages = 1; } pd.AllowCurrentPage = false; pd.AllowSomePages = (ReportPages > 1) && (!oneprint); pd.AllowSelection = false; if (pd.AllowSomePages) //pdoc.PrinterSettings != null && { pd.PrinterSettings.FromPage = 1; pd.PrinterSettings.ToPage = ReportPages; } pd.AllowPrintToFile = !oneprint; if (papersize.ToUpper() != "ASK") { setPrintDocument(pd.PrinterSettings, pd.PrinterSettings.DefaultPageSettings); } if (pd.ShowDialog(this) != DialogResult.OK) { operating = false; return(false); } //Reimposto il formato carta //setPrintDocument(ref pdoc); //pdoc.PrinterSettings = pd.PrinterSettings; //pdoc.PrinterSettings.Collate = pd.PrinterSettings.Collate; //if (pdoc.PrinterSettings != null) { pd.PrinterSettings.Collate = (pd.PrinterSettings.Copies > 1) && (pd.PrinterSettings.ToPage > pd.PrinterSettings.FromPage); //} //imposto la stampante selezionata try { //ReportDoc.PrintOptions.PrinterName = pdoc.DefaultPageSettings.PrinterSettings.PrinterName; ReportDoc.PrintOptions.PrinterName = pd.PrinterSettings.PrinterName; } catch (Exception E) { operating = false; QueryCreator.ShowException("La stampante selezionata (" + printerName + ") non è valida", E); errore = true; return(false); } //Se non sono in anteprima stampo direttamente try { ReportDoc.PrintToPrinter(pd.PrinterSettings, pd.PrinterSettings.DefaultPageSettings, false); //ReportDoc.PrintToPrinter(pdoc.PrinterSettings.Copies, // (pdoc.PrinterSettings.Copies > 1) && // (pdoc.PrinterSettings.ToPage > pdoc.PrinterSettings.FromPage), //pdoc.PrinterSettings.Collate, // pdoc.PrinterSettings.FromPage, // pdoc.PrinterSettings.ToPage); printed = true; operating = false; return(true); } catch (Exception E) { errore = true; operating = false; if (!E.ToString().Contains("OnStartPrint") && !E.ToString().Contains("OnEndPage")) { meta.LogError("Errore nella stampa\r\n" + elencoparametri, E); } QueryCreator.ShowException( QueryCreator.GetPrintable( "Si è verificato un errore in fase di invio dei dati alla stampante.\n" + "Controllare che il server di stampa sia acceso ed accessibile dal proprio computer."), E); return(false); } }