コード例 #1
0
ファイル: StoreHelper.cs プロジェクト: rhw1111/DCEM
        /// <summary>
        /// 为实体元数据数据从DbDataReader中赋值
        /// </summary>
        /// <param name="queue"></param>
        /// <param name="reader"></param>
        /// <param name="prefix"></param>
        public static void SetEntityAttributeInfoSelectFields(EntityAttributeInfo metadata, DbDataReader reader, string prefix)
        {
            metadata.ID = (Guid)reader[string.Format("{0}id", prefix)];

            if (reader[string.Format("{0}entityinfoid", prefix)] != DBNull.Value)
            {
                metadata.EntityInfoId = (Guid)reader[string.Format("{0}entityinfoid", prefix)];
            }
            if (reader[string.Format("{0}name", prefix)] != DBNull.Value)
            {
                metadata.Name = reader[string.Format("{0}name", prefix)].ToString();
            }
            if (reader[string.Format("{0}type", prefix)] != DBNull.Value)
            {
                metadata.Type = reader[string.Format("{0}type", prefix)].ToString();
            }
            if (reader[string.Format("{0}createtime", prefix)] != DBNull.Value)
            {
                metadata.CreateTime = (DateTime)reader[string.Format("{0}createtime", prefix)];
            }
            if (reader[string.Format("{0}modifytime", prefix)] != DBNull.Value)
            {
                metadata.ModifyTime = (DateTime)reader[string.Format("{0}modifytime", prefix)];
            }
        }
コード例 #2
0
        protected TableAttributeInfo GetTableAttributeInfo(Type type)
        {
            EntityAttributeInfo EAttr = entityAttrList.Find(x => x.ObjType.Equals(type));

            if (EAttr == null)
            {
                throw new Exception("此对象没有配置实体自定义属性");
            }
            TableAttributeInfo tableAttrInfo = EAttr.TableAttributeInfoList.Find(x => x.Alias == Alias);

            //if (tableAttrInfo) throw new Exception("找不到相同别名的表自定义属性");
            return(tableAttrInfo);
        }
コード例 #3
0
        public async Task <object> ConvertFrom(EntityAttributeInfo attributeInfo, string strKey)
        {
            TextFragment fragment;

            if (strKey == null)
            {
                fragment = new TextFragment()
                {
                    Code = TextCodes.EntityKeyValueRequireNotNull,
                    DefaultFormatting = "实体类型为{0}的实体元数据的属性{1}的值类型{2}要求转换的字符串不为空,发生位置为{3}",
                    ReplaceParameters = new List <object>()
                    {
                        attributeInfo.EntityInfo.EntityType, attributeInfo.Name, attributeInfo.Type, $"{typeof(EntityAttributeValueKeyConvertServiceForDecimal).FullName},ConvertFrom"
                    }
                };

                throw new UtilityException((int)Errors.EntityKeyValueRequireNotNull, fragment);
            }

            if (attributeInfo.Type != EntityAttributeTypes.Decimal)
            {
                fragment = new TextFragment()
                {
                    Code = TextCodes.EntityAttributeMetadataValueTypeNotMatchEntityAttributeValueKeyConvertServiceRequire,
                    DefaultFormatting = "实体类型为{0}的实体元数据的属性{1}的值类型为{2},但实体属性值转换成关键字字符串服务{3}期待的类型为{4},两者不匹配,发生位置为{5}",
                    ReplaceParameters = new List <object>()
                    {
                        attributeInfo.EntityInfo.EntityType, attributeInfo.Name, attributeInfo.Type, typeof(EntityAttributeValueKeyConvertServiceForDecimal).FullName, typeof(decimal).FullName, $"{typeof(EntityAttributeValueKeyConvertServiceForDecimal).FullName},ConvertFrom"
                    }
                };

                throw new UtilityException((int)Errors.EntityAttributeMetadataValueTypeNotMatchEntityAttributeValueKeyConvertServiceRequire, fragment);
            }
            if (!Decimal.TryParse(strKey, out decimal result))
            {
                fragment = new TextFragment()
                {
                    Code = TextCodes.EntityKeyValueNotMatchEntityAttributeMetadataValueType,
                    DefaultFormatting = "实体类型为{0}的实体元数据的属性{1}的值类型为{2},但实体关键字{3}无法转换成该值类型,发生位置为{4}",
                    ReplaceParameters = new List <object>()
                    {
                        attributeInfo.EntityInfo.EntityType, attributeInfo.Name, attributeInfo.Type, strKey, $"{typeof(EntityAttributeValueKeyConvertServiceForDecimal).FullName},ConvertFrom"
                    }
                };

                throw new UtilityException((int)Errors.EntityKeyValueNotMatchEntityAttributeMetadataValueType, fragment);
            }

            return(await Task.FromResult(result));
        }
