Ejemplo n.º 1
0
        /// <summary>
        /// Performs call to MatchMaker if AutoMatchMembres is True
        /// </summary>
        public void FinalizeRules()
        {
            if (AutoMatchMembers)
            {
                if (MatchMaker == null)
                {
                    throw new NullReferenceException(nameof(MatchMaker));
                }

                var unmappedDestinations = DestinationFields.Where(x => !FieldExpressions.Keys.Contains(x.Key) &&
                                                                   !FieldSkips.Contains(x.Key))
                                           .Select(x => x.Value)
                                           .ToList();

                var matchedPairs = MatchMaker.FindMemberPairs(unmappedDestinations, SourceFields.Values);
                foreach (var pair in matchedPairs)
                {
                    var expression = ExpressionBuilder.GetMapExpression <TSource>(pair.DestinationMember, pair.SourceMember);
                    FieldExpressions.Add(pair.DestinationMember.Name, expression);
                }
            }

            IsFinalized = true;
        }
 public void AddOCMField(FieldMappings.OCMField field)
 {
     DestinationFields.Add(field);
     cboDestinationField.Items.Add(field);
 }
 public void RemoveOCMField(FieldMappings.OCMField field)
 {
     DestinationFields.Remove(field);
     cboDestinationField.Items.Remove(field);
 }
        private void cboSourceField_SelectedIndexChanged(object sender, EventArgs e)
        {
            FieldMappings.BCMField newField = null;
            FieldMappingEventArgs  fieldMappingEventArgs;

            try
            {
                //Get the selected field
                if (cboSourceField.SelectedIndex != -1)
                {
                    //TESTED Find by object instead of index
                    newField = (FieldMappings.BCMField)cboSourceField.SelectedItem;
                    // SourceFields[cboSourceField.SelectedIndex];
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex);
                return;
            }

            try
            {
                if (newField == null)
                {
                    goto continueHere; //Null selection - an automatic mapping reset
                }
                //Update list of mapped fields with the current field and remove it from the list of mapped fields
                //e.g. Business Fax is selected; add it to mapped list, remove it from unmapped list
                switch (newField.BCMDataSetType)
                {
                case FieldMappings.BCMDataSetTypes.Accounts:
                    FieldMappings.BCMAccountFields.BCMFields.MappedFields.Add(newField);
                    FieldMappings.BCMAccountFields.BCMFields.UnMappedFields.Remove(newField);
                    break;

                case FieldMappings.BCMDataSetTypes.BusinessContacts:
                    FieldMappings.BCMBusinessContactFields.BCMFields.MappedFields.Add(newField);
                    FieldMappings.BCMBusinessContactFields.BCMFields.UnMappedFields.Remove(newField);
                    break;

                case FieldMappings.BCMDataSetTypes.Opportunities:
                    FieldMappings.BCMOpportunityFields.BCMFields.MappedFields.Add(newField);
                    FieldMappings.BCMOpportunityFields.BCMFields.UnMappedFields.Remove(newField);
                    break;
                }

                //Fire OnSourceFieldChange event so parent control (eg. Accounts) can handle it and force an update on all other FieldMapping controls it contains. The currently selected field should be removed from the source combo in all those controls
                fieldMappingEventArgs = new FieldMappingEventArgs(FieldMappingEventArgs.ChangeTypes.Added, DestinationField, newField);
                OnSourceFieldChange(fieldMappingEventArgs);

continueHere:

                if (SourceField != null)
                {
                    //The current selection is changed to another field (e.g. Notes). The previous field (Business Fax) should be removed from mapped fields and added to unmapped fields.  Current selection is handled above

                    switch (newField.BCMDataSetType)
                    {
                    case FieldMappings.BCMDataSetTypes.Accounts:
                        FieldMappings.BCMAccountFields.BCMFields.MappedFields.Remove(SourceField);
                        FieldMappings.BCMAccountFields.BCMFields.UnMappedFields.Add(SourceField);
                        break;

                    case FieldMappings.BCMDataSetTypes.BusinessContacts:
                        FieldMappings.BCMBusinessContactFields.BCMFields.MappedFields.Remove(SourceField);
                        FieldMappings.BCMBusinessContactFields.BCMFields.UnMappedFields.Add(SourceField);
                        break;

                    case FieldMappings.BCMDataSetTypes.Opportunities:
                        FieldMappings.BCMOpportunityFields.BCMFields.MappedFields.Remove(SourceField);
                        FieldMappings.BCMOpportunityFields.BCMFields.UnMappedFields.Add(SourceField);
                        break;
                    }

                    fieldMappingEventArgs = new FieldMappingEventArgs(FieldMappingEventArgs.ChangeTypes.Removed, SourceField);
                    OnSourceFieldChange(fieldMappingEventArgs);

                    //NOTE If the previously selected field is an automatic field, we need to also nullify the selection in the other combo. Just set index to -1??. Also do NOT do if newField is null, otherwise we will be resetting the field that was just changed and triggered the change to THIS combo
                    if (SourceField?.FieldMappingType == FieldMappings.FieldMappingTypes.OptionalAutomatic && newField != null)
                    {
                        cboDestinationField.SelectedIndex = -1;
                    }
                }

                //NOW update/cache the selected field as the current SourceField in the control
                SourceField = newField;

                if (SourceField == null)
                {
                    //Happens when deleting a mappingRemoved
                    //Log.Verbose("SourceField is null");
                    return;
                }

                if (SourceField.FieldMappingType == FieldMappings.FieldMappingTypes.OptionalAutomatic && SourceField.BCMDataSetType == FieldMappings.BCMDataSetTypes.Accounts)
                {
                    //Special case for Account/Company Notes field only. Now only for Company notes because Account notes are now auto-mapped
                    IsReadOnlyButOptional = true;
                    //Find Notes field in SourceFields
                    int index = DestinationFields.FindIndex(item => item.Name == FieldMappings.OCMAccountFields.Notes.Name);
                    //TESTED Setting to field
                    if (cboDestinationField.ValueMember != FieldMappings.OCMAccountFields.Notes.Name)
                    {
                        //if (cboDestinationField.SelectedIndex != index) //See if it is already mapped - this combo may have just been automapped from the other control so we don't need to automap the other control in return!
                        //cboDestinationField.SelectedIndex = index;
                        //cboDestinationField.Text = FieldMappings.OCMAccountFields.Notes.Name;
                        cboDestinationField.SelectedValue = FieldMappings.OCMAccountFields.Notes; //TESTED Setting to field
                    }
                }
            }
            catch (System.Exception ex)
            {
                Log.Error(ex);
            }
        }