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

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

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

            if (identity == null || identity == DBNull.Value)
            {
                return(0);
            }
            return(Convert.ToInt32(identity));
        }
Пример #2
0
        public string CmsUpdateSubmit()
        {
            int    _cmsid          = FormString.IntSafeQ("cmsid");
            string _title          = FormString.SafeQ("title");
            string _templetcontent = FormString.SafeQNo("templetcontent", 1000000);
            int    _productnum     = FormString.IntSafeQ("productnum");
            int    _cmstype        = FormString.IntSafeQ("cmstype");
            int    _isactive       = FormString.IntSafeQ("isactive");

            CmsTempletEntity _entity = new CmsTempletEntity();

            _entity.Id             = _cmsid;
            _entity.Title          = _title;
            _entity.TempletContent = _templetcontent;
            _entity.ProductNum     = _productnum;
            _entity.CMSType        = _cmstype;
            _entity.CreateDate     = DateTime.Now;
            _entity.IsActive       = _isactive;

            int _count = CmsTempletBLL.Instance.UpdateCmsTemplet(_entity);

            if (_count > 0)
            {
                return(((int)CommonStatus.Success).ToString());
            }

            return(((int)CommonStatus.Fail).ToString());
        }
Пример #3
0
        public IList <CmsTempletEntity> GetCmsTempletListBySearchCondition(string title, int cmstype, int isactive)
        {
            string    sql = @"SELECT [Id],[Title],[TempletContent],[ProductNum],[CMSType],[CreateDate],[IsActive] 
                         FROM
                         dbo.[CmsTemplet] WITH(NOLOCK)
                         WHERE [CMSType]=@cmstype AND [IsActive]=@isactive AND [Title] like @title";
            DbCommand cmd = db.GetSqlStringCommand(sql);

            db.AddInParameter(cmd, "@CMSType", DbType.Int32, cmstype);
            db.AddInParameter(cmd, "@IsActive", DbType.Int32, isactive);
            db.AddInParameter(cmd, "@Title", DbType.String, "%" + title + "%");
            IList <CmsTempletEntity> _entitylist = new List <CmsTempletEntity>();

            using (IDataReader reader = db.ExecuteReader(cmd))
            {
                while (reader.Read())
                {
                    CmsTempletEntity _entity = new CmsTempletEntity();
                    _entity.Id             = StringUtils.GetDbInt(reader["Id"]);
                    _entity.Title          = StringUtils.GetDbString(reader["Title"]);
                    _entity.TempletContent = StringUtils.GetDbString(reader["TempletContent"]);
                    _entity.ProductNum     = StringUtils.GetDbInt(reader["ProductNum"]);
                    _entity.CMSType        = StringUtils.GetDbInt(reader["CMStype"]);
                    _entity.CreateDate     = StringUtils.GetDbDateTime(reader["CreateDate"]);
                    _entity.IsActive       = StringUtils.GetDbInt(reader["IsActive"]);
                    _entitylist.Add(_entity);
                }
            }
            return(_entitylist);
        }
Пример #4
0
        public CmsTempletEntity GetCmsTempletByTitle(string title)
        {
            string    sql = @"SELECT  [Id],[Title],[TempletContent],[ProductNum],[CMSType],[CreateDate],[IsActive]
							FROM
							dbo.[CmsTemplet] WITH(NOLOCK)	
							WHERE [Title]=@title"                            ;
            DbCommand cmd = db.GetSqlStringCommand(sql);

            db.AddInParameter(cmd, "@Title", DbType.String, title);
            CmsTempletEntity entity = new CmsTempletEntity();

            using (IDataReader reader = db.ExecuteReader(cmd))
            {
                if (reader.Read())
                {
                    entity.Id             = StringUtils.GetDbInt(reader["Id"]);
                    entity.Title          = StringUtils.GetDbString(reader["Title"]);
                    entity.TempletContent = StringUtils.GetDbString(reader["TempletContent"]);
                    entity.ProductNum     = StringUtils.GetDbInt(reader["ProductNum"]);
                    entity.CMSType        = StringUtils.GetDbInt(reader["CMSType"]);
                    entity.CreateDate     = StringUtils.GetDbDateTime(reader["CreateDate"]);
                    entity.IsActive       = StringUtils.GetDbInt(reader["IsActive"]);
                }
            }
            return(entity);
        }
Пример #5
0
        /// <summary>
        /// 获取CMS模板
        /// </summary>
        /// <returns></returns>
        public string GetCmsTemplet()
        {
            int _cmstempletid       = FormString.IntSafeQ("cmstempletid");
            CmsTempletEntity entity = CmsTempletBLL.Instance.GetCmsTemplet(_cmstempletid);
            string           str    = JsonJC.ObjectToJson(entity);

            return(str);
        }
Пример #6
0
        /// <summary>
        /// 对CMS模板做生效处理
        /// </summary>
        /// <returns></returns>
        public int CmsTempletEnable()
        {
            int _templetId           = FormString.IntSafeQ("templetId");
            CmsTempletEntity _entity = CmsTempletBLL.Instance.GetCmsTemplet(_templetId);

            _entity.IsActive = 1;
            return(CmsTempletBLL.Instance.UpdateCmsTemplet(_entity));
        }
