static void UpdatePosts() { QueryBlog(); BlogBusinessLayerss bbl = new BlogBusinessLayerss(); Console.WriteLine("请输入一个博客ID"); int blogID = int.Parse(Console.ReadLine()); DisplayPosts(blogID); Console.WriteLine("请输入要修改的帖子ID"); int postID = int.Parse(Console.ReadLine()); Post post = bbl.postQuery(postID); Console.WriteLine("请输入新题目"); string newTitle = Console.ReadLine(); post.Title = newTitle; Console.WriteLine("请输入新内容"); string newContent = Console.ReadLine(); post.Content = newContent; bbl.pUpdate(post); DisplayPosts(blogID); }
//删除博客 static void Delete() { BlogBusinessLayerss bbl = new BlogBusinessLayerss(); Console.WriteLine("请输入一个博客ID"); int id = int.Parse(Console.ReadLine()); Blog blog = bbl.Query(id); bbl.Delete(blog); }
static void QueryBlog() { BlogBusinessLayerss bbl = new BlogBusinessLayerss(); var blogs = bbl.Query(); foreach (var item in blogs) { Console.WriteLine(item.BlogId + "" + item.Name); } }
//新增博客 static void createBlog() { Console.WriteLine("请输入一个博客名称"); string name = Console.ReadLine(); Blog blog = new Blog(); blog.Name = name; BlogBusinessLayerss bbl = new BlogBusinessLayerss(); bbl.Add(blog); }
static void DisplayPosts(int blogID) { BlogBusinessLayerss bbl = new BlogBusinessLayerss(); Blog blog = bbl.Query(blogID); List <Post> postList = bbl.pQuery(blogID); foreach (var item in postList) { Console.WriteLine("博客ID:{0} --- 帖子题目:{1} --- 帖子内容:{2} ---帖子ID:{3}", item.BlogId, item.Title, item.Content, item.PostId); } }
//修改博客 static void Update() { Console.WriteLine("请输入id"); int id = int.Parse(Console.ReadLine()); BlogBusinessLayerss bbl = new BlogBusinessLayerss(); Blog blog = bbl.Query(id); Console.WriteLine("请输入新名字"); string name = Console.ReadLine(); blog.Name = name; bbl.Update(blog); }
//模糊查找 static void ALLQuery() { Console.WriteLine("输入博客名称"); string i = Console.ReadLine(); BlogBusinessLayerss bbl = new BlogBusinessLayerss(); List <Blog> blog = bbl.ALLQuery(i); foreach (var item in blog) { Console.WriteLine(item.Name); } Console.ReadKey(); }
static void MHQuery() { Console.WriteLine("输入博客名称关键字"); string i = Console.ReadLine(); BlogBusinessLayerss bbl = new BlogBusinessLayerss(); var blog = bbl.mhQuery(i); foreach (var item in blog) { Console.WriteLine("{0}---{1}", item.Name, item.BlogId); } Console.ReadKey(); }
//删除帖子 static void DeletePosts() { BlogBusinessLayerss bbl = new BlogBusinessLayerss(); Console.WriteLine("请输入一个博客ID"); int blogID = int.Parse(Console.ReadLine()); DisplayPosts(blogID); Console.WriteLine("请输入要删除的帖子ID"); int postID = int.Parse(Console.ReadLine()); Post post = bbl.postQuery(postID); bbl.DeletePost(post); DisplayPosts(blogID); }
static void CheckPostID(int blogID) { BlogBusinessLayerss bbl = new BlogBusinessLayerss(); Blog blog = bbl.Query(blogID); if (blog == null) { Console.WriteLine("没有此博客"); opBlog(); } else { return; } }
//新增帖子 static void CreatNewPosts(int blogid) { Console.WriteLine("请输入一个博客ID"); int id = int.Parse(Console.ReadLine()); Console.WriteLine("请输入一个帖子名称"); string title = Console.ReadLine(); Console.WriteLine("请输入一个帖子名称"); string content = Console.ReadLine(); Post post = new Post(); post.BlogId = id; post.Title = title; post.Content = content; BlogBusinessLayerss bbl = new BlogBusinessLayerss(); bbl.pAdd(post); }