Ejemplo n.º 1
0
        /// <summary>
        /// 修改数据
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int Update(Model.ContentDetailInfo model)
        {
            if (model == null)
            {
                return(-1);
            }

            if (IsExist(model.Title, model.ContentTypeID.ToString(), model.NumberID.ToString()))
            {
                return(110);
            }

            //定义查询命令
            string cmdText = @"update [ContentDetail] set ContentTypeID = @ContentTypeID,Title = @Title,ContentText = @ContentText,Sort = @Sort,LastUpdatedDate = @LastUpdatedDate 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)
            };
            parms[0].Value = model.NumberID;
            parms[1].Value = model.ContentTypeID;
            parms[2].Value = model.Title;
            parms[3].Value = model.ContentText;
            parms[4].Value = model.Sort;
            parms[5].Value = model.LastUpdatedDate;

            return(SqlHelper.ExecuteNonQuery(SqlHelper.SqlProviderConnString, CommandType.Text, cmdText, parms));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 获取当前根节点下的所有内容类型和内容
        /// </summary>
        /// <param name="typeName"></param>
        /// <returns></returns>
        public List <Model.ContentDetailInfo> GetSiteContent(string typeName)
        {
            List <Model.ContentDetailInfo> list = new List <Model.ContentDetailInfo>();

            string cmdText = @"SELECT ct2.TypeName,cd.NumberID,cd.Title,cd.ContentTypeID
                                FROM dbo.ContentType ct1,dbo.ContentType ct2,dbo.ContentDetail cd
                                WHERE ct1.NumberID = ct2.ParentID and ct2.NumberID = cd.ContentTypeID 
                                and ct1.TypeName = @TypeName";

            SqlParameter parm = new SqlParameter("@TypeName", SqlDbType.NVarChar, 256);

            using (SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.SqlProviderConnString, CommandType.Text, cmdText, parm))
            {
                if (reader != null && reader.HasRows)
                {
                    list = new List <Model.ContentDetailInfo>();

                    while (reader.Read())
                    {
                        Model.ContentDetailInfo model = new Model.ContentDetailInfo();
                        model.NumberID      = reader["NumberID"];
                        model.ContentTypeID = reader["ContentTypeID"];
                        model.Title         = reader["Title"].ToString();
                        model.TypeName      = reader["TypeName"].ToString();

                        list.Add(model);
                    }
                }
            }

            return(list);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 获取内容列表
        /// </summary>
        /// <returns></returns>
        public List <Model.ContentDetailInfo> GetList()
        {
            List <Model.ContentDetailInfo> list = new List <Model.ContentDetailInfo>();

            string cmdText = "select NumberID,ContentTypeID,Title from ContentDetail order by Sort";

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

                    while (reader.Read())
                    {
                        Model.ContentDetailInfo model = new Model.ContentDetailInfo();
                        model.NumberID      = reader["NumberID"];
                        model.ContentTypeID = reader["ContentTypeID"];
                        model.Title         = reader["Title"].ToString();

                        list.Add(model);
                    }
                }
            }

            return(list);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 添加数据到数据库
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int Insert(Model.ContentDetailInfo model)
        {
            if (model == null)
            {
                return(-1);
            }

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

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

            //创建查询命令参数集
            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)
            };
            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;

            //执行数据库操作
            return(SqlHelper.ExecuteNonQuery(SqlHelper.SqlProviderConnString, CommandType.Text, cmdText, parms));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 获取对应的数据
        /// </summary>
        /// <param name="numberId"></param>
        /// <returns></returns>
        public Model.ContentDetailInfo GetModel(string numberId)
        {
            Model.ContentDetailInfo model = null;

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

            parm.Value = numberId;

            using (SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.SqlProviderConnString, CommandType.Text, cmdText, parm))
            {
                if (reader != null)
                {
                    while (reader.Read())
                    {
                        model                 = new Model.ContentDetailInfo();
                        model.NumberID        = reader["NumberID"];
                        model.ContentTypeID   = reader["ContentTypeID"];
                        model.Title           = reader["Title"].ToString();
                        model.ContentText     = reader["ContentText"].ToString();
                        model.Sort            = int.Parse(reader["Sort"].ToString());
                        model.LastUpdatedDate = DateTime.Parse(reader["LastUpdatedDate"].ToString());
                    }
                }
            }

            return(model);
        }
Ejemplo n.º 6
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.ContentDetail();
            }
            Model.ContentDetailInfo model = new Model.ContentDetailInfo();
            model.Title           = sTitle;
            model.ContentTypeID   = contentTypeId;
            model.ContentText     = sContent;
            model.Sort            = 0;
            model.LastUpdatedDate = DateTime.Now;

            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.Messager(this.Page, lbtnPostBack, "操作成功");
            }
            else
            {
                WebHelper.MessageBox.Messager(this.Page, lbtnPostBack, "操作失败");
            }
        }
Ejemplo n.º 7
0
 private void Bind()
 {
     if (!string.IsNullOrEmpty(nId))
     {
         if (bll == null)
         {
             bll = new BLL.ContentDetail();
         }
         Model.ContentDetailInfo model = bll.GetModel(nId);
         if (model != null)
         {
             txtTitle.Value  = model.Title;
             txtParent.Value = model.ContentTypeID.ToString();
             hEditor1.Value  = model.ContentText;
         }
     }
 }
Ejemplo n.º 8
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.ContentDetailInfo> 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.SqlProviderConnString, 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 from [ContentDetail] t1 ";
            if (!string.IsNullOrEmpty(sqlWhere))
            {
                cmdText += "where 1=1 " + sqlWhere;
            }
            cmdText += ")as objTable where RowNumber between " + startIndex + " and " + endIndex + " ";

            IList <Model.ContentDetailInfo> list = null;

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

                    while (reader.Read())
                    {
                        Model.ContentDetailInfo model = new Model.ContentDetailInfo();
                        model.NumberID        = reader["NumberID"];
                        model.ContentTypeID   = reader["ContentTypeID"];
                        model.Title           = reader["Title"].ToString();
                        model.ContentText     = reader["ContentText"].ToString();
                        model.Sort            = int.Parse(reader["Sort"].ToString());
                        model.LastUpdatedDate = DateTime.Parse(reader["LastUpdatedDate"].ToString());

                        list.Add(model);
                    }
                }
            }

            return(list);
        }
Ejemplo n.º 9
0
        private void Bind()
        {
            if (!Page.IsPostBack)
            {
                BLL.ContentDetail       bll   = new BLL.ContentDetail();
                Model.ContentDetailInfo model = bll.GetModel(nId);
                if (model != null)
                {
                    StringBuilder sb = new StringBuilder();
                    sb.AppendFormat("<div id='cTitle' class='tc'>{0}</div>", model.Title, model.ContentTypeID);
                    sb.AppendFormat("<div id='cContent' class='mt10'>{0}</div>", model.ContentText);

                    ltrContent.Text = sb.ToString();
                }
                else
                {
                    ltrContent.Text = "<div id='cTitle' class='tc'></div><div id='cContent' class='mt10'></div>";
                }
            }
        }