public void FillSourceIfFoundDestination(ColumnParser parser, string caption) { if (_migration.Source.ColumnCaptionsWithIndexDictionary.ContainsKey(caption)) { parser.SourceColumnName = caption; parser.SourceColumnIndex = _migration.Source.ColumnCaptionsWithIndexDictionary[caption]; } else { if (_migration.Source.ColumnCaptionsWithIndexDictionary.ContainsKey(caption)) { parser.SourceColumnName = caption; parser.SourceColumnIndex = _migration.Source.ColumnCaptionsWithIndexDictionary[caption.ToLower()]; } else { string highest = string.Empty; int memory = 100; foreach (var par in _migration.Source.ColumnCaptionList) { int distance = Levenstein.NettoDistance(par, caption); if (distance < memory) { highest = par; memory = distance; } } if (memory <= 3) { parser.SourceColumnName = highest; parser.SourceColumnIndex = _migration.Source.ColumnCaptionsWithIndexDictionary[highest]; } else { var s = _migration.Source.ColumnCaptionsWithIndexDictionary.First(); parser.SourceColumnName = s.Key; parser.SourceColumnIndex = s.Value; } } } }
private void MergeCheckTextMatch() { if (IsSecondKeyChecked() && IsKeyChecked()) { var keycolumn = from el in columnParsers where el.IsKey == true select el; var matchcolumn = from el in columnParsers where el.LookupMatch == true select el; if (keycolumn.Count() != 1 || matchcolumn.Count() != 1) { var msg = new MessageView("You cannot specify more than one first key!"); msg.Show(); } else { var keycol = keycolumn.FirstOrDefault(); var matchcol = matchcolumn.FirstOrDefault(); Dictionary <string, int> sourceKeys = new Dictionary <string, int>(); Dictionary <string, int> destinationKeys = new Dictionary <string, int>(); sourceKeys = LoadColumn(_migration.Source, keycol.SourceColumnIndex); destinationKeys = LoadColumn(_migration.Destination, keycol.DestinationColumnIndex); SortedDictionary <string, int> sortedSourceKeys = new SortedDictionary <string, int>(sourceKeys); Dictionary <string, int> sourceNames = new Dictionary <string, int>(); Dictionary <string, int> destinationNames = new Dictionary <string, int>(); sourceNames = LoadColumn(_migration.Source, matchcol.SourceColumnIndex); destinationNames = LoadColumn(_migration.Destination, matchcol.DestinationColumnIndex); int ifNotFoundKeyRow = LastEmptyRow(_migration.Destination); bool permission = true; int row = 0; int columncaptionsindex = _migration.Destination.ColumnCaptionRow; foreach (var cl in sortedSourceKeys) { if (cl.Key != string.Empty) { if (destinationKeys.ContainsKey(cl.Key)) { row = destinationKeys[cl.Key] + columncaptionsindex; int rowsource = sourceKeys[cl.Key] + columncaptionsindex; decimal percent = Levenstein.Percent( _migration.Source.ReadCell(rowsource, matchcol.SourceColumnIndex), _migration.Destination.ReadCell(row, matchcol.DestinationColumnIndex) ); if (percent < 80) { var elements = from el in destinationNames where Levenstein.NettoDistance(cl.Key, el.Key) <= 3 && el.Key != string.Empty select el; if (elements.Count() > 0) { KeyValuePair <string, int> result = new KeyValuePair <string, int>(); var comp = new SimilarNames(elements, result); comp.ShowDialog(); } } } else { row = ifNotFoundKeyRow++; } FromSource2DestinationWithRelationByRow(row, cl, sourceKeys, permission); } } _migration.Destination.Save(); _migration.Source.Save(); } } }