/// <summary> /// 构造数据源 /// </summary> public AcfunDataSource() { for (int count = 1; count < 11; count++) { //页码 dataCore.CreateGroup(" 第-" + count + "-页 ", "Group Title: " + count, "Group Subtitle: " + count, typeof(MainForm).Namespace + ".Assets.DarkGray.png", "哈哈哈哈哈哈哈哈哈哈"); //数据库分页查10个 string sql = ""; dt = conn.ExecuteDataTable(sql); //循环写入 for (int dtcount = 0; dtcount < dt.Rows.Count; dtcount++) { Article.Model.Article article = new Model.Article(); article.setComments(dt.Rows[dtcount]["comments"].ToString()); article.setTitle(dt.Rows[dtcount]["title"].ToString()); article.setContentId(dt.Rows[dtcount]["contentId"].ToString()); article.setDescription(dt.Rows[dtcount]["description"].ToString()); article.setTxt(dt.Rows[dtcount]["txt"].ToString()); dataCore.AddItem(new ArticleDataItem(article.getTitle(), " 评论数: " + article.getComments(), typeof(MainForm).Namespace + ".Assets.LightGray.png", "Description: " + article.getDescription(), article.getTxt(), " 第-" + count + "-页 ", article.getComments(), article.getContentId())); } } }
/// <summary> /// 获取并保存所有评论内容 /// </summary> /// <param name="article"></param> /// <returns></returns> public List <Comment> getCommentByArticle(Article.Model.Article article) { List <Comment> commentList = new List <Comment>(); int commentCount = 0; int.TryParse(article.getComments(), out commentCount); if (commentCount != 0 && commentCount < 50) { string commentJson = webutil.GetCommentList(article.getContentId(), 1, 100); if (commentJson.Length < 250) { return(null); } commentList = getCommentFromJson(commentJson, article.getContentId()); } else if (commentCount == 0) { return(null); } else { for (int count = 1; count <= commentCount % 50; count++) { List <Comment> tempList = null; string commentJson = webutil.GetCommentList(article.getContentId(), count, 100); if (commentJson.Length < 250) { return(null); } tempList = getCommentFromJson(commentJson, article.getContentId()); tempList.ForEach(i => commentList.Add(i)); } } return(commentList); }
/// <summary> /// 保存文章到数据库 /// </summary> /// <param name="article"></param> /// <returns></returns> public bool SaveArticle(Article.Model.Article article) { string sql = "select * from Article where contentId =" + article.getContentId(); dt = conn.ExecuteDataTable(sql); if (dt.Rows.Count == 0) { string sqlInsert = "INSERT INTO 'Article' ('user', 'txt', 'description', 'contentId', 'isArticle', 'channelId', 'releaseDate', 'title', 'isRecommend', 'views', 'comments', 'stows', 'toplevel', 'cover', 'viewOnly') VALUES ('" + article.getUser() + "', '" + article.getTxt() + "', '" + article.getDescription() + "', '" + article.getContentId() + "', '" + article.getIsArticle() + "', '" + article.getChannelId() + "', '" + article.getReleaseDate() + "', '" + article.getTitle() + "', '" + article.getIsRecommend() + "', '" + article.getViews() + "', '" + article.getComments() + "', '" + article .getStows() + "', '" + article.getToplevel() + "', '" + article.getCover() + "', '" + article.getViewOnly() + "');"; conn.ExecuteScalar(sqlInsert); } return(true); }