Example #1
0
        private static BeeDataAdapter GetHeaderItem(PropertySchema propertySchema)
        {
            ModelPropertyAttribute modelPropertyAttribute
                = propertySchema.GetCustomerAttribute <ModelPropertyAttribute>();

            BeeDataAdapter dataAdapter = new BeeDataAdapter();
            string         descriptionInfo;

            if (modelPropertyAttribute != null)
            {
                if (!modelPropertyAttribute.Visible)
                {
                    return(null);
                }
                descriptionInfo = modelPropertyAttribute.Description;
                if (string.IsNullOrEmpty(descriptionInfo))
                {
                    descriptionInfo = propertySchema.Name;
                }

                dataAdapter.Add("description", descriptionInfo);
                dataAdapter.Add("name", propertySchema.Name);

                if (modelPropertyAttribute.ColumnWidth != 0)
                {
                    dataAdapter.Add("width", modelPropertyAttribute.ColumnWidth.ToString());
                }

                if (!string.IsNullOrEmpty(modelPropertyAttribute.Align))
                {
                    dataAdapter.Add("align", modelPropertyAttribute.Align);
                }

                if (modelPropertyAttribute.OrderableFlag)
                {
                    dataAdapter.Add("orderField", propertySchema.Name);
                }
            }
            else
            {
                dataAdapter.Add("description", propertySchema.Name);
                dataAdapter.Add("Name", propertySchema.Name);
            }

            return(dataAdapter);
        }
Example #2
0
        private BeeDataAdapter GetSearchItem(PropertySchema propertySchema)
        {
            BeeDataAdapter         dataAdapter = null;
            ModelPropertyAttribute modelPropertyAttribute
                = propertySchema.GetCustomerAttribute <ModelPropertyAttribute>();

            if (modelPropertyAttribute != null)
            {
                if (!modelPropertyAttribute.Visible)
                {
                    return(null);
                }

                if (!modelPropertyAttribute.Queryable)
                {
                    return(null);
                }

                dataAdapter = new BeeDataAdapter();

                string descriptionInfo = modelPropertyAttribute.Description;
                if (string.IsNullOrEmpty(descriptionInfo))
                {
                    descriptionInfo = propertySchema.Name;
                }

                dataAdapter.Add("name", propertySchema.Name);
                dataAdapter.Add("Type", propertySchema.PropertyType);
                dataAdapter.Add("QueryType", modelPropertyAttribute.QueryType);
                dataAdapter.Add("Description", descriptionInfo);

                if (!string.IsNullOrEmpty(modelPropertyAttribute.MappingName))
                {
                    dataAdapter.Add("MappingName", modelPropertyAttribute.MappingName);
                }

                if (propertySchema.PropertyType.IsEnum && !dataAdapter.ContainsKey("MappingName"))
                {
                    dataAdapter.Add("MappingName", propertySchema.PropertyType.ToString());
                }
            }

            return(dataAdapter);
        }
Example #3
0
        protected virtual string GetQuerySelectClause(Type modelType)
        {
            IEntityProxy entityProxy = EntityProxyManager.Instance.GetEntityProxyFromType(modelType);

            string      tableName   = OrmUtil.GetTableName(modelType);
            TableSchema tableSchema = DbSession.Current.GetTableSchema(tableName);

            StringBuilder selectClause = new StringBuilder();

            foreach (PropertySchema propertySchema in entityProxy.GetPropertyList())
            {
                string columnName = propertySchema.Name;
                ModelPropertyAttribute modelPropertyAttribute
                    = propertySchema.GetCustomerAttribute <ModelPropertyAttribute>();
                if (modelPropertyAttribute != null)
                {
                    if (!modelPropertyAttribute.Visible)
                    {
                        continue;
                    }
                }

                OrmColumnAttribute ormColumnAttribute = propertySchema.GetCustomerAttribute <OrmColumnAttribute>();
                if (ormColumnAttribute != null && !string.IsNullOrEmpty(ormColumnAttribute.DbColumnName))
                {
                    columnName = ormColumnAttribute.DbColumnName;
                }

                if (tableSchema != null && !tableSchema.ContainsColumn(columnName))
                {
                    continue;
                }

                selectClause.AppendFormat("{0},", columnName);
            }
            selectClause.Remove(selectClause.Length - 1, 1);

            return(selectClause.ToString());
        }
