Esempio n. 1
0
        /// <summary>The entry point for the application.</summary>
        /// <param name="argv">A list of arguments</param>
        public static void Main(String[] argv)
        {
            Boolean booleanParseCommandLineArguments = false;
            String  exceptionMessage = null;

            StringBuilder internetDictionaryProjectIDPSQL   = null;
            StringBuilder internetDictionaryProjectIDPQuery = null;

            IDataReader iDataReader = null;

            AccountChartArgument accountChartArgument = null;

            accountChartArgument = new AccountChartArgument();

            booleanParseCommandLineArguments = UtilityParseCommandLineArgument.ParseCommandLineArguments
                                               (
                argv,
                accountChartArgument
                                               );

            if (booleanParseCommandLineArguments == false)
            {
                // error encountered in arguments. Display usage message
                UtilityDebug.Write
                (
                    UtilityParseCommandLineArgument.CommandLineArgumentsUsage(typeof(AccountChartArgument))
                );
                return;
            }//if ( booleanParseCommandLineArguments  == false )

            if (accountChartArgument.DataFile != null && accountChartArgument.DataFile.Length != 0)
            {
                FileImport
                (
                    ref DatabaseConnectionString,
                    ref accountChartArgument,
                    ref exceptionMessage
                );
            }//if ( accountChartArgument.DataFile != null && accountChartArgument.DataFile != String.Empty )

            /*
             * Query
             * (
             * ref DatabaseConnectionString,
             * ref exceptionMessage,
             * ref accountChartArgument,
             * ref internetDictionaryProjectIDPSQL,
             * ref internetDictionaryProjectIDPQuery,
             * ref iDataReader
             * );
             */
        }//main()
