/// <summary> /// 将期刊信息保存到数据库 /// </summary> private void ProcessForButtonSavetoDatabase() { //if (journalList == null) return; CategoryWebsiteBLL categoryWebsiteBLL = new CategoryWebsiteBLL(); IList<CategoryWebsite> categoryWebsiteList = categoryWebsiteBLL.GetAllCategoryWebsites(); foreach(CategoryWebsite cate in categoryWebsiteList) { webUrl[0] = cate.Website; int count = cate.WebsiteCount; int id = cate.CategoryWebsiteID; int num = count / 10; if (count % 10 > 0) num++; string folderName = Tools.GetFolderName(webUrl[0]); string filePath = directoryPath + folderName; for(int i = 0; i < num; i++) { webUrl[0] = filePath + (i + 1) + ".html"; journalList = ExtractJournals(directoryPath, webUrl); JournalBLL journalBusiness = new JournalBLL(); foreach (Journal jnlInfo in journalList) { try { jnlInfo.CategoryWebsiteID = id; journalBusiness.Add(jnlInfo); } catch (Exception ex_for1) { continue; textBoxDisplay.AppendText(ex_for1.ToString() + newLine); } textBoxDisplay.AppendText(twoLine); } textBoxDisplay.AppendText(twoLine + "All Journals are saved!" + twoLine); buttonSaveToDatabase.Text = "Conserve To Database"; } } //paperBusiness.RemoveDuplicate(); //authorBusiness.RemoveDuplicate(); buttonSaveToDatabase.Enabled = true; buttonDownloadJournal.Enabled = true; buttonSettings.Enabled = true; }
/// <summary> /// 从下载到本地的期刊页面中读取所有需要的信息 /// </summary> /// <param name="directoryPath">下面下载后所在路径</param> /// <param name="webUrl">页面网址(决定了所在的本地文件夹)</param> /// <returns>信息列表</returns> private List<Journal> ExtractJournals(string directoryPath, string[] webUrl) { JournalBLL journalBLL = new JournalBLL(); List<Journal> jnlInfoList = new List<Journal>(); try { if (Tools.FileExsits(webUrl[0]) == false) return null; string text = Tools.ReadFile(webUrl[0]); int curPos = 0; string journalFlag = "<div class=\"data\">"; while (curPos < text.Length) { curPos = text.IndexOf(journalFlag, curPos); if (curPos == -1) break; Journal jnlInfo = new Journal(); jnlInfo.JournalName = Tools.DeleteStringInParent(Tools.StringExtractor(text, "<b>", "</b>", curPos), '<', '>').Trim(); jnlInfo.JournalName = Tools.DeleteBeginAndEndIllegalChar(jnlInfo.JournalName); //ISSN and EISSN curPos = text.IndexOf("<div style=\"color: #585858\">", curPos); string temp = Tools.StringExtractor(text, "</strong>:", "<br>", curPos); IList<string> ISSNAndEISSN = Tools.GetISSNAndEISSN(Tools.DeleteBeginAndEndIllegalChar(temp)); if (ISSNAndEISSN.Count == 2) { jnlInfo.ISSN = ISSNAndEISSN[0]; jnlInfo.EISSN = ISSNAndEISSN[1]; } else if (ISSNAndEISSN.Count == 1) { jnlInfo.ISSN = ISSNAndEISSN[0]; } //publisher curPos = text.IndexOf("<br>", curPos); jnlInfo.Publisher = Tools.DeleteBeginAndEndIllegalChar(Tools.StringExtractor(text, "</strong>:", "<br>", curPos)); //subject curPos = text.IndexOf("<br><strong>Subject</strong>", curPos); int nextPos = text.IndexOf("<br><b>Country</b>", curPos); string subjectStr = ""; while (curPos < nextPos) { string temp2 = Tools.DeleteBeginAndEndIllegalChar(Tools.StringExtractor(text, "\">", "</a>", curPos)); if (text.IndexOf(temp2) > nextPos) break; else subjectStr += temp2 + ","; curPos = text.IndexOf("\">", curPos) + 2; } if (subjectStr.Length != 0) subjectStr = subjectStr.Substring(0, subjectStr.Length - 1); jnlInfo.Subject = subjectStr; curPos = nextPos; //country //language curPos = text.IndexOf("<b>Language</b>", curPos); jnlInfo.JournalLanguage = Tools.DeleteBeginAndEndIllegalChar(Tools.StringExtractor(text, "</b>:", "</br>", curPos)); //start year curPos = text.IndexOf("<b>Start year</b>", curPos); jnlInfo.StartYear = Tools.DeleteBeginAndEndIllegalChar(Tools.StringExtractor(text, "</b>", "</b>", curPos)); //fee curPos = text.IndexOf("<b>Publication fee</b>", curPos); jnlInfo.PublicationFee = Tools.DeleteBeginAndEndIllegalChar(Tools.StringExtractor(text, "\">", "</span>", curPos)); jnlInfoList.Add(jnlInfo); } } catch (Exception ex) { textBoxDisplay.AppendText(ex.ToString() + newLine); } return jnlInfoList; }