/// <summary> /// Tracks changes in the mapping data table /// Synchronizes them to the Import map object /// Takes care of some interface actions /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void MappingGrid_RowChanged(object sender, DataRowChangeEventArgs e) { //when saved map is selected and something changes in the grid //changes radio selection to a custom map if (!_ignoreDtChanges && MappingRadioGroup.SelectedIndex != 1) { MappingRadioGroup.SelectedIndex = 1; } var allowNext = false; var table = ((DataTable)sender); //Enables next button if at least one column is mapped if (table.Rows.OfType <DataRow>() .Where(p => { var lastOrDefault = p.ItemArray.LastOrDefault(); return(lastOrDefault != null && !string.IsNullOrEmpty(lastOrDefault.ToString())); }) .GroupBy(p => p.ItemArray.LastOrDefault()) .Select(g => new { g.Key, count = g.Count() }).Any()) { allowNext = true; } //select all rows that are mapped var gridMappings = table.Rows.OfType <DataRow>() .Where(p => { var orDefault = p.ItemArray.LastOrDefault(); return(orDefault != null && !string.IsNullOrEmpty(orDefault.ToString())); }); //synchronize columns mappings with Importmap object foreach (var gridMapping in gridMappings) { var mapping = gridMapping; var firstOrDefault = mapping.ItemArray.FirstOrDefault(); var mpng = ImportMap.Mappings.FirstOrDefault(p => firstOrDefault != null && p.Column == firstOrDefault.ToString()) ?? new Mapping(ObjectSpace.Session) { Map = ImportMap }; mpng.Column = gridMapping.ItemArray.First().ToString(); var lastOrDefault = gridMapping.ItemArray.LastOrDefault(); if (lastOrDefault != null) { var mapedTo = lastOrDefault.ToString(); mpng.MapedTo = mapedTo; var mappableProperty = MappableColumns.FirstOrDefault(p => p.Name == mapedTo); if (mappableProperty != null) { mappableProperty.Mapped = true; } } } gridLookUpEdit2View.RefreshData(); wizardPage1.AllowNext = allowNext; }
private void AssingMapping(ImportMap importMap) { _ignoreDtChanges = true; var dt = MappingGrid.DataSource as DataTable; if (dt == null || importMap == null) { return; } var rows = dt.Rows; for (var i = 0; i < rows.Count; i++) { if (!string.IsNullOrEmpty(rows[i][dt.Columns.Count - 1].ToString())) { continue; } var index = i; var mapping = importMap.Mappings.FirstOrDefault(p => p.Column == rows[index][0].ToString()); if (mapping != null) { var mapedTo = mapping.MapedTo; dt.Rows[i][dt.Columns.Count - 1] = mapedTo; var mappableCol = MappableColumns.FirstOrDefault(p => p.Name == mapedTo); if (mappableCol != null) { mappableCol.Mapped = true; } } dt.Rows[i][dt.Columns.Count - 1] = null; } _ignoreDtChanges = false; }