private void PageSetup(object sender, ReportCardWorkerJob e) { Publisher.PageSetup setup = (Publisher.PageSetup)e.Data; double width = (float)setup.PageWidth * 96.0 / 72.0; double height = (float)setup.PageHeight * 96.0 / 72.0; if (InvokeRequired) { Invoke(new ReportCardWorkerJobHandler(PageSetup), new object[] { sender, e }); } else { pdPrint.UserPageRangeEnabled = false; pdPrint.PrintTicket.PageMediaSize = new PageMediaSize(width, height); pdPrint.PrintTicket.CopyCount = 1; pdPrint.PrintTicket.Collation = Collation.Collated; pdPrint.PrintTicket.PageMediaType = PageMediaType.Plain; if (width > height) { pdPrint.PrintTicket.PageOrientation = PageOrientation.Landscape; } else { pdPrint.PrintTicket.PageOrientation = PageOrientation.Portrait; } this.TemplateGood = true; if (worker.DataSourcePath != null) { datasourcepath = worker.DataSourcePath; tbDatasource.Text = datasourcepath; tbDatasource.Select(tbDatasource.Text.Length, 0); tbDatasource.ScrollToCaret(); OpenDatasource(); } else { BrowseForDatasource(); } } }
private void PrintXPSDocument(object sender, ReportCardWorkerJob e) { if (InvokeRequired) { Invoke(new ReportCardWorkerJobHandler(PrintXPSDocument), new object[] { sender, e }); } else { XpsDocument exps = e.Data as XpsDocument; if (exps != null) { try { pdPrint.PrintDocument(exps.GetFixedDocumentSequence().DocumentPaginator, Path.GetFileNameWithoutExtension(this.templatepath)); } catch { CancelMerge(); } } } }
private void OperationStatus(object sender, ReportCardWorkerJob e) { if (InvokeRequired) { Invoke(new ReportCardWorkerJobHandler(OperationStatus), new object[] { sender, e }); } else { if (e.Error != null) { string msg; if (e.Error is System.IO.IOException && e.Msg == ReportCardWorkerMessage.SavePDF) { msg = String.Format( "Could not write to the PDF file when merging record {0}\n" + "Please check that the PDF file is not open\n" + "Do you wish to retry the operation, skip the record, or cancel?", e.Data.ToString() ); } else { msg = String.Format( "Caught error when processing record {0}\n" + "Do you wish to retry the operation, skip the record, or cancel?\n\n" + " Operation = {1}\n" + " Name = {2}\n" + " Error:\n{3}\n", e.Data.ToString(), e.Msg.ToString(), e.Name, e.Error.ToString() ); } int res = NativeMethods.MsgBox( IntPtr.Zero, msg, "Error processing record", NativeMethods.MB_CANCELTRYCONTINUE | NativeMethods.MB_ICONERROR | NativeMethods.MB_TASKMODAL | NativeMethods.MB_DEFBUTTON2 ); if (res == NativeMethods.IDCANCEL) { e.Cancel = true; ssStatusText.Text = "Error processing record"; CancelMerge(); } else if (res == NativeMethods.IDTRYAGAIN) { e.Retry = true; } } } }
private void MergeComplete(object sender, ReportCardWorkerJob e) { if (InvokeRequired) { Invoke(new ReportCardWorkerJobHandler(MergeComplete), new object[] { sender, e }); } else { ssProgress.Visible = false; ssStatusText.Text = "Merge complete"; EnableControls(); } }
private void UpdateStatusBar(object sender, ReportCardWorkerJob e) { if (InvokeRequired) { Invoke(new ReportCardWorkerJobHandler(UpdateStatusBar), new object[] { sender, e }); } else { ssStatusText.Text = e.Name; if (e.Data == null) { ssProgress.Visible = false; } else if (e.Data is int) { ssProgress.Value = (int)e.Data; ssProgress.Visible = true; } else if (e.Data is float) { ssProgress.Value = (int)((float)e.Data * 100); ssProgress.Visible = true; } else { ssProgress.Visible = false; } } }
private void TemplateOpened(object sender, ReportCardWorkerJob e) { if (InvokeRequired) { Invoke(new ReportCardWorkerJobHandler(TemplateOpened), new object[] { sender, e }); } else { if (e.Error != null) { ssStatusText.Text = "Could not open template"; MessageBox.Show("Could not open the specified template.\n" + "Please specify the Microsoft Publisher template to use.\n" + e.Error.ToString(), "Could not open template", MessageBoxButtons.OK, MessageBoxIcon.Error); btnTemplateBrowse_Click(this, EventArgs.Empty); } else { ssStatusText.Text = "Fetching Page Setup"; worker.BeginGetPageSetup(PageSetup); } } }
private void SetNames(object sender, ReportCardWorkerJob e) { if (InvokeRequired) { Invoke(new ReportCardWorkerJobHandler(SetNames), new object[] { sender, e }); } else { if (e.Error != null) { ssStatusText.Text = "Could not open datasource"; MessageBox.Show("Could not open the datasource.\n" + "Please specify the Microsoft Excel workbook to use as a datasource.\n" + e.Error.ToString(), "Could not open datasource", MessageBoxButtons.OK, MessageBoxIcon.Error); btnDatasourceBrowse_Click(this, EventArgs.Empty); } else { this.names = (string[])e.Data; clbNames.Items.Clear(); foreach (string name in names) { clbNames.Items.Add(name); if (this.initialnames == null || this.initialnames.Count == 0 || this.initialnames.Contains(name)) { clbNames.SetItemCheckState(clbNames.Items.IndexOf(name), CheckState.Checked); } } this.initialnames = null; DatasourceGood = true; ssStatusText.Text = "Ready"; EnableControls(); } } }