Example #1
0
        // ----------------------------------------------------------------------------------------
        /// <!-- ImportErrorsInsert -->
        /// <summary>
        ///      Inserts all module import errors into the database
        /// </summary>
        /// <param name="statusErrorLog"></param>
        /// <param name="itemIdByLineNum"></param>
        /// <param name="connection"></param>
        /// <returns></returns>
        public static int ImportErrorsInsert(DataTable statusErrorLog, Dictionary <int, int> itemIdByLineNum
                                             , string moduleName, InfoAspect aspect)
        {
            int errorCount = 0;

            try
            {
                string query = ImportDalCommon.ImportErrorQuery(moduleName);
                for (int row = 0; row < statusErrorLog.Rows.Count; ++row)
                {
                    // ------------------------------------------------------------------
                    //  Process the row
                    // ------------------------------------------------------------------
                    string statusErrorCode = statusErrorLog.Rows[row]["Status_Error_Code"].ToString();
                    if (!Regex.IsMatch(statusErrorCode, "0[01]$"))
                    {
                        ImportDalCommon.ImportErrorInsert(query, statusErrorLog, row, statusErrorCode
                                                          , itemIdByLineNum, moduleName, aspect.Enter(moduleName, "ImportErrorInsert")); aspect--;
                        errorCount++;
                    }
                }
            }
            catch (Exception ex) { Pause(); aspect.Rethrow(ex); }

            return(errorCount);
        }
Example #2
0
        // ----------------------------------------------------------------------------------------
        /// <!-- ImportErrorInsert -->
        /// <summary>
        ///      Inserts a module import error row
        /// </summary>
        /// <param name="query"></param>
        /// <param name="statusErrorLog"></param>
        /// <param name="row"></param>
        /// <param name="itemIdByLineNum"></param>
        /// <param name="connection"></param>
        /// <returns></returns>
        public static void ImportErrorInsert(string query, DataTable statusErrorLog, int row
                                             , string statusErrorCode, Dictionary <int, int> itemIdByLineNum, string moduleName, InfoAspect aspect)
        {
            SqlCommand errorInsert = new SqlCommand(query, aspect.SecondaryConnection);

            using (errorInsert)
            {
                // ------------------------------------------------------------------
                //  Insert the error into the error table
                // ------------------------------------------------------------------
                int lineNumber = int.Parse(statusErrorLog.Rows[row]["FileLineNumber"].ToString());
                int itemId     = itemIdByLineNum[lineNumber];
                ImportDalCommon.ImportErrorFill(errorInsert, itemId, statusErrorCode, statusErrorLog.Rows[row], moduleName);
                int errorId = (int)errorInsert.ExecuteScalar();
            }
        }
        // ----------------------------------------------------------------------------------------
        /// <!-- Import -->
        /// <summary>
        ///      Imports a DataTable of location elements into one of the location tables
        /// </summary>
        /// <param name="importData"></param>
        /// <param name="aspect"></param>
        /// <returns></returns>
        public DataTable Import(DataTable importData, string tableName, InfoAspect aspect)
        {
            // --------------------------------------------------------------------------
            //  Initialize variables
            // --------------------------------------------------------------------------
            DataTable importedData = ImportDalCommon.InitializeImportedDataTable(importData, tableName + "DbId", aspect.Enter()); aspect--; // the output table
            string    insertQuery  = InsertQuery(tableName, aspect.Enter()); aspect--;
            string    updateQuery  = UpdateQuery(tableName, aspect.Enter()); aspect--;


            for (int row = 0; row < importData.Rows.Count; ++row)
            {
                DataRow field = importData.Rows[row];
                try
                {
                    // ------------------------------------------------------------------
                    //  Insert or Update a valid location record in one of four location tables
                    // ------------------------------------------------------------------
                    bool     isValid = (bool)field["IsValid"];
                    SqlInt32 id      = SqlInt32.Null;
                    if (isValid)
                    {
                        bool isUpdate = (bool)field["IsUpdate"];
                        if (!isUpdate)
                        {
                            isUpdate = ElementExists(tableName, field, aspect.Enter()); aspect--;
                        }
                        if (isUpdate)
                        {
                            id = Update(tableName, field, importedData, aspect.Enter(tableName, "Update")); aspect--;
                        }
                        else
                        {
                            id = Insert(insertQuery, tableName, field, importedData, aspect.Enter(tableName, "Insert")); aspect--;
                        }
                    }
                }
                catch (Exception ex) { Pause(); aspect.Rethrow(ex); }
            }

            return(importedData);
        }