private void btnRemove_Click(object sender, EventArgs e)
        {
            if (dgvMappings.SelectedRows.Count == 0)
            {
                MessageBox.Show("Please select a mapped field",
                                "Details Required",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Exclamation);
                return;
            }

            var mappedRow = dgvMappings.SelectedRows[0];

            dgvMappings.Rows.Remove(mappedRow);

            var sourceMappedFields = dgvMappings.Rows.Cast <DataGridViewRow>()
                                     .Where(x => x.Index != dgvMappings.NewRowIndex)
                                     .Select(r => r.Cells["Source"].Value.ToString());

            var destinationMappedFields = dgvMappings.Rows.Cast <DataGridViewRow>()
                                          .Where(x => x.Index != dgvMappings.NewRowIndex)
                                          .Select(r => r.Cells["Destination"].Value.ToString());

            var sourceFields      = SourceFields.Where(x => !x.Name.In(sourceMappedFields));
            var destinationFields = DestinationFields.Where(x => !x.Name.In(destinationMappedFields));

            dgvSource.DataSource      = GetFieldsDataTable(sourceFields);
            dgvDestination.DataSource = GetFieldsDataTable(destinationFields);
        }
        /// <summary>
        /// Reconciles the targets2.
        /// </summary>
        private void ReconcileTargets2()
        {
            //var bag = Mappings;
            Mappings.LoadHints2(TargetFieldModels, DataContextObject, SourceFields.OfType <MOriginalField>().ToList());
            foreach (var field in TargetFieldModels)
            {
                var mappedFrom = Mappings[field.Name];

                if (string.IsNullOrEmpty(mappedFrom))
                {
                    continue;
                }

                var sourceField = SourceFields.OfType <MOriginalField>()
                                  .FirstOrDefault(fld => fld.Name == mappedFrom);

                if (sourceField == null)
                {
                    continue;
                }

                sourceField.TargetField  = field;
                field.MappedField        = sourceField;
                sourceField.IsAutoMapped = true;
            }

            UpdateMappedFieldsCount();
        }
        /// <summary>
        /// Reconciles the mapping bag2.
        /// </summary>
        /// <param name="mSourceField">The m source field.</param>
        private void ReconcileMappingBag2(MOriginalField mSourceField)
        {
            var bag = Mappings;

            if (mSourceField != null && mSourceField.TargetField != null && !mSourceField.RemoveMapping)
            {
                bag[mSourceField.TargetField.Name] = mSourceField.Name;
            }
            else if (mSourceField != null && mSourceField.TargetField != null && mSourceField.RemoveMapping)
            {
                if (mSourceField.RemoveMapping)
                {
                    if (!string.IsNullOrEmpty(Mappings[mSourceField.TargetField.Name]))
                    {
                        Mappings.Remove(mSourceField.TargetField.Name);
                    }

                    mSourceField.TargetField = null;
                    SourceFields.CommitEdit();
                    SourceFields.Refresh();

                    UpdateMappedFieldsCount();
                }
            }
        }
        /// <summary>
        /// Executes the show sample values command.
        /// </summary>
        /// <param name="action">The action.</param>
        private void ExecuteShowSampleValuesCommand(string action)
        {
            if (string.IsNullOrEmpty(action))
            {
                return;
            }

            switch (action.ToUpper())
            {
            case "SHOW":

                MappedFieldsForValues = SourceFields.OfType <MOriginalField>()
                                        .Where(f => f.IsMapped && f.TargetField != null && f.TargetField.IsMapped)
                                        .ToObservableCollection();

                ShowMappedValuesPopup = true;
                break;

            default:
                ShowMappedValuesPopup = false;

                MappedFieldsForValues = new ObservableCollection <MOriginalField>();
                break;
            }
        }
