/// <summary>
        /// Writes data contained in ADO.NET DataTable object to path stored in OutputFileName property.
        /// </summary>
        /// <param name="dt">DataTable object containing data to be output.</param>
        /// <returns>True if output operation is successful. False if write fails.</returns>
        public bool WriteDataToOutput(DataTable dt)
        {
            bool          success = true;
            PFPDFDocument pdfDoc  = null;

            try
            {
                if (File.Exists(_outputFileName))
                {
                    if (_replaceExistingFile)
                    {
                        File.SetAttributes(_outputFileName, FileAttributes.Normal);
                        File.Delete(_outputFileName);
                    }
                    else
                    {
                        _msg.Length = 0;
                        _msg.Append("File exists and ReplaceExistingFile set to False. Write to Output has failed.");
                        throw new System.Exception(_msg.ToString());
                    }
                }

                pdfDoc = new PFPDFDocument(this.OutputFileName, this.ReplaceExistingFile);
                pdfDoc.WriteDataToDocument(dt);
            }
            catch (System.Exception ex)
            {
                success     = false;
                _msg.Length = 0;
                _msg.Append(AppGlobals.AppMessages.FormatErrorMessage(ex));
                throw new System.Exception(_msg.ToString());
            }
            finally
            {
                if (pdfDoc != null)
                {
                    pdfDoc = null;
                }
            }

            return(success);
        }
Exemplo n.º 2
0
        public void OutputToPDFDocument(MainForm frm)
        {
            PFPDFDocument pdfDoc = null;
            DataSet       ds     = null;

            try
            {
                _msg.Length = 0;
                _msg.Append("OutputToPDFDocument started ...\r\n");
                Program._messageLog.WriteLine(_msg.ToString());

                ds = new DataSet();
                ds.ReadXml(@"C:\Testfiles\C1Testing\BostonZipInfo.xml");
                ds.Tables[0].TableName = "RandomNames";

                pdfDoc = new PFPDFDocument(@"c:\temp\SharpRandomNames5Cols.pdf", true);
                pdfDoc.WriteDataToDocument(ds.Tables[0]);

                ds = null;
                ds = new DataSet();
                ds.ReadXml(@"C:\Testfiles\C1Testing\RandomNames100Lines.xml");
                ds.Tables[0].TableName = "RandomNames";

                pdfDoc = new PFPDFDocument(@"c:\temp\SharpRandomNames17Cols.pdf", true);
                pdfDoc.WriteDataToDocument(ds.Tables[0]);
            }
            catch (System.Exception ex)
            {
                _msg.Length = 0;
                _msg.Append(AppGlobals.AppMessages.FormatErrorMessage(ex));
                Program._messageLog.WriteLine(_msg.ToString());
                AppMessages.DisplayErrorMessage(_msg.ToString(), _saveErrorMessagesToAppLog);
            }
            finally
            {
                _msg.Length = 0;
                _msg.Append("\r\n... OutputToPDFDocument finished.");
                Program._messageLog.WriteLine(_msg.ToString());
            }
        }