示例#1
0
        public static RepositoryEntityReader <T> ReadEntities <T>(Action <IMRecordset> conditionHandler)
            where T : class, IRepositoryEntity, IRepositoryReadedEntity, new()
        {
            var entity = new T();

            var entityDbName = entity.GetTableName();
            var idFieldName  = entity.GetIdFieldName();
            var fields       = entity.GetFieldNames();

            var source = new IMRecordset(entityDbName, IMRecordset.Mode.ReadOnly);

            conditionHandler(source);
            source.Select(fields);

            var reader = new RepositoryEntityReader <T>(source);

            return(reader);
        }
示例#2
0
        public static void CreateEntity <T>(T entity)
            where T : class, IRepositoryEntity, IRepositoryCreatedEntity, new()
        {
            var entityDbName = entity.GetTableName();
            var idFieldName  = entity.GetIdFieldName();
            var fields       = entity.GetFieldNames();

            var source = new IMRecordset(entityDbName, IMRecordset.Mode.ReadWrite);

            source.Select(fields);
            source.SetWhere(idFieldName, IMRecordset.Operation.Eq, -1);

            using (source.OpenWithScope())
            {
                source.AddNew();
                entity.SaveToRecordset(source);
                source.Update();
            }
        }
示例#3
0
        public static int GetCurrentUserId()
        {
            var    result   = IM.NullI;
            string userName = IM.ConnectedUser();

            var employeeRs = new IMRecordset(Employee.TableName, IMRecordset.Mode.ReadOnly);

            employeeRs.Select(Employee.Fields.Id);
            employeeRs.SetWhere(Employee.Fields.AppUser, IMRecordset.Operation.Eq, userName);

            using (employeeRs.OpenWithScope())
            {
                if (!employeeRs.IsEOF())
                {
                    result = employeeRs.GetI(Employee.Fields.Id);
                }
            }

            return(result);
        }
示例#4
0
        public static void UpdateEntity <T>(T entity)
            where T : class, IRepositoryEntity, IRepositoryUpdatedEntity, new()
        {
            var entityDbName = entity.GetTableName();
            var idFieldName  = entity.GetIdFieldName();
            var fields       = entity.GetFieldNames();
            var id           = entity.GetId();

            var source = new IMRecordset(entityDbName, IMRecordset.Mode.ReadWrite);

            source.Select(fields);
            source.SetWhere(idFieldName, IMRecordset.Operation.Eq, id.ToString());
            using (source.OpenWithScope())
            {
                if (source.IsEOF())
                {
                    throw new InvalidOperationException($"Not found a record of {entityDbName} by Id #{id}");
                }

                source.Edit();
                entity.SaveToRecordset(source);
                source.Update();
            }
        }
示例#5
0
        public static T ReadFirstEntity <T>(Action <IMRecordset> conditionHandler)
            where T : class, IRepositoryEntity, IRepositoryReadedEntity, new()
        {
            var entity = new T();

            var entityDbName = entity.GetTableName();
            var fields       = entity.GetFieldNames();

            var source = new IMRecordset(entityDbName, IMRecordset.Mode.ReadOnly);

            source.Select(fields);
            conditionHandler(source);
            using (source.OpenWithScope())
            {
                if (source.IsEOF())
                {
                    return(default(T));
                }

                entity.LoadFromRecordset(source);
            }

            return(entity);
        }
示例#6
0
        public static T ReadEntityById <T>(int id)
            where T : class, IRepositoryEntity, IRepositoryReadedEntity, new()
        {
            var entity = new T();

            var entityDbName = entity.GetTableName();
            var idFieldName  = entity.GetIdFieldName();
            var fields       = entity.GetFieldNames();

            var source = new IMRecordset(entityDbName, IMRecordset.Mode.ReadOnly);

            source.Select(fields);
            source.SetWhere(idFieldName, IMRecordset.Operation.Eq, id.ToString());
            using (source.OpenWithScope())
            {
                if (source.IsEOF())
                {
                    throw new InvalidOperationException($"Not found a record of {entityDbName} by Id #{id}");
                }
                entity.LoadFromRecordset(source);
            }

            return(entity);
        }
示例#7
0
 public static OpenedRecordsetScope OpenForAdd(this IMRecordset recordset, params string[] fields)
 {
     recordset.Select(string.Join(",", fields));
     recordset.SetWhere(fields[0], IMRecordset.Operation.Eq, -1);
     return(recordset.OpenWithScope());
 }
示例#8
0
 public static void Select(this IMRecordset recordset, params string[] fields)
 {
     recordset.Select(string.Join(",", fields));
 }