Ejemplo n.º 1
0
        /// <summary>
        /// 根据主键值读取记录。如果数据库不存在这条数据将返回null
        /// </summary>
        /// <param name="db">数据库操作对象</param>
        /// <param name="columns">需要返回的列,不提供任何列名时默认将返回所有列</param>
        public ConfigSmsProviderEntity GetConfigSmsProvider(int id)
        {
            string    sql = @"SELECT  [Id],[AppId],[UserCode],[Name],[Url],[PassWord],[Remark],[IsActive],[Sort]
							FROM
							dbo.[ConfigSmsProvider] WITH(NOLOCK)	
							WHERE [Id]=@id"                            ;
            DbCommand cmd = db.GetSqlStringCommand(sql);

            db.AddInParameter(cmd, "@Id", DbType.Int32, id);
            ConfigSmsProviderEntity entity = new ConfigSmsProviderEntity();

            using (IDataReader reader = db.ExecuteReader(cmd))
            {
                if (reader.Read())
                {
                    entity.Id       = StringUtils.GetDbInt(reader["Id"]);
                    entity.AppId    = StringUtils.GetDbString(reader["AppId"]);
                    entity.UserCode = StringUtils.GetDbString(reader["UserCode"]);
                    entity.Name     = StringUtils.GetDbString(reader["Name"]);
                    entity.Url      = StringUtils.GetDbString(reader["Url"]);
                    entity.PassWord = StringUtils.GetDbString(reader["PassWord"]);
                    entity.Remark   = StringUtils.GetDbString(reader["Remark"]);
                    entity.IsActive = StringUtils.GetDbInt(reader["IsActive"]);
                    entity.Sort     = StringUtils.GetDbInt(reader["Sort"]);
                }
            }
            return(entity);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 判断当前节点是否已存在相同的
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public int  ExistNum(ConfigSmsProviderEntity entity)
        {
            ///id=0,判断总数,ID>0判断除自己之外的总数
            string sql = @"Select count(1) from dbo.[ConfigSmsProvider] WITH(NOLOCK) ";

            string where = "where ";
            if (entity.Id == 0)
            {
                where = where + "  (Name=@Name) ";
            }
            else
            {
                where = where + " id<>@Id and  (Name=@Name) ";
            }
            sql = sql + where;
            DbCommand cmd = db.GetSqlStringCommand(sql);

            if (entity.Id > 0)
            {
                db.AddInParameter(cmd, "@Id", DbType.Int32, entity.Id);
            }

            db.AddInParameter(cmd, "@Name", DbType.String, entity.Name);
            object identity = db.ExecuteScalar(cmd);

            if (identity == null || identity == DBNull.Value)
            {
                return(0);
            }
            return(Convert.ToInt32(identity));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 读取记录列表。
        /// </summary>
        /// <param name="db">数据库操作对象</param>
        /// <param name="columns">需要返回的列,不提供任何列名时默认将返回所有列</param>
        public IList <ConfigSmsProviderEntity> GetConfigSmsProviderList(int pagesize, int pageindex, ref int recordCount)
        {
            string sql = @"SELECT   [Id],[AppId],[UserCode],[Name],[Url],[PassWord],[Remark],[IsActive],[Sort]
						FROM
						(SELECT ROW_NUMBER() OVER (ORDER BY Id desc) AS ROWNUMBER,
						 [Id],[AppId],[UserCode],[Name],[Url],[PassWord],[Remark],[IsActive],[Sort] from dbo.[ConfigSmsProvider] WITH(NOLOCK)	
						WHERE  1=1 ) as temp 
						where rownumber BETWEEN ((@PageIndex - 1) * @PageSize + 1) AND @PageIndex * @PageSize"                        ;

            string sql2 = @"Select count(1) from dbo.[ConfigSmsProvider] with (nolock) ";
            IList <ConfigSmsProviderEntity> entityList = new List <ConfigSmsProviderEntity>();
            DbCommand cmd = db.GetSqlStringCommand(sql);

            db.AddInParameter(cmd, "@PageIndex", DbType.Int32, pageindex);
            db.AddInParameter(cmd, "@PageSize", DbType.Int32, pagesize);

            using (IDataReader reader = db.ExecuteReader(cmd))
            {
                while (reader.Read())
                {
                    ConfigSmsProviderEntity entity = new ConfigSmsProviderEntity();
                    entity.Id       = StringUtils.GetDbInt(reader["Id"]);
                    entity.AppId    = StringUtils.GetDbString(reader["AppId"]);
                    entity.UserCode = StringUtils.GetDbString(reader["UserCode"]);
                    entity.Name     = StringUtils.GetDbString(reader["Name"]);
                    entity.Url      = StringUtils.GetDbString(reader["Url"]);
                    entity.PassWord = StringUtils.GetDbString(reader["PassWord"]);
                    entity.Remark   = StringUtils.GetDbString(reader["Remark"]);
                    entity.IsActive = StringUtils.GetDbInt(reader["IsActive"]);
                    entity.Sort     = StringUtils.GetDbInt(reader["Sort"]);
                    entityList.Add(entity);
                }
            }
            cmd = db.GetSqlStringCommand(sql2);
            using (IDataReader reader = db.ExecuteReader(cmd))
            {
                if (reader.Read())
                {
                    recordCount = StringUtils.GetDbInt(reader[0]);
                }
                else
                {
                    recordCount = 0;
                }
            }
            return(entityList);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 根据主键值更新记录的全部字段(注意:该方法不会对自增字段、timestamp类型字段以及主键字段更新!如果要更新主键字段,请使用Update方法)。
        /// 如果数据库有数据被更新了则返回True,否则返回False
        /// </summary>
        /// <param name="db">数据库操作对象</param>
        /// <param name="configSmsProvider">待更新的实体对象</param>
        public int UpdateConfigSmsProvider(ConfigSmsProviderEntity entity)
        {
            string    sql = @" UPDATE dbo.[ConfigSmsProvider] SET
                       [AppId]=@AppId,[UserCode]=@UserCode,[Name]=@Name,[Url]=@Url,[PassWord]=@PassWord,[Remark]=@Remark,[IsActive]=@IsActive,[Sort]=@Sort
                       WHERE [Id]=@id";
            DbCommand cmd = db.GetSqlStringCommand(sql);

            db.AddInParameter(cmd, "@Id", DbType.Int32, entity.Id);
            db.AddInParameter(cmd, "@AppId", DbType.String, entity.AppId);
            db.AddInParameter(cmd, "@UserCode", DbType.String, entity.UserCode);
            db.AddInParameter(cmd, "@Name", DbType.String, entity.Name);
            db.AddInParameter(cmd, "@Url", DbType.String, entity.Url);
            db.AddInParameter(cmd, "@PassWord", DbType.String, entity.PassWord);
            db.AddInParameter(cmd, "@Remark", DbType.String, entity.Remark);
            db.AddInParameter(cmd, "@IsActive", DbType.Int32, entity.IsActive);
            db.AddInParameter(cmd, "@Sort", DbType.Int32, entity.Sort);
            return(db.ExecuteNonQuery(cmd));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 读取记录列表。
        /// </summary>
        /// <param name="db">数据库操作对象</param>
        /// <param name="columns">需要返回的列,不提供任何列名时默认将返回所有列</param>
        public IList <ConfigSmsProviderEntity> GetConfigSmsProviderAll(int smstype, int isactive)
        {
            string where = " where 1=1 ";
            if (smstype > 0)
            {
                where += " and SmsType=@SmsType ";
            }
            if (isactive != -1)
            {
                where += " and IsActive=@IsActive ";
            }
            string sql = @"SELECT    [Id],[AppId],[UserCode],[Name],[Url],[PassWord],[Remark],[IsActive],[Sort] from dbo.[ConfigSmsProvider] WITH(NOLOCK)	"+ where + " Order By Sort desc";
            IList <ConfigSmsProviderEntity> entityList = new List <ConfigSmsProviderEntity>();
            DbCommand cmd = db.GetSqlStringCommand(sql);

            if (smstype > 0)
            {
                db.AddInParameter(cmd, "@SmsType", DbType.Int32, smstype);
            }
            if (isactive != -1)
            {
                db.AddInParameter(cmd, "@IsActive", DbType.Int32, isactive);
            }
            using (IDataReader reader = db.ExecuteReader(cmd))
            {
                while (reader.Read())
                {
                    ConfigSmsProviderEntity entity = new ConfigSmsProviderEntity();
                    entity.Id       = StringUtils.GetDbInt(reader["Id"]);
                    entity.AppId    = StringUtils.GetDbString(reader["AppId"]);
                    entity.UserCode = StringUtils.GetDbString(reader["UserCode"]);
                    entity.Name     = StringUtils.GetDbString(reader["Name"]);
                    entity.Url      = StringUtils.GetDbString(reader["Url"]);
                    entity.PassWord = StringUtils.GetDbString(reader["PassWord"]);
                    entity.Remark   = StringUtils.GetDbString(reader["Remark"]);
                    entity.IsActive = StringUtils.GetDbInt(reader["IsActive"]);
                    entity.Sort     = StringUtils.GetDbInt(reader["Sort"]);
                    entityList.Add(entity);
                }
            }
            return(entityList);
        }
        /// <summary>
        /// 插入一条记录到表ConfigSmsProvider,如果表中存在自增字段,则返回值为新记录的自增字段值,否则返回0。
        /// 该方法提供给界面等UI层调用
        /// </summary>
        /// <param name="configSmsProvider">要添加的ConfigSmsProvider数据实体对象</param>
        public int AddConfigSmsProvider(ConfigSmsProviderEntity configSmsProvider)
        {
            if (configSmsProvider.Id > 0)
            {
                return(UpdateConfigSmsProvider(configSmsProvider));
            }
            else if (string.IsNullOrEmpty(configSmsProvider.Name))
            {
                return((int)CommonStatus.ADD_Fail_Empty);
            }

            else if (ConfigSmsProviderBLL.Instance.IsExist(configSmsProvider))
            {
                return((int)CommonStatus.ADD_Fail_Exist);
            }
            else
            {
                return(ConfigSmsProviderDA.Instance.AddConfigSmsProvider(configSmsProvider));
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 插入一条记录到表ConfigSmsProvider,如果表中存在自增字段,则返回值为新记录的自增字段值,否则返回0
        /// </summary>
        /// <param name="db">数据库操作对象</param>
        /// <param name="configSmsProvider">待插入的实体对象</param>
        public int AddConfigSmsProvider(ConfigSmsProviderEntity entity)
        {
            string    sql = @"insert into ConfigSmsProvider( [AppId],[UserCode],[Name],[Url],[PassWord],[Remark],[IsActive],[Sort])VALUES
			            ( @AppId,@UserCode,@Name,@Url,@PassWord,@Remark,@IsActive,@Sort);
			SELECT SCOPE_IDENTITY();"            ;
            DbCommand cmd = db.GetSqlStringCommand(sql);

            db.AddInParameter(cmd, "@AppId", DbType.String, entity.AppId);
            db.AddInParameter(cmd, "@UserCode", DbType.String, entity.UserCode);
            db.AddInParameter(cmd, "@Name", DbType.String, entity.Name);
            db.AddInParameter(cmd, "@Url", DbType.String, entity.Url);
            db.AddInParameter(cmd, "@PassWord", DbType.String, entity.PassWord);
            db.AddInParameter(cmd, "@Remark", DbType.String, entity.Remark);
            db.AddInParameter(cmd, "@IsActive", DbType.Int32, entity.IsActive);
            db.AddInParameter(cmd, "@Sort", DbType.Int32, entity.Sort);
            object identity = db.ExecuteScalar(cmd);

            if (identity == null || identity == DBNull.Value)
            {
                return(0);
            }
            return(Convert.ToInt32(identity));
        }
 /// <summary>
 /// 更新一条ConfigSmsProvider记录。
 /// 该方法提供给界面等UI层调用
 /// </summary>
 /// <param name="configSmsProvider">待更新的实体对象</param>
 /// <param name="columns">要更新的列名,不提供任何列名时默认将更新主键之外的所有列</param>
 public int UpdateConfigSmsProvider(ConfigSmsProviderEntity configSmsProvider)
 {
     return(ConfigSmsProviderDA.Instance.UpdateConfigSmsProvider(configSmsProvider));
 }
 /// <summary>
 /// 判断对象是否存在
 /// </summary>
 /// <param name="dicEnum"></param>
 /// <returns></returns>
 public bool IsExist(ConfigSmsProviderEntity configSmsProvider)
 {
     return(ConfigSmsProviderDA.Instance.ExistNum(configSmsProvider) > 0);
 }