예제 #1
0
        /// <summary>
        /// 修改数据
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int Update(Model.Bbs.ContentDetail model)
        {
            if (IsExist(model.Title, model.NumberID))
            {
                return(110);
            }

            //定义查询命令
            string cmdText = @"update [ContentDetail] set ContentTypeID = @ContentTypeID,Title = @Title,ContentText = @ContentText,Sort = @Sort,LastUpdatedDate = @LastUpdatedDate,UserId = @UserId where NumberID = @NumberID";

            //创建查询命令参数集
            SqlParameter[] parms =
            {
                new SqlParameter("@NumberID",        SqlDbType.UniqueIdentifier),
                new SqlParameter("@ContentTypeID",   SqlDbType.UniqueIdentifier),
                new SqlParameter("@Title",           SqlDbType.NVarChar,256),
                new SqlParameter("@ContentText",     SqlDbType.NText),
                new SqlParameter("@Sort",            SqlDbType.Int),
                new SqlParameter("@LastUpdatedDate", SqlDbType.DateTime),
                new SqlParameter("@UserId",          SqlDbType.UniqueIdentifier)
            };
            parms[0].Value = model.ContentTypeID;
            parms[1].Value = model.Title;
            parms[2].Value = model.ContentText;
            parms[3].Value = model.Sort;
            parms[4].Value = model.LastUpdatedDate;
            parms[5].Value = model.UserId;


            return(SqlHelper.ExecuteNonQuery(SqlHelper.SqlProviderBbsConnString, CommandType.Text, cmdText, parms));
        }
예제 #2
0
        /// <summary>
        /// 添加数据到数据库
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int Insert(Model.Bbs.ContentDetail model)
        {
            if (model == null)
            {
                return(-1);
            }

            //判断当前记录是否存在,如果存在则返回;
            if (IsExist(model.Title, ""))
            {
                return(110);
            }

            string cmdText = "insert into [ContentDetail] (ContentTypeID,Title,ContentText,Sort,LastUpdatedDate,UserId) values (@ContentTypeID,@Title,@ContentText,@Sort,@LastUpdatedDate,@UserId)";

            //创建查询命令参数集
            SqlParameter[] parms =
            {
                new SqlParameter("@ContentTypeID",   SqlDbType.UniqueIdentifier),
                new SqlParameter("@Title",           SqlDbType.NVarChar,256),
                new SqlParameter("@ContentText",     SqlDbType.NText),
                new SqlParameter("@Sort",            SqlDbType.Int),
                new SqlParameter("@LastUpdatedDate", SqlDbType.DateTime),
                new SqlParameter("@UserId",          SqlDbType.UniqueIdentifier)
            };
            parms[0].Value = model.ContentTypeID;
            parms[1].Value = model.Title;
            parms[2].Value = model.ContentText;
            parms[3].Value = model.Sort;
            parms[4].Value = model.LastUpdatedDate;
            parms[5].Value = model.UserId;

            //执行数据库操作
            return(SqlHelper.ExecuteNonQuery(SqlHelper.SqlProviderBbsConnString, CommandType.Text, cmdText, parms));
        }
예제 #3
0
        private void OnSave()
        {
            string sTitle = txtTitle.Value.Trim();

            if (string.IsNullOrEmpty(sTitle))
            {
                WebHelper.MessageBox.Messager(this.Page, lbtnPostBack, "标题不能为空,请检查", "温馨提醒", "error");
                return;
            }
            string sParent       = txtParent.Value.Trim();
            Guid   contentTypeId = Guid.Empty;

            if (!string.IsNullOrEmpty(sParent))
            {
                Guid.TryParse(sParent, out contentTypeId);
            }
            string sContent = HttpUtility.UrlDecode(hEditor1.Value).Trim();

            if (bll == null)
            {
                bll = new BLL.Bbs.ContentDetail();
            }
            Model.Bbs.ContentDetail model = new Model.Bbs.ContentDetail();
            model.Title           = sTitle;
            model.ContentTypeID   = contentTypeId;
            model.ContentText     = sContent;
            model.Sort            = 0;
            model.LastUpdatedDate = DateTime.Now;
            model.UserId          = WebHelper.Common.GetUserId();

            int effectCount = -1;

            if (!string.IsNullOrEmpty(nId))
            {
                effectCount = bll.Update(model);
            }
            else
            {
                effectCount = bll.Insert(model);
            }

            if (effectCount == 110)
            {
                WebHelper.MessageBox.Messager(this.Page, lbtnPostBack, "已存在相同记录", "温馨提醒", "error");
                return;
            }
            if (effectCount > 0)
            {
                WebHelper.MessageBox.MessagerShow(this.Page, lbtnPostBack, "操作成功");
            }
            else
            {
                WebHelper.MessageBox.Messager(this.Page, lbtnPostBack, "操作失败");
            }
        }
