/// <summary> /// 删除实体对象 /// 该方法是根据实体对象主键删除数据 /// </summary> /// <param name="entity">实体公共接口</param> /// <returns></returns> //public int Delete(IEntity entity) //{ // IDataParameter[] param = null; // string sql = Factory.CreateDeleteSql(entity,out param); // using (IDbProvider provider = new SqlProvider()) // { // return BaseHelper.ExecuteNonQuery( sql, param); // } //} /// <summary> /// 根据实体多个属性删除数据 /// 实体中必须包含该属性 /// 传递参数数组不能为空 /// </summary> /// <param name="component">实体属性公共接口</param> /// <param name="bolType">实体属性名称数组</param> /// <returns></returns> public int Delete <T>(ConditionComponent component, bool bolType) where T : IEntity { IDataParameter[] param = null; string sql = Factory.CreateDeleteSql(typeof(T), component, out param, bolType); return(BaseHelper.ExecuteNonQuery(sql, param)); }
/// <summary> /// 根据某个实体属性删除数据 /// 该实体必须包含指定的属性名称 /// 而且实体属性值不能为空 /// </summary> /// <param name="entity">实体属性公共接口</param> /// <param name="propertyName">实体属性名称</param> /// <returns></returns> public int Delete <T>(string strKeyValue, bool bolType) where T : IEntity { IDataParameter[] param = null; string sql = Factory.CreateDeleteSql(typeof(T), out param, strKeyValue, bolType); return((int)BaseHelper.ExecuteNonQuery(sql, param as OracleParameter[])); }
/// <summary> /// 根据实体的多个属性修改数据 /// 数组中的属性名称必须存在. /// 传递参数数组不能为null /// </summary> /// <param name="entity">实体公共接口</param> /// <param name="propertyNames">属性名称数组</param> /// <returns></returns> public int Update(IEntity entity, string[] propertyNames) { IDataParameter[] param = null; string sql = Factory.CreateUpdateSql(entity, out param, propertyNames); return(BaseHelper.ExecuteNonQuery(sql, param)); }
/// <summary> /// 修改实体信息 /// 该实体是根据主键修改 /// </summary> /// <param name="entity">泛型实例</param> /// <param name="component">泛型实例</param> /// <returns></returns> public int Update(IEntity entity, ConditionComponent component) { IDataParameter[] param = null; string sql = Factory.CreateUpdateSql(entity, out param, component); return(int.Parse(BaseHelper.ExecuteNonQuery(sql, param as OracleParameter[]).ToString())); }
/// <summary> /// 根据实体的某个属性修改数据 /// entity 中必须包含该属性,而且该属性的 /// 值不能为空 /// </summary> /// <param name="entity">实体公共接口</param> /// <param name="propertyName">实体属性名称</param> /// <returns></returns> public int Update(IEntity entity, string propertyName) { IDataParameter[] param = null; string sql = Factory.CreateUpdateSql(entity, out param, propertyName); return(int.Parse(BaseHelper.ExecuteNonQuery(sql, param as OracleParameter[]).ToString())); }
/// <summary> /// 添加实体对象 /// 将实体数据信息映射为一条插入sql语句 /// </summary> /// <param name="entity">实体公共接口</param> /// <returns></returns> public int Add(IEntity entity) { IDataParameter[] param = null; string sql = Factory.CreateInsertSql(entity, out param); //return int.Parse(BaseHelper.ExecuteScalar(sql, param as OracleParameter[]).ToString()); return(int.Parse(BaseHelper.ExecuteNonQuery(sql, param as OracleParameter[]).ToString())); }
/// <summary> /// 添加实体对象 /// 将泛型数据信息映射为一条插入sql语句 /// 该泛型类必须实现IEntity 接口 /// </summary> /// <typeparam name="T">实体泛型类型</typeparam> /// <param name="t">泛型实体值</param> /// <returns></returns> //public int Add<T>(T t) where T : IEntity //{ // IDataParameter[] param = null; // string sql = Factory.CreateInsertSql<T>(t,out param); // using (IDbProvider provider = new SqlProvider()) // { // return BaseHelper.ExecuteNonQuery( sql, param); // } //} /// <summary> /// 添加实体对象 /// value 的类型必须和type一致,这样才能保存值 /// </summary> /// <param name="type">实体类型</param> /// <param name="value">实体类型实例</param> /// <returns></returns> //public int Add(Type type, object value) //{ // IDataParameter[] param = null; // string sql = Factory.CreateInsertSql(type,value,out param); // using (IDbProvider provider = new SqlProvider()) // { // return BaseHelper.ExecuteNonQuery( sql, param); // } //} /// <summary> /// 根据实体公共接口修改该实体信息 /// 该实体是根据主键修改 /// </summary> /// <param name="entity">实体公共接口</param> /// <returns></returns> public int AddOrUpdate(IEntity entity) { IDataParameter[] param = null; string sql = Factory.CreateUpdateSql(entity, out param); //多条语句的场合 if (sql.IndexOf(";") > 0) { return(Convert.ToInt32(BaseHelper.ExecuteScalar(sql, param as SqlParameter[]))); } else { return(BaseHelper.ExecuteNonQuery(sql, param as SqlParameter[])); } }
///// <summary> ///// 根据泛型类的某个实体属性来修改该数据。 ///// 泛型实体实例中该属性不能为空 ///// </summary> ///// <typeparam name="T">泛型类</typeparam> ///// <param name="t">泛型实例</param> ///// <param name="propertyName"></param> ///// <returns></returns> //public int Update<T>(T t, string propertyName) where T : IEntity //{ // IDataParameter[] param = null; // string sql = Factory.CreateUpdateSql(typeof(T), t, out param,propertyName); // return (int)BaseHelper.ExecuteNonQuery(sql, param as OracleParameter[]); //} ///// <summary> ///// 根据实体的多个属性修改数据 ///// 数组中的属性名称在泛型类中必须存在, ///// 数组不能传递null值 ///// </summary> ///// <typeparam name="T">泛型类</typeparam> ///// <param name="t">泛型实例</param> ///// <param name="propertyNames">属性名称数组</param> ///// <returns></returns> //public int Update<T>(T t, string[] propertyNames) where T : IEntity //{ // IDataParameter[] param = null; // string sql = Factory.CreateUpdateSql(typeof(T), t, out param, propertyNames); // return (int)BaseHelper.ExecuteNonQuery(sql, param as OracleParameter[]); //} ///// <summary> ///// 修改实体信息 ///// 该实体是根据主键修改 ///// </summary> ///// <param name="type">实体类型</param> ///// <param name="value">实体对象实例</param> ///// <returns></returns> //public int Update(Type type, object value) //{ // IDataParameter[] param = null; // string sql = Factory.CreateUpdateSql(type,value,out param); // return (int)BaseHelper.ExecuteNonQuery(sql, param as OracleParameter[]); //} ///// <summary> ///// 根据实体的某个属性来修改数据信息 ///// 该方法使用Type 来确定需要修改的实体对象 ///// value 实例中必须包含propertyName 这个属性 ///// 而且propertyName 属性值不能为空 ///// </summary> ///// <param name="type">实体类型</param> ///// <param name="value">实体实例</param> ///// <param name="propertyName">属性名称</param> ///// <returns></returns> //public int Update(Type type, object value, string propertyName) //{ // IDataParameter[] param = null; // string sql = Factory.CreateUpdateSql(type, value, out param, propertyName); // return (int)BaseHelper.ExecuteNonQuery(sql, param as OracleParameter[]); //} ///// <summary> ///// 根据实体的多个属性来修改数据信息 ///// 该方法使用Type 来确定需要修改的实体对象 ///// 数组中的属性名称在泛型类中必须存在, ///// 而且数组传递参数不能为null ///// </summary> ///// <param name="type">实体类型</param> ///// <param name="value">实体实例</param> ///// <param name="propertyNames">属性名称数组</param> ///// <returns></returns> //public int Update(Type type, object value, string[] propertyNames) //{ // IDataParameter[] param = null; // string sql = Factory.CreateUpdateSql(type, value, out param, propertyNames); // return (int)BaseHelper.ExecuteNonQuery(sql, param as OracleParameter[]); //} /// <summary> /// 删除实体对象 /// 该方法是根据实体对象主键删除数据 /// </summary> /// <param name="strTableName">实体公共接口</param> /// <param name="strKeyName">实体公共接口</param> /// <param name="strKeyValue">实体公共接口</param> /// <param name="bolType">实体公共接口</param> /// <returns></returns> public int Delete(string strTableName, string strKeyName, string strKeyValue, bool bolType) { //OracleParameter[] param = new OracleParameter[1]; IDataParameter[] param = new OracleParameter[1]; string strSql; if (bolType) { if (strKeyValue.IndexOf(",") > -1) { strSql = string.Format(" delete {0} where {1} in ({2}) ", strTableName, strKeyName, strKeyValue); } else { strSql = string.Format(" delete {0} where {1} =:{1}", strTableName, strKeyName); } } else { if (strKeyValue.IndexOf(",") > -1) { strSql = string.Format(" update {0} set isdel=1 where {1} in({2})", strTableName, strKeyName, strKeyValue); } else { strSql = string.Format(" update {0} set isdel=1 where {1}=:{1}", strTableName); } } param[0] = new OracleParameter(strKeyName, strKeyValue); if (strKeyValue.IndexOf(",") > -1) { param = null; } return((int)BaseHelper.ExecuteNonQuery(strSql, param as OracleParameter[])); }
public int ExecuteSql(string strSql) { return(BaseHelper.ExecuteNonQuery(strSql)); }
///// <summary> ///// 添加实体对象 ///// 将泛型数据信息映射为一条插入sql语句 ///// 该泛型类必须实现IEntity 接口 ///// </summary> ///// <typeparam name="T">实体泛型类型</typeparam> ///// <param name="t">泛型实体值</param> ///// <returns></returns> //public int Add<T>(T t) where T : IEntity //{ // IDataParameter[] param = null; // string sql = Factory.CreateInsertSql<T>(t,out param); // return (int)BaseHelper.ExecuteNonQuery(sql, param as OracleParameter[]); //} ///// <summary> ///// 添加实体对象 ///// value 的类型必须和type一致,这样才能保存值 ///// </summary> ///// <param name="type">实体类型</param> ///// <param name="value">实体类型实例</param> ///// <returns></returns> //public int Add(Type type, object value) //{ // IDataParameter[] param = null; // string sql = Factory.CreateInsertSql(type,value,out param); // return (int)BaseHelper.ExecuteNonQuery(sql, param as OracleParameter[]); //} /// <summary> /// 根据实体公共接口修改该实体信息 /// 该实体是根据主键修改 /// </summary> /// <param name="entity">实体公共接口</param> /// <returns></returns> public int AddOrUpdate(IEntity entity) { IDataParameter[] param = null; string sql = Factory.CreateUpdateSql(entity, out param); //多条语句的场合 if (sql.IndexOf(";") > 0) { string[] strSQLS = sql.Split(";".ToCharArray()); bool bolInTrans = BaseHelper.IsRransaction; try { this.BeginTransaction(); int iRet = int.Parse(BaseHelper.ExecuteNonQuery(strSQLS[0], param as OracleParameter[]).ToString()); if (iRet > 0) { string strRet = BaseHelper.ExecuteScalar(strSQLS[1]).ToString(); decSeqence = decimal.Parse(strRet); if (strRet.Length <= 10) { if (long.Parse(strRet) <= 2147483647) //因为设计时没考虑主键会超过int型最大值,超过最大值的返回不了当前序列 { iRet = int.Parse(strRet); } else { iRet = 1; } } else { iRet = 1; } } //事务的场合 if (!bolInTrans) { if (iRet > 0) { this.Commit(); } else { this.RollBack(); } } return(iRet); } catch (Exception ex) { if (!bolInTrans) { this.RollBack(); } throw ex; } } else //单语句场合 { return(int.Parse(BaseHelper.ExecuteNonQuery(sql, param as OracleParameter[]).ToString())); } }