Пример #1
0
        public static void RunDataReaderTest(MainForm frm)
        {
            PFOleDb db = new PFOleDb();

            Program._messageLog.WriteLine("RunDataReaderTest started ...");
            try
            {
                db.ConnectionString = frm.cboConnectionString.Text;
                db.OpenConnection();

                _msg.Length = 0;
                _msg.Append("Connection string is ");
                _msg.Append(db.ConnectionString);
                _msg.Append("\r\n");
                _msg.Append("Connection state is  ");
                _msg.Append(db.Connection.State.ToString());
                _msg.Append("\r\n");
                _msg.Append("Query text is:\r\n");
                _msg.Append(frm.txtSqlQuery.Text.ToString());
                Program._messageLog.WriteLine(_msg.ToString());

                db.returnResult += new PFOleDb.ResultDelegate(OutputResults);
                db.SQLQuery      = frm.txtSqlQuery.Text;
                db.CommandType   = CommandType.Text;
                OleDbDataReader rdr = (OleDbDataReader)db.RunQueryDataReader();
                db.ProcessDataReader(rdr);
                rdr.Close();
                db.returnResult -= OutputResults;

                db.returnResultAsString += new PFOleDb.ResultAsStringDelegate(OutputResultsToFile);
                if (_textFile.FileIsOpen)
                {
                    _textFile.CloseFile();
                }
                _textFile.OpenFile(@"c:\temp\OleDbRdrDelimited.txt", PFFileOpenOperation.OpenFileForWrite);
                rdr = (OleDbDataReader)db.RunQueryDataReader();
                db.ExtractDelimitedDataFromDataReader(rdr, ",", "\r\n", true);
                rdr.Close();

                if (_textFile.FileIsOpen)
                {
                    _textFile.CloseFile();
                }
                _textFile.OpenFile(@"c:\temp\OleDbRdrFixedLength.txt", PFFileOpenOperation.OpenFileForWrite);
                rdr = (OleDbDataReader)db.RunQueryDataReader();
                db.ExtractFixedLengthDataFromDataReader(rdr, true, true, false);
                rdr.Close();

                if (_textFile.FileIsOpen)
                {
                    _textFile.CloseFile();
                }

                rdr = (OleDbDataReader)db.RunQueryDataReader();
                db.SaveDataReaderToXmlFile(rdr, @"c:\temp\OleDbTestrdr.xml");
                rdr.Close();
                rdr = (OleDbDataReader)db.RunQueryDataReader();
                db.SaveDataReaderWithSchemaToXmlFile(rdr, @"c:\temp\OleDbTestrdrplus.xml");
                rdr.Close();
                rdr = (OleDbDataReader)db.RunQueryDataReader();
                db.SaveDataReaderToXmlSchemaFile(rdr, @"c:\temp\OleDbTestrdr.xsd");
                rdr.Close();


                rdr = (OleDbDataReader)db.RunQueryDataReader();
                PFDataProcessor dataProcessor = new PFDataProcessor();
                XmlDocument     xmlDoc        = dataProcessor.CopyDataTableToXmlDocument(db.ConvertDataReaderToDataTable(rdr));
                Program._messageLog.WriteLine("\r\n" + xmlDoc.OuterXml + "\r\n");
                rdr.Close();
            }
            catch (System.Exception ex)
            {
                _msg.Length = 0;
                _msg.Append(AppGlobals.AppMessages.FormatErrorMessage(ex));
                Program._messageLog.WriteLine(_msg.ToString());
                AppMessages.DisplayErrorMessage(_msg.ToString(), _saveErrorMessagesToAppLog);
            }
            finally
            {
                if (_textFile.FileIsOpen)
                {
                    _textFile.CloseFile();
                }
                if (db.Connection.State == ConnectionState.Open)
                {
                    db.CloseConnection();
                }
                Program._messageLog.WriteLine("... RunDataReaderTest finished.");
            }
        }