예제 #1
0
 public FieldMappingEventArgs(ChangeTypes changeType, FieldMappings.OCMField ocmField, FieldMappings.BCMField bcmField)
 {
     OCMField   = ocmField; BCMField = bcmField;
     ChangeType = changeType;
 }
 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 cboDestinationField_SelectedIndexChanged(object sender, EventArgs e)
        {
            FieldMappings.OCMField newField = null;
            FieldMappingEventArgs  fieldMappingEventArgs;

            try
            {
                //Get the selected field
                if (cboDestinationField.SelectedIndex != -1)
                {
                    //newField = DestinationFields.Find(item => item.Name == cboDestinationField.Text);
                    //newField = DestinationFields.Find(item => item.Name == cboDestinationField.ValueMember);
                    newField = (FieldMappings.OCMField)cboDestinationField.SelectedItem; //TESTED Getting field by SelectedItem
                }
            }
            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.OCMDataSetType)
                {
                case FieldMappings.OCMDataSetTypes.Accounts:
                    FieldMappings.OCMAccountFields.OCMFields.MappedFields.Add(newField);
                    FieldMappings.OCMAccountFields.OCMFields.UnMappedFields.Remove(newField);
                    break;

                case FieldMappings.OCMDataSetTypes.BusinessContacts:
                    FieldMappings.OCMBusinessContactFields.OCMFields.MappedFields.Add(newField);
                    FieldMappings.OCMBusinessContactFields.OCMFields.UnMappedFields.Remove(newField);
                    break;

                case FieldMappings.OCMDataSetTypes.Deals:
                    FieldMappings.OCMDealFields.OCMFields.MappedFields.Add(newField);
                    FieldMappings.OCMDealFields.OCMFields.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, newField, SourceField);
                OnDestinationFieldChange(fieldMappingEventArgs);

continueHere:

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

                    switch (newField.OCMDataSetType)
                    {
                    case FieldMappings.OCMDataSetTypes.Accounts:
                        FieldMappings.OCMAccountFields.OCMFields.MappedFields.Remove(DestinationField);
                        FieldMappings.OCMAccountFields.OCMFields.UnMappedFields.Add(DestinationField);
                        break;

                    case FieldMappings.OCMDataSetTypes.BusinessContacts:
                        FieldMappings.OCMBusinessContactFields.OCMFields.MappedFields.Remove(DestinationField);
                        FieldMappings.OCMBusinessContactFields.OCMFields.UnMappedFields.Add(DestinationField);
                        break;

                    case FieldMappings.OCMDataSetTypes.Deals:
                        FieldMappings.OCMDealFields.OCMFields.MappedFields.Remove(DestinationField);
                        FieldMappings.OCMDealFields.OCMFields.UnMappedFields.Add(DestinationField);
                        break;
                    }

                    fieldMappingEventArgs = new FieldMappingEventArgs(FieldMappingEventArgs.ChangeTypes.Removed, DestinationField);
                    OnDestinationFieldChange(fieldMappingEventArgs);

                    //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
                    if (DestinationField?.FieldMappingType == FieldMappings.FieldMappingTypes.OptionalAutomatic && newField != null)
                    {
                        cboSourceField.SelectedIndex = -1;
                    }
                }

                //NOW update/cache the selected field as the current DestinationField in the control
                DestinationField = newField;
                //LastDestinationFieldIndex = cboDestinationField.SelectedIndex;
                if (DestinationField == null)
                {
                    Log.Warn("DestinationField is null");
                    return;
                }

                if (DestinationField.FieldMappingType == FieldMappings.FieldMappingTypes.OptionalAutomatic && DestinationField.OCMDataSetType == FieldMappings.OCMDataSetTypes.Accounts)
                {
                    //Special case for Account/Company Notes field only
                    IsReadOnlyButOptional = true;
                    //Find Notes field in SourceFields
                    int index = SourceFields.FindIndex(item => item.Name == FieldMappings.BCMAccountFields.Notes.Name);
                    //TESTED Setting to field
                    if (cboSourceField.SelectedItem != FieldMappings.BCMAccountFields.Notes)
                    {
                        //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!
                        //cboSourceField.SelectedIndex = index;
                        //cboSourceField.Text = FieldMappings.BCMAccountFields.Notes.Name;
                        cboSourceField.SelectedValue = FieldMappings.BCMAccountFields.Notes;
                    }
                }
            }
            catch (System.Exception ex)
            {
                Log.Error(ex);
            }
        }