/// <summary> /// 随机获取一个单词实体 /// </summary> /// <returns></returns> public LearnSite.Model.English GetNextModel(int Eid, int Elevel) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 Eid,Eword,Emeaning,Elevel from English where Elevel=@Elevel and Eid>@Eid order by Eid asc"); SqlParameter[] parameters = { new SqlParameter("@Eid", SqlDbType.Int, 4), new SqlParameter("@Elevel", SqlDbType.Int, 4) }; parameters[0].Value = Eid; parameters[1].Value = Elevel; LearnSite.Model.English model = new LearnSite.Model.English(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["Eid"].ToString() != "") { model.Eid = int.Parse(ds.Tables[0].Rows[0]["Eid"].ToString()); } model.Eword = ds.Tables[0].Rows[0]["Eword"].ToString(); model.Emeaning = ds.Tables[0].Rows[0]["Emeaning"].ToString(); return(model); } else { return(null); } }
/// <summary> /// 增加一条数据 /// </summary> public int Add(LearnSite.Model.English model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into English("); strSql.Append("Eword,Emeaning,Elevel)"); strSql.Append(" values ("); strSql.Append("@Eword,@Emeaning,@Elevel)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@Eword", SqlDbType.NVarChar, 50), new SqlParameter("@Emeaning", SqlDbType.NText), new SqlParameter("@Elevel", SqlDbType.Int, 4) }; parameters[0].Value = model.Eword; parameters[1].Value = model.Emeaning; parameters[2].Value = model.Elevel; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(1); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(LearnSite.Model.English model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update English set "); strSql.Append("Eword=@Eword,"); strSql.Append("Emeaning=@Emeaning,"); strSql.Append("Elevel=@Elevel"); strSql.Append(" where Eid=@Eid"); SqlParameter[] parameters = { new SqlParameter("@Eid", SqlDbType.Int, 4), new SqlParameter("@Eword", SqlDbType.NVarChar, 50), new SqlParameter("@Emeaning", SqlDbType.NText), new SqlParameter("@Elevel", SqlDbType.Int, 4) }; parameters[0].Value = model.Eid; parameters[1].Value = model.Eword; parameters[2].Value = model.Emeaning; parameters[3].Value = model.Elevel; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }