Ejemplo n.º 1
0
 public int Edit <T>(DB type, Action <T> handler) where T : DataObject, new()
 {
     using (IConnectinContext cc = DBContext.GetConnection(type))
     {
         return(Edit <T>(cc, handler));
     }
 }
Ejemplo n.º 2
0
 public static T ExecProcToObject <T>(object parameter) where T : new()
 {
     using (IConnectinContext cc = DBContext.DB1)
     {
         return(ExecProcToObject <T>(cc, parameter));
     }
 }
Ejemplo n.º 3
0
 public static object ExecProc(object parameter)
 {
     using (IConnectinContext cc = DBContext.DB1)
     {
         return(ExecProc(cc, parameter));
     }
 }
Ejemplo n.º 4
0
        public int Edit <T>(IConnectinContext cc, Action <T> handler) where T : DataObject, new()
        {
            T item = new T();

            handler(item);
            return(Edit <T>(cc, item.GetChangeFields()));
        }
Ejemplo n.º 5
0
 public static object ExecProc(DB db, object parameter)
 {
     using (IConnectinContext cc = DBContext.GetConnection(db))
     {
         return(ExecProc(cc, parameter));
     }
 }
Ejemplo n.º 6
0
 public static IList <T> List <T>(this string sql) where T : new()
 {
     using (IConnectinContext cc = DBContext.DB1)
     {
         return(List <T>(sql, cc));
     }
 }
Ejemplo n.º 7
0
 public static IList <T> List <T>(this string sql, DB db, Region region) where T : new()
 {
     using (IConnectinContext cc = DBContext.GetConnection(db))
     {
         return(List <T>(sql, cc, region));
     }
 }
Ejemplo n.º 8
0
        /// <summary>
        /// 数据保存后处理过程
        /// </summary>
        /// <param name="cc">数据库上下文</param>
        /// <param name="data">实体对象</param>
        /// <param name="pm">属性映射描述</param>
        /// <param name="table">相关表信息</param>
        public override void Executed(IConnectinContext cc, object data, PropertyMapper pm, string table)
        {
            Command cmd   = new Command("select @@IDENTITY ");
            object  value = cc.ExecuteScalar(cmd);

            pm.Handler.Set(data, Convert.ChangeType(value, pm.Handler.Property.PropertyType));
        }
Ejemplo n.º 9
0
 public static T ListFirst <T>(this string sql, DB db) where T : new()
 {
     using (IConnectinContext cc = DBContext.GetConnection(db))
     {
         return(ListFirst <T>(sql, cc));
     }
 }
Ejemplo n.º 10
0
 public IList <RESULT> GetValues <RESULT, Entity>(IFieldInfo field, DB type, Region region, params string[] orderby) where Entity : Mappings.DataObject
 {
     using (IConnectinContext cc = DBContext.GetConnection(type))
     {
         return(GetValues <RESULT, Entity>(field, cc, region, orderby));
     }
 }
Ejemplo n.º 11
0
 public IList <T> List <T>(JoinTable table, params string[] orders) where T : new()
 {
     using (IConnectinContext cc = DBContext.GetConnection(DB.DB1))
     {
         return(List <T>(table, cc, null, null));
     }
 }
Ejemplo n.º 12
0
 public RESULT GetValue <RESULT, Entity>(IFieldInfo field) where Entity : Mappings.DataObject
 {
     using (IConnectinContext cc = DBContext.DB1)
     {
         return(GetValue <RESULT, Entity>(field));
     }
 }
Ejemplo n.º 13
0
 public static IList <T> List <T>(this string sql, string connName) where T : new()
 {
     using (IConnectinContext cc = DBContext.GetConnection(connName))
     {
         return(List <T>(sql, cc));
     }
 }
Ejemplo n.º 14
0
 public T ListFirst <T>(DB type) where T : Mappings.DataObject, new()
 {
     using (IConnectinContext cc = DBContext.GetConnection(type))
     {
         return(ListFirst <T>(cc, null));
     }
 }
Ejemplo n.º 15
0
 public RESULT Min <RESULT, Entity>(string field, bool DISTINCT) where Entity : Mappings.DataObject
 {
     using (IConnectinContext cc = DBContext.DB1)
     {
         return(Min <RESULT, Entity>(field, DISTINCT, cc));
     }
 }
