예제 #1
0
        private void UpdateCategoryTable()
        {
            MetadataCategoryBuilder CategoryBuilder;
            DIQueries TempDBQueries = null;
            string    DataPrefix    = string.Empty;
            string    LanguageCode  = string.Empty;
            string    CategoryNid   = string.Empty;
            string    CategoryGID   = string.Empty;

            string    SourceCategoryTable = string.Empty;
            DataTable CategoryTable;

            try
            {
                // step1: create table for all dataset
                foreach (DataRow DataPrefixRow in this._DBConnection.DIDataSets().Rows)
                {
                    DataPrefix = DataPrefixRow[DBAvailableDatabases.AvlDBPrefix].ToString() + "_";

                    // get language for all available languages
                    foreach (DataRow LanguageRow in this._DBConnection.DILanguages(DataPrefix).Rows)
                    {
                        LanguageCode = "_" + LanguageRow[Language.LanguageCode].ToString();

                        // check table already exists or not
                        TempDBQueries = new DIQueries(DataPrefix, LanguageCode);

                        if (string.IsNullOrEmpty(SourceCategoryTable))
                        {
                            // update GID in only one language table and for other  language tables, use this language table
                            CategoryBuilder = new MetadataCategoryBuilder(this._DBConnection, TempDBQueries);

                            CategoryTable = CategoryBuilder.GetAllRecordsFromMetadataCategory();

                            foreach (DataRow Row in CategoryTable.Rows)
                            {
                                //update metdata category table (set parent_nid to -1 and update gids)
                                //CategoryGID = Convert.ToString(Row[Metadata_Category.CategoryName]).ToUpper().Replace(" ", "_");
                                //CategoryGID = MetaDataBuilder.GetNewMetaDataCategoryGID();

                                CategoryNid = Convert.ToString(Row[Metadata_Category.CategoryNId]);
                                CategoryGID = DICommon.GetValidGIdForSDMXRule(Convert.ToString(Row[Metadata_Category.CategoryName]).ToUpper()) + "_" + CategoryNid;

                                this.DBConnection.ExecuteNonQuery(DevInfo.Lib.DI_LibDAL.Queries.MetadataCategory.Update.UpdateMetadataCategory(TempDBQueries.TablesName.MetadataCategory, Convert.ToInt32(CategoryNid), CategoryGID, "-1", false, false));
                            }

                            SourceCategoryTable = TempDBQueries.TablesName.MetadataCategory;
                        }
                        else
                        {
                            // use first language table  to update other language table
                            this.DBConnection.ExecuteNonQuery("UPDATE " + SourceCategoryTable + " AS src INNER JOIN " + TempDBQueries.TablesName.MetadataCategory + " AS trg ON src." + Metadata_Category.CategoryNId + " = trg." + Metadata_Category.CategoryNId + "  SET trg." + Metadata_Category.CategoryGId + "=src." + Metadata_Category.CategoryGId + " and trg." + Metadata_Category.ParentCategoryNId + "=src." + Metadata_Category.ParentCategoryNId + ";");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionFacade.ThrowException(ex);
            }
        }