Exemplo n.º 1
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Cms.Model.C_collect model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update C_collect set ");
            strSql.Append("article_id=@article_id,");
            strSql.Append("typeId=@typeId,");
            strSql.Append("user_id=@user_id,");
            strSql.Append("title=@title,");
            strSql.Append("price=@price,");
            strSql.Append("integral=@integral,");
            strSql.Append("updateTime=@updateTime");
            strSql.Append(" where id=@id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@article_id", SqlDbType.Int,         4),
                new SqlParameter("@typeId",     SqlDbType.Int,         4),
                new SqlParameter("@user_id",    SqlDbType.Int,         4),
                new SqlParameter("@title",      SqlDbType.VarChar,   150),
                new SqlParameter("@price",      SqlDbType.Money,       8),
                new SqlParameter("@integral",   SqlDbType.Int,         4),
                new SqlParameter("@updateTime", SqlDbType.DateTime),
                new SqlParameter("@id",         SqlDbType.Int, 4)
            };
            parameters[0].Value = model.article_id;
            parameters[1].Value = model.typeId;
            parameters[2].Value = model.user_id;
            parameters[3].Value = model.title;
            parameters[4].Value = model.price;
            parameters[5].Value = model.integral;
            parameters[6].Value = model.updateTime;
            parameters[7].Value = model.id;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 public Cms.Model.C_collect DataRowToModel(DataRow row)
 {
     Cms.Model.C_collect model = new Cms.Model.C_collect();
     if (row != null)
     {
         if (row["id"] != null && row["id"].ToString() != "")
         {
             model.id = int.Parse(row["id"].ToString());
         }
         if (row["article_id"] != null && row["article_id"].ToString() != "")
         {
             model.article_id = int.Parse(row["article_id"].ToString());
         }
         if (row["typeId"] != null && row["typeId"].ToString() != "")
         {
             model.typeId = int.Parse(row["typeId"].ToString());
         }
         if (row["user_id"] != null && row["user_id"].ToString() != "")
         {
             model.user_id = int.Parse(row["user_id"].ToString());
         }
         if (row["title"] != null)
         {
             model.title = row["title"].ToString();
         }
         if (row["price"] != null && row["price"].ToString() != "")
         {
             model.price = decimal.Parse(row["price"].ToString());
         }
         if (row["integral"] != null && row["integral"].ToString() != "")
         {
             model.integral = int.Parse(row["integral"].ToString());
         }
         if (row["updateTime"] != null && row["updateTime"].ToString() != "")
         {
             model.updateTime = DateTime.Parse(row["updateTime"].ToString());
         }
     }
     return(model);
 }
Exemplo n.º 3
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Cms.Model.C_collect model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into C_collect(");
            strSql.Append("article_id,typeId,user_id,title,price,integral,updateTime)");
            strSql.Append(" values (");
            strSql.Append("@article_id,@typeId,@user_id,@title,@price,@integral,@updateTime)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@article_id", SqlDbType.Int,       4),
                new SqlParameter("@typeId",     SqlDbType.Int,       4),
                new SqlParameter("@user_id",    SqlDbType.Int,       4),
                new SqlParameter("@title",      SqlDbType.VarChar, 150),
                new SqlParameter("@price",      SqlDbType.Money,     8),
                new SqlParameter("@integral",   SqlDbType.Int,       4),
                new SqlParameter("@updateTime", SqlDbType.DateTime)
            };
            parameters[0].Value = model.article_id;
            parameters[1].Value = model.typeId;
            parameters[2].Value = model.user_id;
            parameters[3].Value = model.title;
            parameters[4].Value = model.price;
            parameters[5].Value = model.integral;
            parameters[6].Value = model.updateTime;

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

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Cms.Model.C_collect GetModel(int id)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 id,article_id,typeId,user_id,title,price,integral,updateTime from C_collect ");
            strSql.Append(" where id=@id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@id", SqlDbType.Int, 4)
            };
            parameters[0].Value = id;

            Cms.Model.C_collect model = new Cms.Model.C_collect();
            DataSet             ds    = DbHelperSQL.Query(strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                return(DataRowToModel(ds.Tables[0].Rows[0]));
            }
            else
            {
                return(null);
            }
        }