Ejemplo n.º 16
0
 public RESULT Avg <RESULT, Entity>(string field, bool DISTINCT, DB type) where Entity : Mappings.DataObject
 {
     using (IConnectinContext cc = DBContext.GetConnection(type))
     {
         return(Avg <RESULT, Entity>(field, DISTINCT, cc));
     }
 }
Ejemplo n.º 17
0
 public static T GetValue <T>(this string sql)
 {
     using (IConnectinContext cc = DBContext.DB1)
     {
         return(GetValue <T>(sql, cc));
     }
 }
Ejemplo n.º 18
0
 public int Count <T>(string field, bool DISTINCT, DB type) where T : Mappings.DataObject
 {
     using (IConnectinContext cc = DBContext.GetConnection(type))
     {
         return(Count <T>(field, DISTINCT, cc));
     }
 }
Ejemplo n.º 19
0
 public IList <RESULT> GetValues <RESULT, Entity>(IFieldInfo field, params string[] orderby) where Entity : Mappings.DataObject
 {
     using (IConnectinContext cc = DBContext.DB1)
     {
         return(GetValues <RESULT, Entity>(field, cc, (Region)null, orderby));
     }
 }
Ejemplo n.º 20
0
 public IList <T> List <T>(DB type, Region region) where T : Mappings.DataObject, new()
 {
     using (IConnectinContext cc = DBContext.GetConnection(type))
     {
         return(List <T>(cc, region, null));
     }
 }
Ejemplo n.º 21
0
 public IList <RESULT> GetValues <RESULT, Entity>(IFieldInfo field, int pageindex, int pagesize, params string[] orderby) where Entity : Mappings.DataObject
 {
     using (IConnectinContext cc = DBContext.DB1)
     {
         return(GetValues <RESULT, Entity>(field, cc, new Region(pageindex, pagesize), orderby));
     }
 }
Ejemplo n.º 22
0
 public IList <RESULT> GetValues <RESULT, Entity>(IFieldInfo field, DB type, int pageindex, int pagesize) where Entity : Mappings.DataObject
 {
     using (IConnectinContext cc = DBContext.GetConnection(type))
     {
         return(GetValues <RESULT, Entity>(field, cc, pageindex, pagesize));
     }
 }
Ejemplo n.º 23
0
 public IList <RESULT> GetValues <RESULT, Entity>(IFieldInfo field, Region region) where Entity : Mappings.DataObject
 {
     using (IConnectinContext cc = DBContext.DB1)
     {
         return(GetValues <RESULT, Entity>(field, cc, region));
     }
 }
Ejemplo n.º 24
0
 public int Edit <T>(DB type, params Field[] fields) where T : DataObject, new()
 {
     using (IConnectinContext cc = DBContext.GetConnection(type))
     {
         return(Edit <T>(cc, fields));
     }
 }
Ejemplo n.º 25
0
 public static int Execute(this string sql)
 {
     using (IConnectinContext cc = DBContext.DB1)
     {
         return(Execute(sql, cc));
     }
 }
Ejemplo n.º 26
0
 public int Count <T>(DB type) where T : Mappings.DataObject
 {
     using (IConnectinContext cc = DBContext.GetConnection(type))
     {
         return(Count <T>(cc));
     }
 }
Ejemplo n.º 27
0
 public static int Execute(this string sql, string connName)
 {
     using (IConnectinContext cc = DBContext.GetConnection(connName))
     {
         return(Execute(sql, cc));
     }
 }
Ejemplo n.º 28
0
 public IList <T> List <T>(DB type, params string[] orderby) where T : Mappings.DataObject, new()
 {
     using (IConnectinContext cc = DBContext.GetConnection(type))
     {
         return(List <T>(cc, null, orderby));
     }
 }
Ejemplo n.º 29
0
 public static T GetValue <T>(this string sql, string connName)
 {
     using (IConnectinContext cc = DBContext.GetConnection(connName))
     {
         return(GetValue <T>(sql, cc));
     }
 }
