예제 #1
0
 public void UpdateFieldOptionSet(string entityType, string fieldName, PicklistOptionSet optionSet)
 {
     throw new NotImplementedException();
 }
예제 #2
0
        public static IEnumerable <PicklistOptionSet> ExtractOptionSetsFromExcel(string excelFile,
                                                                                 LogController controller, CustomisationImportResponse response)
        {
            var result = new List <PicklistOptionSet>();

            try
            {
                var rows = ExcelUtility.SelectPropertyBagsFromExcelTab(excelFile,
                                                                       OptionSetsTabName);

                rows = rows.Where(row => !row.GetColumnNames().Contains(Headings.OptionSets.Ignore) ||
                                  !row.GetFieldAsBoolean(Headings.OptionSets.Ignore))
                       .ToArray();

                var optionSetNames = rows
                                     .Where(r => !string.IsNullOrWhiteSpace(r.GetFieldAsString("Option Set Name")))
                                     .Select(r => r.GetFieldAsString("Option Set Name"))
                                     .Distinct()
                                     .ToArray();

                foreach (var optionSetName in optionSetNames)
                {
                    var thisOptionSetName = optionSetName;
                    var picklistOptionSet = new PicklistOptionSet();
                    try
                    {
                        var setDetailRow = rows
                                           .First(r => r.GetFieldAsString(Headings.OptionSets.OptionSetName) == thisOptionSetName);
                        var schemaName = setDetailRow.GetFieldAsString(Headings.OptionSets.SchemaName);
                        picklistOptionSet.SchemaName = schemaName;
                        var isShared = setDetailRow.GetFieldAsBoolean(Headings.OptionSets.IsSharedOptionSet);
                        picklistOptionSet.IsSharedOptionSet = isShared;
                        picklistOptionSet.DisplayName       = thisOptionSetName;
                        var options = rows
                                      .Where(r => r.GetFieldAsString(Headings.OptionSets.OptionSetName) == thisOptionSetName)
                                      .Select(r => new ImportPicklistOption(r.GetFieldAsString(Headings.OptionSets.Index), r.GetFieldAsString(Headings.OptionSets.Label), r.Index))
                                      .ToArray();

                        foreach (var option in options)
                        {
                            try
                            {
                                if (isShared && string.IsNullOrWhiteSpace(schemaName))
                                {
                                    throw new NullReferenceException(string.Format("{0} Is Required", Headings.OptionSets.SchemaName));
                                }
                                if (string.IsNullOrWhiteSpace(option.Key))
                                {
                                    throw new NullReferenceException(string.Format("{0} Is Required", Headings.OptionSets.Index));
                                }
                                if (string.IsNullOrWhiteSpace(option.Value))
                                {
                                    throw new NullReferenceException(string.Format("{0} Is Required", Headings.OptionSets.Label));
                                }
                                if (option.Value.StartsWith("TXT_"))
                                {
                                    option.Value = option.Value.Substring(4);
                                }
                            }
                            catch (Exception ex)
                            {
                                response.AddResponseItem(option.ExcelRow, picklistOptionSet, ex);
                            }
                        }
                        picklistOptionSet.PicklistOptions = options;
                        result.Add(picklistOptionSet);
                    }
                    catch (Exception ex)
                    {
                        throw new Exception("Error loading option set " + thisOptionSetName, ex);
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Error reading option sets from excel", ex);
            }
            return(result);
        }
예제 #3
0
 public void CreateOrUpdateSharedOptionSet(PicklistOptionSet sharedOptionSet)
 {
     throw new NotImplementedException();
 }
예제 #4
0
        public static IDictionary <int, FieldMetadata> ExtractFieldMetadataFromExcel(string excelFile,
                                                                                     LogController controller,
                                                                                     IEnumerable <PicklistOptionSet>
                                                                                     picklistOptionSets, CustomisationImportResponse response)
        {
            var rows = ExcelUtility.SelectPropertyBagsFromExcelTab(excelFile,
                                                                   FieldsTabName);
            var fields = new Dictionary <int, FieldMetadata>();

            foreach (var row in rows)
            {
                if (row.GetColumnNames().Contains(Headings.Fields.Ignore) &&
                    row.GetFieldAsBoolean(Headings.Fields.Ignore))
                {
                    continue;
                }

                var fieldSchemaName = row.GetFieldAsString(Headings.Fields.SchemaName);

                FieldMetadata fieldMetadata = null;
                try
                {
                    var type = row.GetFieldAsEnum <RecordFieldType>(Headings.Fields.FieldType);

                    if (!String.IsNullOrWhiteSpace(fieldSchemaName))
                    {
                        var recordTypeSchemaName = row.GetFieldAsString(Headings.Fields.RecordTypeSchemaName);

                        var displayName = row.GetFieldAsString(Headings.Fields.DisplayName);
                        if (string.IsNullOrWhiteSpace(displayName))
                        {
                            throw new NullReferenceException(string.Format("{0} Is Required", Headings.Fields.DisplayName));
                        }


                        switch (type)
                        {
                        case (RecordFieldType.Boolean):
                        {
                            fieldMetadata = new BooleanFieldMetadata(recordTypeSchemaName, fieldSchemaName,
                                                                     displayName);
                            break;
                        }

                        case (RecordFieldType.Date):
                        {
                            fieldMetadata = new DateFieldMetadata(recordTypeSchemaName, fieldSchemaName,
                                                                  displayName);
                            fieldMetadata.IncludeTime = row.GetFieldAsBoolean(Headings.Fields.IncludeTime);
                            var dateBehaviour = !row.GetColumnNames().Contains(Headings.Fields.DateBehaviour) || string.IsNullOrWhiteSpace(row.GetFieldAsString(Headings.Fields.DateBehaviour))
                                            ? "UserLocal"
                                            : row.GetFieldAsString(Headings.Fields.DateBehaviour);
                            fieldMetadata.DateBehaviour = dateBehaviour;
                            break;
                        }

                        case (RecordFieldType.Decimal):
                        {
                            fieldMetadata = new DecimalFieldMetadata(recordTypeSchemaName, fieldSchemaName,
                                                                     displayName);
                            fieldMetadata.MinValue         = row.GetFieldAsDecimal(Headings.Fields.Minimum);
                            fieldMetadata.MaxValue         = row.GetFieldAsDecimal(Headings.Fields.Maximum);
                            fieldMetadata.DecimalPrecision = row.GetFieldAsInteger(Headings.Fields.DecimalPrecision);
                            break;
                        }

                        case (RecordFieldType.Integer):
                        {
                            fieldMetadata = new IntegerFieldMetadata(recordTypeSchemaName, fieldSchemaName,
                                                                     displayName);
                            fieldMetadata.MinValue      = row.GetFieldAsInteger(Headings.Fields.Minimum);
                            fieldMetadata.MaxValue      = row.GetFieldAsInteger(Headings.Fields.Maximum);
                            fieldMetadata.IntegerFormat =
                                !row.GetColumnNames().Contains(Headings.Fields.IntegerFormat) || string.IsNullOrWhiteSpace(row.GetFieldAsString(Headings.Fields.IntegerFormat))
                                                ? IntegerType.None
                                                : row.GetFieldAsEnum <IntegerType>(Headings.Fields.IntegerFormat);
                            break;
                        }

                        case (RecordFieldType.Lookup):
                        {
                            fieldMetadata = new LookupFieldMetadata(recordTypeSchemaName, fieldSchemaName,
                                                                    displayName,
                                                                    row.GetFieldAsString(Headings.Fields.ReferencedRecordType))
                            {
                                DisplayInRelated = row.GetFieldAsBoolean(Headings.Fields.DisplayInRelated)
                            };
                            break;
                        }

                        case (RecordFieldType.Money):
                        {
                            fieldMetadata = new MoneyFieldMetadata(recordTypeSchemaName, fieldSchemaName,
                                                                   displayName);
                            fieldMetadata.MinValue = row.GetFieldAsDecimal(Headings.Fields.Minimum);
                            fieldMetadata.MaxValue = row.GetFieldAsDecimal(Headings.Fields.Maximum);
                            break;
                        }

                        case (RecordFieldType.Picklist):
                        {
                            fieldMetadata = new PicklistFieldMetadata(recordTypeSchemaName, fieldSchemaName,
                                                                      displayName);
                            var pFieldMetadata = (PicklistFieldMetadata)fieldMetadata;
                            var optionSetName  = row.GetFieldAsString(Headings.Fields.PicklistOptions);
                            var optionSet      = new PicklistOptionSet();
                            if (!string.IsNullOrWhiteSpace(optionSetName))
                            {
                                if (picklistOptionSets.Any(p => p.DisplayName == optionSetName))
                                {
                                    optionSet = picklistOptionSets.First(p => p.DisplayName == optionSetName);
                                }
                            }
                            pFieldMetadata.PicklistOptionSet = optionSet;
                            pFieldMetadata.IsMultiSelect     = row.GetColumnNames().Contains(Headings.Fields.IsMultiSelect) &&
                                                               row.GetFieldAsBoolean(Headings.Fields.IsMultiSelect);
                            break;
                        }

                        case (RecordFieldType.String):
                        {
                            fieldMetadata = new StringFieldMetadata(recordTypeSchemaName, fieldSchemaName,
                                                                    displayName)
                            {
                                IsPrimaryField = row.GetFieldAsBoolean(Headings.Fields.IsPrimaryField)
                            };
                            fieldMetadata.MaxLength  = row.GetFieldAsInteger(Headings.Fields.MaxLength);
                            fieldMetadata.TextFormat =
                                string.IsNullOrWhiteSpace(row.GetFieldAsString(Headings.Fields.TextFormat))
                                            ? TextFormat.Text
                                            : row.GetFieldAsEnum <TextFormat>(Headings.Fields.TextFormat);
                            break;
                        }

                        case RecordFieldType.Memo:
                        {
                            fieldMetadata           = new MemoFieldMetadata(recordTypeSchemaName, fieldSchemaName, displayName);
                            fieldMetadata.MaxLength = row.GetFieldAsInteger(Headings.Fields.MaxLength);
                            break;
                        }

                        case RecordFieldType.Status:
                        {
                            fieldMetadata = new StatusFieldMetadata(recordTypeSchemaName, fieldSchemaName,
                                                                    displayName, null);
                            break;
                        }

                        case (RecordFieldType.Double):
                        {
                            fieldMetadata = new DoubleFieldMetadata(recordTypeSchemaName, fieldSchemaName,
                                                                    displayName);
                            fieldMetadata.MinValue         = row.GetFieldAsDecimal(Headings.Fields.Minimum);
                            fieldMetadata.MaxValue         = row.GetFieldAsDecimal(Headings.Fields.Maximum);
                            fieldMetadata.DecimalPrecision = row.GetFieldAsInteger(Headings.Fields.DecimalPrecision);
                            break;
                        }

                        case (RecordFieldType.Uniqueidentifier):
                        {
                            fieldMetadata = new UniqueidentifierFieldMetadata(recordTypeSchemaName, fieldSchemaName,
                                                                              displayName);
                            break;
                        }

                        case (RecordFieldType.State):
                        {
                            fieldMetadata = new StateFieldMetadata(recordTypeSchemaName, fieldSchemaName,
                                                                   displayName);
                            break;
                        }

                        case (RecordFieldType.BigInt):
                        {
                            fieldMetadata = new BigIntFieldMetadata(recordTypeSchemaName, fieldSchemaName,
                                                                    displayName);
                            break;
                        }

                        case (RecordFieldType.Customer):
                        {
                            fieldMetadata = new CustomerFieldMetadata(recordTypeSchemaName, fieldSchemaName,
                                                                      displayName)
                            {
                                DisplayInRelated = row.GetFieldAsBoolean(Headings.Fields.DisplayInRelated)
                            };
                            break;
                        }

                        case (RecordFieldType.Owner):
                        {
                            fieldMetadata = new OwnerFieldMetadata(recordTypeSchemaName, fieldSchemaName,
                                                                   displayName)
                            {
                                DisplayInRelated = row.GetFieldAsBoolean(Headings.Fields.DisplayInRelated)
                            };
                            break;
                        }

                        default:
                        {
                            fieldMetadata = new AnyFieldMetadata(recordTypeSchemaName, fieldSchemaName,
                                                                 displayName, type);
                            break;
                        }
                        }

                        fieldMetadata.Description = row.GetFieldAsString(Headings.Fields.Description);
                        fieldMetadata.IsMandatory = row.GetFieldAsBoolean(Headings.Fields.IsMandatory);
                        fieldMetadata.Audit       = row.GetFieldAsBoolean(Headings.Fields.Audit);
                        fieldMetadata.Searchable  = row.GetFieldAsBoolean(Headings.Fields.Searchable);
                        fields.Add(row.Index + 1, fieldMetadata);
                    }
                }
                catch (Exception ex)
                {
                    response.AddResponseItem(row.Index + 1, fieldMetadata, ex);
                }
            }
            return(fields);
        }