private void SetupColumnDestinationFieldGroupName(
            Dictionary <string, object> dict,
            IConfigurationUnitStore configStore,
            int nextColumn,
            UPSERowConfiguration defaultConfiguration,
            List <UPSEColumn> columnArray)
        {
            var          destinationColumnFieldGroupName = dict.ValueOrDefault("DestFG") as string;
            FieldControl destFieldControl = null;

            if (!string.IsNullOrWhiteSpace(destinationColumnFieldGroupName))
            {
                destFieldControl = configStore.FieldControlByNameFromGroup("Edit", destinationColumnFieldGroupName);
            }

            if (destFieldControl != null)
            {
                var destColumnDictionary = new Dictionary <string, UPSEColumn>();
                for (var i = nextColumn; i < defaultConfiguration.Columns.Count; i++)
                {
                    var column = defaultConfiguration.Columns[i];
                    if (!(column is UPSEDestinationColumn))
                    {
                        break;
                    }

                    destColumnDictionary[column.CrmField.FieldIdentification] = column;
                }

                var tab = destFieldControl.TabAtIndex(0);
                foreach (var field in tab.Fields)
                {
                    if (destColumnDictionary.ValueOrDefault(field.Field.FieldIdentification) is UPSEDestinationColumn column)
                    {
                        columnArray.Add(new UPSEDestinationColumn(field, column));
                    }
                }
            }
            else
            {
                for (var i = nextColumn; i < defaultConfiguration.Columns.Count; i++)
                {
                    var column = defaultConfiguration.Columns[i];
                    if (!(column is UPSEDestinationColumn))
                    {
                        break;
                    }

                    columnArray.Add(column);
                }
            }
        }
        private void SetupDefaultConfiguration(
            string sourceColumnFieldGroupName,
            IConfigurationUnitStore configStore,
            UPSERowConfiguration defaultConfiguration,
            ref int nextColumn,
            List <UPSEColumn> columnArray)
        {
            FieldControl sourceFieldControl = null;

            if (!string.IsNullOrWhiteSpace(sourceColumnFieldGroupName))
            {
                sourceFieldControl = configStore.FieldControlByNameFromGroup("List", sourceColumnFieldGroupName);
            }

            if (sourceFieldControl != null)
            {
                var sourceColumnDictionary = new Dictionary <string, UPSEColumn>();
                for (var i = 0; i < defaultConfiguration.Columns.Count; i++)
                {
                    var column = defaultConfiguration.Columns[i];
                    if (!(column is UPSESourceColumn))
                    {
                        nextColumn = i;
                        break;
                    }

                    sourceColumnDictionary[column.CrmField.FieldIdentification] = column;
                }

                var tab = sourceFieldControl.TabAtIndex(0);
                foreach (var field in tab.Fields)
                {
                    var column = sourceColumnDictionary.ValueOrDefault(field.Field.FieldIdentification);
                    if (column != null)
                    {
                        columnArray.Add(new UPSESourceColumn(field, column));
                    }
                }
            }
            else
            {
                for (var i = 0; i < defaultConfiguration.Columns.Count; i++)
                {
                    var column = defaultConfiguration.Columns[i];
                    if (!(column is UPSESourceColumn))
                    {
                        nextColumn = i;
                        break;
                    }

                    columnArray.Add(column);
                }
            }

            for (var i = nextColumn; i < defaultConfiguration.Columns.Count; i++)
            {
                var column = defaultConfiguration.Columns[i];
                if (!(column is UPSESourceAdditionalColumn))
                {
                    nextColumn = i;
                    break;
                }

                columnArray.Add(column);
            }
        }
        private void SetupSourceAndDestinationColumns(
            Dictionary <string, object> dict,
            IConfigurationUnitStore configStore,
            ref int nextColumn,
            UPSERowConfiguration defaultConfiguration,
            List <UPSEColumn> columnArray)
        {
            if (SerialEntry.ChildrenCount > 0)
            {
                var sourceChildFG = dict.ValueOrDefault("SourceChildFG") as string;
                var destChildFG   = dict.ValueOrDefault("DestChildFG") as string;
                if (!string.IsNullOrWhiteSpace(sourceChildFG) || !string.IsNullOrWhiteSpace(destChildFG))
                {
                    FieldControlTab sourceFieldTab = null, destFieldTab = null;
                    if (!string.IsNullOrWhiteSpace(sourceChildFG))
                    {
                        sourceFieldTab = configStore.FieldControlByNameFromGroup("List", sourceChildFG).TabAtIndex(0);
                    }

                    if (!string.IsNullOrWhiteSpace(destChildFG))
                    {
                        destFieldTab = configStore.FieldControlByNameFromGroup("Edit", destChildFG).TabAtIndex(0);
                    }

                    if (sourceFieldTab == null)
                    {
                        sourceFieldTab = SerialEntry.SourceChildFieldControl.TabAtIndex(0);
                    }

                    if (destFieldTab == null)
                    {
                        destFieldTab = SerialEntry.DestChildFieldControl.TabAtIndex(0);
                    }

                    var sourceChildFieldDictionary = new Dictionary <string, UPSEColumn>();
                    var destChildFieldDictionary   = new Dictionary <string, UPSEColumn>();
                    for (var i = nextColumn; i < defaultConfiguration.Columns.Count; i++)
                    {
                        var configurationColumn = defaultConfiguration.Columns[i];
                        if (configurationColumn is UPSESourceChildColumn column)
                        {
                            var colKey = $"{column.ChildIndex}_{column.CrmField.FieldIdentification}";
                            sourceChildFieldDictionary.SetObjectForKey(column, colKey);
                        }
                        else if (configurationColumn is UPSEDestinationChildColumn childColumn)
                        {
                            var colKey = $"{childColumn.ChildIndex}_{childColumn.CrmField.FieldIdentification}";
                            destChildFieldDictionary[colKey] = childColumn;
                        }
                        else
                        {
                            nextColumn = i;
                            break;
                        }
                    }

                    for (var j = 0; j < SerialEntry.ChildrenCount; j++)
                    {
                        var count = sourceFieldTab.NumberOfFields;
                        for (var i = 0; i < count; i++)
                        {
                            var configField = sourceFieldTab.FieldAtIndex(i);
                            var colKey      = $"{j}_{configField.Field.FieldIdentification}";
                            if (sourceChildFieldDictionary.ValueOrDefault(colKey) is UPSESourceChildColumn col)
                            {
                                columnArray.Add(new UPSESourceChildColumn(configField, col));
                            }
                        }

                        count = destFieldTab.NumberOfFields;
                        for (var i = 0; i < count; i++)
                        {
                            var configField = destFieldTab.FieldAtIndex(i);
                            var colKey      = $"{j}_{configField.Field.FieldIdentification}";
                            if (destChildFieldDictionary.ValueOrDefault(colKey) is UPSEDestinationChildColumn col)
                            {
                                columnArray.Add(new UPSEDestinationChildColumn(configField, col));
                            }
                        }
                    }
                }
                else
                {
                    for (var i = nextColumn; i < defaultConfiguration.Columns.Count; i++)
                    {
                        var column = defaultConfiguration.Columns[i];
                        if (!(column is UPSESourceChildColumn) && !(column is UPSEDestinationChildColumn))
                        {
                            nextColumn = i;
                            break;
                        }

                        columnArray.Add(column);
                    }
                }
            }
        }