예제 #1
0
        public static ExcelBindingDefinitionFormulaResult CreateInstance(ExcelTemplateDefinition templateDefinition, string definition)
        {
            try
            {
                definition = definition.Replace(FORMULA_RESULT_PREFIX, string.Empty);
                definition = definition.TrimEnd('}');

                //UseFormulaBindingDefinition
                string[] parts = definition.Split(';');
                if (parts.Count() > 2)
                {
                    throw new ArgumentException($"dataAccessor '{definition}' is invalid.");
                }

                string useFormulaDefinition = null;
                string underlyingDefinition;
                if (parts.Count() == 1)
                {
                    underlyingDefinition = $"{{{parts[0].Trim()}}}";
                }
                else
                {
                    useFormulaDefinition = $"{{{parts[0].Trim()}}}";
                    underlyingDefinition = $"{{{parts[1].Trim()}}}";
                }

                BindingDefinitionDescription bindingDefinitionDescription = BindingDefinitionDescription.CreateBindingDescription(templateDefinition, underlyingDefinition, underlyingDefinition);
                IBindingDefinition           underlyingBindingDefinition  = BindingDefinitionFactory.CreateInstances(templateDefinition, bindingDefinitionDescription);

                IBindingDefinition useFormulaBindingDefinition = null;
                if (!string.IsNullOrEmpty(useFormulaDefinition))
                {
                    bindingDefinitionDescription = BindingDefinitionDescription.CreateBindingDescription(templateDefinition, useFormulaDefinition, useFormulaDefinition);
                    useFormulaBindingDefinition  = BindingDefinitionFactory.CreateInstances(templateDefinition, bindingDefinitionDescription);
                }
                ExcelBindingDefinitionFormulaResult ret = new ExcelBindingDefinitionFormulaResult(bindingDefinitionDescription, underlyingBindingDefinition, useFormulaBindingDefinition);
                return(ret);
            }
            catch (Exception ex)
            {
                string message = $"Cannot retrieve the formula result binding dataAccessor '{definition.EmptyIfNull()}'. {ex.Message}";
                throw new EtkException(message);
            }
        }
예제 #2
0
        public ExcelContextItemFormulaResult(IBindingContextElement parent, IBindingDefinition bindingDefinition)
            : base(parent, bindingDefinition)
        {
            excelBindingDefinitionFormulaResult = bindingDefinition as ExcelBindingDefinitionFormulaResult;
            CanNotify = excelBindingDefinitionFormulaResult.CanNotify;
            //NestedContextItem = nestedContextItem;

            if (CanNotify)
            {
                objectsToNotify = bindingDefinition.GetObjectsToNotify(DataSource);
                if (objectsToNotify != null)
                {
                    foreach (INotifyPropertyChanged obj in objectsToNotify)
                    {
                        obj.PropertyChanged += OnPropertyChanged;
                    }
                }
            }
        }