Example #1
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(BCW.Model.Submit model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into tb_Submit(");
            strSql.Append("Types,UsID,Title,Content,AddTime)");
            strSql.Append(" values (");
            strSql.Append("@Types,@UsID,@Title,@Content,@AddTime)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Types",   SqlDbType.Int,       4),
                new SqlParameter("@UsID",    SqlDbType.Int,       4),
                new SqlParameter("@Title",   SqlDbType.NVarChar, 50),
                new SqlParameter("@Content", SqlDbType.NText),
                new SqlParameter("@AddTime", SqlDbType.DateTime)
            };
            parameters[0].Value = model.Types;
            parameters[1].Value = model.UsID;
            parameters[2].Value = model.Title;
            parameters[3].Value = model.Content;
            parameters[4].Value = model.AddTime;

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

            if (obj == null)
            {
                return(1);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
Example #2
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public BCW.Model.Submit GetSubmit(int ID)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 ID,Types,UsID,Title,Content,AddTime from tb_Submit ");
            strSql.Append(" where ID=@ID ");
            SqlParameter[] parameters =
            {
                new SqlParameter("@ID", SqlDbType.Int, 4)
            };
            parameters[0].Value = ID;

            BCW.Model.Submit model = new BCW.Model.Submit();
            using (SqlDataReader reader = SqlHelper.ExecuteReader(strSql.ToString(), parameters))
            {
                if (reader.HasRows)
                {
                    reader.Read();
                    model.ID      = reader.GetInt32(0);
                    model.Types   = reader.GetInt32(1);
                    model.UsID    = reader.GetInt32(2);
                    model.Title   = reader.GetString(3);
                    model.Content = reader.GetString(4);
                    model.AddTime = reader.GetDateTime(5);
                    return(model);
                }
                else
                {
                    return(null);
                }
            }
        }
Example #3
0
        /// <summary>
        /// 取得每页记录
        /// </summary>
        /// <param name="p_pageIndex">当前页</param>
        /// <param name="p_pageSize">分页大小</param>
        /// <param name="p_recordCount">返回总记录数</param>
        /// <param name="strWhere">查询条件</param>
        /// <returns>IList Submit</returns>
        public IList <BCW.Model.Submit> GetSubmits(int p_pageIndex, int p_pageSize, string strWhere, out int p_recordCount)
        {
            IList <BCW.Model.Submit> listSubmits = new List <BCW.Model.Submit>();
            string sTable     = "tb_Submit";
            string sPkey      = "id";
            string sField     = "ID,Types,UsID,Title,Content,AddTime";
            string sCondition = strWhere;
            string sOrder     = "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(listSubmits);
                }
                while (reader.Read())
                {
                    BCW.Model.Submit objSubmit = new BCW.Model.Submit();
                    objSubmit.ID      = reader.GetInt32(0);
                    objSubmit.Types   = reader.GetInt32(1);
                    objSubmit.UsID    = reader.GetInt32(2);
                    objSubmit.Title   = reader.GetString(3);
                    objSubmit.Content = reader.GetString(4);
                    objSubmit.AddTime = reader.GetDateTime(5);
                    listSubmits.Add(objSubmit);
                }
            }
            return(listSubmits);
        }
Example #4
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public void Update(BCW.Model.Submit model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update tb_Submit set ");
            strSql.Append("Types=@Types,");
            strSql.Append("UsID=@UsID,");
            strSql.Append("Title=@Title,");
            strSql.Append("Content=@Content,");
            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("@UsID",    SqlDbType.Int,       4),
                new SqlParameter("@Title",   SqlDbType.NVarChar, 50),
                new SqlParameter("@Content", SqlDbType.NText),
                new SqlParameter("@AddTime", SqlDbType.DateTime)
            };
            parameters[0].Value = model.ID;
            parameters[1].Value = model.Types;
            parameters[2].Value = model.UsID;
            parameters[3].Value = model.Title;
            parameters[4].Value = model.Content;
            parameters[5].Value = model.AddTime;

            SqlHelper.ExecuteSql(strSql.ToString(), parameters);
        }