Пример #7
0
        /// <summary>
        /// CMS模板添加
        /// </summary>
        /// <returns></returns>
        public ActionResult CmsAdd()
        {
            int _cmsid = QueryString.IntSafeQ("cmsid");
            CmsTempletEntity _entity = CmsTempletBLL.Instance.GetCmsTemplet(_cmsid);

            ViewBag.CmsEntity = _entity;
            return(View());
        }
Пример #8
0
        /// <summary>
        /// 插入一条记录到表CmsTemplet,如果表中存在自增字段,则返回值为新记录的自增字段值,否则返回0。
        /// 该方法提供给界面等UI层调用
        /// </summary>
        /// <param name="cmsTemplet">要添加的CmsTemplet数据实体对象</param>
        public int AddCmsTemplet(CmsTempletEntity cmsTemplet)
        {
            if (cmsTemplet.Id > 0)
            {
                return(UpdateCmsTemplet(cmsTemplet));
            }

            else if (IsExist(cmsTemplet))
            {
                return((int)CommonStatus.ADD_Fail_Exist);
            }
            else
            {
                return(CmsTempletDA.Instance.AddCmsTemplet(cmsTemplet));
            }
        }
Пример #9
0
        /// <summary>
        /// 根据主键值更新记录的全部字段(注意:该方法不会对自增字段、timestamp类型字段以及主键字段更新!如果要更新主键字段,请使用Update方法)。
        /// 如果数据库有数据被更新了则返回True,否则返回False
        /// </summary>
        /// <param name="db">数据库操作对象</param>
        /// <param name="cmsTemplet">待更新的实体对象</param>
        public int UpdateCmsTemplet(CmsTempletEntity entity)
        {
            string    sql = @" UPDATE dbo.[CmsTemplet] SET
                       [Title]=@Title,[TempletContent]=@TempletContent,[ProductNum]=@ProductNum,[CMSType]=@CMSType,[CreateDate]=@CreateDate,[IsActive]=@IsActive
                       WHERE [Id]=@id";
            DbCommand cmd = db.GetSqlStringCommand(sql);

            db.AddInParameter(cmd, "@Id", DbType.Int32, entity.Id);
            db.AddInParameter(cmd, "@Title", DbType.String, entity.Title);
            db.AddInParameter(cmd, "@TempletContent", DbType.String, entity.TempletContent);
            db.AddInParameter(cmd, "@ProductNum", DbType.Int32, entity.ProductNum);
            db.AddInParameter(cmd, "@CMSType", DbType.Int32, entity.CMSType);
            db.AddInParameter(cmd, "@CreateDate", DbType.DateTime, entity.CreateDate);
            db.AddInParameter(cmd, "@IsActive", DbType.Int32, entity.IsActive);
            return(db.ExecuteNonQuery(cmd));
        }
Пример #10
0
        /// <summary>
        /// 插入一条记录到表CmsTemplet,如果表中存在自增字段,则返回值为新记录的自增字段值,否则返回0
        /// </summary>
        /// <param name="db">数据库操作对象</param>
        /// <param name="cmsTemplet">待插入的实体对象</param>
        public int AddCmsTemplet(CmsTempletEntity entity)
        {
            string    sql = @"insert into CmsTemplet( [Title],[TempletContent],[ProductNum],[CMSType],[CreateDate],[IsActive])VALUES
			            ( @Title,@TempletContent,@ProductNum,@CMSType,@CreateDate,@IsActive);
			SELECT SCOPE_IDENTITY();"            ;
            DbCommand cmd = db.GetSqlStringCommand(sql);

            db.AddInParameter(cmd, "@Title", DbType.String, entity.Title);
            db.AddInParameter(cmd, "@TempletContent", DbType.String, entity.TempletContent);
            db.AddInParameter(cmd, "@ProductNum", DbType.Int32, entity.ProductNum);
            db.AddInParameter(cmd, "@CMSType", DbType.Int32, entity.CMSType);
            db.AddInParameter(cmd, "@CreateDate", DbType.DateTime, entity.CreateDate);
            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));
        }
Пример #11
0
        /// <summary>
        /// 读取记录列表。
        /// </summary>
        /// <param name="db">数据库操作对象</param>
        /// <param name="columns">需要返回的列,不提供任何列名时默认将返回所有列</param>
        public IList <CmsTempletEntity> GetCmsTempletAll()
        {
            string sql = @"SELECT    [Id],[Title],[TempletContent],[ProductNum],[CMSType],[CreateDate],[IsActive] from dbo.[CmsTemplet] WITH(NOLOCK)	";
            IList <CmsTempletEntity> entityList = new List <CmsTempletEntity>();
            DbCommand cmd = db.GetSqlStringCommand(sql);

            using (IDataReader reader = db.ExecuteReader(cmd))
            {
                while (reader.Read())
                {
                    CmsTempletEntity entity = new CmsTempletEntity();
                    entity.Id             = StringUtils.GetDbInt(reader["Id"]);
                    entity.Title          = StringUtils.GetDbString(reader["Title"]);
                    entity.TempletContent = StringUtils.GetDbString(reader["TempletContent"]);
                    entity.ProductNum     = StringUtils.GetDbInt(reader["ProductNum"]);
                    entity.CMSType        = StringUtils.GetDbInt(reader["CMSType"]);
                    entity.CreateDate     = StringUtils.GetDbDateTime(reader["CreateDate"]);
                    entity.IsActive       = StringUtils.GetDbInt(reader["IsActive"]);
                    entityList.Add(entity);
                }
            }
            return(entityList);
        }
