Beispiel #1
0
        internal static IEnumerable <LocalizedResource> GetLocalizationTable(string language)
        {
            List <LocalizedResource> resources = new List <LocalizedResource>();
            const string             sql       = "SELECT * FROM localization.get_localization_table(@Language);";

            using (NpgsqlConnection connection = new NpgsqlConnection(ConnectionStringHelper.GetConnectionString()))
            {
                using (NpgsqlCommand command = new NpgsqlCommand(sql, connection))
                {
                    command.Parameters.AddWithValue("@Language", language);

                    using (NpgsqlDataAdapter adapter = new NpgsqlDataAdapter(command))
                    {
                        using (DataTable dataTable = new DataTable())
                        {
                            dataTable.Locale = CultureManager.GetCurrent();
                            adapter.Fill(dataTable);

                            if (dataTable.Rows.Count > 0)
                            {
                                foreach (DataRow row in dataTable.Rows)
                                {
                                    LocalizedResource resource = new LocalizedResource();

                                    resource.Id            = long.Parse(row["id"].ToString());
                                    resource.ResourceClass = row["resource_class"].ToString();
                                    resource.Key           = row["key"].ToString();
                                    resource.Original      = row["original"].ToString();
                                    resource.Translated    = row["translated"].ToString();

                                    resources.Add(resource);
                                }
                            }
                        }
                    }
                }
            }

            return(resources);
        }
        internal static IEnumerable<LocalizedResource> GetLocalizationTable(string language)
        {
            List<LocalizedResource> resources = new List<LocalizedResource>();
            const string sql = "SELECT * FROM localization.get_localization_table(@Language) WHERE COALESCE(key, '') != '';";

            using (NpgsqlConnection connection = new NpgsqlConnection(ConnectionStringHelper.GetConnectionString()))
            {
                using (NpgsqlCommand command = new NpgsqlCommand(sql, connection))
                {
                    command.Parameters.AddWithValue("@Language", language);

                    using (NpgsqlDataAdapter adapter = new NpgsqlDataAdapter(command))
                    {
                        using (DataTable dataTable = new DataTable())
                        {
                            dataTable.Locale = CultureManager.GetCurrent();
                            adapter.Fill(dataTable);

                            if (dataTable.Rows.Count > 0)
                            {
                                foreach (DataRow row in dataTable.Rows)
                                {
                                    LocalizedResource resource = new LocalizedResource();

                                    resource.Id = long.Parse(row["id"].ToString());
                                    resource.ResourceClass = row["resource_class"].ToString();
                                    resource.Key = row["key"].ToString();
                                    resource.Original = row["original"].ToString();
                                    resource.Translated = row["translated"].ToString();

                                    resources.Add(resource);
                                }
                            }
                        }
                    }
                }
            }

            return resources;
        }