Esempio n. 1
0
        private void ConvertPropertyType(EntityProp entityProp, EntityMeta entityMeta, Type type)
        {
            switch (Type.GetTypeCode(type))
            {
            case TypeCode.String:
            case TypeCode.Char:
                entityProp.PropType = PropType.Text;
                break;

            case TypeCode.Byte:
            case TypeCode.SByte:
            case TypeCode.UInt16:
            case TypeCode.UInt32:
            case TypeCode.UInt64:
            case TypeCode.Int16:
            case TypeCode.Int32:
            case TypeCode.Int64:
            case TypeCode.Decimal:
            case TypeCode.Double:
            case TypeCode.Single:
                entityProp.PropType = PropType.Number;
                break;

            case TypeCode.DateTime:
                entityProp.PropType = PropType.Date;
                break;

            case TypeCode.Boolean:
                entityProp.PropType = PropType.Boolean;
                break;

            default:
                if (type.IsEnum)
                {
                    entityProp.PropType = PropType.Enum;
                }
                else if (typeof(IEnumerable).IsAssignableFrom(type) && type.IsGenericType)
                {
                    entityProp.PropType = PropType.Collection;
                }
                else if (type.IsClass && type.Namespace == entityMeta.Namespace)
                {
                    entityProp.PropType = PropType.LookUp;
                }
                else if (type.BaseType == typeof(ValueType))
                {
                    entityProp.PropType = PropType.Text;
                }
                else
                {
                    entityProp.PropType = PropType.Unsupported;
                }
                break;
            }
        }
Esempio n. 2
0
        private StringBuilder GenerateDetailTabPage(EntityMeta entityMeta, EntityProp entityProp)
        {
            var result = new StringBuilder();

            result = result.AppendFormat("<dx:TabPage Text=\"{0}\" Visible=\"true\">{1}", entityProp.Name, Environment.NewLine);
            result = result.AppendFormat("    <ContentCollection>{0}", Environment.NewLine);
            result = result.AppendFormat("        <dx:ContentControl runat=\"server\">{0}", Environment.NewLine);
            result = result.Append(GenerateDetailGridView(entityMeta, entityProp));
            result = result.AppendFormat("        </dx:ContentControl>{0}", Environment.NewLine);
            result = result.AppendFormat("    </ContentCollection>{0}", Environment.NewLine);
            result = result.AppendFormat("</dx:TabPage>{0}", Environment.NewLine);

            return(result);
        }
Esempio n. 3
0
        private StringBuilder GenerateDetailDataSourceDesigner(EntityProp entityProp)
        {
            Console.WriteLine("INFO: Generating detail data sources designer-code for property {0}", entityProp.Name);
            var ds = new StringBuilder();

            ds = ds.Append(Environment.NewLine);
            ds = ds.AppendFormat("        /// <summary>{0}", Environment.NewLine);
            ds = ds.AppendFormat("        /// {0}DataSource control.{1}", entityProp.CollectionEntity.EntitySetName, Environment.NewLine);
            ds = ds.AppendFormat("        /// </summary>{0}", Environment.NewLine);
            ds = ds.AppendFormat("        /// <remarks>{0}", Environment.NewLine);
            ds = ds.AppendFormat("        /// Auto-generated field.{0}", Environment.NewLine);
            ds = ds.AppendFormat("        /// To modify move field declaration from designer file to code-behind file.{0}", Environment.NewLine);
            ds = ds.AppendFormat("        /// </remarks>{0}", Environment.NewLine);
            ds = ds.AppendFormat("        protected global::Microsoft.AspNet.EntityDataSource.EntityDataSource {0}DataSource;{1}", entityProp.CollectionEntity.EntitySetName.ToCamelCase(), Environment.NewLine);

            return(ds);
        }
Esempio n. 4
0
        private StringBuilder GenerateDetailDataSource(EntityMeta entityMeta, EntityProp entityProp)
        {
            Console.WriteLine("INFO: Generating detail data source for entity {0}", entityProp.CollectionEntity.Name);
            StringBuilder result = new StringBuilder();

            result = result.AppendFormat("<ef:EntityDataSource ID=\"{0}DataSource\" runat=\"server\" ContextTypeName=\"{1}\" EntitySetName=\"{2}\" EnableInsert=\"true\" EnableUpdate=\"true\" EnableDelete=\"true\"{3}",
                                         entityProp.CollectionEntity.EntitySetName.ToCamelCase(), dbApp.GetType().FullName, entityProp.CollectionEntity.EntitySetName, Environment.NewLine);
            result = result.AppendFormat("    AutoGenerateWhereClause=\"True\">{0}", Environment.NewLine);
            result = result.AppendFormat("    <WhereParameters>{0}", Environment.NewLine);
            EntityProp primaryKeyProp = entityMeta.EntityProps.Where(p => p.IsPrimaryKey == true).SingleOrDefault();

            if (primaryKeyProp == null)
            {
                throw new ApplicationException(string.Format("{0} does not have primary key", entityMeta.Name));
            }
            result = result.AppendFormat("        <asp:SessionParameter SessionField=\"{0}{1}\" Name=\"{0}{1}\" DbType=\"Int64\"/>{2}",
                                         entityMeta.Name, entityMeta.PrimaryKey, Environment.NewLine);
            result = result.AppendFormat("    </WhereParameters>{0}", Environment.NewLine);
            result = result.AppendFormat("</ef:EntityDataSource>{0}", Environment.NewLine);

            return(result);
        }