コード例 #4
0
    /// <summary>
    /// Creates and initializes a new instance of the Panel class with the specified Data.com contact mapping, and returns it.
    /// </summary>
    /// <param name="formInfo">The CMS contact form info.</param>
    /// <param name="entityInfo">The Data.com contact entity info.</param>
    /// <param name="mapping">The Data.com contact mapping.</param>
    /// <returns>A new instance of the Panel class initialized with the specified Data.com contact mapping.</returns>
    private Panel CreateMappingPanel(FormInfo formInfo, EntityInfo entityInfo, EntityMapping mapping)
    {
        Panel mappingPanel = new Panel {
            CssClass = "mapping"
        };

        mappingPanel.Controls.Add(CreateHeaderPanel());
        foreach (IField formItem in formInfo.ItemsList)
        {
            FormFieldInfo formField = formItem as FormFieldInfo;
            if (formField != null)
            {
                EntityMappingItem mappingItem = mapping.GetItem(formField.Name);
                if (mappingItem != null)
                {
                    EntityAttributeInfo entityAttribute = entityInfo.GetAttributeInfo(mappingItem.EntityAttributeName);
                    if (entityAttribute != null)
                    {
                        Panel row = new Panel {
                            CssClass = "control-group-inline"
                        };
                        mappingPanel.Controls.Add(row);

                        Panel formFieldPanel = new Panel {
                            CssClass = "input-width-60 cms-form-group-text"
                        };
                        row.Controls.Add(formFieldPanel);
                        formFieldPanel.Controls.Add(new Literal {
                            Text = ResHelper.LocalizeString(formField.GetDisplayName(MacroContext.CurrentResolver))
                        });

                        Panel entityAttributePanel = new Panel {
                            CssClass = "input-width-60 cms-form-group-text"
                        };
                        row.Controls.Add(entityAttributePanel);
                        entityAttributePanel.Controls.Add(new Literal {
                            Text = ResHelper.LocalizeString(entityAttribute.DisplayName)
                        });
                    }
                }
            }
        }

        return(mappingPanel);
    }
コード例 #5
0
    /// <summary>
    /// Creates a mapping of CMS contact (or account) fields and Data.com contact (or company) attributes from the current form state, and returns it.
    /// </summary>
    /// <returns>A mapping of CMS contact (or account) fields and Data.com contact (or company) attributes.</returns>
    private EntityMapping CreateEntityMappingFromForm()
    {
        EntityMapping mapping = new EntityMapping();

        foreach (FormFieldInfo fieldInfo in mContext.FormInfo.GetFields(true, false))
        {
            CMSDropDownList dropDownList = mAttributeNamesDropDownLists[fieldInfo.Name];
            if (dropDownList.SelectedIndex != 0)
            {
                EntityAttributeInfo attributeInfo = mContext.EntityInfo.GetAttributeInfo(dropDownList.SelectedValue);
                if (attributeInfo != null)
                {
                    mapping.Add(attributeInfo, fieldInfo);
                }
            }
        }

        return(mapping);
    }
コード例 #6
0
    /// <summary>
    /// Creates and initializes a new instance of the Panel class with the specified Data.com contact mapping, and returns it.
    /// </summary>
    /// <param name="formInfo">The CMS contact form info.</param>
    /// <param name="entityInfo">The Data.com contact entity info.</param>
    /// <param name="mapping">The Data.com contact mapping.</param>
    /// <returns>A new instance of the Panel class initialized with the specified Data.com contact mapping.</returns>
    private Panel CreateMappingPanel(FormInfo formInfo, EntityInfo entityInfo, EntityMapping mapping)
    {
        Panel mappingPanel = new Panel {
            CssClass = "mapping"
        };
        HtmlTable mappingTable = new HtmlTable();

        mappingTable.Controls.Add(CreateHeaderPanel());
        mappingPanel.Controls.Add(mappingTable);

        foreach (IDataDefinitionItem formItem in formInfo.ItemsList)
        {
            FormFieldInfo formField = formItem as FormFieldInfo;
            if (formField != null)
            {
                EntityMappingItem mappingItem = mapping.GetItem(formField.Name);
                if (mappingItem != null)
                {
                    EntityAttributeInfo entityAttribute = entityInfo.GetAttributeInfo(mappingItem.EntityAttributeName);
                    if (entityAttribute != null)
                    {
                        HtmlTableRow row = new HtmlTableRow();
                        mappingTable.Controls.Add(row);

                        HtmlTableCell formFieldCell = new HtmlTableCell();
                        formFieldCell.Controls.Add(new Literal {
                            Text = ResHelper.LocalizeString(formField.GetDisplayName(MacroContext.CurrentResolver))
                        });

                        HtmlTableCell entityAttributeCell = new HtmlTableCell();
                        entityAttributeCell.Controls.Add(new Literal {
                            Text = ResHelper.LocalizeString(entityAttribute.DisplayName)
                        });

                        row.Controls.Add(formFieldCell);
                        row.Controls.Add(entityAttributeCell);
                    }
                }
            }
        }

        return(mappingPanel);
    }
