コード例 #1
0
        /// <summary>
        /// 序列化
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="serializer"></param>
        /// <returns></returns>
        public override IDictionary <string, object> Serialize(object obj, JavaScriptSerializer serializer)
        {
            Dictionary <string, object> dictionary = new Dictionary <string, object>();
            EntityFieldValue            data       = (EntityFieldValue)obj;

            //dictionary.AddNonDefaultValue("FieldID", data.Definition.ID);
            dictionary.AddNonDefaultValue("CodeName", data.Definition.CodeName);
            if (!string.IsNullOrEmpty(data.Definition.ReferenceEntityCodeName))
            {
                dictionary.AddNonDefaultValue("EntityCodeName", data.Definition.ReferenceEntityCodeName);
            }
            dictionary.AddNonDefaultValue("FieldName", data.Definition.Name);

            if (data.Definition.FieldType == Enums.FieldTypeEnum.Collection)
            {
                DEEntityInstanceBaseCollection coll = data.GetRealValue() as DEEntityInstanceBaseCollection;
                if (coll != null)
                {
                    coll.ForEach(i =>
                    {
                        i._notSerialize = true;
                    });
                    dictionary.AddNonDefaultValue("StringValue", coll);
                }
                //else
                //{
                //    dictionary.AddNonDefaultValue("StringValue", " ");
                //}
            }
            else
            {
                if (string.IsNullOrEmpty(data.StringValue))
                {
                    //dictionary.AddNonDefaultValue("StringValue", " ");
                }
                else
                {
                    dictionary.AddNonDefaultValue("StringValue", data.StringValue);
                }
            }
            return(dictionary);
        }
コード例 #2
0
        private static void SetRelationObjectKeyValues(ITypeFieldValueList valueTypeList, Type entityType, Type childEntityType
                                                       , IEnumerable <IEntity> childObjects, IRelation relation)
        {
            EntityInfo            entityInfo = CacheManager.GetEntityInfo(entityType);
            ICollection <IColumn> columns    = entityInfo.Columns;

            foreach (RelationColumnMapping mapping in relation.TableColumnMappings)
            {
                IColumn          matchColumn = entityInfo.FindColumnByAttribute(mapping.FromField);
                EntityFieldValue fieldValue  = valueTypeList.GetFieldValue(matchColumn.AttributeName);

                if (fieldValue != null)
                {
                    SetChildPrimaryKeys(fieldValue, childEntityType, childObjects, mapping);
                }
                else
                {
                    string message = String.Format("The column {0} does not have a matching column in the object {1}", matchColumn.ColumnName, valueTypeList.Type.FullName);
                    throw new NoMatchingColumnFoundException(message);
                }
            }
        }
コード例 #3
0
        private void SetInstanceValue(DEEntityInstanceBase instance, List <SapValue> keyvalues)
        {
            keyvalues.ForEach(p =>
            {
                //找到实例中对应的键值
                EntityFieldValue fieldValue = instance.Fields.FirstOrDefault(f => f.Definition.Name.Equals(p.Key));

                if (fieldValue != null)
                {
                    if (p.Value is string)
                    {
                        instance.Fields.TrySetValue <string>(p.Key, p.Value.ToString().Trim());
                    }
                    else
                    {
                        //集合类型
                        var childValue      = p.Value as List <SapValue>;
                        var refInstanceColl = fieldValue.GetRealValue() as DEEntityInstanceBaseCollection;

                        if (childValue != null)
                        {
                            if (refInstanceColl != null && childValue.Count == refInstanceColl.Count)
                            {
                                //调用RFC之前该实例集合已有值,现在只需将SAP返回值更新至该实例即可
                                int index = 0;
                                childValue.ForEach(child =>
                                {
                                    DEEntityInstanceBase ins = refInstanceColl[index++];
                                    if (ins != null)
                                    {
                                        SetInstanceValue(ins, child.Value as List <SapValue>);
                                    }
                                });
                            }
                            else
                            {
                                //调用RFC之前该实体没有值(有可能是null),现在需要将SAP返回值转换为实例集合类型将赋值给fieldValue
                                DEEntityInstanceBaseCollection coll = new DEEntityInstanceBaseCollection();

                                //新添加  判断  如果是 Struct类型 时 应该返回 一条的子表数据类型  但是返回的不是集合类型  所以加一个这样的判断来 接收返回数据
                                if (fieldValue.Definition.IsStruct)
                                {
                                    DEEntityInstanceBase ins = fieldValue.Definition.ReferenceEntity.CreateInstance();
                                    childValue.ForEach(child =>
                                    {
                                        if (child.Value is string)
                                        {
                                            ins.Fields.TrySetValue <string>(child.Key, child.Value.ToString().Trim());
                                        }
                                    });
                                    coll.Add(ins);
                                }
                                else
                                {
                                    childValue.ForEach(child =>
                                    {
                                        DEEntityInstanceBase ins = fieldValue.Definition.ReferenceEntity.CreateInstance();
                                        //递归方法
                                        SetInstanceValue(ins, child.Value as List <SapValue>);
                                        coll.Add(ins);
                                    });
                                }


                                instance.Fields.TrySetValue <DEEntityInstanceBaseCollection>(p.Key, coll);
                            }
                        }
                    }
                }
            });
        }
