Exemplo n.º 1
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Entity.BASE_WORD entity)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into Base_Word(");
            strSql.Append("WordName,Score,WordIDParent,Enable");
            strSql.Append(") values (");
            strSql.Append("@WordName,@Score,@WordIDParent,@Enable");
            strSql.Append(") ");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@WordName",     SqlDbType.VarChar, 50),
                new SqlParameter("@Score",        SqlDbType.Float,    8),
                new SqlParameter("@WordIDParent", SqlDbType.Int,      4),
                new SqlParameter("@Enable",       SqlDbType.Int, 4)
            };

            parameters[0].Value = entity.WordName;
            parameters[1].Value = entity.Score;
            parameters[2].Value = entity.WordIDParent;
            parameters[3].Value = entity.Enable;

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

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Entity.BASE_WORD GetEntity(int WordID)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select WordID, WordName, Score, WordIDParent, Enable  ");
            strSql.Append("  from Base_Word ");
            strSql.Append(" where WordID=@WordID");
            SqlParameter[] parameters =
            {
                new SqlParameter("@WordID", SqlDbType.Int, 4)
            };
            parameters[0].Value = WordID;


            Entity.BASE_WORD entity = new Entity.BASE_WORD();
            DataSet          ds     = SqlServerHelper.Query(strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["WordID"].ToString() != "")
                {
                    entity.WordID = int.Parse(ds.Tables[0].Rows[0]["WordID"].ToString());
                }
                entity.WordName = ds.Tables[0].Rows[0]["WordName"].ToString();
                if (ds.Tables[0].Rows[0]["Score"].ToString() != "")
                {
                    entity.Score = decimal.Parse(ds.Tables[0].Rows[0]["Score"].ToString());
                }
                if (ds.Tables[0].Rows[0]["WordIDParent"].ToString() != "")
                {
                    entity.WordIDParent = int.Parse(ds.Tables[0].Rows[0]["WordIDParent"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Enable"].ToString() != "")
                {
                    entity.Enable = int.Parse(ds.Tables[0].Rows[0]["Enable"].ToString());
                }

                return(entity);
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Entity.BASE_WORD entity)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update Base_Word set ");

            strSql.Append(" WordName = @WordName , ");
            strSql.Append(" Score = @Score , ");
            strSql.Append(" WordIDParent = @WordIDParent , ");
            strSql.Append(" Enable = @Enable  ");
            strSql.Append(" where WordID=@WordID ");

            SqlParameter[] parameters =
            {
                new SqlParameter("@WordID",       SqlDbType.Int,      4),
                new SqlParameter("@WordName",     SqlDbType.VarChar, 50),
                new SqlParameter("@Score",        SqlDbType.Float,    8),
                new SqlParameter("@WordIDParent", SqlDbType.Int,      4),
                new SqlParameter("@Enable",       SqlDbType.Int, 4)
            };

            parameters[4].Value = entity.WordID;
            parameters[5].Value = entity.WordName;
            parameters[6].Value = entity.Score;
            parameters[7].Value = entity.WordIDParent;
            parameters[8].Value = entity.Enable;
            int rows = SqlServerHelper.ExecuteSql(strSql.ToString(), parameters);

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }