//SSMS类->和处理直接与数据库相连的公共方法有关的类. /// <summary> /// 通过文章id获得文章 /// </summary> public static Article GetArticleById(int id) { string sql = "SELECT * FROM news WHERE nID = " + id.ToString(); int authorId; SqlDataReader reader = SSMS.GetReader(sql); if (reader.Read()) { Article article = new Article(); article.NID = (int)reader["nID"]; article.NTitle = (string)reader["ntitle"]; article.NContent = (string)reader["ncontent"]; article.NDate = (DateTime)reader["ndate"]; authorId = (int)reader["id"]; article.Nkey = (string)reader["nkey"]; article.Aname = (string)reader["aname"]; reader.Close(); article.Author = UserServer.GetUserById(authorId); return(article); } else { reader.Close(); return(null); } }
/// <summary> /// 通过用户名查找用户 /// </summary> /// <param name="loginId"></param> /// <returns></returns> public static User GetUserByLoginId(string loginId) { string sql = "SELECT * FROM Users WHERE LoginId ='" + loginId + "'"; SqlDataReader reader = SSMS.GetReader(sql); if (reader.Read()) { User user = new User(); user.Id = (int)reader["Id"]; user.LoginId = (string)reader["LoginId"]; user.LoginPwd = (string)reader["LoginPwd"]; user.Name = (string)reader["Name"]; user.QQ = (string)reader["QQ"]; user.Mail = (string)reader["Mail"]; reader.Close(); return(user); } else { reader.Close(); return(null); } }