Пример #12
0
 /// <summary>
 /// 更新一条CmsTemplet记录。
 /// 该方法提供给界面等UI层调用
 /// </summary>
 /// <param name="cmsTemplet">待更新的实体对象</param>
 /// <param name="columns">要更新的列名,不提供任何列名时默认将更新主键之外的所有列</param>
 public int UpdateCmsTemplet(CmsTempletEntity cmsTemplet)
 {
     return(CmsTempletDA.Instance.UpdateCmsTemplet(cmsTemplet));
 }
Пример #13
0
 public int NewAddCmsTemplet(CmsTempletEntity cmsTemplet)
 {
     return(CmsTempletDA.Instance.AddCmsTemplet(cmsTemplet));
 }
Пример #14
0
 /// <summary>
 /// 判断对象是否存在
 /// </summary>
 /// <param name="dicEnum"></param>
 /// <returns></returns>
 public bool IsExist(CmsTempletEntity cmsTemplet)
 {
     return(CmsTempletDA.Instance.ExistNum(cmsTemplet) > 0);
 }
Пример #15
0
        /// <summary>
        /// 读取记录列表。
        /// </summary>
        /// <param name="db">数据库操作对象</param>
        /// <param name="columns">需要返回的列,不提供任何列名时默认将返回所有列</param>
        public IList <CmsTempletEntity> GetCmsTempletList(int pagesize, int pageindex, ref int recordCount, string searchkey, int cmstype, int isactive, string sortkeyword)
        {
            string where = " where 1=1 ";
            string where2 = "";

            if (!string.IsNullOrEmpty(searchkey))
            {
                where += " and Title like @Title ";
            }
            if (cmstype > 0)
            {
                where += " and CMSType=@CMSType ";
            }
            if (isactive > 0)
            {
                where += " and IsActive=@IsActive ";
            }
            if (!string.IsNullOrEmpty(sortkeyword))
            {
                where2 = " order by " + sortkeyword + " desc";
            }
            string sql = @"SELECT   [Id],[Title],[TempletContent],[ProductNum],[CMSType],[CreateDate],[IsActive]
						FROM
						(SELECT ROW_NUMBER() OVER (ORDER BY Id desc) AS ROWNUMBER,
						 [Id],[Title],[TempletContent],[ProductNum],[CMSType],[CreateDate],[IsActive] from dbo.[CmsTemplet] WITH(NOLOCK)	
						"                         + where + @") as temp 
						where rownumber BETWEEN ((@PageIndex - 1) * @PageSize + 1) AND @PageIndex * @PageSize"                         + where2;

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

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

            if (!string.IsNullOrEmpty(searchkey))
            {
                db.AddInParameter(cmd, "@Title", DbType.String, "%" + searchkey + "%");
            }
            if (cmstype > 0)
            {
                db.AddInParameter(cmd, "@CMSType", DbType.Int32, cmstype);
            }
            if (isactive > 0)
            {
                db.AddInParameter(cmd, "@IsActive", DbType.Int32, isactive);
            }

            using (IDataReader reader = db.ExecuteReader(cmd))
            {
                while (reader.Read())
                {
                    CmsTempletEntity entity = new CmsTempletEntity();
                    entity.Id             = StringUtils.GetDbInt(reader["Id"]);
                    entity.Title          = StringUtils.GetDbString(reader["Title"]);
                    entity.TempletContent = StringUtils.GetDbString(reader["TempletContent"]);
                    entity.ProductNum     = StringUtils.GetDbInt(reader["ProductNum"]);
                    entity.CMSType        = StringUtils.GetDbInt(reader["CMSType"]);
                    entity.CreateDate     = StringUtils.GetDbDateTime(reader["CreateDate"]);
                    entity.IsActive       = StringUtils.GetDbInt(reader["IsActive"]);
                    entityList.Add(entity);
                }
            }
            cmd = db.GetSqlStringCommand(sql2);
            if (!string.IsNullOrEmpty(searchkey))
            {
                db.AddInParameter(cmd, "@Title", DbType.String, "%" + searchkey + "%");
            }
            if (cmstype > 0)
            {
                db.AddInParameter(cmd, "@CMSType", DbType.Int32, cmstype);
            }
            if (isactive > 0)
            {
                db.AddInParameter(cmd, "@IsActive", DbType.Int32, isactive);
            }
            using (IDataReader reader = db.ExecuteReader(cmd))
            {
                if (reader.Read())
                {
                    recordCount = StringUtils.GetDbInt(reader[0]);
                }
                else
                {
                    recordCount = 0;
                }
            }
            return(entityList);
        }