public static void ModifyReaderComment(ReaderComment readerComment) { string sql = "UPDATE ReaderComments " + "SET " + "BookId = @BookId, " + //FK "Id = @Id, " + "Title = @Title, " + "Comment = @Comment, " + "Date = @Date " + "WHERE ReaderName = @ReaderName"; try { SqlParameter[] para = new SqlParameter[] { new SqlParameter("@ReaderName", readerComment.ReaderName), new SqlParameter("@BookId", readerComment.Book.Id), //FK new SqlParameter("@Id", readerComment.Id), new SqlParameter("@Title", readerComment.Title), new SqlParameter("@Comment", readerComment.Comment), new SqlParameter("@Date", readerComment.Date) }; DBHelper.ExecuteCommand(sql, para); } catch (Exception e) { Console.WriteLine(e.Message); throw e; } }
/// <summary> /// 从SqlDataReader中读取数据,返回ReaderComment对象 /// </summary> /// <param name="reader"></param> /// <returns></returns> private ReaderComment LoadReaderComment(SqlDataReader reader) { Book book = new BookService().GetBookById(reader.GetInt32(1)); ReaderComment readerComment = new ReaderComment(reader.GetInt32(0), book, reader.GetString(2), reader.GetString(3), reader.GetString(4), reader.GetDateTime(5)); return(readerComment); }
private static IList <ReaderComment> GetReaderCommentsBySql(string sql, params SqlParameter[] values) { List <ReaderComment> list = new List <ReaderComment>(); try { DataTable table = DBHelper.GetDataSet(sql, values); foreach (DataRow row in table.Rows) { ReaderComment readerComment = new ReaderComment(); readerComment.Id = (int)row["Id"]; readerComment.ReaderName = (string)row["ReaderName"]; readerComment.Title = (string)row["Title"]; readerComment.Comment = (string)row["Comment"]; readerComment.Date = (DateTime)row["Date"]; readerComment.Book = BookService.GetBookById((int)row["BookId"]); //FK list.Add(readerComment); } return(list); } catch (Exception e) { Console.WriteLine(e.Message); return(null); } }
public static ReaderComment AddReaderComment(ReaderComment readerComment) { string sql = "INSERT ReaderComments (Id, BookId, Title, Comment, Date)" + "VALUES (@Id, @BookId, @Title, @Comment, @Date)"; sql += " ; SELECT @@IDENTITY"; try { SqlParameter[] para = new SqlParameter[] { new SqlParameter("@BookId", readerComment.Book.Id), //FK new SqlParameter("@Id", readerComment.Id), new SqlParameter("@Title", readerComment.Title), new SqlParameter("@Comment", readerComment.Comment), new SqlParameter("@Date", readerComment.Date) }; int newId = DBHelper.GetScalar(sql, para); return(GetReaderCommentByReaderName(newId)); } catch (Exception e) { Console.WriteLine(e.Message); return(null); } }
/// <summary> /// 根据Id获得ReaderComment对象 /// </summary> /// <param name="id"></param> /// <returns></returns> public ReaderComment GetReaderCommentById(int id) { ReaderComment readerComment = null; string sql = "select Id,BookId,ReaderName,Title,Comment,Date from ReaderComments where Id = @Id"; SqlDataReader reader = DBHelper.ExecuteReader(sql, CommandType.Text, new SqlParameter("@Id", id)); if (reader.HasRows) { if (reader.Read()) { readerComment = LoadReaderComment(reader); } } reader.Close(); return(readerComment); }
/// <summary>Function for skipping white spaces and reading comments.</summary> public void FindNextWord(IList <TextElement> outElements, bool inline) { do { // Skip whitespaces. //string ws = " \r\n\t"; string ws = inline ? " \t" : " \r\n\t"; // Read white spaces while (!IsEnd() && ws.Contains(GetChar())) { IncPointer(); } } while (ReaderComment.Load(outElements, inline) && !inline); if (outElements != null) { InsertComments(outElements); } }
public static ReaderComment GetReaderCommentByReaderName(string readerName) { string sql = "SELECT * FROM ReaderComments WHERE ReaderName = @ReaderName"; int bookId; try { SqlDataReader reader = DBHelper.GetReader(sql, new SqlParameter("@ReaderName", readerName)); if (reader.Read()) { ReaderComment readerComment = new ReaderComment(); readerComment.Id = (int)reader["Id"]; readerComment.ReaderName = (string)reader["ReaderName"]; readerComment.Title = (string)reader["Title"]; readerComment.Comment = (string)reader["Comment"]; readerComment.Date = (DateTime)reader["Date"]; bookId = (int)reader["BookId"]; //FK reader.Close(); readerComment.Book = BookService.GetBookById(bookId); return(readerComment); } else { reader.Close(); return(null); } } catch (Exception e) { Console.WriteLine(e.Message); return(null); } }
public static void ModifyReaderComment(ReaderComment readerComment) { ReaderCommentService.ModifyReaderComment(readerComment); }
public static void DeleteReaderComment(ReaderComment readerComment) { ReaderCommentService.DeleteReaderComment(readerComment); }
public static ReaderComment AddReaderComment(ReaderComment readerComment) { return(ReaderCommentService.AddReaderComment(readerComment)); }
public static void DeleteReaderComment(ReaderComment readerComment) { DeleteReaderCommentByReaderName(readerComment.ReaderName); }