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

            utilityAussieHomeLoansTransactionHistoryArgument = new UtilityAussieHomeLoansTransactionHistoryArgument();
            booleanParseCommandLineArguments = UtilityParseCommandLineArgument.ParseCommandLineArguments
                                               (
                argv,
                utilityAussieHomeLoansTransactionHistoryArgument
                                               );
            if (booleanParseCommandLineArguments == false)
            {
                // error encountered in arguments. Display usage message
                System.Console.Write
                (
                    UtilityParseCommandLineArgument.CommandLineArgumentsUsage(typeof(UtilityAussieHomeLoansTransactionHistoryArgument))
                );
                return;
            }//if ( booleanParseCommandLineArguments  == false )
            Import(ref utilityAussieHomeLoansTransactionHistoryArgument, ref exceptionMessage);
        }
Ejemplo n.º 2
0
        ///<summary>Import</summary>
        public static void Import
        (
            ref UtilityAussieHomeLoansTransactionHistoryArgument utilityAussieHomeLoansTransactionHistoryArgument,
            ref string exceptionMessage
        )
        {
            int rowCount  = -1;
            int rowAffect = -1;

            string[]        column      = null;
            string          commandText = null;
            string          line        = null;
            DateTime        transactionDate;
            DateTime        transactionEffectiveDate;
            OleDbCommand    oleDbCommand    = null;
            OleDbConnection oleDbConnection = null;
            StreamReader    streamReader    = null;

            System.Globalization.CultureInfo cultureInfoAU;
            System.Globalization.CultureInfo cultureInfoUS;
            try
            {
                cultureInfoAU = new System.Globalization.CultureInfo("en-AU");
                cultureInfoUS = new System.Globalization.CultureInfo("en-US");
                System.Threading.Thread.CurrentThread.CurrentCulture   = cultureInfoAU;
                System.Threading.Thread.CurrentThread.CurrentUICulture = cultureInfoAU;
                System.Threading.Thread.CurrentThread.CurrentCulture.DateTimeFormat.ShortDatePattern = "dd/MM/yyyy";
                oleDbConnection = new OleDbConnection(DatabaseConnectionString);
                oleDbConnection.Open();
                oleDbCommand = new OleDbCommand(DateFormat, oleDbConnection);
                oleDbCommand.ExecuteNonQuery();
                foreach (string filenameSource in utilityAussieHomeLoansTransactionHistoryArgument.filenameSource)
                {
                    streamReader = new StreamReader(filenameSource);
                    rowCount     = 0;
                    while (streamReader != StreamReader.Null)
                    {
                        line = streamReader.ReadLine();
                        if (line == null)
                        {
                            break;
                        }
                        ++rowCount;
                        if (rowCount < utilityAussieHomeLoansTransactionHistoryArgument.firstRow)
                        {
                            continue;
                        }
                        column    = line.Split(',');
                        column[0] = column[0].Trim();
                        DateTime.TryParse(column[1], out transactionDate);
                        DateTime.TryParse(column[2], out transactionEffectiveDate);

                        /*
                         * commandText  = string.Format
                         * (
                         * SQLInsert,
                         * column[0],
                         * transactionDate.ToString("d", cultureInfoUS),
                         * transactionEffectiveDate.ToString("d", cultureInfoUS),
                         * column[3],
                         * column[4],
                         * column[5],
                         * column[6]
                         * );
                         */
                        commandText = string.Format
                                      (
                            SQLInsert,
                            column[0],
                            column[1],
                            column[2],
                            column[3],
                            column[4],
                            column[5],
                            column[6]
                                      );
                        oleDbCommand = new OleDbCommand(commandText, oleDbConnection);
                        rowAffect    = oleDbCommand.ExecuteNonQuery();
                    }
                    if (streamReader != null)
                    {
                        streamReader.Close();
                    }
                }
            }
            catch (SqlException exception) { UtilityException.ExceptionLog(exception, exception.GetType().Name, ref exceptionMessage); }
            catch (InvalidOperationException exception) { UtilityException.ExceptionLog(exception, exception.GetType().Name, ref exceptionMessage); }
            catch (Exception exception) { UtilityException.ExceptionLog(exception, exception.GetType().Name, ref exceptionMessage); }
            if (oleDbConnection != null)
            {
                oleDbConnection.Close();
            }
        }