private static void RemoveCountriesFromColumn(DataTable table, List <string> countries) { const string COL_COUNTRIES = "Countries"; List <DataRow> delRows = new List <DataRow>(); foreach (DataRow row in table.Rows) { string origCC = ImportVariablesForm.GetFieldStringValue(row, COL_COUNTRIES).ToUpper().Trim(), cleanedCC = origCC; foreach (string country in countries) // for the examples below: countries = { XX } { if (cleanedCC == country) { cleanedCC = string.Empty; break; } // XX -> empty cleanedCC = cleanedCC.Replace(", " + country + ",", ","); // ... C1, XX, C2 ... -> ... C1, C2 ... if (cleanedCC.EndsWith(", " + country)) // ... CC, XX -> ... CC { cleanedCC = cleanedCC.Substring(0, cleanedCC.Length - (", " + country).Length); } if (cleanedCC.StartsWith(country + ", ")) // XX, CC ... -> CC ... { cleanedCC = cleanedCC.Substring((country + ", ").Length); } } if (cleanedCC == origCC) { continue; } if (cleanedCC == string.Empty) { delRows.Add(row); } else { row.SetField <string>(COL_COUNTRIES, cleanedCC); } } foreach (DataRow delRow in delRows) { foreach (DataRelation rel in delRow.Table.ChildRelations) // for Cur_DerivedVariables the conditions must be deleted { foreach (DataRow subRow in delRow.GetChildRows(rel)) { subRow.Delete(); } } delRow.Delete(); } }
void btnImportVariables_ItemClick(object sender, ItemClickEventArgs e) { ImportVariablesForm form = new ImportVariablesForm(_varConfigFacade, this); form.ShowDialog(); }