/// <summary> /// 更新一条数据 /// </summary> public bool Update(Maticsoft.Model.genre model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update genre set "); strSql.Append("Name=@Name,"); strSql.Append("Description=@Description"); strSql.Append(" where GenreId=@GenreId "); MySqlParameter[] parameters = { new MySqlParameter("@Name", MySqlDbType.VarChar, 120), new MySqlParameter("@Description", MySqlDbType.VarChar, 4000), new MySqlParameter("@GenreId", MySqlDbType.Int32, 11) }; parameters[0].Value = model.Name; parameters[1].Value = model.Description; parameters[2].Value = model.GenreId; int rows = DbHelperMySQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 增加一条数据 /// </summary> public bool Add(Maticsoft.Model.genre model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into genre("); strSql.Append("GenreId,Name,Description)"); strSql.Append(" values ("); strSql.Append("@GenreId,@Name,@Description)"); MySqlParameter[] parameters = { new MySqlParameter("@GenreId", MySqlDbType.Int32, 11), new MySqlParameter("@Name", MySqlDbType.VarChar, 120), new MySqlParameter("@Description", MySqlDbType.VarChar, 4000) }; parameters[0].Value = model.GenreId; parameters[1].Value = model.Name; parameters[2].Value = model.Description; int rows = DbHelperMySQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
public ActionResult Create([Bind(Include = "GenreId,Name,Description")] Maticsoft.Model.genre gmodel) { try { // TODO: Add insert logic here bool bflag = genrebll.Add(gmodel); return(RedirectToAction("Index")); } catch (Exception e) { return(View(e.Message)); } }
public ActionResult Edit([Bind(Include = "GenreId,Name,Description")] Maticsoft.Model.genre gmodel) { try { // TODO: Add update logic here if (ModelState.IsValid) { genrebll.Update(gmodel); } return(RedirectToAction("Index")); } catch { return(View()); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Maticsoft.Model.genre DataRowToModel(DataRow row) { Maticsoft.Model.genre model = new Maticsoft.Model.genre(); if (row != null) { if (row["GenreId"] != null && row["GenreId"].ToString() != "") { model.GenreId = int.Parse(row["GenreId"].ToString()); } if (row["Name"] != null) { model.Name = row["Name"].ToString(); } if (row["Description"] != null) { model.Description = row["Description"].ToString(); } } return(model); }
/// <summary> /// 得到一个对象实体 /// </summary> public Maticsoft.Model.genre GetModel(int GenreId) { StringBuilder strSql = new StringBuilder(); strSql.Append("select GenreId,Name,Description from genre "); strSql.Append(" where GenreId=@GenreId "); MySqlParameter[] parameters = { new MySqlParameter("@GenreId", MySqlDbType.Int32, 11) }; parameters[0].Value = GenreId; Maticsoft.Model.genre model = new Maticsoft.Model.genre(); DataSet ds = DbHelperMySQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }