Example #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));
     }
 }
Example #2
0
 public static T ExecProcToObject <T>(object parameter) where T : new()
 {
     using (IConnectinContext cc = DBContext.DB1)
     {
         return(ExecProcToObject <T>(cc, parameter));
     }
 }
Example #3
0
 public static object ExecProc(object parameter)
 {
     using (IConnectinContext cc = DBContext.DB1)
     {
         return(ExecProc(cc, parameter));
     }
 }
Example #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()));
        }
Example #5
0
 public static object ExecProc(DB db, object parameter)
 {
     using (IConnectinContext cc = DBContext.GetConnection(db))
     {
         return(ExecProc(cc, parameter));
     }
 }
Example #6
0
 public static IList <T> List <T>(this string sql) where T : new()
 {
     using (IConnectinContext cc = DBContext.DB1)
     {
         return(List <T>(sql, cc));
     }
 }
Example #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));
     }
 }
Example #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));
        }
Example #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));
     }
 }
Example #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));
     }
 }
Example #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));
     }
 }
Example #12
0
 public RESULT GetValue <RESULT, Entity>(IFieldInfo field) where Entity : Mappings.DataObject
 {
     using (IConnectinContext cc = DBContext.DB1)
     {
         return(GetValue <RESULT, Entity>(field));
     }
 }
Example #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));
     }
 }
Example #14
0
 public T ListFirst <T>(DB type) where T : Mappings.DataObject, new()
 {
     using (IConnectinContext cc = DBContext.GetConnection(type))
     {
         return(ListFirst <T>(cc, null));
     }
 }
Example #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));
     }
 }
Example #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));
     }
 }
Example #17
0
 public static T GetValue <T>(this string sql)
 {
     using (IConnectinContext cc = DBContext.DB1)
     {
         return(GetValue <T>(sql, cc));
     }
 }
Example #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));
     }
 }
Example #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));
     }
 }
Example #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));
     }
 }
Example #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));
     }
 }
Example #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));
     }
 }
Example #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));
     }
 }
Example #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));
     }
 }
Example #25
0
 public static int Execute(this string sql)
 {
     using (IConnectinContext cc = DBContext.DB1)
     {
         return(Execute(sql, cc));
     }
 }
Example #26
0
 public int Count <T>(DB type) where T : Mappings.DataObject
 {
     using (IConnectinContext cc = DBContext.GetConnection(type))
     {
         return(Count <T>(cc));
     }
 }
Example #27
0
 public static int Execute(this string sql, string connName)
 {
     using (IConnectinContext cc = DBContext.GetConnection(connName))
     {
         return(Execute(sql, cc));
     }
 }
Example #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));
     }
 }
Example #29
0
 public static T GetValue <T>(this string sql, string connName)
 {
     using (IConnectinContext cc = DBContext.GetConnection(connName))
     {
         return(GetValue <T>(sql, cc));
     }
 }
Example #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));
     }
 }
Example #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;
 }
Example #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;
     
 }
Example #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;
        }
Example #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;
        }
Example #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;

        }
Example #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);
        
 }
Example #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);
Example #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;
 }
Example #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;
        }
Example #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);
 }
Example #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;
        }
Example #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)
 {
 }
Example #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);
     
 }
Example #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);
 }
Example #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));
 }
Example #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());
 }
Example #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));
     }
 }