Example #4
0
        /// <summary>
        /// Gets the conditions via the attribute of the modeltype and the data from page.
        /// </summary>
        /// <param name="modelType">the model type.</param>
        /// <param name="dataAdapter">the data from page.</param>
        /// <returns>the condition.</returns>
        protected virtual SqlCriteria GetQueryCondition(Type modelType, BeeDataAdapter dataAdapter)
        {
            IEntityProxy entityProxy = EntityProxyManager.Instance.GetEntityProxyFromType(modelType);
            SqlCriteria  result      = new SqlCriteria();

            dataAdapter = new BeeDataAdapter(dataAdapter);
            dataAdapter.RemoveEmptyOrNull();

            ModelAttribute modelAttribute = entityProxy.GetCustomerAttribute <ModelAttribute>();

            foreach (PropertySchema propertySchema in entityProxy.GetPropertyList())
            {
                string propertyName = propertySchema.Name;
                ModelPropertyAttribute modelPropertyAttribute
                    = propertySchema.GetCustomerAttribute <ModelPropertyAttribute>();
                if (modelPropertyAttribute != null)
                {
                    if (dataAdapter.ContainsKey(propertyName))
                    {
                        if (modelPropertyAttribute.Queryable)
                        {
                            object conditionValue = dataAdapter[propertyName];

                            if (propertySchema.PropertyType == typeof(string))
                            {
                                conditionValue = HttpUtility.HtmlDecode(conditionValue.ToString());
                            }

                            if (modelPropertyAttribute.QueryType == ModelQueryType.Equal &&
                                propertySchema.PropertyType == typeof(bool))
                            {
                                bool value = false;
                                bool.TryParse(conditionValue.ToString(), out value);
                                if (value)
                                {
                                    conditionValue = 1;
                                }
                                else
                                {
                                    conditionValue = 0;
                                }
                            }

                            if (propertySchema.PropertyType == typeof(DateTime))
                            {
                                DateTime propertyValue = dataAdapter.TryGetValue <DateTime>(propertyName, DateTime.MinValue);
                                if (propertyValue != DateTime.MinValue)
                                {
                                    conditionValue = propertyValue;
                                }
                                else
                                {
                                    // 若是时间,而又没有赋值, 则略过
                                    continue;
                                }
                            }

                            AddCondition(result, modelPropertyAttribute.QueryType, propertyName, conditionValue);
                        }
                    }
                    else
                    {
                        if (modelPropertyAttribute.Queryable &&
                            modelPropertyAttribute.QueryType == ModelQueryType.Between)
                        {
                            if (dataAdapter.ContainsKey(propertyName + "begin"))
                            {
                                if (propertySchema.PropertyType == typeof(DateTime))
                                {
                                    DateTime beginTime = dataAdapter.TryGetValue <DateTime>(propertyName + "begin", DateTime.MinValue);
                                    result.GreaterThanOrEqual(propertyName, beginTime);
                                }
                                else
                                {
                                    result.GreaterThanOrEqual(propertyName, dataAdapter[propertyName + "begin"]);
                                }
                            }

                            if (dataAdapter.ContainsKey(propertyName + "end"))
                            {
                                DateTime endTime = dataAdapter.TryGetValue <DateTime>(propertyName + "end", DateTime.MinValue);
                                if (propertySchema.PropertyType == typeof(DateTime))
                                {
                                    if (endTime == endTime.Date)
                                    {
                                        endTime = endTime.AddDays(1);
                                    }

                                    //result.LessThan(propertyName, endTime.ToString("yyyy-MM-dd"));
                                    result.LessThan(propertyName, endTime);
                                }
                                else
                                {
                                    result.LessThanOrEqual(propertyName, dataAdapter[propertyName + "end"]);
                                }
                            }
                        }
                    }
                }
            }

            return(result);
        }
Example #5
0
        private BeeDataAdapter GetDetailItem(PropertySchema propertySchema, string identityColumn)
        {
            ModelPropertyAttribute modelPropertyAttribute
                = propertySchema.GetCustomerAttribute <ModelPropertyAttribute>();
            BeeDataAdapter dataAdapter = new BeeDataAdapter();
            string         descriptionInfo;
            bool           readOnly = false;

            if (string.Compare(identityColumn, propertySchema.Name, true) == 0)
            {
                dataAdapter.Add("showonly", true);
                readOnly = true;
            }

            if (modelPropertyAttribute != null)
            {
                descriptionInfo = modelPropertyAttribute.Description;
                if (string.IsNullOrEmpty(descriptionInfo))
                {
                    descriptionInfo = propertySchema.Name;
                }

                if (!modelPropertyAttribute.Visible)
                {
                    dataAdapter.Add("visible", false);
                }
                if (!string.IsNullOrEmpty(modelPropertyAttribute.MappingName))
                {
                    dataAdapter.Add("mappingname", modelPropertyAttribute.MappingName);
                }

                readOnly = readOnly || modelPropertyAttribute.ReadonlyFlag;

                if (!readOnly)
                {
                    if (propertySchema.PropertyType.UnderlyingSystemType == typeof(DateTime))
                    {
                        if (string.Compare("modifytime", propertySchema.Name, true) == 0 ||
                            string.Compare("updatetime", propertySchema.Name, true) == 0 ||
                            string.Compare("createtime", propertySchema.Name, true) == 0)
                        {
                            readOnly = true;
                            dataAdapter.Add("showonly", true);
                        }
                    }
                }
            }
            else
            {
                descriptionInfo = propertySchema.Name;
            }

            dataAdapter.Add("description", descriptionInfo);
            dataAdapter.Add("name", propertySchema.Name);
            dataAdapter.Add("readonly", readOnly);

            if (propertySchema.PropertyType == typeof(DateTime))
            {
                dataAdapter.Add("date", true);
            }

            if (propertySchema.PropertyType.IsEnum && !dataAdapter.ContainsKey("mappingname"))
            {
                dataAdapter.Add("mappingname", propertySchema.PropertyType.ToString());
            }

            return(dataAdapter);
        }