Esempio n. 2
0
        }//main()

        ///<summary>Stub.</summary>
        public static void FileImport
        (
            ref String databaseConnectionString,
            ref AccountChartArgument accountChartArgument,
            ref String exceptionMessage
        )
        {
            int dataFileIndex = 0;
            int sQLStatementAttributeIndex        = -1;
            int sQLStatementAttributeIndexCurrent = -1;
            int streamRecordIndex = 0;

            String databaseStatementUpdate   = null;
            String databaseStatementTruncate = null;

            String directoryNameRoot = null;
            String fileNameCurrent   = null;
            String fileNamePattern   = null;
            String streamColumn      = null;
            String streamRecord      = null;


            StringBuilder[] stringBuilderStreamColumn = null;

            ArrayList arrayListDirectoryName = null;
            ArrayList arrayListFileName      = null;

            OleDbConnection oleDbConnection = null;

            stringBuilderStreamColumn = new StringBuilder[SQLStatementAttribute.Length];

            oleDbConnection = UtilityDatabase.DatabaseConnectionInitialize
                              (
                databaseConnectionString,
                ref exceptionMessage
                              );

            if (accountChartArgument.TableTruncate)
            {
                databaseStatementTruncate = String.Format
                                            (
                    SQLStatementTruncate,
                    SQLStatementClass
                                            );

                UtilityDebug.Write(databaseStatementTruncate);

                UtilityDatabase.DatabaseNonQuery
                (
                    oleDbConnection,
                    ref exceptionMessage,
                    databaseStatementTruncate
                );
            }//if ( accountChartArgument.TableTruncate )

            try
            {
                for (dataFileIndex = 0; dataFileIndex < accountChartArgument.dataFile.Length; ++dataFileIndex)
                {
                    UtilityDirectory.Dir
                    (
                        ref accountChartArgument.dataFile[dataFileIndex],
                        ref directoryNameRoot,
                        ref fileNamePattern,
                        ref arrayListDirectoryName,
                        ref arrayListFileName
                    );

                    UtilityDebug.Write
                    (
                        String.Format
                        (
                            "accountChartArgument.dataFile[{0}]: {1}",
                            dataFileIndex,
                            accountChartArgument.dataFile[dataFileIndex]
                        )
                    );

                    foreach (object fileNameObject in arrayListFileName)
                    {
                        fileNameCurrent = fileNameObject.ToString();

                        UtilityDebug.Write
                        (
                            String.Format
                            (
                                "fileNameCurrent: {0}",
                                fileNameCurrent
                            )
                        );

                        // Create an instance of StreamReader to read from a file.
                        // The using statement also closes the StreamReader.
                        using (StreamReader streamReader = new StreamReader(fileNameCurrent))
                        {
                            while (true)
                            {
                                //Read and display lines from the file until the end of the file is reached.
                                streamRecord = streamReader.ReadLine();

                                if (streamRecord == null)
                                {
                                    break;
                                }//if ( streamRecord == null )

                                /*
                                 * UtilityDebug.Write
                                 * (
                                 * String.Format
                                 * (
                                 * "streamRecord: {0}",
                                 * streamRecord
                                 * )
                                 * );
                                 */

                                for
                                (
                                    sQLStatementAttributeIndex = 0;
                                    sQLStatementAttributeIndex < SQLStatementAttribute.Length;
                                    ++sQLStatementAttributeIndex
                                )
                                {
                                    streamRecordIndex = streamRecord.IndexOf
                                                        (
                                        SQLStatementAttribute[sQLStatementAttributeIndex][SQLStatementAttributeRankName]
                                                        );

                                    if (streamRecordIndex == 0)
                                    {
                                        sQLStatementAttributeIndexCurrent = sQLStatementAttributeIndex;
                                        break;
                                    } //if ( streamRecordIndex == 0 )
                                }     //for

                                if (sQLStatementAttributeIndexCurrent == -1)
                                {
                                    continue;
                                }//if ( sQLStatementAttributeIndexCurrent == -1 )

                                streamRecord = streamRecord.Trim();

                                streamRecord = streamRecord.Replace("'", "''");

                                if (sQLStatementAttributeIndex < SQLStatementAttribute.Length)
                                {
                                    streamColumn = streamRecord.Substring(SQLStatementAttribute[sQLStatementAttributeIndexCurrent][SQLStatementAttributeRankName].Length + 1);
                                    streamColumn = streamColumn.Trim();
                                    stringBuilderStreamColumn[sQLStatementAttributeIndexCurrent] = new StringBuilder(streamColumn);
                                }
                                else
                                {
                                    streamColumn = streamRecord.Trim();
                                    stringBuilderStreamColumn[sQLStatementAttributeIndexCurrent].Append(streamColumn);
                                }

                                /*
                                 * UtilityDebug.Write
                                 * (
                                 * String.Format
                                 * (
                                 * "Name: {0} | Value: {1}",
                                 * SQLStatementAttribute[ sQLStatementAttributeIndexCurrent ][ SQLStatementAttributeRankName ],
                                 * stringBuilderStreamColumn[ sQLStatementAttributeIndexCurrent ]
                                 * )
                                 * );
                                 */

                                if (sQLStatementAttributeIndexCurrent != SQLStatementAttribute.Length - 1)
                                {
                                    continue;
                                }//if ( sQLStatementAttributeIndexCurrent < SQLStatementAttribute.Length - 1 )

                                databaseStatementUpdate = String.Format
                                                          (
                                    SQLStatementUpdate,
                                    SQLStatementClass,
                                    stringBuilderStreamColumn[SQLStatementAttributeIndexAccountNumber],
                                    SQLStatementAttribute[SQLStatementAttributeIndexAccountTitle][SQLStatementAttributeRankAlias],
                                    SQLStatementAttribute[SQLStatementAttributeIndexAccountNumber][SQLStatementAttributeRankAlias],
                                    SQLStatementAttribute[SQLStatementAttributeIndexNormalBalance][SQLStatementAttributeRankAlias],
                                    SQLStatementAttribute[SQLStatementAttributeIndexDefinition][SQLStatementAttributeRankAlias],
                                    stringBuilderStreamColumn[SQLStatementAttributeIndexAccountTitle],
                                    stringBuilderStreamColumn[SQLStatementAttributeIndexNormalBalance],
                                    stringBuilderStreamColumn[SQLStatementAttributeIndexDefinition]
                                                          );

                                /*
                                 * UtilityDebug.Write( databaseStatementUpdate );
                                 */

                                UtilityDatabase.DatabaseNonQuery
                                (
                                    oleDbConnection,
                                    ref exceptionMessage,
                                    databaseStatementUpdate
                                );

                                if (exceptionMessage != null)
                                {
                                    UtilityDebug.Write
                                    (
                                        String.Format
                                        (
                                            "databaseStatementUpdate: {0}",
                                            databaseStatementUpdate
                                        )
                                    );
                                }
                            } //while ( true )
                        }     //using (StreamReader streamReader = new StreamReader(fileNameCurrent))
                    }         //foreach ( object fileNameCurrent in arrayListFileName )
                }             //for ( dataFileIndex = 0; dataFileIndex < accountChartArgument.dataFile.Length; ++dataFileIndex )
            }                 //try
            catch (Exception exception)
            {
                UtilityDebug.Write
                (
                    String.Format
                    (
                        "Exception: {0}",
                        exception.Message
                    )
                );
            }//catch ( Exception exception )

            UtilityDatabase.DatabaseConnectionHouseKeeping
            (
                oleDbConnection,
                ref exceptionMessage
            );
        }//public static void FileImport()