示例#5
0
 private bool mapSourceFields(DataSet ds, DataRow dr)
 {
     DataRow[] drSourceFields = ds.Tables["ConstraintSourceFieldInfo"].Select("parent_id = " + dr["id"]);
     if (drSourceFields != null && drSourceFields.Length > 0)
     {
         foreach (DataRow drSrc in drSourceFields)
         {
             SourceFieldNames.Add(drSrc["field_name"].ToString().ToLower());
             foreach (FieldInfo fi in this.Table.Fields)
             {
                 if (fi.Name.ToUpper().Trim() == drSrc["field_name"].ToString().ToUpper().Trim())
                 {
                     SourceFields.Add(fi);
                     //fi.IsForeignKey = true;
                     //fi.ForeignKeyTableName = ReferencesTableName;
                     //fi.ForeignKeyFieldName =
                     break;
                 }
             }
         }
         return(SourceFields.Count > 0);
     }
     else
     {
         throw new InvalidOperationException(getDisplayMember("mapSourceFields", "Constraint {0} is defined with parent_id={1} but no fields were found in ConstraintSourceFieldInfo for it.", dr["constraint_name"].ToString(), dr["id"].ToString()));
     }
 }
示例#6
0
        protected override void BuildRequest(ref Dictionary <string, object> request)
        {
            var sourceFields = SourceFields.Get(Context.ExecutionContext)
                               .Split(new[] { "|" }, StringSplitOptions.RemoveEmptyEntries);
            var destinationFields = DestinationFields.Get(Context.ExecutionContext)
                                    .Split(new[] { "|" }, StringSplitOptions.RemoveEmptyEntries);

            if (sourceFields.Length != destinationFields.Length)
            {
                throw new InvalidPluginExecutionException("Number of Source Fields is not equal to number of Destination Fields");
            }

            var entityReference = ConvertToEntityReference(RecordId.Get(Context.ExecutionContext));

            var sourceRecord = Context.SystemService.Retrieve(entityReference.LogicalName, entityReference.Id,
                                                              new ColumnSet(sourceFields));

            for (var i = 0; i < sourceFields.Length; i++)
            {
                object targetFieldValue = null;

                if (sourceRecord.Contains(sourceFields[i]))
                {
                    targetFieldValue = sourceRecord[sourceFields[i]];
                }

                request.Add(destinationFields[i], targetFieldValue);
            }
        }