コード例 #7
0
        public async Task <string> ConvertTo(EntityAttributeInfo attributeInfo, object value)
        {
            TextFragment fragment;

            if (value == null)
            {
                await Task.FromResult(string.Empty);
            }
            if (!(value is decimal))
            {
                fragment = new TextFragment()
                {
                    Code = TextCodes.EntityAttributeMetadataValueTypeNotMatchEntityAttributeValueKeyConvertService,
                    DefaultFormatting = "实体类型为{0}的实体元数据的属性{1}的值的实际类型为{2},但实体属性值转换成关键字字符串服务{3}期待的类型为{4},两者不匹配,发生位置为{5}",
                    ReplaceParameters = new List <object>()
                    {
                        attributeInfo.EntityInfo.EntityType, attributeInfo.Name, value.GetType().FullName, typeof(EntityAttributeValueKeyConvertServiceForDecimal).FullName, typeof(decimal).FullName, $"{typeof(EntityAttributeValueKeyConvertServiceForDecimal).FullName},ConvertTo"
                    }
                };

                throw new UtilityException((int)Errors.EntityAttributeMetadataValueTypeNotMatchEntityAttributeValueKeyConvertService, fragment);
            }

            if (attributeInfo.Type != EntityAttributeTypes.Decimal)
            {
                fragment = new TextFragment()
                {
                    Code = TextCodes.EntityAttributeMetadataValueTypeNotMatchActual,
                    DefaultFormatting = "实体类型为{0}的实体元数据的属性{1}的值类型为{2},但实际值类型为{3},两者不匹配,发生位置为{4}",
                    ReplaceParameters = new List <object>()
                    {
                        attributeInfo.EntityInfo.EntityType, attributeInfo.Name, attributeInfo.Type, value.GetType().FullName, $"{typeof(EntityAttributeValueKeyConvertServiceForDecimal).FullName},ConvertTo"
                    }
                };

                throw new UtilityException((int)Errors.EntityAttributeMetadataValueTypeNotMatchActual, fragment);
            }

            return(await Task.FromResult(((decimal)value).ToString()));
        }
コード例 #8
0
    /// <summary>
    /// Creates and initializes a new instance of the HtmlTable class with the specified Data.com company mapping, and returns it.
    /// </summary>
    /// <param name="formInfo">The CMS account form info.</param>
    /// <param name="entityInfo">The Data.com company entity info.</param>
    /// <param name="mapping">The Data.com company mapping.</param>
    /// <returns>A new instance of the HtmlTable class initialized with the specified Data.com company mapping.</returns>
    private HtmlTable CreateTable(FormInfo formInfo, EntityInfo entityInfo, EntityMapping mapping)
    {
        HtmlTable table = new HtmlTable();

        table.Rows.Add(CreateHeaderRow());
        foreach (IFormItem formItem in formInfo.ItemsList)
        {
            FormFieldInfo formField = formItem as FormFieldInfo;
            if (formField != null)
            {
                EntityMappingItem mappingItem = mapping.GetItem(formField.Name);
                if (mappingItem != null)
                {
                    EntityAttributeInfo entityAttribute = entityInfo.GetAttributeInfo(mappingItem.EntityAttributeName);
                    if (entityAttribute != null)
                    {
                        HtmlTableRow row = new HtmlTableRow();
                        table.Rows.Add(row);
                        HtmlTableCell formFieldCell = new HtmlTableCell();
                        row.Cells.Add(formFieldCell);
                        formFieldCell.InnerText = ResHelper.LocalizeString(formField.Caption);
                        HtmlTableCell entityAttributeCell = new HtmlTableCell();
                        row.Cells.Add(entityAttributeCell);
                        entityAttributeCell.InnerText = ResHelper.LocalizeString(entityAttribute.DisplayName);

                        if (!Enabled)
                        {
                            formFieldCell.Style.Add("color", "#888888");
                            entityAttributeCell.Style.Add("color", "#888888");
                        }
                    }
                }
            }
        }

        return(table);
    }
コード例 #9
0
        public async Task <object> ConvertFrom(EntityAttributeInfo attributeInfo, string strKey)
        {
            if (strKey == null)
            {
                return(await Task.FromResult <string>(null));
            }

            if (attributeInfo.Type != EntityAttributeTypes.String)
            {
                var fragment = new TextFragment()
                {
                    Code = TextCodes.EntityAttributeMetadataValueTypeNotMatchEntityAttributeValueKeyConvertServiceRequire,
                    DefaultFormatting = "实体类型为{0}的实体元数据的属性{1}的值类型为{2},但实体属性值转换成关键字字符串服务{3}期待的类型为{4},两者不匹配,发生位置为{5}",
                    ReplaceParameters = new List <object>()
                    {
                        attributeInfo.EntityInfo.EntityType, attributeInfo.Name, attributeInfo.Type, typeof(EntityAttributeValueKeyConvertServiceForString).FullName, typeof(string).FullName, $"{typeof(EntityAttributeValueKeyConvertServiceForString).FullName},ConvertFrom"
                    }
                };

                throw new UtilityException((int)Errors.EntityAttributeMetadataValueTypeNotMatchEntityAttributeValueKeyConvertServiceRequire, fragment);
            }

            return(await Task.FromResult(strKey));
        }