/// <summary> /// Executes a transaction (a sequence of SQL sentences) from /// <para/>the "buffer". After completion of the "buffer" excecution, /// <para/>the "buffer" is cleared and buffering is disabled. /// </summary> public void EndBufferMSSQL() { if (buffer) { buffer = false; using (SqlTransaction trans = MSSQLConnection.BeginTransaction()) { using (SqlCommand command = new SqlCommand(sql_entry, MSSQLConnection, trans)) { command.CommandText = sql_entry; command.ExecuteNonQuery(); } trans.Commit(); } sql_entry = string.Empty; } }
/// <summary> /// The most important method in LangLib. This creates the database, /// <para/>the tables to it (MESSAGES, FORMITEMS, CULTURES). /// <para/><para/>Also the FallBackCulture is updated for the underlying form/window. /// <para/>Messages from the given <paramref name="messageResource"/> are inserted to /// <para/>the database if their don't exists. /// <para/><para/>The table fields FORMITEMS.INUSE and MESSAGES.INUSE are updated /// <para/>for the FallBackCulture. /// </summary> /// <param name="messageResource">A resource name that contains the application /// <para/>messages in the fall FallBackCulture language. /// <para/>For example if I have an application which assembly name is /// <para/>LangLibTestWinforms and it has a .resx file called Messages /// <para/>I would give this parameter a value of "LangLibTestWinforms.Messages".</param> /// <param name="culture">The culture to use for the localization. /// <para/>If no culture is given the current system culture is used and /// <para/>the FallBackCulture is used as fallback culture.</param> /// <param name="loadItems">To load language items or not.</param> public void InitalizeLanguageMSSQL(string messageResource, CultureInfo culture = null, bool loadItems = true) { if (culture == null) { culture = CultureInfo.CurrentCulture; } if (!Design) { try { DateTime dt = DateTime.Now; if (!Directory.Exists(DataDir)) { Directory.CreateDirectory(DataDir); } if (MSSQLConnection == null) { string connStr = dbConnectionStr == string.Empty ? string.Format("Persist Security Info=False;User ID={3};Password={4};Initial Catalog={2};Server={0};", dbHost, dbPort, dbName, dbUser, dbPassword) : dbConnectionStr; MSSQLConnection = new SqlConnection(connStr); MSSQLConnection.Open(); } if (!tablesCreated && !dbNoTables) { using (SqlCommand command = new SqlCommand(TableCreateMessages, MSSQLConnection)) { command.ExecuteNonQuery(); } using (SqlCommand command = new SqlCommand(TableCreateFormItems, MSSQLConnection)) { command.ExecuteNonQuery(); } using (SqlCommand command = new SqlCommand(TableCreateCultures, MSSQLConnection)) { command.ExecuteNonQuery(); } tablesCreated = true; } if (!culturesInserted && !loadItems) { string sql = string.Empty; CultureInfo[] allCultures; allCultures = CultureInfo.GetCultures(CultureTypes.AllCultures); foreach (CultureInfo ci in allCultures) { sql += InsertCulture(ci); } using (SqlTransaction trans = MSSQLConnection.BeginTransaction()) { using (SqlCommand command = new SqlCommand(sql, MSSQLConnection, trans)) { command.CommandText = sql; command.ExecuteNonQuery(); } trans.Commit(); } culturesInserted = true; } if (!loadItems) { GetGuiObjets(fallBackCulture); if (!langUseUpdated) { using (SqlTransaction trans = MSSQLConnection.BeginTransaction()) { using (SqlCommand command = new SqlCommand("UPDATE " + Schema + "FORMITEMS SET INUSE = 0 WHERE CULTURE = '" + fallBackCulture + "' ", MSSQLConnection, trans)) { command.ExecuteNonQuery(); } trans.Commit(); } langUseUpdated = true; } SaveLanguageItems(this.BaseInstance, fallBackCulture); } if (loadItems) { List <string> localProps = LocalizedPropsMSSQL(AppForm, CultureInfo.CurrentCulture); GetGuiObjets(CultureInfo.CurrentCulture, localProps); LoadLanguageItems(CultureInfo.CurrentCulture); } if (!loadItems) { SaveMessages(messageResource, Assembly.GetExecutingAssembly(), ref MSSQLConnection); } ts = ts.Add((DateTime.Now - dt)); } catch (Exception ex) { if (ex.GetType() == typeof(MissingManifestResourceException)) // This is fun. The user actually gets some help from the exception message ;-) { throw new LangLibException(string.Format("Missing resource '{0}'.{1}Perhaps {2}.[Resource file name] would do,{3}without the .resx file extension.", messageResource, Environment.NewLine, GetAssemblyName(this.appType), Environment.NewLine)); } else { throw; } } } }