示例#7
0
        public ScalarPropertyDefinition ToPropertyDefinition()
        {
            if (SourceFields.Count() > 1)
            {
                throw new InvalidOperationException(string.Format("Cannot convert property {0} to PropertyDefinition", Identifier));
            }

            var sf = SourceFields.First();

            var p = new ScalarPropertyDefinition(Entity, Name)
            {
                SourceField = new SourceFieldDefinition(SourceFragment, sf.SourceFieldExpression, sf.SourceType, sf.SourceTypeSize, sf.IsNullable, false, sf.DefaultValue)
            };

            CopyTo(p);
            return(p);
        }
        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();

            //Message Type
            sb.Append(Type.ToString());
            //Requestid
            sb.Append(String.Format("~{0}", RequestId.ToString()));
            //UnitNumber
            sb.Append(String.Format("~A{0}", UnitNumber));
            //VendorId
            sb.Append(String.Format("~B{0}", VendorName));
            //D-F CardNumber based access
            sb.Append(String.Format("~DCARD~F{0}{1}", CardNumber, SourceAccount));
            //G and H fields Repgen Name / Locator Names
            sb.Append(Type == SymConnectMessageType.RG ? String.Format("~G{0}", Repgen.RepgenName) : String.Empty);
            //H - record locator
            sb.Append(Type == SymConnectMessageType.IQ || Type == SymConnectMessageType.FM ? FormatSourceRecord() : String.Empty);
            //Optional J params for FM
            sb.Append(Type == SymConnectMessageType.FM && FmType != null ? String.Format("~JFMTYPE={0}", (int)FmType.Value) : String.Empty);
            //J Params .. For Repgen calls, this is JRGSESSION, etc. For IQs this is our record locators, for FMs this is our revised fields, for TRS, nothing
            sb.Append(
                Type == SymConnectMessageType.RG
                //RG J params
                    ? Repgen.RepgenParameters.Aggregate(String.Empty,
                                                        (x, y) => x + String.Format("~JRG{0}={1}", y.Key, y.Value)) +
                String.Format("~JRGSESSION={0}", Repgen.RepgenSession)
                //TR, nothing
                    : Type == SymConnectMessageType.TR
                        ? String.Empty
                //IQ source fields
                        : Type == SymConnectMessageType.IQ
                            ? SourceFields.Aggregate(String.Empty, (x, y) => x + String.Format("~J{0}", y))
                //FM fields
                            : Type == SymConnectMessageType.FM
                                ? TargetFields.Aggregate(String.Empty,
                                                         (s, pair) => s + String.Format("~J{0}={1}", pair.Key, pair.Value))
                                : String.Empty);



            return(sb.ToString());
        }
 private void ValidateSymConnectContent()
 {
     //if the repgen name or parameters contain reserved characters, throw an exception
     if (Type == SymConnectMessageType.RG && (ContainsReservedChars(Repgen.RepgenName) ||
                                              Repgen.RepgenParameters.Aggregate(false, (agg, kvp) => agg || ContainsReservedChars(kvp.Key) || ContainsReservedChars(kvp.Value))))
     {
         throw new InvalidOperationException("Repgen name or parameters cannot contain symconnect reserved characters");
     }
     //if any of the source fields contain reserved characters, throw an exception
     if (Type == SymConnectMessageType.IQ && SourceFields.Aggregate(false, (agg, str) => agg || ContainsReservedChars(str)))
     {
         throw new InvalidOperationException("Source fields for iq cannot contain symconnect reserved characters");
     }
     //if any of the target fields contain reserved characters, throw an exception
     if (Type == SymConnectMessageType.FM &&
         TargetFields.Aggregate(false,
                                (agg, kvp) => agg || ContainsReservedChars(kvp.Key) || ContainsReservedChars(kvp.Value)))
     {
         throw new InvalidOperationException("Target fields for fm cannot contain symconnect reserved characters");
     }
 }
 void IUtf8JsonSerializable.Write(Utf8JsonWriter writer)
 {
     writer.WriteStartObject();
     writer.WritePropertyName("name");
     writer.WriteStringValue(Name);
     if (SearchMode != null)
     {
         writer.WritePropertyName("searchMode");
         writer.WriteStringValue(SearchMode);
     }
     if (SourceFields != null && SourceFields.Any())
     {
         writer.WritePropertyName("sourceFields");
         writer.WriteStartArray();
         foreach (var item in SourceFields)
         {
             writer.WriteStringValue(item);
         }
         writer.WriteEndArray();
     }
     writer.WriteEndObject();
 }
示例#11
0
        internal SqlField RegisterSourceField(ISqlExpression baseExpression, ISqlExpression expression, int index, Func <SqlField> fieldFactory)
        {
            var baseField = baseExpression as SqlField;

            if (baseField != null && _sourceFieldsByBase.TryGetValue(baseField, out var value))
            {
                return(value.Item1);
            }

            if (baseField == null && expression != null && _sourceFieldsByExpression.TryGetValue(expression, out value))
            {
                return(value.Item1);
            }

            var newField = fieldFactory();

            Utils.MakeUniqueNames(new[] { newField }, _sourceFieldsByExpression.Values.Select(t => t.Item1.Name), f => f.Name, (f, n, a) =>
            {
                f.Name         = n;
                f.PhysicalName = n;
            }, f => "source_field");

            SourceFields.Insert(index, newField);

            if (expression != null && !_sourceFieldsByExpression.ContainsKey(expression))
            {
                _sourceFieldsByExpression.Add(expression, Tuple.Create(newField, index));
            }

            if (baseField != null)
            {
                _sourceFieldsByBase.Add(baseField, Tuple.Create(newField, index));
            }

            return(newField);
        }
