} // GetInstalledLanguages // For the time being assume that the first language installed is the "default" system language. // NOTE: This relies on the assumption that an unordered SQL query will return the information in the order in which it was entered into the database. public Languages.Language GetDefaultLanguage() { Languages installedLanguages; Languages.Language defaultLanguage; ErrorCode errorCode = GetInstalledLanguages(out installedLanguages); if ((errorCode == ErrorCode.Success) && (installedLanguages.Count > 0)) { defaultLanguage = installedLanguages[0]; } else { defaultLanguage = new Languages.Language("", ""); Console.Error.WriteLine("{0} No languages installed - cannot determine default language.", DateTime.Now); } return(defaultLanguage); }
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// public ErrorCode AddMenu(string i_sMenuName, Languages.Language i_language) { ErrorCode eRet = ErrorCode.Success; try { using (IDbConnection sqlConn = GetDbConnection()) using (IDbCommand sqlCmd = sqlConn.CreateCommand()) { IDbDataParameter param; sqlCmd.CommandText = "INSERT INTO tblMenus (sMenuName, sLanguageCode, bConfirmationEnabled) VALUES (@MenuName, @LanguageCode, '1')"; param = sqlCmd.CreateParameter(); param.DbType = DbType.String; param.ParameterName = "@MenuName"; param.Value = i_sMenuName; sqlCmd.Parameters.Add(param); param = sqlCmd.CreateParameter(); param.DbType = DbType.String; param.ParameterName = "@LanguageCode"; param.Value = i_language.Code; sqlCmd.Parameters.Add(param); sqlConn.Open(); sqlCmd.ExecuteNonQuery(); sqlConn.Close(); } } catch (System.Data.SqlClient.SqlException excSql) { if (excSql.Number == 2627) { eRet = ErrorCode.UniqueViolation; Console.Error.WriteLine(DateTime.Now.ToString() + " DialogDesignerDAL.AddMenu caught exception, UNIQUE violation:" + excSql.ToString()); } else { eRet = ErrorCode.UnknownSql; Console.Error.WriteLine(DateTime.Now.ToString() + " DialogDesignerDAL.AddMenu caught exception:" + excSql.ToString()); } } catch (Npgsql.NpgsqlException excSql) { if (excSql.ErrorCode == 23505) { eRet = ErrorCode.UniqueViolation; Console.Error.WriteLine(DateTime.Now.ToString() + " DialogDesignerDAL.AddMenu caught exception, UNIQUE violation:" + excSql.ToString()); } else { eRet = ErrorCode.UnknownSql; Console.Error.WriteLine(DateTime.Now.ToString() + " DialogDesignerDAL.AddMenu caught exception:" + excSql.ToString()); } } catch (Exception exci) { eRet = ErrorCode.Unknown; Console.Error.WriteLine(DateTime.Now.ToString() + " DialogDesignerDAL.AddMenu caught exception:" + exci.ToString()); } return(eRet); } // AddMenu