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

            strSql.Append("update ProductImg set ");
            strSql.Append("productId=@productId,");
            strSql.Append("imgURL=@imgURL,");
            strSql.Append("title=@title,");
            strSql.Append("alt=@alt,");
            strSql.Append("linkurl=@linkurl,");
            strSql.Append("status=@status,");
            strSql.Append("remark=@remark");
            strSql.Append(" where id=@id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@productId", SqlDbType.Int,       4),
                new SqlParameter("@imgURL",    SqlDbType.VarChar,  50),
                new SqlParameter("@title",     SqlDbType.VarChar, 150),
                new SqlParameter("@alt",       SqlDbType.VarChar, 150),
                new SqlParameter("@linkurl",   SqlDbType.VarChar, 150),
                new SqlParameter("@status",    SqlDbType.Int,       4),
                new SqlParameter("@remark",    SqlDbType.VarChar,  50),
                new SqlParameter("@id",        SqlDbType.Int, 4)
            };
            parameters[0].Value = model.productId;
            parameters[1].Value = model.imgURL;
            parameters[2].Value = model.title;
            parameters[3].Value = model.alt;
            parameters[4].Value = model.linkurl;
            parameters[5].Value = model.status;
            parameters[6].Value = model.remark;
            parameters[7].Value = model.id;

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

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 public Model.ProductImg DataRowToModel(DataRow row)
 {
     Model.ProductImg model = new Model.ProductImg();
     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["imgURL"] != null)
         {
             model.imgURL = row["imgURL"].ToString();
         }
         if (row["title"] != null)
         {
             model.title = row["title"].ToString();
         }
         if (row["alt"] != null)
         {
             model.alt = row["alt"].ToString();
         }
         if (row["linkurl"] != null)
         {
             model.linkurl = row["linkurl"].ToString();
         }
         if (row["status"] != null && row["status"].ToString() != "")
         {
             model.status = int.Parse(row["status"].ToString());
         }
         if (row["remark"] != null)
         {
             model.remark = row["remark"].ToString();
         }
     }
     return(model);
 }
Ejemplo n.º 3
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public static int Add(Model.ProductImg model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into ProductImg(");
            strSql.Append("productId,imgURL,title,alt,linkurl,status,remark)");
            strSql.Append(" values (");
            strSql.Append("@productId,@imgURL,@title,@alt,@linkurl,@status,@remark)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@productId", SqlDbType.Int,       4),
                new SqlParameter("@imgURL",    SqlDbType.VarChar,  50),
                new SqlParameter("@title",     SqlDbType.VarChar, 150),
                new SqlParameter("@alt",       SqlDbType.VarChar, 150),
                new SqlParameter("@linkurl",   SqlDbType.VarChar, 150),
                new SqlParameter("@status",    SqlDbType.Int,       4),
                new SqlParameter("@remark",    SqlDbType.VarChar, 50)
            };
            parameters[0].Value = model.productId;
            parameters[1].Value = model.imgURL;
            parameters[2].Value = model.title;
            parameters[3].Value = model.alt;
            parameters[4].Value = model.linkurl;
            parameters[5].Value = model.status;
            parameters[6].Value = model.remark;

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

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

            strSql.Append("select  top 1 id,productId,imgURL,title,alt,linkurl,status,remark from ProductImg ");
            strSql.Append(" where id=@id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@id", SqlDbType.Int, 4)
            };
            parameters[0].Value = id;

            Model.ProductImg model = new Model.ProductImg();
            DataSet          ds    = DBHelperSQL.Query(strSql.ToString(), parameters);

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