/// <summary> /// Add operation into checkPoint /// </summary> /// <param name="order_Number">Operation order number in checkPoint</param> /// <param name="section">Operation object</param> public void AddOperation(int order_Number, Database_Objects.Operation_Translation operation) { operations.Add(order_Number, operation); }
/// <summary> /// Get all operations for selected language /// </summary> /// <param name="language">Selected language</param> /// <param name="connection">Database connection</param> /// <returns>List of operations</returns> public static List <Database_Objects.Operation_Translation> Operations(string language, Connection connection) { List <Database_Objects.Operation_Translation> operations = new List <Database_Objects.Operation_Translation>(); // Database operations SqlCommand myCommand; SqlDataReader reader; SqlConnection myConnection = connection.GetConnection(); // Object ID List <int> all = new List <int>(); myCommand = new SqlCommand("SELECT [ID_Operation] FROM [Operations]", myConnection); reader = myCommand.ExecuteReader(); while (reader.Read()) { all.Add(reader.GetInt32(0)); } reader.Close(); // Object translations List <Database_Objects.Operation_Translation> all_Translations = new List <Database_Objects.Operation_Translation>(); myCommand = new SqlCommand("SELECT [ID_Operation], [Language_Code], [Name] FROM [Operations_Translation]", myConnection); reader = myCommand.ExecuteReader(); Database_Objects.Operation_Translation current_Translation; while (reader.Read()) { current_Translation = new Database_Objects.Operation_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.Operation_Translation translation in all_Translations) { if (id == translation.GetID() && language == translation.GetLanguage_Code()) { operations.Add(translation); haveTranslation = true; break; } } // If no translation, use EN if (haveTranslation == false) { foreach (Database_Objects.Operation_Translation translation in all_Translations) { if (id == translation.GetID() && defaultLanguage == translation.GetLanguage_Code()) { operations.Add(translation); break; } } } } return(operations); }
/// <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 GetOperations(string language, SqlConnection myConnection) { // Database operations SqlCommand myCommand; SqlDataReader reader; // Object ID List <int> all = new List <int>(); using (myCommand = new SqlCommand("SELECT [ID_Operation] FROM [Operations]", myConnection)) { using (reader = myCommand.ExecuteReader()) { while (reader.Read()) { all.Add(reader.GetInt32(0)); } } } // Object translations List <Database_Objects.Operation_Translation> all_Translations = new List <Database_Objects.Operation_Translation>(); using (myCommand = new SqlCommand("SELECT [ID_Operation], [Language_Code], [Name] FROM [Operations_Translation]", myConnection)) { using (reader = myCommand.ExecuteReader()) { Database_Objects.Operation_Translation current_Translation; while (reader.Read()) { current_Translation = new Database_Objects.Operation_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.Operation_Translation translation in all_Translations) { if (id == translation.GetID() && language == translation.GetLanguage_Code()) { operations[id.ToString()] = translation; haveTranslation = true; break; } } // If no translation, use EN if (haveTranslation == false) { foreach (Database_Objects.Operation_Translation translation in all_Translations) { if (id == translation.GetID() && language == defaultLanguage) { operations[id.ToString()] = translation; break; } } } } }