Ejemplo n.º 1
0
        /// <summary>
        /// 判断当前节点是否已存在相同的
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public int  ExistNum(ClassesMenuADEntity entity)
        {
            ///id=0,判断总数,ID>0判断除自己之外的总数
            string sql = @"Select count(1) from dbo.[ClassesMenuAD] WITH(NOLOCK) ";

            string where = "where ";
            if (entity.Id == 0)
            {
            }
            else
            {
            }
            sql = sql + where;
            DbCommand cmd = db.GetSqlStringCommand(sql);

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

            if (identity == null || identity == DBNull.Value)
            {
                return(0);
            }
            return(Convert.ToInt32(identity));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 获取广告位信息
        /// </summary>
        /// <param name="classid">分类id</param>
        /// <param name="showtype">广告类型:1品牌,2产品</param>
        /// <returns></returns>
        public IList <ClassesMenuADEntity> GetClassesMenuADAll(int classid, int showtype)
        {
            string sql = @"SELECT    [Id],[ClassId],[BrandOrProductId],[Sort],[ShowType],[BeginTime],[EndTime],[IsActive] from dbo.[ClassesMenuAD] WITH(NOLOCK)	
                        where ClassId=@ClassId and ShowType=@ShowType and IsActive=1 and BeginTime<=getdate() and EndTime>=getdate() Order By Sort Desc";
            IList <ClassesMenuADEntity> entityList = new List <ClassesMenuADEntity>();
            DbCommand cmd = db.GetSqlStringCommand(sql);

            db.AddInParameter(cmd, "@ClassId", DbType.Int32, classid);
            db.AddInParameter(cmd, "@ShowType", DbType.Int32, showtype);
            using (IDataReader reader = db.ExecuteReader(cmd))
            {
                while (reader.Read())
                {
                    ClassesMenuADEntity entity = new ClassesMenuADEntity();
                    entity.Id               = StringUtils.GetDbInt(reader["Id"]);
                    entity.ClassId          = StringUtils.GetDbInt(reader["ClassId"]);
                    entity.BrandOrProductId = StringUtils.GetDbInt(reader["BrandOrProductId"]);
                    entity.Sort             = StringUtils.GetDbInt(reader["Sort"]);
                    entity.ShowType         = StringUtils.GetDbInt(reader["ShowType"]);
                    entity.BeginTime        = StringUtils.GetDbDateTime(reader["BeginTime"]);
                    entity.EndTime          = StringUtils.GetDbDateTime(reader["EndTime"]);
                    entity.IsActive         = StringUtils.GetDbInt(reader["IsActive"]);
                    entityList.Add(entity);
                }
            }
            return(entityList);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 根据主键值读取记录。如果数据库不存在这条数据将返回null
        /// </summary>
        /// <param name="db">数据库操作对象</param>
        /// <param name="columns">需要返回的列,不提供任何列名时默认将返回所有列</param>
        public ClassesMenuADEntity GetClassesMenuAD(int id)
        {
            string    sql = @"SELECT  [Id],[ClassId],[BrandOrProductId],[Sort],[ShowType],[BeginTime],[EndTime],[IsActive]
							FROM
							dbo.[ClassesMenuAD] WITH(NOLOCK)	
							WHERE [Id]=@id"                            ;
            DbCommand cmd = db.GetSqlStringCommand(sql);

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

            using (IDataReader reader = db.ExecuteReader(cmd))
            {
                if (reader.Read())
                {
                    entity.Id               = StringUtils.GetDbInt(reader["Id"]);
                    entity.ClassId          = StringUtils.GetDbInt(reader["ClassId"]);
                    entity.BrandOrProductId = StringUtils.GetDbInt(reader["BrandOrProductId"]);
                    entity.Sort             = StringUtils.GetDbInt(reader["Sort"]);
                    entity.ShowType         = StringUtils.GetDbInt(reader["ShowType"]);
                    entity.BeginTime        = StringUtils.GetDbDateTime(reader["BeginTime"]);
                    entity.EndTime          = StringUtils.GetDbDateTime(reader["EndTime"]);
                    entity.IsActive         = StringUtils.GetDbInt(reader["IsActive"]);
                }
            }
            return(entity);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 插入一条记录到表ClassesMenuAD,如果表中存在自增字段,则返回值为新记录的自增字段值,否则返回0。
        /// 该方法提供给界面等UI层调用
        /// </summary>
        /// <param name="classesMenuAD">要添加的ClassesMenuAD数据实体对象</param>
        public int AddClassesMenuAD(ClassesMenuADEntity classesMenuAD)
        {
            if (classesMenuAD.Id > 0)
            {
                return(UpdateClassesMenuAD(classesMenuAD));
            }

            else if (ClassesMenuADBLL.Instance.IsExist(classesMenuAD))
            {
                return((int)CommonStatus.ADD_Fail_Exist);
            }
            else
            {
                return(ClassesMenuADDA.Instance.AddClassesMenuAD(classesMenuAD));
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 根据分类Id获取对应品牌
        /// </summary>
        /// <param name="classid"></param>
        /// <returns></returns>
        public IList <BrandEntity> GetBrandsByClassId(int classid)
        {
            IList <ClassesMenuADEntity> listmenu  = ClassesMenuADDA.Instance.GetClassesMenuADAll(classid, (int)ClassesAdShowType.Brand);
            IList <BrandEntity>         brandlist = new List <BrandEntity>();

            if (listmenu != null && listmenu.Count > 0)
            {
                for (int i = 0; i < listmenu.Count; i++)
                {
                    ClassesMenuADEntity entity = listmenu[i];
                    BrandEntity         brand  = BrandBLL.Instance.GetBrand(entity.BrandOrProductId);
                    brandlist.Add(brand);
                }
            }

            return(brandlist);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 根据主键值更新记录的全部字段(注意:该方法不会对自增字段、timestamp类型字段以及主键字段更新!如果要更新主键字段,请使用Update方法)。
        /// 如果数据库有数据被更新了则返回True,否则返回False
        /// </summary>
        /// <param name="db">数据库操作对象</param>
        /// <param name="classesMenuAD">待更新的实体对象</param>
        public int UpdateClassesMenuAD(ClassesMenuADEntity entity)
        {
            string    sql = @" UPDATE dbo.[ClassesMenuAD] SET
                       [ClassId]=@ClassId,[BrandOrProductId]=@BrandOrProductId,[Sort]=@Sort,[ShowType]=@ShowType,[BeginTime]=@BeginTime,[EndTime]=@EndTime,[IsActive]=@IsActive
                       WHERE [Id]=@id";
            DbCommand cmd = db.GetSqlStringCommand(sql);

            db.AddInParameter(cmd, "@Id", DbType.Int32, entity.Id);
            db.AddInParameter(cmd, "@ClassId", DbType.Int32, entity.ClassId);
            db.AddInParameter(cmd, "@BrandOrProductId", DbType.Int32, entity.BrandOrProductId);
            db.AddInParameter(cmd, "@Sort", DbType.Int32, entity.Sort);
            db.AddInParameter(cmd, "@ShowType", DbType.Int32, entity.ShowType);
            db.AddInParameter(cmd, "@BeginTime", DbType.DateTime, entity.BeginTime);
            db.AddInParameter(cmd, "@EndTime", DbType.DateTime, entity.EndTime);
            db.AddInParameter(cmd, "@IsActive", DbType.Int32, entity.IsActive);
            return(db.ExecuteNonQuery(cmd));
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 读取记录列表。
        /// </summary>
        /// <param name="db">数据库操作对象</param>
        /// <param name="columns">需要返回的列,不提供任何列名时默认将返回所有列</param>
        public IList <ClassesMenuADEntity> GetClassesMenuADList(int pagesize, int pageindex, ref int recordCount)
        {
            string sql = @"SELECT   [Id],[ClassId],[BrandOrProductId],[Sort],[ShowType],[BeginTime],[EndTime],[IsActive]
						FROM
						(SELECT ROW_NUMBER() OVER (ORDER BY Id desc) AS ROWNUMBER,
						 [Id],[ClassId],[BrandOrProductId],[Sort],[ShowType],[BeginTime],[EndTime],[IsActive] from dbo.[ClassesMenuAD] WITH(NOLOCK)	
						WHERE  1=1 ) as temp 
						where rownumber BETWEEN ((@PageIndex - 1) * @PageSize + 1) AND @PageIndex * @PageSize"                        ;

            string sql2 = @"Select count(1) from dbo.[ClassesMenuAD] with (nolock) ";
            IList <ClassesMenuADEntity> entityList = new List <ClassesMenuADEntity>();
            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())
                {
                    ClassesMenuADEntity entity = new ClassesMenuADEntity();
                    entity.Id               = StringUtils.GetDbInt(reader["Id"]);
                    entity.ClassId          = StringUtils.GetDbInt(reader["ClassId"]);
                    entity.BrandOrProductId = StringUtils.GetDbInt(reader["BrandOrProductId"]);
                    entity.Sort             = StringUtils.GetDbInt(reader["Sort"]);
                    entity.ShowType         = StringUtils.GetDbInt(reader["ShowType"]);
                    entity.BeginTime        = StringUtils.GetDbDateTime(reader["BeginTime"]);
                    entity.EndTime          = StringUtils.GetDbDateTime(reader["EndTime"]);
                    entity.IsActive         = StringUtils.GetDbInt(reader["IsActive"]);
                    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.º 8
0
        /// <summary>
        /// 插入一条记录到表ClassesMenuAD,如果表中存在自增字段,则返回值为新记录的自增字段值,否则返回0
        /// </summary>
        /// <param name="db">数据库操作对象</param>
        /// <param name="classesMenuAD">待插入的实体对象</param>
        public int AddClassesMenuAD(ClassesMenuADEntity entity)
        {
            string    sql = @"insert into ClassesMenuAD( [ClassId],[BrandOrProductId],[Sort],[ShowType],[BeginTime],[EndTime],[IsActive])VALUES
			            ( @ClassId,@BrandOrProductId,@Sort,@ShowType,@BeginTime,@EndTime,@IsActive);
			SELECT SCOPE_IDENTITY();"            ;
            DbCommand cmd = db.GetSqlStringCommand(sql);

            db.AddInParameter(cmd, "@ClassId", DbType.Int32, entity.ClassId);
            db.AddInParameter(cmd, "@BrandOrProductId", DbType.Int32, entity.BrandOrProductId);
            db.AddInParameter(cmd, "@Sort", DbType.Int32, entity.Sort);
            db.AddInParameter(cmd, "@ShowType", DbType.Int32, entity.ShowType);
            db.AddInParameter(cmd, "@BeginTime", DbType.DateTime, entity.BeginTime);
            db.AddInParameter(cmd, "@EndTime", DbType.DateTime, entity.EndTime);
            db.AddInParameter(cmd, "@IsActive", DbType.Int32, entity.IsActive);
            object identity = db.ExecuteScalar(cmd);

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