/// <summary> /// 发布用户选择的按钮单击事件处理 /// </summary> private String btnPublishSelectedClick() { String strResult = String.Empty; String strSelected = cbBoxDefaultURL.SelectedItem.ToString(); if (String.IsNullOrEmpty(strSelected) == false) { String strCategories = GetSelectedCategories(); switch (strSelected) { case ConfigEntity.TechCrunch_Article_Name: { /* TechCrunch 文章列表 */ for (int i = 0; i < dgvDefault.SelectedRows.Count; i++) { Int32 nIndex = (Int32)dgvDefault.SelectedRows[i].Cells[0].Value - 1; String strTechCrunchHTML = String.Empty; String strTechCrunchURL = strTechCrunchUrlList[nIndex]; if (DownloadBLL.DownloadHTML2String(strTechCrunchURL, Encoding.UTF8, ref strTechCrunchHTML) == true && String.IsNullOrEmpty(strTechCrunchHTML) == false) { String strBodyOuterHtml = String.Empty; String strBodyInnerHtml = String.Empty; String strBodyInnerText = String.Empty; TechCrunchBLL.GetArticleBodyFromTechCrunch(strTechCrunchHTML, ref strBodyOuterHtml, ref strBodyInnerHtml, ref strBodyInnerText); try { MetaWeblogEntity.Post post = new MetaWeblogEntity.Post(); post.title = strTechCrunchTitleList[nIndex]; post.description = strBodyOuterHtml; post.categories = String.IsNullOrEmpty(strCategories) == true ? null : strCategories.Split(','); post.post_status = "new"; post.dateCreated = DateTime.Now; String strPostID = metaWeblog.newPost(String.Empty, strUserName, strPassword, post, true); strResult = " Publish Blog Succeed."; } catch (Exception ex) { strResult = " Publish Blog Failed,Error Message: " + ex.Message; } } } break; } case ConfigEntity.InfoSecurity_Article_Name: { /* 资安人文章列表 */ for (int i = 0; i < dgvDefault.SelectedRows.Count; i++) { Int32 nIndex = (Int32)dgvDefault.SelectedRows[i].Cells[0].Value - 1; String strInfoSecurityHTML = String.Empty; String strInfoSecurityURL = strInfoSecurityUrlList[nIndex]; if (DownloadBLL.DownloadHTML2String(strInfoSecurityURL, Encoding.UTF8, ref strInfoSecurityHTML) == true && String.IsNullOrEmpty(strInfoSecurityHTML) == false) { String strBodyOuterHtml = String.Empty; String strBodyInnerHtml = String.Empty; String strBodyInnerText = String.Empty; InfoSecurityBLL.GetArticleBodyFromInfoSecurity(strInfoSecurityHTML, ref strBodyOuterHtml, ref strBodyInnerHtml, ref strBodyInnerText); try { MetaWeblogEntity.Post post = new MetaWeblogEntity.Post(); post.title = strInfoSecurityTitleList[nIndex]; post.description = strBodyOuterHtml; post.categories = String.IsNullOrEmpty(strCategories) == true ? null : strCategories.Split(','); post.post_status = "new"; post.dateCreated = DateTime.Now; String strPostID = metaWeblog.newPost(String.Empty, strUserName, strPassword, post, true); strResult = " Publish Blog Succeed."; } catch (Exception ex) { strResult = " Publish Blog Failed,Error Message: " + ex.Message; } } } break; } case ConfigEntity.CIOAge_HomePage_Name: { /* CIOAge 首页 */ for (int i = 0; i < dgvDefault.SelectedRows.Count; i++) { Int32 nIndex = (Int32)dgvDefault.SelectedRows[i].Cells[0].Value - 1; String strCIOAgeBlogsHTML = String.Empty; String strCIOAgeBlogsURL = strCIOAgeHomePageUrlList[nIndex]; if (DownloadBLL.DownloadHTML2String(strCIOAgeBlogsURL, Encoding.Default, ref strCIOAgeBlogsHTML) == true && String.IsNullOrEmpty(strCIOAgeBlogsHTML) == false) { String strBodyOuterHtml = String.Empty; String strBodyInnerHtml = String.Empty; String strBodyInnerText = String.Empty; CIOAgeBLL.GetArticleBodyFromCIOAge(strCIOAgeBlogsHTML, ref strBodyOuterHtml, ref strBodyInnerHtml, ref strBodyInnerText); try { MetaWeblogEntity.Post post = new MetaWeblogEntity.Post(); post.title = strCIOAgeHomePageTitleList[nIndex]; post.description = strBodyOuterHtml; post.categories = String.IsNullOrEmpty(strCategories) == true ? null : strCategories.Split(','); post.post_status = "new"; post.dateCreated = DateTime.Now; String strPostID = metaWeblog.newPost(String.Empty, strUserName, strPassword, post, true); strResult = " Publish Blog Succeed."; } catch (Exception ex) { strResult = " Publish Blog Failed,Error Message: " + ex.Message; } } } break; } case ConfigEntity.CppBlog_HomePage_Name: { /* C++ 博客首页区 */ for (int i = 0; i < dgvDefault.SelectedRows.Count; i++) { Int32 nIndex = (Int32)dgvDefault.SelectedRows[i].Cells[0].Value - 1; String strCppBlogBlogsHTML = String.Empty; String strCppBlogBlogsURL = strCppBlogHomePageUrlList[nIndex]; if (DownloadBLL.DownloadHTML2String(strCppBlogBlogsURL, Encoding.UTF8, ref strCppBlogBlogsHTML) == true && String.IsNullOrEmpty(strCppBlogBlogsHTML) == false) { String strBodyOuterHtml = String.Empty; String strBodyInnerHtml = String.Empty; String strBodyInnerText = String.Empty; CppBlogBLL.GetBlogsBodyFromCppBlog(strCppBlogBlogsHTML, ref strBodyOuterHtml, ref strBodyInnerHtml, ref strBodyInnerText); try { MetaWeblogEntity.Post post = new MetaWeblogEntity.Post(); post.dateCreated = DateTime.Now; post.title = strCppBlogHomePageTitleList[nIndex]; post.description = strBodyOuterHtml; post.categories = String.IsNullOrEmpty(strCategories) == true ? null : strCategories.Split(','); post.dateCreated = DateTime.Now; String strPostID = metaWeblog.newPost(String.Empty, strUserName, strPassword, post, true); strResult = " Publish Blog Succeed."; } catch (Exception ex) { strResult = " Publish Blog Failed,Error Message: " + ex.Message; } } } break; } case ConfigEntity.CnBlogs_HomePage_Name: { /* 博客园首页区 */ for (int i = 0; i < dgvDefault.SelectedRows.Count; i++) { Int32 nIndex = (Int32)dgvDefault.SelectedRows[i].Cells[0].Value - 1; String strCnBlogsBlogsHTML = String.Empty; String strCnBlogsBlogsURL = strCnBlogsHomePageUrlList[nIndex]; if (DownloadBLL.DownloadHTML2String(strCnBlogsBlogsURL, Encoding.UTF8, ref strCnBlogsBlogsHTML) == true && String.IsNullOrEmpty(strCnBlogsBlogsHTML) == false) { String strBodyOuterHtml = String.Empty; String strBodyInnerHtml = String.Empty; String strBodyInnerText = String.Empty; CnBlogsBLL.GetBlogsBodyFromCnBlogs(strCnBlogsBlogsHTML, ref strBodyOuterHtml, ref strBodyInnerHtml, ref strBodyInnerText); try { MetaWeblogEntity.Post post = new MetaWeblogEntity.Post(); post.dateCreated = DateTime.Now; post.title = strCnBlogsHomePageTitleList[nIndex]; post.description = strBodyOuterHtml; post.categories = String.IsNullOrEmpty(strCategories) == true ? null : strCategories.Split(','); post.dateCreated = DateTime.Now; String strPostID = metaWeblog.newPost(String.Empty, strUserName, strPassword, post, true); strResult = " Publish Blog Succeed."; } catch (Exception ex) { strResult = " Publish Blog Failed,Error Message: " + ex.Message; } } } break; } case ConfigEntity.CnBlogs_News_Name: { /* 博客园新闻区 */ for (int i = 0; i < dgvDefault.SelectedRows.Count; i++) { Int32 nIndex = (Int32)dgvDefault.SelectedRows[i].Cells[0].Value - 1; String strCnBlogsNewsHTML = String.Empty; String strCnBlogsNewsURL = strCnBlogsNewsUrlList[nIndex];; if (DownloadBLL.DownloadHTML2String(strCnBlogsNewsURL, Encoding.UTF8, ref strCnBlogsNewsHTML) == true && String.IsNullOrEmpty(strCnBlogsNewsHTML) == false) { String strBodyOuterHtml = String.Empty; String strBodyInnerHtml = String.Empty; String strBodyInnerText = String.Empty; CnBlogsBLL.GetNewsBodyFromCnBlogs(strCnBlogsNewsHTML, ref strBodyOuterHtml, ref strBodyInnerHtml, ref strBodyInnerText); try { MetaWeblogEntity.Post post = new MetaWeblogEntity.Post(); post.dateCreated = DateTime.Now; post.title = strCnBlogsNewsTitleList[nIndex]; post.description = strBodyOuterHtml; post.categories = String.IsNullOrEmpty(strCategories) == true ? null : strCategories.Split(','); post.dateCreated = DateTime.Now; String strPostID = metaWeblog.newPost(String.Empty, strUserName, strPassword, post, true); strResult = " Publish Blog Succeed."; } catch (Exception ex) { strResult = " Publish Blog Failed,Error Message: " + ex.Message; } } } break; } case ConfigEntity.CnBlogs_Precious_Name: { /* 博客园精华区 */ for (int i = 0; i < dgvDefault.SelectedRows.Count; i++) { Int32 nIndex = (Int32)dgvDefault.SelectedRows[i].Cells[0].Value - 1; String strCnBlogsBlogsHTML = String.Empty; String strCnBlogsBlogsURL = strCnBlogsPreciousUrlList[nIndex];; if (DownloadBLL.DownloadHTML2String(strCnBlogsBlogsURL, Encoding.UTF8, ref strCnBlogsBlogsHTML) == true && String.IsNullOrEmpty(strCnBlogsBlogsHTML) == false) { String strBodyOuterHtml = String.Empty; String strBodyInnerHtml = String.Empty; String strBodyInnerText = String.Empty; CnBlogsBLL.GetBlogsBodyFromCnBlogs(strCnBlogsBlogsHTML, ref strBodyOuterHtml, ref strBodyInnerHtml, ref strBodyInnerText); try { MetaWeblogEntity.Post post = new MetaWeblogEntity.Post(); post.dateCreated = DateTime.Now; post.title = strCnBlogsPreciousTitleList[nIndex]; post.description = strBodyOuterHtml; post.categories = String.IsNullOrEmpty(strCategories) == true ? null : strCategories.Split(','); post.dateCreated = DateTime.Now; String strPostID = metaWeblog.newPost(String.Empty, strUserName, strPassword, post, true); strResult = " Publish Blog Succeed."; } catch (Exception ex) { strResult = " Publish Blog Failed,Error Message: " + ex.Message; } } } break; } default: { break; } } ClearDefaultSelectedBlogs(); } System.Threading.Thread.Sleep(1500); return(strResult); }
/// <summary> /// 用户选择 URL 选择事件改变处理 /// </summary> private void cbBoxDefaultURLChanged() { String strSelected = cbBoxDefaultURL.SelectedItem.ToString(); if (String.IsNullOrEmpty(strSelected) == false) { switch (strSelected) { case ConfigEntity.TechCrunch_Article_Name: { /* 重置数据 */ InitReLoadData(); /* TechCrunch 首页 */ Int32 nCount = TechCrunchBLL.GetArticlesFromTechCrunch(ref strTechCrunchTitleList, ref strTechCrunchUrlList, ref strTechCrunchDescList, ref strTechCrunchAuthorList, ref strTechCrunchDateTimeList); /* 重新绑定数据 */ dgvDefault.Rows.Clear(); for (int i = 0; i <= nCount; i++) { dgvDefault.Rows.Add(i + 1, strTechCrunchTitleList[i], strTechCrunchAuthorList[i], strTechCrunchDateTimeList[i]); } break; } case ConfigEntity.InfoSecurity_Article_Name: { /* 重置数据 */ InitReLoadData(); /* InfoSecurity 首页 */ Int32 nCount = InfoSecurityBLL.GetArticlesFromInfoSecurity(ref strInfoSecurityTitleList, ref strInfoSecurityUrlList, ref strInfoSecurityDescList, ref strInfoSecurityAuthorList, ref strInfoSecurityDateTimeList); /* 重新绑定数据 */ dgvDefault.Rows.Clear(); for (int i = 0; i <= nCount; i++) { dgvDefault.Rows.Add(i + 1, strInfoSecurityTitleList[i], strInfoSecurityAuthorList[i], strInfoSecurityDateTimeList[i]); } break; } case ConfigEntity.CIOAge_HomePage_Name: { /* 重置数据 */ InitReLoadData(); /* CIOAge 首页 */ Int32 nCount = CIOAgeBLL.GetHomePageBlogsFromCIOAge(ref strCIOAgeHomePageTitleList, ref strCIOAgeHomePageUrlList, ref strCIOAgeHomePageDescList, ref strCIOAgeHomePageAuthorList, ref strCIOAgeHomePageDateTimeList); /* 重新绑定数据 */ dgvDefault.Rows.Clear(); for (int i = 0; i <= nCount; i++) { dgvDefault.Rows.Add(i + 1, strCIOAgeHomePageTitleList[i], strCIOAgeHomePageAuthorList[i], strCIOAgeHomePageDateTimeList[i]); } break; } case ConfigEntity.CppBlog_HomePage_Name: { /* 重置数据 */ InitReLoadData(); /* C++ 博客首页区 */ Int32 nCount = CppBlogBLL.GetHomePageBlogsFromCppBlog(ref strCppBlogHomePageTitleList, ref strCppBlogHomePageUrlList, ref strCppBlogHomePageDescList, ref strCppBlogHomePageAuthorList, ref strCppBlogHomePageDateTimeList); /* 重新绑定数据 */ dgvDefault.Rows.Clear(); for (int i = 0; i <= nCount; i++) { dgvDefault.Rows.Add(i + 1, strCppBlogHomePageTitleList[i], strCppBlogHomePageAuthorList[i], strCppBlogHomePageDateTimeList[i]); } break; } case ConfigEntity.CnBlogs_HomePage_Name: { /* 重置数据 */ InitReLoadData(); /* 博客园首页区 */ Int32 nCount = CnBlogsBLL.GetHomePageBlogsFromCnBlogs(ref strCnBlogsHomePageTitleList, ref strCnBlogsHomePageUrlList, ref strCnBlogsHomePageDescList, ref strCnBlogsHomePageAuthorList, ref strCnBlogsHomePageDateTimeList); /* 重新绑定数据 */ dgvDefault.Rows.Clear(); for (int i = 0; i <= nCount; i++) { dgvDefault.Rows.Add(i + 1, strCnBlogsHomePageTitleList[i], strCnBlogsHomePageAuthorList[i], strCnBlogsHomePageDateTimeList[i]); } break; } case ConfigEntity.CnBlogs_News_Name: { /* 重置数据 */ InitReLoadData(); /* 博客园新闻区 */ Int32 nCount = CnBlogsBLL.GetNewsFromCnBlogs(ref strCnBlogsNewsTitleList, ref strCnBlogsNewsUrlList, ref strCnBlogsNewsDescList, ref strCnBlogsNewsAuthorList, ref strCnBlogsNewsDateTimeList); /* 重新绑定数据 */ dgvDefault.Rows.Clear(); for (int i = 0; i <= nCount; i++) { dgvDefault.Rows.Add(i + 1, strCnBlogsNewsTitleList[i], strCnBlogsNewsAuthorList[i], strCnBlogsNewsDateTimeList[i]); } break; } case ConfigEntity.CnBlogs_Precious_Name: { /* 重置数据 */ InitReLoadData(); /* 博客园精华区 */ Int32 nCount = CnBlogsBLL.GetPreciousFromCnBlogs(ref strCnBlogsPreciousTitleList, ref strCnBlogsPreciousUrlList, ref strCnBlogsPreciousDescList, ref strCnBlogsPreciousAuthorList, ref strCnBlogsPreciousDateTimeList); /* 重新绑定数据 */ dgvDefault.Rows.Clear(); for (int i = 0; i <= nCount; i++) { dgvDefault.Rows.Add(i + 1, strCnBlogsPreciousTitleList[i], strCnBlogsPreciousAuthorList[i], strCnBlogsPreciousDateTimeList[i]); } break; } default: { break; } } } System.Threading.Thread.Sleep(1500); }