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

            strSql.Append("insert into c_product_albums(");
            strSql.Append("productId,thumb_path,original_path,remark,add_time)");
            strSql.Append(" values (");
            strSql.Append("@productId,@thumb_path,@original_path,@remark,@add_time)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@productId",     SqlDbType.Int,        4),
                new SqlParameter("@thumb_path",    SqlDbType.NVarChar, 255),
                new SqlParameter("@original_path", SqlDbType.NVarChar, 255),
                new SqlParameter("@remark",        SqlDbType.NVarChar, 500),
                new SqlParameter("@add_time",      SqlDbType.DateTime)
            };
            parameters[0].Value = model.productId;
            parameters[1].Value = model.thumb_path;
            parameters[2].Value = model.original_path;
            parameters[3].Value = model.remark;
            parameters[4].Value = model.add_time;

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

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
Example #2
0
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 public Cms.Model.c_product_albums DataRowToModel(DataRow row)
 {
     Cms.Model.c_product_albums model = new Cms.Model.c_product_albums();
     if (row != null)
     {
         if (row["id"] != null && row["id"].ToString() != "")
         {
             model.id = int.Parse(row["id"].ToString());
         }
         if (row["productId"] != null && row["productId"].ToString() != "")
         {
             model.productId = int.Parse(row["productId"].ToString());
         }
         if (row["thumb_path"] != null)
         {
             model.thumb_path = row["thumb_path"].ToString();
         }
         if (row["original_path"] != null)
         {
             model.original_path = row["original_path"].ToString();
         }
         if (row["remark"] != null)
         {
             model.remark = row["remark"].ToString();
         }
         if (row["add_time"] != null && row["add_time"].ToString() != "")
         {
             model.add_time = DateTime.Parse(row["add_time"].ToString());
         }
     }
     return(model);
 }
Example #3
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Cms.Model.c_product_albums model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update c_product_albums set ");
            strSql.Append("productId=@productId,");
            strSql.Append("thumb_path=@thumb_path,");
            strSql.Append("original_path=@original_path,");
            strSql.Append("remark=@remark,");
            strSql.Append("add_time=@add_time");
            strSql.Append(" where id=@id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@productId",     SqlDbType.Int,         4),
                new SqlParameter("@thumb_path",    SqlDbType.NVarChar,  255),
                new SqlParameter("@original_path", SqlDbType.NVarChar,  255),
                new SqlParameter("@remark",        SqlDbType.NVarChar,  500),
                new SqlParameter("@add_time",      SqlDbType.DateTime),
                new SqlParameter("@id",            SqlDbType.Int, 4)
            };
            parameters[0].Value = model.productId;
            parameters[1].Value = model.thumb_path;
            parameters[2].Value = model.original_path;
            parameters[3].Value = model.remark;
            parameters[4].Value = model.add_time;
            parameters[5].Value = model.id;

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

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #4
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Cms.Model.c_product_albums GetModel(int id)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 id,productId,thumb_path,original_path,remark,add_time from c_product_albums ");
            strSql.Append(" where id=@id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@id", SqlDbType.Int, 4)
            };
            parameters[0].Value = id;

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

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