示例#12
0
 private bool mapSourceFields(DataSet ds, TableInfo target)
 {
     // rescan dataset for constraint info
     DataRow[] drSourceFields = ds.Tables["ConstraintSourceFieldInfo"].Select("constraint_name = '" + target.TableName + "'");
     if (drSourceFields != null && drSourceFields.Length > 0)
     {
         foreach (DataRow drSrc in drSourceFields)
         {
             SourceFieldNames.Add(drSrc["field_name"].ToString().ToLower());
             foreach (FieldInfo fi in target.Fields)
             {
                 if (fi.Name.ToUpper().Trim() == drSrc["field_name"].ToString().ToUpper().Trim())
                 {
                     SourceFields.Add(fi);
                     //fi.IsForeignKey = true;
                     //fi.ForeignKeyTableName = ReferencesTableName;
                     //fi.ForeignKeyFieldName =
                     break;
                 }
             }
         }
     }
     return(SourceFields.Count > 0);
 }
        /// <summary>
        /// For when yous need to set up some values that can't be directly bound to UI elements.
        /// </summary>
        public override void BeforeShow()
        {
            _isLoading = true;

            Dataservices = DataContextObject.Services;
            var providerFactory = new DataproviderFactory(Dataservices);

            providerFactory.InitDataProvider();
            var stage = new ImportStageModel(providerFactory);

            var temp = stage.SourceFields.Select(fld => new MOriginalField
            {
                Name       = fld.Name,
                Values     = new ObservableCollection <string>(stage.GetColumnValues(fld.Name, true)),
                FieldOrder = fld.Order
            }).ToList();

            var original      = new ObservableCollection <MOriginalField>(temp);
            var factory       = ServiceLocator.Current.GetInstance <IDomainSessionFactoryProvider>().SessionFactory;
            int positionIndex = 0;

            using (var session = factory.OpenSession())
            {
                DataContextObject.TargetElements = session.Query <Element>()
                                                   .Where(elem => elem.Owner.Id == DataContextObject.SelectedDataType.Target.Id)
                                                   .ToList();
            }

            var targetFields = DataContextObject.TargetElements
                               .Where(ElementFilter)
                               .Select(elem => new MTargetField(elem, original)
            {
                Position   = positionIndex++,
                IsRequired = elem.IsRequired
            })
                               .ToList();


            //TargetFields = MakeView(targetFields);
            DataTypeRequiredFieldCount = MappedFieldsCount = targetFields.Count(f => f.IsRequired);

            TargetFields      = new ListCollectionView(targetFields);
            SourceFields      = MakeView(temp);
            TotalSourceFields = SourceFields.Count;
            //ReconcileTargets();
            ReconcileTargets2();



            foreach (var f in SourceFields.OfType <MOriginalField>())
            {
                f.MappingChanged += f_MappingChanged2;
            }

            FilterText      = string.Empty;
            ShowEnumeration = new ObservableCollection <string> {
                ALL, AUTOMAPPED, MAPPED, UNMAPPED
            };
            SelectedShow = ShowEnumeration[0];

            FieldSortOrder = new ObservableCollection <string> {
                ORDER, NAME
            };
            SelectedSortOrder = FieldSortOrder[0];

            TargetFieldModels.ToList().Clear();
            var newList = TargetFieldModels.Where(field => !SourceFields.OfType <MOriginalField>()
                                                  .ToList()
                                                  .Any(f => f.TargetField != null && f.TargetField.Name.EqualsIgnoreCase(field.Name)))
                          .ToList();

            _targetFields = new ListCollectionView(newList);

            var requiredFields = TargetFieldModels.Where(f => f.IsRequired).OrderBy(f => f.Name).ToList();

            RequiredTargetFields = new ListCollectionView(requiredFields)
            {
                CustomSort = new MTargetFieldComparer()
            };

            var optionalFields = TargetFieldModels.Where(f => !f.IsRequired).OrderBy(f => f.Name).ToList();

            OptionalTargetFields = new ListCollectionView(optionalFields)
            {
                CustomSort = new MTargetFieldComparer()
            };

            _isLoading = false;
        }
        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);
            }
        }