Example #6
0
        /*
         *
         * private List<BeeDataAdapter> GetSearchInfo(BeeDataAdapter dataAdapter)
         * {
         *  List<BeeDataAdapter> result = new List<BeeDataAdapter>();
         *
         *  EntityProxy<T> entityProxy = EntityProxyManager.Instance.GetEntityProxy<T>();
         *  foreach (PropertySchema propertySchema in entityProxy.GetPropertyList())
         *  {
         *      ModelPropertyAttribute modelPropertyAttribute
         *          = propertySchema.GetCustomerAttribute<ModelPropertyAttribute>();
         *      if (modelPropertyAttribute != null)
         *      {
         *          if (!modelPropertyAttribute.Visible)
         *          {
         *              continue;
         *          }
         *
         *          if (!modelPropertyAttribute.Queryable)
         *          {
         *              continue;
         *          }
         *
         *          BeeDataAdapter dataItem = new BeeDataAdapter();
         *
         *          string descriptionInfo = modelPropertyAttribute.Description;
         *          if (string.IsNullOrEmpty(descriptionInfo))
         *          {
         *              descriptionInfo = propertySchema.Name;
         *          }
         *
         *          dataItem.Add("name", propertySchema.Name);
         *          dataItem.Add("Type", propertySchema.PropertyType);
         *          dataItem.Add("QueryType", modelPropertyAttribute.QueryType);
         *          dataItem.Add("Description", descriptionInfo);
         *          dataItem.Add("MappingName", modelPropertyAttribute.MappingName);
         *
         *          result.Add(dataItem);
         *      }
         *  }
         *
         *  return result;
         * }
         *
         * private List<BeeDataAdapter> GetHeaderInfo()
         * {
         *  List<BeeDataAdapter> result = new List<BeeDataAdapter>();
         *  EntityProxy<T> entityProxy = EntityProxyManager.Instance.GetEntityProxy<T>();
         *
         *  ModelAttribute modelAttribute = entityProxy.GetCustomerAttribute<ModelAttribute>();
         *
         *  foreach (PropertySchema propertySchema in entityProxy.GetPropertyList())
         *  {
         *      ModelPropertyAttribute modelPropertyAttribute
         *          = propertySchema.GetCustomerAttribute<ModelPropertyAttribute>();
         *
         *      BeeDataAdapter dataAdapter = new BeeDataAdapter();
         *      string descriptionInfo;
         *      if (modelPropertyAttribute != null)
         *      {
         *          if (!modelPropertyAttribute.Visible)
         *          {
         *              continue;
         *          }
         *
         *          descriptionInfo = modelPropertyAttribute.Description;
         *          if (string.IsNullOrEmpty(descriptionInfo))
         *          {
         *              descriptionInfo = propertySchema.Name;
         *          }
         *
         *          dataAdapter.Add("description", descriptionInfo);
         *          dataAdapter.Add("name", propertySchema.Name);
         *
         *          if (modelPropertyAttribute.ColumnWidth != 0)
         *          {
         *              dataAdapter.Add("width", modelPropertyAttribute.ColumnWidth.ToString());
         *          }
         *
         *          if (!string.IsNullOrEmpty(modelPropertyAttribute.Align))
         *          {
         *              dataAdapter.Add("align", modelPropertyAttribute.Align);
         *          }
         *
         *          if (modelPropertyAttribute.OrderableFlag)
         *          {
         *              dataAdapter.Add("orderField", propertySchema.Name);
         *          }
         *
         *      }
         *      else
         *      {
         *          dataAdapter.Add("description", propertySchema.Name);
         *          dataAdapter.Add("Name", propertySchema.Name);
         *      }
         *
         *      result.Add(dataAdapter);
         *  }
         *
         *
         *  return result;
         * }
         *
         * private List<BeeDataAdapter> GetDetailInfo()
         * {
         *  List<BeeDataAdapter> result = new List<BeeDataAdapter>();
         *
         *  EntityProxy<T> entityProxy = EntityProxyManager.Instance.GetEntityProxy<T>();
         *
         *  ModelAttribute modelAttribute = entityProxy.GetCustomerAttribute<ModelAttribute>();
         *  string identityColumn = OrmUtil.GetIdentityColumnName<T>();
         *
         *  foreach (PropertySchema propertySchema in entityProxy.GetPropertyList())
         *  {
         *      ModelPropertyAttribute modelPropertyAttribute
         *          = propertySchema.GetCustomerAttribute<ModelPropertyAttribute>();
         *      BeeDataAdapter dataAdapter = new BeeDataAdapter();
         *      string descriptionInfo;
         *      if (modelPropertyAttribute != null)
         *      {
         *          descriptionInfo = modelPropertyAttribute.Description;
         *          if (string.IsNullOrEmpty(descriptionInfo))
         *          {
         *              descriptionInfo = propertySchema.Name;
         *          }
         *      }
         *      else
         *      {
         *          descriptionInfo = propertySchema.Name;
         *      }
         *
         *      dataAdapter.Add("description", descriptionInfo);
         *      dataAdapter.Add("name", propertySchema.Name);
         *      bool readOnly = false;
         *
         *      if (string.Compare(identityColumn, propertySchema.Name, true) == 0)
         *      {
         *          readOnly = true;
         *      }
         *
         *      dataAdapter.Add("readonly", readOnly);
         *      dataAdapter.Add("mappingname", modelPropertyAttribute.MappingName);
         *
         *      result.Add(dataAdapter);
         *  }
         *
         *  return result;
         * }
         *
         */


        private BeeAutoModelInfo InitBeeAutoModelInfo()
        {
            BeeAutoModelInfo result = new BeeAutoModelInfo();

            List <BeeDataAdapter>       headerInfo      = new List <BeeDataAdapter>();
            List <BeeDataAdapter>       searchInfo      = new List <BeeDataAdapter>();
            List <BeeDataAdapter>       detailInfo      = new List <BeeDataAdapter>();
            Dictionary <string, string> dataMappingInfo = new Dictionary <string, string>(StringComparer.InvariantCultureIgnoreCase);

            EntityProxy <T> entityProxy = EntityProxyManager.Instance.GetEntityProxy <T>();

            ModelAttribute modelAttribute = entityProxy.GetCustomerAttribute <ModelAttribute>();

            string identityColumn = OrmUtil.GetIdentityColumnName <T>();

            TableSchema tableSchema = null;

            using (DbSession dbSession = GetDbSession())
            {
                tableSchema = dbSession.GetTableSchema(OrmUtil.GetTableName <T>());
            }

            foreach (PropertySchema propertySchema in entityProxy.GetPropertyList())
            {
                string             columnName         = propertySchema.Name;
                OrmColumnAttribute ormColumnAttribute = propertySchema.GetCustomerAttribute <OrmColumnAttribute>();
                if (ormColumnAttribute != null && !string.IsNullOrEmpty(ormColumnAttribute.DbColumnName))
                {
                    columnName = ormColumnAttribute.DbColumnName;
                }

                if (tableSchema != null && !tableSchema.ContainsColumn(columnName))
                {
                    continue;
                }

                BeeDataAdapter headerItem = GetHeaderItem(propertySchema);
                if (headerItem != null)
                {
                    headerInfo.Add(headerItem);
                }

                BeeDataAdapter searchItem = GetSearchItem(propertySchema);
                if (searchItem != null)
                {
                    searchInfo.Add(searchItem);
                }

                BeeDataAdapter detailItem = GetDetailItem(propertySchema, identityColumn);
                if (detailItem != null)
                {
                    detailInfo.Add(detailItem);
                }

                ModelPropertyAttribute modelPropertyAttribute
                    = propertySchema.GetCustomerAttribute <ModelPropertyAttribute>();
                if (modelPropertyAttribute != null && !string.IsNullOrEmpty(modelPropertyAttribute.MappingName))
                {
                    dataMappingInfo.Add(propertySchema.Name, modelPropertyAttribute.MappingName);
                }

                if (propertySchema.PropertyType.IsEnum && !dataMappingInfo.ContainsKey("mappingname"))
                {
                    dataMappingInfo.Add(propertySchema.Name, propertySchema.PropertyType.ToString());
                }
            }

            result.DetailInfo      = detailInfo;
            result.HeaderInfo      = headerInfo;
            result.SearchInfo      = searchInfo;
            result.DataMappingInfo = dataMappingInfo;

            return(result);
        }