/// <summary> /// Зарежда данните от публикацията /// </summary> private void LoadPost(int postId, HtmlDocument htmlDoc, PExtractTemplate pePost) { HtmlNode postContent = htmlDoc.DocumentNode.SelectSingleNode(pePost.XPContent); HtmlDocument htmlContent = new HtmlDocument(); htmlDoc.OptionDefaultStreamEncoding = Encoding.UTF8; htmlContent.LoadHtml(postContent.InnerHtml); PPost pPost = new PPost(); pPost.Title = SelectHtmlText(htmlContent, pePost.XPTitle); pPost.Text = SelectHtmlText(htmlContent, pePost.XPText); pPost.Images = new List<string>(); if (!String.IsNullOrWhiteSpace(pePost.XPImages)) { HtmlNodeCollection nodeImages = htmlDoc.DocumentNode.SelectNodes(pePost.XPImages); if (nodeImages != null) { foreach (HtmlNode nImage in nodeImages) { HtmlAttribute attSrc = nImage.Attributes["src"]; pPost.Images.Add(attSrc.Value.Trim()); } } } pPost.Attributes = new List<string>(); if (!String.IsNullOrWhiteSpace(pePost.XPAttributes)) { HtmlNodeCollection nodeAttributes = htmlDoc.DocumentNode.SelectNodes(pePost.XPAttributes); if (nodeAttributes != null) { foreach (HtmlNode nAttributes in nodeAttributes) { pPost.Attributes.Add(nAttributes.InnerText.Trim().Replace("\n", ";").Replace("\t", " ")); } } } pPost.Price = SelectHtmlText(htmlContent, pePost.XPPrice); pPost.Location = SelectHtmlText(htmlContent, pePost.XPLocation); pPost.Date = SelectHtmlText(htmlContent, pePost.XPDate); pPost.Posted = SelectHtmlText(htmlContent, pePost.XPPosted); if (_IsDebug > 0) { Console.WriteLine("Title : {0}", pPost.Title); Console.WriteLine("Text : {0}", pPost.Text); Console.WriteLine("Price : {0}", pPost.Price); Console.WriteLine("Location : {0}", pPost.Location); Console.WriteLine("Date : {0}", pPost.Date); Console.WriteLine("Posted : {0}", pPost.Posted); } if (postId > 0) { _DBExtract.SaveNewPost(postId, pePost.CategoryId, pePost.TemplateId, pPost); } }
/// <summary> /// Записва публикацията /// </summary> public void SaveNewPost(int postId, int categoryId, int templateId, PPost pPost) { string commandText = String.Format( @"UPDATE new_post SET post_title = {1} , post_text = {2} , post_price = {3} , post_location = {4} , post_date = {5} , post_posted = {6} WHERE id = {0}", SQLInt(postId) , SQLString(pPost.Title) , SQLString(pPost.Text) , SQLString(pPost.Price) , SQLString(pPost.Location) , SQLString(pPost.Date) , SQLString(pPost.Posted)); base.ExecuteNonQuery(commandText); foreach (string imgSrc in pPost.Images) { commandText = String.Format( @"INSERT INTO new_post_image ( new_post_id, img_src ) VALUES ( {0}, {1} ) ", SQLInt(postId), SQLString(imgSrc)); base.ExecuteNonQuery(commandText); } foreach (string attribute in pPost.Attributes) { commandText = String.Format( @"INSERT INTO new_post_attribute ( new_post_id, attribute_value, n_category_id, n_template_id ) VALUES ( {0}, {1}, {2}, {3}) ", SQLInt(postId), SQLString(attribute), SQLInt(categoryId), SQLInt(templateId)); base.ExecuteNonQuery(commandText); } }