/// <summary> /// Returns the database language code /// </summary> /// <param name="dbConnection"></param> /// <returns></returns> public static string GetDBLanguageCode(DIConnection dbConnection) { string RetVal = string.Empty; string DataPrefix = dbConnection.DIDataSetDefault(); if (dbConnection.IsValidDILanguage(DataPrefix, DataAdmin.DAAppliationLangCode)) { RetVal = "_" + DataAdmin.DAAppliationLangCode; } else { RetVal = dbConnection.DILanguageCodeDefault(DataPrefix); } return RetVal; }
/// <summary> /// Returns the DIQueries object /// </summary> /// <param name="dbConnection"></param> /// <returns></returns> public static DIQueries GetDBQueries(DIConnection dbConnection) { DIQueries RetVal = null; string LanguageCode = string.Empty; string DataPrefix = dbConnection.DIDataSetDefault(); if (dbConnection.IsValidDILanguage(DataPrefix, DataAdmin.DAAppliationLangCode)) { LanguageCode = "_" + DataAdmin.DAAppliationLangCode; } else { LanguageCode = dbConnection.DILanguageCodeDefault(DataPrefix); } RetVal = new DIQueries(DataPrefix, LanguageCode); return RetVal; }
private void ImportAssistant(DIConnection sourceDBConnection, DIQueries sourceDBQueries) { string DataPrefix = string.Empty; string LanguageCode = string.Empty; DITables TargetTableNames; DITables SourceTableNames; string SqlString = string.Empty; Dictionary<string, string> SkippedTopics = new Dictionary<string, string>(); try { DataPrefix = this._TargetDBConnection.DIDataSetDefault(); //Get all languages from target database foreach (DataRow Row in this._TargetDBConnection.DILanguages(DataPrefix).Rows) { // check language exists in source database LanguageCode = Row[Language.LanguageCode].ToString(); if (sourceDBConnection.IsValidDILanguage(DataPrefix, LanguageCode)) { try { LanguageCode = "_" + LanguageCode; //create source table names SourceTableNames = new DITables(DataPrefix, LanguageCode); //create target table names TargetTableNames = new DITables(DataPrefix, LanguageCode); // overwrite Assistant_EBook table from source database to Target database this.ImportEBook(ref sourceDBConnection, ref sourceDBQueries, LanguageCode, SourceTableNames, TargetTableNames); //import topic info from source database try { // check Topic exists in target database foreach (DataRow SourceTopicRow in sourceDBConnection.ExecuteDataTable(AssistantQueries.GetALLTopics(SourceTableNames.AssistantTopic)).Rows) { DataTable TargetTopicsTable = null; try { TargetTopicsTable = this._TargetDBConnection.ExecuteDataTable(AssistantQueries.GetALLTopics(TargetTableNames.AssistantTopic, " where Topic_Name='" + SourceTopicRow[Assistant_Topic.TopicName].ToString() + "' ")); // Check Indicator_Gid or IUS Gids exists in target database.If not exists, then skip topic. if (this.IsIndicatorGidExistsForAssistant(SourceTopicRow[Assistant_Topic.IndicatorGId].ToString())) { if (TargetTopicsTable.Rows.Count > 0) // Overwrite { SqlString = AssistantQueries.UpdateTopicIntro(TargetTableNames.AssistantTopic, DICommon.RemoveQuotes(SourceTopicRow[Assistant_Topic.TopicIntro].ToString()), DICommon.RemoveQuotes(SourceTopicRow[Assistant_Topic.TopicName].ToString()), DICommon.RemoveQuotes(SourceTopicRow[Assistant_Topic.IndicatorGId].ToString())); } else // create new record { SqlString = AssistantQueries.InsertTopicInfo(TargetTableNames.AssistantTopic, DICommon.RemoveQuotes(SourceTopicRow[Assistant_Topic.TopicName].ToString()), SourceTopicRow[Assistant_Topic.IndicatorGId].ToString(), DICommon.RemoveQuotes(SourceTopicRow[Assistant_Topic.TopicIntro].ToString())); } this._TargetDBConnection.ExecuteNonQuery(SqlString); } else { if (!SkippedTopics.ContainsKey(SourceTopicRow[Assistant_Topic.TopicName].ToString())) { SkippedTopics.Add(SourceTopicRow[Assistant_Topic.TopicName].ToString(), SourceTopicRow[Assistant_Topic.TopicName].ToString()); } } } catch (Exception) { if (TargetTopicsTable != null) { TargetTopicsTable.Dispose(); } } } } catch (Exception ex) { ExceptionHandler.ExceptionFacade.ThrowException(ex); } finally { //dispose source database connection } try { // get All Values of Assistant from source Database DataTable SourceDbTable = sourceDBConnection.ExecuteDataTable(AssistantQueries.GetAssistantWTopicInfo(SourceTableNames.Assistant, SourceTableNames.AssistantTopic)); // check record exists in target database foreach (DataRow SrcRow in SourceDbTable.Rows) { DataTable TargetDBTable = null; try { // Check Indicator_Gid or IUS Gids exists in target database.If not exists, then skip topic. if (!SkippedTopics.ContainsKey(SrcRow[Assistant_Topic.TopicName].ToString())) { SqlString = AssistantQueries.GetAssistantWTopicInfo(TargetTableNames.Assistant, TargetTableNames.AssistantTopic, " where T.Topic_Name='" + DICommon.RemoveQuotes(SrcRow[Assistant_Topic.TopicName].ToString()) + "' and A.Assistant_Type='" + DICommon.RemoveQuotes(SrcRow[Assistant.AssistantType].ToString()) + "' "); TargetDBTable = this._TargetDBConnection.ExecuteDataTable(SqlString); if (Microsoft.VisualBasic.Information.IsDBNull(SrcRow[Assistant.AssistantText].ToString())) { SrcRow[Assistant.AssistantText] = string.Empty; } if (TargetDBTable.Rows.Count > 0) // overwrite { SqlString = AssistantQueries.UpdateBlankTopicRecord(TargetTableNames.Assistant, DICommon.RemoveQuotes(SrcRow[Assistant.AssistantText].ToString()), SrcRow[Assistant.AssistantType].ToString(), TargetDBTable.Rows[0][Assistant.AssistantNId].ToString()); } else // create new record { // get Topic Nid from Target Database SqlString = AssistantQueries.GetALLTopics(TargetTableNames.AssistantTopic, " where Topic_Name ='" + DICommon.RemoveQuotes(SrcRow[Assistant_Topic.TopicName].ToString()) + "' "); int TopicNid = Convert.ToInt32(this._TargetDBConnection.ExecuteDataTable(SqlString).Rows[0][Assistant_Topic.TopicNId].ToString()); SqlString = AssistantQueries.CreateNewAssistantInfo(TargetTableNames.Assistant, TopicNid, SrcRow[Assistant.AssistantType].ToString(), DICommon.RemoveQuotes(SrcRow[Assistant.AssistantText].ToString()), SrcRow[Assistant.AssistantOrder].ToString()); } this._TargetDBConnection.ExecuteNonQuery(SqlString); } } catch (Exception e1) { ExceptionHandler.ExceptionFacade.ThrowException(e1); } finally { if (TargetDBTable != null) { TargetDBTable.Dispose(); } } } } catch (Exception ex) { ExceptionHandler.ExceptionFacade.ThrowException(ex); } finally { //dispose source database connection } } catch (Exception ex) { ExceptionHandler.ExceptionFacade.ThrowException(ex); } } } } catch (Exception ex) { ExceptionHandler.ExceptionFacade.ThrowException(ex); } }
private void UpdateTablesForTargetLanguage(string languageName, DIConnection dbConnection, DIQueries dbQueries, string dataPrefix, string languageCode) { LanguageBuilder DILanguageBuilder; // create langauge dependent tables if not exists in the new template if (!dbConnection.IsValidDILanguage(dataPrefix, languageCode)) { DILanguageBuilder = new LanguageBuilder(dbConnection, dbQueries); DILanguageBuilder.CreateNewLanguageTables(languageCode, languageName, dataPrefix); // delete "_en" tables & delete langauge code from language table DILanguageBuilder.DropLanguageDependentTables(dataPrefix, "_en"); // set default language dbConnection.ExecuteNonQuery(dbQueries.SetDefaultLanguageCode(languageCode)); } }
/// <summary> /// Returns the DIQueries object /// </summary> /// <param name="dbConnection"></param> /// <param name="dataPrefix"></param> /// <returns></returns> public static DIQueries GetDBQueries(DIConnection dbConnection, string dataPrefix) { DIQueries RetVal = null; string LanguageCode = string.Empty; //-- Set Default dataprefix if not passed if (string.IsNullOrEmpty(dataPrefix)) dataPrefix = dbConnection.DIDataSetDefault(); if (dbConnection.IsValidDILanguage(dataPrefix, DataAdmin.DAAppliationLangCode)) { LanguageCode = "_" + DataAdmin.DAAppliationLangCode; } else { LanguageCode = dbConnection.DILanguageCodeDefault(dataPrefix); } RetVal = new DIQueries(dataPrefix, LanguageCode); return RetVal; }