Ejemplo n.º 1
0
        public List <T> QueryData <T>(string sql, IDataRelation <T> relation)
        {
            var list = new List <T>();

            if (NotImplementedAttribute.IsMethodNotImplemented(this.GetType().Name, "CreateDataAdapter") == false &&
                NotImplementedAttribute.IsMethodNotImplemented(relation.GetType().Name, "DataRowToEntity") == false)
            {
                this.CreateDataAdapter(sql);
                var dt = new DataTable();
                this.DataAdapter.Fill(dt);

                foreach (DataRow dr in dt.Rows)
                {
                    list.Add(relation.DataRowToEntity(dr));
                }
                return(list);
            }

            if (NotImplementedAttribute.IsMethodNotImplemented(this.GetType().Name, "CreateDataReader") == false &&
                NotImplementedAttribute.IsMethodNotImplemented(relation.GetType().Name, "DataReaderToEntity") == false)
            {
                this.CreateDataReader(sql);
                while (this.DataReader.Read())
                {
                    list.Add(relation.DataReaderToEntity(this.DataReader));
                }
                return(list);
            }

            throw new NotImplementedException(this.GetType().ToString());
        }
Ejemplo n.º 2
0
        ///// <summary>
        ///// 检索应用于类型成员的自定义属性。
        ///// </summary>
        ///// <param name="element"></param>
        ///// <returns></returns>
        //public new static BindRelationAttribute[] GetCustomAttributes(MemberInfo element)
        //{
        //    Attribute[] atts = GetCustomAttributes(element, typeof(BindRelationAttribute), true);
        //    if (atts == null || atts.Length < 1) return null;

        //    List<BindRelationAttribute> list = new List<BindRelationAttribute>();
        //    foreach (Attribute item in atts)
        //    {
        //        list.Add(item as BindRelationAttribute);
        //    }
        //    return list.ToArray();
        //}

        /// <summary>填充索引</summary>
        /// <param name="relation"></param>
        internal void Fill(IDataRelation relation)
        {
            relation.Column = Column;
            relation.Unique = Unique;
            relation.RelationTable = RelationTable;
            relation.RelationColumn = RelationColumn;
        }
Ejemplo n.º 3
0
 /// <summary>填充关系</summary>
 /// <param name="relation"></param>
 internal void Fill(IDataRelation relation)
 {
     relation.Column         = Column;
     relation.Unique         = Unique;
     relation.RelationTable  = RelationTable;
     relation.RelationColumn = RelationColumn;
 }
Ejemplo n.º 4
0
        public void Insert(object item, IDataRelation relation)
        {
            var   itemType = item.GetType();
            var   keyType  = relation.GetPrimaryKeyType(item);
            IList storage;

            storage = GetStorageCopyForType(itemType);

            object newKey = null;

            if (keyType == typeof(string))
            {
                newKey = Guid.NewGuid().ToString();
            }
            else
            {
                throw new NotImplementedException($"key generation not implemented for key type {keyType.FullName}");
            }
            relation.SetPrimaryKey(item, newKey);

            storage.Add(item);
            UpdateStorageForType(itemType, storage);

            PersistData(itemType);
        }
Ejemplo n.º 5
0
 public DataReference(string id, string rowId, string rowIdForeign, string relationId, IDataRelation relation, IDataRow row, IDataRow rowForeign) :
     base(id, rowId, row)
 {
     RowIdForeign = rowIdForeign;
     RelationId   = relationId;
     Relation     = relation;
     RowForeign   = rowForeign;
 }
Ejemplo n.º 6
0
 public void Update(object item, IDataRelation relation)
 {
     // referencing just persist?
     lock (dataLock)
     {
         PersistData(item.GetType());
     }
 }
Ejemplo n.º 7
0
        public List <T> ConvertToList <T>(DbDataReader dataReader, IDataRelation <T> relation)
        {
            var list = new List <T>();

            while (dataReader.Read())
            {
                list.Add(relation.DataReaderToEntity(dataReader));
            }
            return(list);
        }
Ejemplo n.º 8
0
        public List <T> ConvertToList <T>(DataTable dataTable, IDataRelation <T> relation)
        {
            var list = new List <T>();

            foreach (DataRow dr in dataTable.Rows)
            {
                list.Add(relation.DataRowToEntity(dr));
            }
            return(list);
        }
Ejemplo n.º 9
0
        /// <summary>赋值数据列到另一个数据列</summary>
        /// <param name="src"></param>
        /// <param name="des"></param>
        /// <returns></returns>
        public static IDataRelation CopyFrom(this IDataRelation src, IDataRelation des)
        {
            src.Column         = des.Column;
            src.RelationTable  = des.RelationTable;
            src.RelationColumn = des.RelationColumn;
            src.Unique         = des.Unique;
            src.Computed       = des.Computed;

            return(src);
        }
Ejemplo n.º 10
0
        public void Delete(object item, IDataRelation relation)
        {
            var   itemType = item.GetType();
            IList storage;

            storage = GetStorageCopyForType(itemType);

            storage.Remove(item);
            UpdateStorageForType(itemType, storage);


            PersistData(itemType);
        }
Ejemplo n.º 11
0
        public List <T> GetPage <T>(DbDataReader dataReader, IDataRelation <T> relation, int pageSize, int nowIndex)
        {
            for (int i = 0; i < pageSize * nowIndex && dataReader.Read(); i++)
            {
                ;
            }
            var list = new List <T>();

            for (int i = 0; i < pageSize && dataReader.Read(); i++)
            {
                list.Add(relation.DataReaderToEntity(dataReader));
            }
            return(list);
        }
Ejemplo n.º 12
0
        private void btnAddRelation_Click(Object sender, EventArgs e)
        {
            IDataTable table = GetSelectedTable();

            if (table == null)
            {
                return;
            }

            IDataRelation dr = table.CreateRelation();

            table.Relations.Add(dr);

            dgvRelation.DataSource  = null;
            dgvRelation.DataSource  = table.Relations;
            pgColumn.SelectedObject = dr;
        }
Ejemplo n.º 13
0
 /// <summary>根据字段、关联表、关联字段从指定表中查找关系</summary>
 /// <param name="table"></param>
 /// <param name="dr"></param>
 /// <returns></returns>
 public static IDataRelation GetRelation(this IDataTable table, IDataRelation dr)
 {
     return(table.GetRelation(dr.Column, dr.RelationTable, dr.RelationColumn));
 }
Ejemplo n.º 14
0
 public DataProvider(IDataAdapter dataAdapter)
 {
     _dataAdapter  = dataAdapter;
     _dataRelation = new DataRelation();
 }
Ejemplo n.º 15
0
        /// <summary>赋值数据列到另一个数据列</summary>
        /// <param name="src"></param>
        /// <param name="des"></param>
        /// <returns></returns>
        public static IDataRelation CopyFrom(this IDataRelation src, IDataRelation des)
        {
            src.Column = des.Column;
            src.RelationTable = des.RelationTable;
            src.RelationColumn = des.RelationColumn;
            src.Unique = des.Unique;
            src.Computed = des.Computed;

            return src;
        }
Ejemplo n.º 16
0
 /// <summary>根据字段、关联表、关联字段从指定表中查找关系</summary>
 /// <param name="table"></param>
 /// <param name="dr"></param>
 /// <returns></returns>
 public static IDataRelation GetRelation(this IDataTable table, IDataRelation dr)
 {
     return table.GetRelation(dr.Column, dr.RelationTable, dr.RelationColumn);
 }