private void SaveAttach(BidProject info, string htmltxt, string result, bool isUpdate) { List <BaseAttach> list = new List <BaseAttach>(); if (htmltxt.Contains("http")) { Parser parser = new Parser(new Lexer(htmltxt)); NodeList aNode = parser.ExtractAllNodesThatMatch(new TagNameFilter("a")); if (aNode != null && aNode.Count > 0) { for (int j = 0; j < aNode.Count; j++) { ATag aTag = aNode[j].GetATag(); string attachName = aTag.LinkText; string aurl = string.Empty; aurl = aTag.Link.GetReplace("\\\"", ""); if (string.IsNullOrWhiteSpace(attachName)) { attachName = info.PrjName; } try { string url = System.Web.HttpUtility.UrlDecode(aurl); string[] urls = url.Split('&'); BaseAttach entity = null; if (isUpdate) { entity = ToolHtml.GetBaseAttach(url, attachName, result, "SiteManage\\Files\\Attach\\"); } else { entity = ToolHtml.GetBaseAttach(url, attachName, info.Id, "SiteManage\\Files\\Attach\\"); } if (entity != null) { list.Add(entity); } } catch { } } } } if (list.Count > 0) { if (isUpdate) { string delSql = string.Format("delete from BaseAttach where SourceID='{0}'", result); ToolFile.Delete(result); int count = ToolDb.ExecuteSql(delSql); } foreach (BaseAttach attach in list) { ToolDb.SaveEntity(attach, "SourceID,AttachServerPath"); } } }
protected void SaveAttach(string url, string sourceId) { List <BaseAttach> attach = new List <BaseAttach>(); string htmlAnnex = string.Empty; try { htmlAnnex = this.ToolWebSite.GetHtmlByUrl(url, Encoding.UTF8); } catch { } Parser dtparser = new Parser(new Lexer(htmlAnnex)); NodeList dtList = dtparser.ExtractAllNodesThatMatch(new AndFilter(new HasAttributeFilter("id", "ctl00_ContentPlaceHolder1_GridView1"), new TagNameFilter("table"))); if (dtList != null && dtList.Count > 0) { TableTag dttable = dtList[0] as TableTag; for (int t = 1; t < dttable.RowCount; t++) { ATag file = dttable.SearchFor(typeof(ATag), true)[t - 1] as ATag; if (file.IsAtagAttach()) { string aurl = "http://www.szjsjy.com.cn/" + file.Link.Replace("../", "").Replace("./", ""); try { BaseAttach entity = ToolHtml.GetBaseAttach(aurl, file.LinkText, sourceId, "SiteManage\\Files\\Attach\\"); if (entity != null) { attach.Add(entity); } } catch { } } } } if (attach.Count > 0) { string delSql = string.Format("delete from BaseAttach where SourceID='{0}'", sourceId); ToolFile.Delete(sourceId); int count = ToolDb.ExecuteSql(delSql); ToolDb.SaveDatas(attach, string.Empty); } }
private void SaveAttach(BidProject info, string htmltxt, string result, bool isUpdate) { List <BaseAttach> list = new List <BaseAttach>(); if (htmltxt.Contains("http")) { Parser parser = new Parser(new Lexer(htmltxt)); NodeList aNode = parser.ExtractAllNodesThatMatch(new TagNameFilter("a")); if (aNode != null && aNode.Count > 0) { for (int j = 0; j < aNode.Count; j++) { ATag aTag = aNode[j].GetATag(); string attachName = aTag.LinkText; string aurl = string.Empty; if (!aTag.Link.ToLower().Contains("http")) { aurl = "https://www.szjsjy.com.cn:8001/" + aTag.Link.GetReplace("\\"); } else { aurl = aTag.Link.GetReplace("\\"); } if (string.IsNullOrWhiteSpace(attachName)) { attachName = info.PrjName; } try { string url = System.Web.HttpUtility.UrlDecode(aurl); string[] urls = url.Split('&'); url = urls[0] + "&" + urls[2] + "&" + urls[1]; BaseAttach entity = null; if (isUpdate) { entity = ToolHtml.GetBaseAttach(url.Replace("\"", ""), attachName, result, "SiteManage\\Files\\Attach\\"); } else { entity = ToolHtml.GetBaseAttach(url.Replace("\"", ""), attachName, info.Id, "SiteManage\\Files\\Attach\\"); } if (entity != null) { list.Add(entity); } } catch { } } } } else { System.Data.DataTable dtlDtl = ToolHtml.JsonToDataTable(htmltxt); if (dtlDtl != null && dtlDtl.Rows.Count > 0) { for (int i = 0; i < dtlDtl.Rows.Count; i++) { System.Data.DataRow row = dtlDtl.Rows[i]; string attachName = Convert.ToString(row["attachName"]); if (string.IsNullOrWhiteSpace(attachName)) { attachName = info.PrjName; } string attachGuid = Convert.ToString(row["attachGuid"]); string url = "https://www.szjsjy.com.cn:8001/file/downloadFile?fileId=" + attachGuid; try { BaseAttach entity = null; if (isUpdate) { entity = ToolHtml.GetBaseAttachByUrl(url, attachName, result, "SiteManage\\Files\\Attach\\"); } else { entity = ToolHtml.GetBaseAttachByUrl(url, attachName, info.Id, "SiteManage\\Files\\Attach\\"); } if (entity != null) { list.Add(entity); } } catch { } } } } if (list.Count > 0) { if (isUpdate) { string delSql = string.Format("delete from BaseAttach where SourceID='{0}'", result); ToolFile.Delete(result); int count = ToolDb.ExecuteSql(delSql); } foreach (BaseAttach attach in list) { ToolDb.SaveEntity(attach, "SourceID,AttachServerPath"); } } }