コード例 #1
0
ファイル: Tests.cs プロジェクト: mcondon013/pfcodelibrary
        public static void RunDataSetTest(MainForm frm)
        {
            PFOdbc db = new PFOdbc();

            Program._messageLog.WriteLine("RunDataSetTest 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 PFOdbc.ResultDelegate(OutputResults);
                db.SQLQuery      = frm.txtSqlQuery.Text;
                db.CommandType   = CommandType.Text;
                DataSet ds = db.RunQueryDataSet();
                db.ProcessDataSet(ds);
                db.returnResult -= OutputResults;

                db.returnResultAsString += new PFOdbc.ResultAsStringDelegate(OutputResultsToFile);
                if (_textFile.FileIsOpen)
                {
                    _textFile.CloseFile();
                }
                _textFile.OpenFile(@"c:\temp\OdbcDsDelimited.txt", PFFileOpenOperation.OpenFileForWrite);
                ds = db.RunQueryDataSet();
                db.ExtractDelimitedDataFromDataSet(ds, ",", "\r\n", true);

                if (_textFile.FileIsOpen)
                {
                    _textFile.CloseFile();
                }
                _textFile.OpenFile(@"c:\temp\OdbcDsFixedLength.txt", PFFileOpenOperation.OpenFileForWrite);
                ds = db.RunQueryDataSet();
                db.ExtractFixedLengthDataFromDataSet(ds, true, true, false);

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

                ds = db.RunQueryDataSet();
                db.SaveDataSetToXmlFile(ds, @"c:\temp\OdbcTestDs.xml");
                ds = db.RunQueryDataSet();
                db.SaveDataSetWithSchemaToXmlFile(ds, @"c:\temp\OdbcTestDsPlus.xml");
                ds = db.RunQueryDataSet();
                db.SaveDataSetToXmlSchemaFile(ds, @"c:\temp\OdbcTestDs.xsd");


                ds = db.RunQueryDataSet();
                PFDataProcessor dataProcessor = new PFDataProcessor();
                XmlDocument     xmlDoc        = dataProcessor.CopyDataSetToXmlDocument(ds);
                Program._messageLog.WriteLine("\r\n" + xmlDoc.OuterXml + "\r\n");
            }
            catch (System.Exception ex)
            {
                _msg.Length = 0;
                _msg.Append(AppGlobals.AppMessages.FormatErrorMessage(ex));
                //_msg.Append(AppGlobals.AppMessages.FormatErrorMessageWithStackTrace(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("... RunDataSetTest finished.");
            }
        }