コード例 #4
0
        protected override FrameworkElement GenerateElement(DataGridCell cell, object dataItem)
        {
            if (FieldInfo == null)
            {
                return(base.GenerateElement(cell, dataItem));
            }

            FieldType fieldType       = FieldInfo.FieldType;
            string    actualFieldName = null;

            if (fieldType == FieldType.Attachment)
            {
                return(new TextBlock());
                //AttachmentFieldValue attachmentFieldValue = getPropertyValue(FieldInfo.Name, dataItem, out actualFieldName) as AttachmentFieldValue;
                //if (attachmentFieldValue != null && attachmentFieldValue.AttachmentsProvider != null)
                //{
                //return base.GenerateElement(cell, dataItem);
                //StackPanel attachmentsStackPanel = new StackPanel();

                //if (attachmentFieldValue.AttachmentsProvider.HasAlreadyRetrievedAttachments())
                //{
                //    MultipleAttachmentsInfo attachments = attachmentFieldValue.AttachmentsProvider.GetAttachments();
                //    buildAttachmentsPanel(attachmentsStackPanel, attachments);
                //}
                //else
                //{
                //    HyperlinkButton attachmentsAnchor = createHyperlinkButton(null, "Retrieve");
                //    attachmentsAnchor.DataContext = attachmentFieldValue;
                //    attachmentsStackPanel.Children.Add(attachmentsAnchor);
                //    StackPanel attachmentsContainer = new StackPanel();
                //    attachmentsAnchor.Tag = attachmentsStackPanel;
                //    attachmentsAnchor.Click += new RoutedEventHandler(attachmentsAnchor_Click);
                //    attachmentsStackPanel.Children.Add(attachmentsContainer);
                //}

                //return attachmentsStackPanel;
                //}
            }
            else if (fieldType == FieldType.Entity)
            {
                EntityFieldValue entityFieldValue = getPropertyValue(FieldInfo.Name, dataItem, out actualFieldName) as EntityFieldValue;
                if (entityFieldValue != null)
                {
                    return(getHyperlinkButton(string.Format("{0}.LinkUrl", actualFieldName)));
                }
            }
            else if (fieldType == FieldType.Hyperlink)
            {
                HyperlinkFieldValue hyperLinkFieldValue = getPropertyValue(FieldInfo.Name, dataItem, out actualFieldName) as HyperlinkFieldValue;
                if (hyperLinkFieldValue != null)
                {
                    //TextBlock tblock = new TextBlock();
                    //tblock.SetBinding(TextBlock.TextProperty, new System.Windows.Data.Binding(string.Format("{0}.DisplayText", actualFieldName)));
                    //HyperlinkButton hyperlinkButton = new HyperlinkButton();
                    //hyperlinkButton.Click += new RoutedEventHandler(hyperlinkButton_Click);
                    //hyperlinkButton.Content = tblock;
                    //return hyperlinkButton;
                    //return tblock;

                    return(getHyperlinkButton(string.Format("{0}.LinkUrl", actualFieldName)));

                    //TextBlock tblock = new TextBlock();
                    //tblock.SetBinding(TextBlock.TextProperty, new System.Windows.Data.Binding(string.Format("{0}.LinkUrl", actualFieldName)));
                    //return tblock;
                }
            }
            else if (fieldType == FieldType.Image)
            {
                HyperlinkImageFieldValue hyperLinkImageFieldValue = getPropertyValue(FieldInfo.Name, dataItem, out actualFieldName) as HyperlinkImageFieldValue;
                if (hyperLinkImageFieldValue != null)
                {
                    return(getHyperlinkButton(string.Format("{0}.ImageUrl", actualFieldName)));
                }
            }
            else if (fieldType == FieldType.Currency)
            {
                CurrencyFieldValue currencyFieldValue = getPropertyValue(FieldInfo.Name, dataItem, out actualFieldName) as CurrencyFieldValue;
                if (currencyFieldValue != null)
                {
                    TextBlock tblock = new TextBlock();
                    tblock.SetBinding(TextBlock.TextProperty, new System.Windows.Data.Binding(string.Format("{0}.FormattedValue", actualFieldName)));
                    return(tblock);
                }
            }
            else if (fieldType == FieldType.DateTime)
            {
                DateTimeFieldValue dateTimeFieldValue = getPropertyValue(FieldInfo.Name, dataItem, out actualFieldName) as DateTimeFieldValue;
                if (dateTimeFieldValue != null)
                {
                    TextBlock tblock = new TextBlock();
                    tblock.SetBinding(TextBlock.TextProperty, new System.Windows.Data.Binding(string.Format("{0}.FormattedValue", actualFieldName)));
                    return(tblock);
                }
            }

            return(base.GenerateElement(cell, dataItem));
        }
