Ejemplo n.º 1
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());
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
        public virtual PageResult List(BeeDataAdapter dataAdapter)
        {
            DbSession dbSession = GetDbSession();

            DataTable dataTable = null;

            try
            {
                InitPagePara(dataAdapter);

                #region datetime 处理
                EntityProxy <T> entityProxy = EntityProxyManager.Instance.GetEntityProxy <T>();

                //List<PropertySchema> propertyList = entityProxy.GetPropertyList();

                //propertyList = (from item in propertyList
                // where item.PropertyType == typeof(DateTime)
                // select item).ToList();

                BeeDataAdapter realDataAdapter = new BeeDataAdapter(dataAdapter);

                //foreach (PropertySchema item in propertyList)
                //{
                //    string beginkey = "{0}begin".FormatWith(item.Name);
                //    string endkey = "{0}end".FormatWith(item.Name);
                //    if (realDataAdapter.ContainsKey(item.Name))
                //    {
                //        realDataAdapter[item.Name] = ConvertUtil.CommonConvert<DateTime>(realDataAdapter[item.Name]);
                //    }
                //    if (realDataAdapter.ContainsKey(beginkey))
                //    {
                //        realDataAdapter[beginkey] = ConvertUtil.CommonConvert<DateTime>(realDataAdapter[beginkey]);
                //    }
                //    if (realDataAdapter.ContainsKey(endkey))
                //    {
                //        realDataAdapter[endkey] = ConvertUtil.CommonConvert<DateTime>(realDataAdapter[endkey]);
                //    }
                //}

                #endregion

                string tableName = OrmUtil.GetTableName <T>();

                SqlCriteria sqlCriteria = GetQueryCondition(realDataAdapter);

                int recordCount = dataAdapter.TryGetValue <int>("recordcount", 0);

                string selectClause = GetQuerySelectClause(typeof(T));

                dataTable = InnerQuery(tableName, selectClause, dataAdapter, sqlCriteria);
            }
            catch (Exception e)
            {
                Logger.Error("List object({0}) Error".FormatWith(typeof(T)), e);
            }
            finally
            {
                dbSession.Dispose();
            }

            return(View(null, "BeeAutoList", dataTable));
        }