Ejemplo n.º 30
0
 public RESULT Min <RESULT, Entity>(string field, DB type) where Entity : Mappings.DataObject
 {
     using (IConnectinContext cc = DBContext.GetConnection(type))
     {
         return(Min <RESULT, Entity>(field, false, cc));
     }
 }
Ejemplo n.º 31
0
 internal int Delete(IConnectinContext cc)
 {
     int result = 0;
     ObjectMapper om = ObjectMapper.GetOM(this.GetType());
     if (om.ID == null)
         throw new PeanutException(DataMsg.ID_MAP_NOTFOUND);
     result = OnDeleteObject(cc, om.Table, om.ID.ColumnName,
         om.ID.Handler.Get(this));
     return result;
 }
Ejemplo n.º 32
0
 internal int Save(IConnectinContext cc)
 {
     int result = 0;
     ObjectMapper om = ObjectMapper.GetOM(this.GetType());
     
     if (EntityState._Loaded)
     {
         if (EntityState._FieldState.Count == 0)
             return 0;
         result=EditData(cc, om);
     }
     else
     {
         if (EntityState._FieldState.Count == 0)
             throw new PeanutException(DataMsg.OBJECT_UPDATA_NOTFOUND);
        result= NewData(cc, om);
         EntityState._Loaded = true;
     }
     EntityState._FieldState.Clear();
     return result;
     
 }
Ejemplo n.º 33
0
        /// <summary>
        /// 验证处理过程,派生类重写实现具体的验证规则
        /// </summary>
        /// <param name="value">属性值</param>
        /// <param name="source">属性所属对象</param>
        /// <param name="pm">属性映射描述</param>
        /// <param name="cc">数据库上下文</param>
        /// <returns>bool</returns>
        protected override bool OnValidating(object value, object source, Mappings.PropertyMapper pm, IConnectinContext cc)
        {
           
            if (value != null && !string.IsNullOrEmpty(value.ToString()))
            {
                string data = Convert.ToString(value);
                if (System.Text.RegularExpressions.Regex.Match(
                    data, Regex, RegexOptions.IgnoreCase).Length == 0)
                {
                    return false;
                }

            }
            return true;
        }
Ejemplo n.º 34
0
        /// <summary>
        /// 验证处理过程,派生类重写实现具体的验证规则
        /// </summary>
        /// <param name="value">属性值</param>
        /// <param name="source">属性所属对象</param>
        /// <param name="pm">属性映射描述</param>
        /// <param name="cc">数据库上下文</param>
        /// <returns>bool</returns>
        protected override bool OnValidating(object value, object source, Mappings.PropertyMapper pm, IConnectinContext cc)
        {
           
            if (value != null && !string.IsNullOrEmpty(value.ToString()))
            {
                string data = Convert.ToString(value);
                if (MinLength != null && MinLength > data.Length)
                {

                    return false;
                }

                if (MaxLength != null && data.Length > MaxLength)
                {

                    return false;

                }
            }
            return true;
        }
Ejemplo n.º 35
0
        /// <summary>
        /// 验证处理过程,派生类重写实现具体的验证规则
        /// </summary>
        /// <param name="value">属性值</param>
        /// <param name="source">属性所属对象</param>
        /// <param name="pm">属性映射描述</param>
        /// <param name="cc">数据库上下文</param>
        /// <returns>bool</returns>
        protected override bool OnValidating(object value, object source, Mappings.PropertyMapper pm, IConnectinContext cc)
        {
            if (value == null)
                return true;
            if (string.IsNullOrEmpty((string)value))
                return true;
            string sql = "select {0} from {1} where {0}=@p1";
            Command cmd = new Command(string.Format(sql, pm.ColumnName, pm.OM.Table));
            cmd.AddParameter("p1", value);
            object result = cc.ExecuteScalar(cmd);
            return result == null || result == DBNull.Value;

        }
Ejemplo n.º 36
0
 /// <summary>
 /// 验证实体属性值
 /// </summary>
 /// <param name="value">属性值</param>
 /// <param name="source">属性所属对象</param>
 /// <param name="pm">属性映射描述</param>
 /// <param name="cc">数据库上下文</param>
 /// <returns>bool</returns>
 public bool Validating(object value, object source,Mappings.PropertyMapper pm,IConnectinContext cc )
 {
     return OnValidating(value, source, pm, cc);
        
 }
