Exemplo n.º 1
0
        public static void DataTableTest(MainForm frm)
        {
            PFMsOracle oracle           = new PFMsOracle();
            string     connectionString = string.Empty;
            Stopwatch  sw = new Stopwatch();

            try
            {
                oracle.DataSource            = frm.txtDataSource.Text;
                oracle.UseIntegratedSecurity = frm.chkUseIntegratedSecurity.Checked;
                oracle.Username = frm.txtUserId.Text;
                oracle.Password = frm.txtPassword.Text;

                connectionString = oracle.ConnectionString;

                _msg.Length = 0;
                _msg.Append("Connection string is: \r\n");
                _msg.Append(connectionString);
                Program._messageLog.WriteLine(_msg.ToString());

                if (frm.txtSQLQuery.Text.Length == 0)
                {
                    throw new System.Exception("You must specify a SQL query to run.");
                }

                sw.Start();

                oracle.OpenConnection();

                oracle.SQLQuery = frm.txtSQLQuery.Text;
                if (frm.chkIsStoredProcedure.Checked)
                {
                    oracle.CommandType = CommandType.StoredProcedure;
                }
                else
                {
                    oracle.CommandType = CommandType.Text;
                }

                sw.Stop();
                _msg.Length = 0;
                _msg.Append("Open connection time: ");
                _msg.Append(sw.FormattedElapsedTime);
                Program._messageLog.WriteLine(_msg.ToString());

                sw.Start();

                DataTable tab1 = oracle.RunQueryDataTable();
                oracle.returnResult += new PFMsOracle.ResultDelegate(OutputResults);
                oracle.ProcessDataTable(tab1);

                sw.Stop();
                _msg.Length = 0;
                _msg.Append("Process Table time: ");
                _msg.Append(sw.FormattedElapsedTime);
                Program._messageLog.WriteLine(_msg.ToString());


                if (_textFile.FileIsOpen)
                {
                    _textFile.CloseFile();
                }
                _textFile.OpenFile(@"c:\temp\TableTestExtract.txt", PFFileOpenOperation.OpenFileForWrite);

                //sw.Start();
                DataTable tab = oracle.RunQueryDataTable();
                //oracle.returnResultAsString += new PFMsOracle.ResultAsStringDelegate(OutputExtractFormattedData);
                oracle.returnResultAsString += new PFMsOracle.ResultAsStringDelegate(OutputResultsToFile);
                oracle.ExtractDelimitedDataFromTable(tab, ",", "\r\n", true);
                sw.Stop();
                _msg.Length = 0;
                _msg.Append("Extract Delimiated Table time: ");
                _msg.Append(sw.FormattedElapsedTime);
                Program._messageLog.WriteLine(_msg.ToString());
                tab = null;
                sw.Start();

                if (_textFile.FileIsOpen)
                {
                    _textFile.CloseFile();
                }
                _textFile.OpenFile(@"c:\temp\TableTestExtractFXL.txt", PFFileOpenOperation.OpenFileForWrite);
                tab = oracle.RunQueryDataTable();
                oracle.ExtractFixedLengthDataFromTable(tab, true, true, false);

                sw.Stop();
                _msg.Length = 0;
                _msg.Append("Extract Fixed Length Table time: ");
                _msg.Append(sw.FormattedElapsedTime);
                Program._messageLog.WriteLine(_msg.ToString());



                oracle.SaveDataTableToXmlSchemaFile(tab, @"c:\temp\Testtab.xsd");
                oracle.SaveDataTableToXmlFile(tab, @"c:\temp\Testtab.xml");
                oracle.SaveDataTableWithSchemaToXmlFile(tab, @"c:\temp\Testtabplus.xml");
                DataTable tab2    = oracle.LoadXmlFileToDataTable(@"c:\temp\Testtabplus.xml");;
                int       numRows = tab2.Rows.Count;

                PFDataProcessor dataProcessor = new PFDataProcessor();
                XmlDocument     xmlDoc        = dataProcessor.CopyDataTableToXmlDocument(tab);
                Program._messageLog.WriteLine("\r\n" + xmlDoc.OuterXml + "\r\n");
            }
            catch (System.Exception ex)
            {
                frm.OutputErrorMessageToLog(ex);
            }
            finally
            {
                oracle.CloseConnection();
                oracle = null;
                if (_textFile.FileIsOpen)
                {
                    _textFile.CloseFile();
                }
            }
        }//end DataTableTest