Пример #1
0
        public void OutputToRTFDocument(MainForm frm)
        {
            PFRTFDocument rtfDoc = null;
            DataSet       ds     = null;

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

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

                rtfDoc = new PFRTFDocument(@"c:\temp\WordRandomNames.rtf", true);
                rtfDoc.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... OutputToRTFDocument finished.");
                Program._messageLog.WriteLine(_msg.ToString());
            }
        }
Пример #2
0
        /// <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;
            PFRTFDocument rtfDoc  = 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());
                    }
                }

                rtfDoc = new PFRTFDocument(this.OutputFileName, this.ReplaceExistingFile);
                rtfDoc.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 (rtfDoc != null)
                {
                    rtfDoc = null;
                }
            }

            return(success);
        }