Ejemplo n.º 37
0
 /// <summary>
 /// 验证处理过程,派生类重写实现具体的验证规则
 /// </summary>
 /// <param name="value">属性值</param>
 /// <param name="source">属性所属对象</param>
 /// <param name="pm">属性映射描述</param>
 /// <param name="cc">数据库上下文</param>
 /// <returns>bool</returns>
 protected abstract bool OnValidating(object value, object source, Mappings.PropertyMapper pm, IConnectinContext cc);
Ejemplo n.º 38
0
 /// <summary>
 /// 验证处理过程,派生类重写实现具体的验证规则
 /// </summary>
 /// <param name="value">属性值</param>
 /// <param name="source">属性所属对象</param>
 /// <param name="pm">属性映射描述</param>
 /// <param name="cc">数据库上下文</param>
 /// <returns>bool</returns>
 protected override bool OnValidating(object value, object source, Mappings.PropertyMapper pm, IConnectinContext cc)
 {
     bool result= value != null && !string.IsNullOrEmpty(value.ToString());
     if (!result && string.IsNullOrEmpty(Message))
         Message = string.Format("{0}成员值不能为空!", pm.ColumnName);
     return result;
 }
Ejemplo n.º 39
0
        /// <summary>
        /// 验证处理过程,派生类重写实现具体的验证规则
        /// </summary>
        /// <param name="value">属性值</param>
        /// <param name="source">属性所属对象</param>
        /// <param name="pm">属性映射描述</param>
        /// <param name="cc">数据库上下文</param>
        /// <returns>bool</returns>
        protected override bool OnValidating(object value, object source, Mappings.PropertyMapper pm, IConnectinContext cc)
        {
           
            if (value != null && !string.IsNullOrEmpty(value.ToString()))
            {
                DateTime data = Convert.ToDateTime(value);
                if (MinValue != null)
                {
                    if (MinValue >data)
                    {
                        return false;
                    }
                }

                if (MaxValue != null)
                {
                    if (data > MaxValue)
                    {
                        return false;
                    }
                }
            }

            return true;
        }
Ejemplo n.º 40
0
 /// <summary>
 /// 数据保存前处理过程
 /// </summary>
 /// <param name="cc">数据库上下文</param>
 /// <param name="data">实体对象</param>
 /// <param name="pm">属性映射描述</param>
 /// <param name="table">相关表信息</param>
 public override void Executing(IConnectinContext cc, object data, PropertyMapper pm, string table)
 {
     string uid = Guid.NewGuid().ToString("N");
     pm.Handler.Set(data, uid);
 }
Ejemplo n.º 41
0
        private int NewData(IConnectinContext cc, ObjectMapper om)
        {
            int result = 0;
            Insert insert = new Insert(om.Table);
            object value = null;
            if (om.ID != null)
            {
                if (om.ID.Value != null)
                {
                    if (!om.ID.Value.AfterByUpdate)
                    {
                        om.ID.Value.Executing(cc, this, om.ID,om.Table);
                        insert.AddField(om.ID.ColumnName, om.ID.Handler.Get(this));
                    }
                }
                else
                {
                    insert.AddField(om.ID.ColumnName, om.ID.Handler.Get(this));
                }
            }
            for(int i =0;i<om.Properties.Count;i++)
            {
                PropertyMapper pm = om.Properties[i];   
                if (!EntityState._FieldState.ContainsKey(pm.Handler.Property.Name))
                {
                    if (pm.Value != null && !pm.Value.AfterByUpdate)
                    {
                        pm.Value.Executing(cc, this, pm, om.Table);
                    }
                }
                value = pm.Handler.Get(this);
                if (EntityState._FieldState.ContainsKey(pm.Handler.Property.Name))
                {        
                    if (pm.Cast != null)
                    {

                        value = pm.Cast.ToColumn(value, pm.Handler.Property.PropertyType, this);
                    }   
                    insert.AddField(pm.ColumnName, value);
                }
            }
            result=insert.Execute(cc);
            if (om.ID != null && om.ID.Value != null && om.ID.Value.AfterByUpdate)
                om.ID.Value.Executed(cc, this, om.ID,om.Table);
            return result;
        }