Esempio n. 5
0
        private StringBuilder GenerateDetailGridView(EntityMeta entityMeta, EntityProp entityProp)
        {
            Console.WriteLine("INFO: Generating child grid view for entity {0}", entityProp.CollectionEntity.Name);
            var result = new StringBuilder();

            if (entityProp.PropType != PropType.Collection)
            {
                Console.WriteLine("WARNING: {0} is not collection, skip it.", entityProp.Name);
                return(result);
            }
            result = result.Append(File.ReadAllText(string.Concat(templateDirectory, Path.DirectorySeparatorChar, "_detailGridView.aspx.txt")));
            var detailEntity = entityProp.CollectionEntity.EntitySetName.ToCamelCase();

            result = result.Replace("{detailGrid}", string.Concat(detailEntity, "Grid"));
            result = result.Replace("{detailGridDataSource}", string.Concat(detailEntity, "DataSource"));
            result = result.Replace("{detailKeyFieldName}", entityProp.CollectionEntity.PrimaryKey);
            result = result.Replace("{detailColumnList}", GenerateGridColumns(entityProp.CollectionEntity, entityMeta).ToString());

            ReplaceVariablesFromConfig(new StringBuilder[] { result });

            return(result);
        }
Esempio n. 6
0
        private void InspectProp(EntityMeta entityMeta, PropertyInfo propertyInfo)
        {
            Console.WriteLine("INFO: Inspecting entity {0}, property {1}", entityMeta.Name, propertyInfo.Name);
            var entityProp = new EntityProp();

            entityProp.Name = propertyInfo.Name;
            ConvertPropertyType(entityProp, entityMeta, propertyInfo.PropertyType);
            entityProp.ClrPropType  = propertyInfo.PropertyType.Name;
            entityProp.IsPrimaryKey = propertyInfo.Name.ToLower() == "id" || propertyInfo.GetCustomAttributes(typeof(KeyAttribute), false).Length > 0;

            if (entityProp.IsPrimaryKey)
            {
                entityMeta.PrimaryKey = entityProp.Name;
            }
            else if (propertyInfo.GetCustomAttributes(typeof(LookUpDisplayAttribute), false).Length > 0)
            {
                entityMeta.LookUpDisplay = propertyInfo.Name;
            }

            if (propertyInfo.GetCustomAttributes(typeof(ScaffoldColumnAttribute), false).Length > 0)
            {
                var attr = propertyInfo.GetCustomAttributes(typeof(ScaffoldColumnAttribute), false)[0];
                entityProp.IsScaffold = (attr as ScaffoldColumnAttribute).Scaffold;
            }

            entityProp.IsScaffold = propertyInfo.GetCustomAttributes(typeof(ScaffoldColumnAttribute), false).Where(p => (p as ScaffoldColumnAttribute).Scaffold == false).SingleOrDefault() == null;
            entityProp.IsScaffold = propertyInfo.GetCustomAttributes(typeof(NotMappedAttribute), false).SingleOrDefault() == null;

            if (entityProp.IsPrimaryKey)
            {
                entityMeta.EntityProps.Insert(0, entityProp);
            }
            else
            {
                entityMeta.EntityProps.Add(entityProp);
            }
        }
Esempio n. 7
0
        private StringBuilder GenerateDetailDataSourceCodeBehind(EntityMeta entityMeta, EntityProp entityProp)
        {
            Console.WriteLine("INFO: Generating detail data sources code-behind for property {0}", entityProp.Name);
            var ds = new StringBuilder();

            ds = ds.Append(Environment.NewLine);
            ds = ds.AppendFormat("        protected void {0}Grid_DataSelect(object sender, EventArgs e){1}", entityProp.CollectionEntity.EntitySetName.ToCamelCase(), Environment.NewLine);
            ds = ds.Append("        {" + Environment.NewLine);
            ds = ds.AppendFormat("            Session[\"{0}{1}\"] = (sender as ASPxGridView).GetMasterRowKeyValue();{2}", entityMeta.Name, entityMeta.PrimaryKey, Environment.NewLine);
            ds = ds.Append("        }" + Environment.NewLine);

            ds = ds.Append(Environment.NewLine);
            ds = ds.AppendFormat("        protected void {0}Grid_RowInserting(object sender, DevExpress.Web.Data.ASPxDataInsertingEventArgs e){1}", entityProp.CollectionEntity.EntitySetName.ToCamelCase(), Environment.NewLine);
            ds = ds.Append("        {" + Environment.NewLine);
            ds = ds.AppendFormat("            e.NewValues[\"{0}{1}\"] = (sender as ASPxGridView).GetMasterRowKeyValue();{2}", entityMeta.Name, entityMeta.PrimaryKey, Environment.NewLine);
            ds = ds.Append("        }" + Environment.NewLine);

            return(ds);
        }