コード例 #5
0
ファイル: BaseOperationLayer.cs プロジェクト: Adipa-G/ndbgate
        protected ICollection <IReadOnlyEntity> ReadRelationChildrenFromDb(IReadOnlyEntity entity, Type entityType
                                                                           , ITransaction tx, IRelation relation)
        {
            var retrievedEntities = new List <IReadOnlyEntity>();
            ICollection <Type> childTypesToProcess = GetChildTypesToProcess(relation);

            int index = 0;

            foreach (var childType in childTypesToProcess)
            {
                index++;
                IRelation effectiveRelation = relation.Clone();
                effectiveRelation.RelatedObjectType = childType;
                effectiveRelation.RelationShipName  = relation.RelationShipName + "_" + index;

                EntityInfo entityInfo = CacheManager.GetEntityInfo(entityType);
                var        logSb      = new StringBuilder();
                var        query      = entityInfo.GetRelationObjectLoad(DbLayer, effectiveRelation);

                IList <string> fields = new List <string>();
                foreach (RelationColumnMapping mapping in effectiveRelation.TableColumnMappings)
                {
                    fields.Add(mapping.FromField);
                }

                IDbCommand cmd = null;
                try
                {
                    cmd             = tx.CreateCommand();
                    cmd.CommandText = query;
                }
                catch (Exception ex)
                {
                    string message = String.Format("SQL Exception while trying create command for sql {0}", query);
                    throw new CommandCreationException(message, ex);
                }

                bool showQuery = Config.ShowQueries;
                if (showQuery)
                {
                    logSb.Append(query);
                }

                for (int i = 0; i < fields.Count; i++)
                {
                    string field      = fields[i];
                    object fieldValue = null;

                    IColumn matchColumn = entityInfo.FindColumnByAttribute(field);
                    EntityRelationColumnInfo entityRelationColumnInfo =
                        entityInfo.FindRelationColumnInfo(matchColumn != null ? matchColumn.AttributeName : "");
                    if (entityRelationColumnInfo != null)
                    {
                        EntityFieldValue entityFieldValue = entity.Context.ChangeTracker.GetFieldValue(matchColumn.AttributeName);
                        fieldValue = entityFieldValue.Value;
                    }
                    else if (matchColumn != null)
                    {
                        PropertyInfo getter = entityInfo.GetProperty(matchColumn.AttributeName);
                        fieldValue = ReflectionUtils.GetValue(getter, entity);
                    }
                    else
                    {
                        string message = String.Format("The field {0} does not have a matching field in the object {1}"
                                                       , field, entity.GetType().FullName);
                        throw new NoMatchingColumnFoundException(message);
                    }

                    if (showQuery)
                    {
                        logSb.Append(" ,").Append(matchColumn.ColumnName).Append("=").Append(fieldValue);
                    }
                    DbLayer.DataManipulate().SetToPreparedStatement(cmd, fieldValue, i + 1, matchColumn);
                }

                if (showQuery)
                {
                    Logger.GetLogger(Config.LoggerName).Debug(logSb.ToString());
                }
                if (Config.EnableStatistics)
                {
                    Statistics.RegisterSelect(childType);
                }

                ICollection <IReadOnlyEntity> retrievedEntitiesForType = ExecuteAndReadFromPreparedStatement(entity, tx, cmd, childType);
                retrievedEntities.AddRange(retrievedEntitiesForType);
            }
            return(retrievedEntities);
        }