Exemplo n.º 1
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public BCW.Model.Speak GetSpeak(int ID)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 ID,Types,NodeId,UsId,UsName,Notes,AddTime from tb_Speak ");
            strSql.Append(" where ID=@ID ");
            SqlParameter[] parameters =
            {
                new SqlParameter("@ID", SqlDbType.Int, 4)
            };
            parameters[0].Value = ID;

            BCW.Model.Speak model = new BCW.Model.Speak();
            using (SqlDataReader reader = SqlHelper.ExecuteReader(strSql.ToString(), parameters))
            {
                if (reader.HasRows)
                {
                    reader.Read();
                    model.ID      = reader.GetInt32(0);
                    model.Types   = reader.GetInt32(1);
                    model.NodeId  = reader.GetInt32(2);
                    model.UsId    = reader.GetInt32(3);
                    model.UsName  = reader.GetString(4);
                    model.Notes   = reader.GetString(5);
                    model.AddTime = reader.GetDateTime(6);
                    return(model);
                }
                else
                {
                    return(null);
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public void Update(BCW.Model.Speak model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update tb_Speak set ");
            strSql.Append("Types=@Types,");
            strSql.Append("NodeId=@NodeId,");
            strSql.Append("UsId=@UsId,");
            strSql.Append("UsName=@UsName,");
            strSql.Append("Notes=@Notes,");
            strSql.Append("AddTime=@AddTime");
            strSql.Append(" where ID=@ID ");
            SqlParameter[] parameters =
            {
                new SqlParameter("@ID",      SqlDbType.Int,        4),
                new SqlParameter("@Types",   SqlDbType.Int,        4),
                new SqlParameter("@NodeId",  SqlDbType.Int,        4),
                new SqlParameter("@UsId",    SqlDbType.Int,        4),
                new SqlParameter("@UsName",  SqlDbType.NVarChar,  50),
                new SqlParameter("@Notes",   SqlDbType.NVarChar, 500),
                new SqlParameter("@AddTime", SqlDbType.DateTime)
            };
            parameters[0].Value = model.ID;
            parameters[1].Value = model.Types;
            parameters[2].Value = model.NodeId;
            parameters[3].Value = model.UsId;
            parameters[4].Value = model.UsName;
            parameters[5].Value = model.Notes;
            parameters[6].Value = model.AddTime;

            SqlHelper.ExecuteSql(strSql.ToString(), parameters);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 闲聊排行榜
        /// </summary>
        /// <param name="p_pageIndex">当前页</param>
        /// <param name="p_pageSize">每页显示记录数</param>
        /// <param name="p_recordCount">返回总记录数</param>
        /// <param name="strWhere">查询条件</param>
        /// <returns>List</returns>
        public IList <BCW.Model.Speak> GetSpeaksTop2(int p_pageIndex, int p_pageSize, string strWhere, out int p_recordCount)
        {
            IList <BCW.Model.Speak> listSpeak = new List <BCW.Model.Speak>();

            // 计算记录数
            string countString = "SELECT COUNT(DISTINCT UsID) FROM tb_Speak Where " + strWhere + "";

            p_recordCount = Convert.ToInt32(SqlHelper.GetSingle(countString));
            if (p_recordCount > 0)
            {
                int pageCount = BasePage.CalcPageCount(p_recordCount, p_pageSize, ref p_pageIndex);
                if (pageCount > 100)
                {
                    pageCount = 100;
                }
            }
            else
            {
                return(listSpeak);
            }

            // 取出相关记录

            string queryString = "SELECT UsID, COUNT(ID) FROM tb_Speak Where " + strWhere + " GROUP BY UsID ORDER BY COUNT(ID) DESC";

            using (SqlDataReader reader = SqlHelper.ExecuteReader(queryString))
            {
                int stratIndex = (p_pageIndex - 1) * p_pageSize;
                int endIndex   = p_pageIndex * p_pageSize;
                int k          = 0;
                while (reader.Read())
                {
                    if (k >= stratIndex && k < endIndex)
                    {
                        BCW.Model.Speak objSpeak = new BCW.Model.Speak();
                        objSpeak.UsId  = reader.GetInt32(0);
                        objSpeak.Types = reader.GetInt32(1);
                        listSpeak.Add(objSpeak);
                    }

                    if (k == endIndex)
                    {
                        break;
                    }

                    k++;
                }
            }

            return(listSpeak);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 得到会员上一个发言内容和时间
        /// </summary>
        public BCW.Model.Speak GetNotesAddTime(int UsId)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 Notes,AddTime from tb_Speak ");
            strSql.Append(" where UsId=@UsId Order BY ID DESC");
            SqlParameter[] parameters =
            {
                new SqlParameter("@UsId", SqlDbType.Int, 4)
            };
            parameters[0].Value = UsId;

            BCW.Model.Speak model = new BCW.Model.Speak();
            using (SqlDataReader reader = SqlHelper.ExecuteReader(strSql.ToString(), parameters))
            {
                if (reader.HasRows)
                {
                    reader.Read();
                    if (!reader.IsDBNull(0))
                    {
                        model.Notes = reader.GetString(0);
                    }
                    else
                    {
                        model.Notes = "";
                    }
                    if (!reader.IsDBNull(1))
                    {
                        model.AddTime = reader.GetDateTime(1);
                    }
                    else
                    {
                        model.AddTime = DateTime.Now;
                    }

                    return(model);
                }
                else
                {
                    return(null);
                }
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// 取得每页记录
        /// </summary>
        /// <param name="p_pageIndex">当前页</param>
        /// <param name="p_pageSize">分页大小</param>
        /// <param name="p_recordCount">返回总记录数</param>
        /// <param name="strWhere">查询条件</param>
        /// <returns>IList Speak</returns>
        public IList <BCW.Model.Speak> GetSpeaks(int p_pageIndex, int p_pageSize, string strWhere, out int p_recordCount)
        {
            IList <BCW.Model.Speak> listSpeaks = new List <BCW.Model.Speak>();
            string sTable     = "tb_Speak";
            string sPkey      = "id";
            string sField     = "ID,Types,UsId,UsName,Notes,AddTime,ToId,ToName,IsKiss,IsTop";
            string sCondition = strWhere;
            string sOrder     = "IsTop Desc,ID Desc";
            int    iSCounts   = 0;

            using (SqlDataReader reader = SqlHelper.RunProcedureMe(sTable, sPkey, sField, p_pageIndex, p_pageSize, sCondition, sOrder, iSCounts, out p_recordCount))
            {
                //计算总页数
                if (p_recordCount > 0)
                {
                    int pageCount = BasePage.CalcPageCount(p_recordCount, p_pageSize, ref p_pageIndex);
                }
                else
                {
                    return(listSpeaks);
                }
                while (reader.Read())
                {
                    BCW.Model.Speak objSpeak = new BCW.Model.Speak();
                    objSpeak.ID      = reader.GetInt32(0);
                    objSpeak.Types   = reader.GetInt32(1);
                    objSpeak.UsId    = reader.GetInt32(2);
                    objSpeak.UsName  = reader.GetString(3);
                    objSpeak.Notes   = reader.GetString(4);
                    objSpeak.AddTime = reader.GetDateTime(5);
                    objSpeak.ToId    = reader.GetInt32(6);
                    if (!reader.IsDBNull(7))
                    {
                        objSpeak.ToName = reader.GetString(7);
                    }
                    objSpeak.IsKiss = reader.GetByte(8);
                    objSpeak.IsTop  = reader.GetByte(9);
                    listSpeaks.Add(objSpeak);
                }
            }
            return(listSpeaks);
        }
Exemplo n.º 6
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(BCW.Model.Speak model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into tb_Speak(");
            strSql.Append("Types,NodeId,UsId,UsName,ToId,ToName,Notes,AddTime,IsKiss)");
            strSql.Append(" values (");
            strSql.Append("@Types,@NodeId,@UsId,@UsName,@ToId,@ToName,@Notes,@AddTime,@IsKiss)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Types",   SqlDbType.Int,         4),
                new SqlParameter("@NodeId",  SqlDbType.Int,         4),
                new SqlParameter("@UsId",    SqlDbType.Int,         4),
                new SqlParameter("@UsName",  SqlDbType.NVarChar,   50),
                new SqlParameter("@ToId",    SqlDbType.Int,         4),
                new SqlParameter("@ToName",  SqlDbType.NVarChar,   50),
                new SqlParameter("@Notes",   SqlDbType.NVarChar,  500),
                new SqlParameter("@AddTime", SqlDbType.DateTime),
                new SqlParameter("@IsKiss",  SqlDbType.TinyInt, 1)
            };
            parameters[0].Value = model.Types;
            parameters[1].Value = model.NodeId;
            parameters[2].Value = model.UsId;
            parameters[3].Value = model.UsName;
            parameters[4].Value = model.ToId;
            parameters[5].Value = model.ToName;
            parameters[6].Value = model.Notes;
            parameters[7].Value = model.AddTime;
            parameters[8].Value = model.IsKiss;

            object obj = SqlHelper.GetSingle(strSql.ToString(), parameters);

            if (obj == null)
            {
                return(1);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }