/// <summary> /// Add section into scenario /// </summary> /// <param name="order_Number">Section order number in scenario</param> /// <param name="section">Section object</param> public void AddSection(int order_Number, Database_Objects.Section_Translation section) { if (!sections.ContainsKey(order_Number)) { // There was problem, that sections objects where same and thery shared checkPoints // So we need to do copy of translation, with everything sare, but without checkPoints sections.Add(order_Number, new Database_Objects.Section_Translation(section)); } }
/// <summary> /// Get all sections for selected language /// </summary> /// <param name="language">Selected language</param> /// <param name="connection">Database connection</param> /// <returns>List of sections</returns> public static List <Database_Objects.Section_Translation> Sections(string language, Connection connection) { List <Database_Objects.Section_Translation> sections = new List <Database_Objects.Section_Translation>(); // Database operations SqlCommand myCommand; SqlDataReader reader; SqlConnection myConnection = connection.GetConnection(); // Object ID List <int> all = new List <int>(); myCommand = new SqlCommand("SELECT [ID_Section] FROM [Sections]", myConnection); reader = myCommand.ExecuteReader(); while (reader.Read()) { all.Add(reader.GetInt32(0)); } reader.Close(); // Object translations List <Database_Objects.Section_Translation> all_Translations = new List <Database_Objects.Section_Translation>(); myCommand = new SqlCommand("SELECT [ID_Section], [Language_Code], [Name] FROM [Sections_Translation]", myConnection); reader = myCommand.ExecuteReader(); Database_Objects.Section_Translation current_Translation; while (reader.Read()) { current_Translation = new Database_Objects.Section_Translation(reader.GetInt32(0), reader[1].ToString(), reader[2].ToString()); all_Translations.Add(current_Translation); } reader.Close(); // Select wanted translation bool haveTranslation; foreach (int id in all) { // Reset flag haveTranslation = false; // Find wanted translation foreach (Database_Objects.Section_Translation translation in all_Translations) { if (id == translation.GetID() && language == translation.GetLanguage_Code()) { sections.Add(translation); haveTranslation = true; break; } } // If no translation, use EN if (haveTranslation == false) { foreach (Database_Objects.Section_Translation translation in all_Translations) { if (id == translation.GetID() && defaultLanguage == translation.GetLanguage_Code()) { sections.Add(translation); break; } } } } return(sections); }
/// <summary> /// Get selected translation from database, if no translation, use default language /// </summary> /// <param name="language">Selected language</param> /// <param name="myConnection">Database connection</param> private static void GetSections(string language, SqlConnection myConnection) { // Database operations SqlCommand myCommand; SqlDataReader reader; // Object ID List <int> all = new List <int>(); using (myCommand = new SqlCommand("SELECT [ID_Section] FROM [Sections]", myConnection)) { using (reader = myCommand.ExecuteReader()) { while (reader.Read()) { all.Add(reader.GetInt32(0)); } } } // Object translations List <Database_Objects.Section_Translation> all_Translations = new List <Database_Objects.Section_Translation>(); using (myCommand = new SqlCommand("SELECT [ID_Section], [Language_Code], [Name] FROM [Sections_Translation]", myConnection)) { using (reader = myCommand.ExecuteReader()) { Database_Objects.Section_Translation current_Translation; while (reader.Read()) { current_Translation = new Database_Objects.Section_Translation(reader.GetInt32(0), reader[1].ToString(), reader[2].ToString()); all_Translations.Add(current_Translation); } } } // Select wanted translation, if not here, use EN bool haveTranslation; foreach (int id in all) { // Reset flag haveTranslation = false; // Find wanted translation foreach (Database_Objects.Section_Translation translation in all_Translations) { if (id == translation.GetID() && language == translation.GetLanguage_Code()) { sections[id.ToString()] = translation; haveTranslation = true; break; } } // If no translation, use EN if (haveTranslation == false) { foreach (Database_Objects.Section_Translation translation in all_Translations) { if (id == translation.GetID() && language == defaultLanguage) { sections[id.ToString()] = translation; break; } } } } }