Ejemplo n.º 42
0
 /// <summary>
 /// 数据保存后处理过程
 /// </summary>
 /// <param name="cc">数据库上下文</param>
 /// <param name="data">实体对象</param>
 /// <param name="pm">属性映射描述</param>
 /// <param name="table">相关表信息</param>
 public virtual void Executed(IConnectinContext cc, object data, PropertyMapper pm, string table)
 {
 }
Ejemplo n.º 43
0
 private int EditData(IConnectinContext cc,ObjectMapper om)
 {
     if (om.ID == null)
         throw new PeanutException(DataMsg.UPDATE_ERROR_ID_NOTFOUND);
     Update update = new Update(om.Table);
     for (int i = 0; i < om.Properties.Count; i++)
     {
         PropertyMapper pm= om.Properties[i];
     
         System.Reflection.PropertyInfo pi = pm.Handler.Property;
         if (EntityState._FieldState.ContainsKey(pm.Handler.Property.Name))
         {
             if (pm.Cast != null)
             {
                 update.AddField(pm.ColumnName,"p_"+pi.Name,pm.Cast.ToColumn(pm.Handler.Get(this),
                     pm.Handler.Property.PropertyType,this));
             }
             else
             {
                 update.AddField(pm.ColumnName, "p_" + pi.Name, pm.Handler.Get(this));
             }
         }
     }
     update.Where.SqlText.Append(om.ID.ColumnName).Append("=@p1");
     update.Where.Parameters.Add(new Command.Parameter { Name = "p1", Value = om.ID.Handler.Get(this) });
     return update.Execute(cc);
     
 }
Ejemplo n.º 44
0
 /// <summary>
 /// 数据保存前处理过程
 /// </summary>
 /// <param name="cc">数据库上下文</param>
 /// <param name="data">实体对象</param>
 /// <param name="pm">属性映射描述</param>
 /// <param name="table">相关表信息</param>
 public override void Executing(IConnectinContext cc, object data, PropertyMapper pm, string table)
 {
     pm.Handler.Set(data, true);
 }
Ejemplo n.º 45
0
 /// <summary>
 /// 数据保存后处理过程
 /// </summary>
 /// <param name="cc">数据库上下文</param>
 /// <param name="data">实体对象</param>
 /// <param name="pm">属性映射描述</param>
 /// <param name="table">相关表信息</param>
 public override void Executed(IConnectinContext cc, object data, PropertyMapper pm, string table)
 {
     Command cmd = new Command("select @@IDENTITY ");
     object value = cc.ExecuteScalar(cmd);
     pm.Handler.Set(data,Convert.ChangeType( value,pm.Handler.Property.PropertyType));
 }
Ejemplo n.º 46
0
 /// <summary>
 /// 数据保存前处理过程
 /// </summary>
 /// <param name="cc">数据库上下文</param>
 /// <param name="data">实体对象</param>
 /// <param name="pm">属性映射描述</param>
 /// <param name="table">相关表信息</param>
 public override void Executing(IConnectinContext cc, object data, PropertyMapper pm, string table)
 {
     pm.Handler.Set(data, DateTime.Now.Day.ToString());
 }
Ejemplo n.º 47
0
 /// <summary>
 /// 数据保存前处理过程
 /// </summary>
 /// <param name="cc">数据库上下文</param>
 /// <param name="data">实体对象</param>
 /// <param name="pm">属性映射描述</param>
 /// <param name="table">相关表信息</param>
 public override void Executing(IConnectinContext cc, object data, PropertyMapper pm, string table)
 {
     if (mInputType == InputType.Int)
     {
         pm.Handler.Set(data, Enum.GetValues(pm.Handler.Property.PropertyType).GetValue((int)mValue));
     }
     else if (mInputType == InputType.String)
     {
         Enum.Parse(pm.Handler.Property.PropertyType, mValue.ToString());
     }
     else
     {
         pm.Handler.Set(data, Enum.GetValues(pm.Handler.Property.PropertyType).GetValue(0));
     }
 }