예제 #4
0
        /// <summary>
        /// 获取数据分页列表,并返回所有记录数
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="totalCount"></param>
        /// <param name="sqlWhere"></param>
        /// <param name="commandParameters"></param>
        /// <returns></returns>
        public IList <Model.Bbs.ContentDetail> GetList(int pageIndex, int pageSize, out int totalCount, string sqlWhere, params SqlParameter[] commandParameters)
        {
            //获取数据集总数
            string cmdText = "select count(*) from [ContentDetail] t1 ";

            if (!string.IsNullOrEmpty(sqlWhere))
            {
                cmdText += "where 1=1 " + sqlWhere;
            }
            totalCount = (int)SqlHelper.ExecuteScalar(SqlHelper.SqlProviderBbsConnString, CommandType.Text, cmdText, commandParameters);
            //返回分页数据
            int startIndex = (pageIndex - 1) * pageSize + 1;
            int endIndex   = pageIndex * pageSize;

            cmdText = @"select * from(select row_number() over(order by t1.LastUpdatedDate desc) as RowNumber,t1.NumberID,t1.ContentTypeID,t1.Title,t1.ContentText,t1.Sort,t1.LastUpdatedDate,t1.UserId from [ContentDetail] t1 ";
            if (!string.IsNullOrEmpty(sqlWhere))
            {
                cmdText += "where 1=1 " + sqlWhere;
            }
            cmdText += ")as objTable where RowNumber between " + startIndex + " and " + endIndex + " ";

            IList <Model.Bbs.ContentDetail> list = null;

            using (SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.SqlProviderBbsConnString, CommandType.Text, cmdText, commandParameters))
            {
                if (reader != null && reader.HasRows)
                {
                    list = new List <Model.Bbs.ContentDetail>();

                    while (reader.Read())
                    {
                        Model.Bbs.ContentDetail model = new Model.Bbs.ContentDetail();
                        model.NumberID        = reader.GetGuid(1);
                        model.ContentTypeID   = reader.GetGuid(2);
                        model.Title           = reader.GetString(3);
                        model.ContentText     = reader.GetString(4);
                        model.Sort            = reader.GetInt32(5);
                        model.LastUpdatedDate = reader.GetDateTime(6);
                        model.UserId          = reader.GetGuid(7);

                        list.Add(model);
                    }
                }
            }

            return(list);
        }
예제 #5
0
 private void Bind()
 {
     if (!string.IsNullOrEmpty(nId))
     {
         if (bll == null)
         {
             bll = new BLL.Bbs.ContentDetail();
         }
         Model.Bbs.ContentDetail model = bll.GetModel(nId);
         if (model != null)
         {
             txtTitle.Value  = model.Title;
             txtParent.Value = model.ContentTypeID.ToString();
             hEditor1.Value  = model.ContentText;
         }
     }
 }
예제 #6
0
        /// <summary>
        /// 获取对应的数据
        /// </summary>
        /// <param name="numberId"></param>
        /// <returns></returns>
        public Model.Bbs.ContentDetail GetModel(object numberId)
        {
            Guid gId = Guid.Empty;

            Guid.TryParse(numberId.ToString(), out gId);
            if (gId == Guid.Empty)
            {
                return(null);
            }

            Model.Bbs.ContentDetail model = null;

            string       cmdText = @"select top 1 NumberID,ContentTypeID,Title,ContentText,Sort,LastUpdatedDate,UserId from [ContentDetail] where NumberID = @NumberID order by LastUpdatedDate desc ";
            SqlParameter parm    = new SqlParameter("@NumberID", SqlDbType.UniqueIdentifier);

            parm.Value = gId;

            using (SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.SqlProviderBbsConnString, CommandType.Text, cmdText, parm))
            {
                if (reader != null)
                {
                    while (reader.Read())
                    {
                        model                 = new Model.Bbs.ContentDetail();
                        model.NumberID        = reader.GetGuid(0);
                        model.ContentTypeID   = reader.GetGuid(1);
                        model.Title           = reader.GetString(2);
                        model.ContentText     = reader.GetString(3);
                        model.Sort            = reader.GetInt32(4);
                        model.LastUpdatedDate = reader.GetDateTime(5);
                        model.UserId          = reader.GetGuid(6);
                    }
                }
            }

            return(model);
        }
예제 #7
0
 /// <summary>
 /// 修改数据
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public int Update(Model.Bbs.ContentDetail model)
 {
     return(dal.Update(model));
 }
예제 #8
0
 /// <summary>
 /// 添加数据到数据库
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public int Insert(Model.Bbs.ContentDetail model)
 {
     return(dal.Insert(model));
 }