public static void SetItem(ResourceVideosModels item) { item.Spec = item.Spec ?? string.Empty; item.Duration = item.Duration ?? string.Empty; item.Screenshot = item.Screenshot ?? string.Empty; SQLData.Database db = new SQLData.Database(WebInfo.Conn); SQLData.TableObject tableObj = db.GetTableObject("ResourceVideos"); tableObj.GetDataFromObject(item); string sql = "Select 1 From ResourceVideos Where ID = " + item.ID; bool isNew = db.GetFirstValue(sql) == null; if (isNew) { tableObj["Creator"] = MemberDAO.SysCurrent.Id; tableObj["CreateTime"] = DateTime.Now; tableObj.Insert(); } else { string[] removeFields = { "ID", "SiteID", "SourceNo", "SourceType", "Ver", "AreaID", "Code", "Creator", "CreateTime" }; foreach (string f in removeFields) { tableObj.Remove(f); } tableObj["Modifier"] = MemberDAO.SysCurrent.Id; tableObj["ModifyTime"] = DateTime.Now; SQLData.ParameterCollection keys = new SQLData.ParameterCollection(); keys.Add("@ID", item.ID); keys.Add("@SiteID", item.SiteID); keys.Add("@SourceNo", item.SourceNo); keys.Add("@SourceType", item.SourceType); keys.Add("@Ver", item.Ver); keys.Add("@AreaID", item.AreaID); tableObj.Update(keys); } }
/// <summary> /// 取得段落 /// </summary> /// <param name="Id"></param> /// <param name="uploadUrl"></param> /// <param name="uploadPath"></param> /// <returns></returns> public List <ParagraphItem> GetParagraphItem(long Id, string uploadUrl, string uploadPath) { List <ParagraphItem> paragraphList = new List <ParagraphItem>(); IEnumerable <ParagraphModels> paragraphs = ParagraphDAO.GetItems(Id); foreach (var paragraph in paragraphs) { string matchType = (paragraph.MatchType ?? string.Empty).ToLower(); if (matchType == "img") { IEnumerable <ResourceImagesModels> images = paragraph.GetImages().Where(m => m.IsShow); if (images == null) { continue; } if (images.Count() > 1) { List <ParagraphImageList> imgList = new List <ParagraphImageList>(); foreach (var img in images) { int width = 0, height = 0; GetImageWidthAndHeight($"{uploadPath}\\{img.Img}", out width, out height); imgList.Add(new ParagraphImageList() { Url = uploadUrl + img.Img, Width = width, Height = height }); } paragraphList.Add(new ParagraphItem() { Type = "ImageGroup", ContentList = imgList }); } else { foreach (var img in images) { int width = 0, height = 0; GetImageWidthAndHeight($"{uploadPath}\\{img.Img}", out width, out height); ParagraphImage imgItem = new ParagraphImage { Type = "Image", Content = uploadUrl + img.Img, Width = width, Height = height }; paragraphList.Add(imgItem); } } if (!string.IsNullOrWhiteSpace(paragraph.Title)) { paragraphList.Add(new ParagraphItem { Type = "Title", Content = paragraph.Title }); } if (!string.IsNullOrWhiteSpace(paragraph.Contents)) { paragraphList.Add(new ParagraphItem { Type = "Text", Content = paragraph.Contents }); } } else if (matchType == "video") { ResourceVideosModels video = paragraph.GetVideo(); string shotUrl = string.Empty, videoUrl = string.Empty; if (video.Type == "custom") { videoUrl = uploadUrl + video.Link; if (!string.IsNullOrWhiteSpace(video.Screenshot)) { ResourceImagesModels img = Newtonsoft.Json.JsonConvert.DeserializeObject <ResourceImagesModels>(video.Screenshot); shotUrl = uploadUrl + img.Img; } } else { videoUrl = video.Link; shotUrl = video.Screenshot; if (video.ScreenshotIsCustom && !string.IsNullOrWhiteSpace(shotUrl)) { ResourceImagesModels img = Newtonsoft.Json.JsonConvert.DeserializeObject <ResourceImagesModels>(shotUrl); shotUrl = uploadUrl + img.Img; } } paragraphList.Add(new ParagraphVideo { Type = "Video", Content = videoUrl, VideoType = video.Type, Screenshot = shotUrl }); if (!string.IsNullOrWhiteSpace(paragraph.Title)) { paragraphList.Add(new ParagraphItem { Type = "Title", Content = paragraph.Title }); } if (!string.IsNullOrWhiteSpace(paragraph.Contents)) { paragraphList.Add(new ParagraphItem { Type = "Text", Content = paragraph.Contents }); } } else if (matchType == "file") { if (!string.IsNullOrWhiteSpace(paragraph.Title)) { paragraphList.Add(new ParagraphItem { Type = "Title", Content = paragraph.Title }); } if (!string.IsNullOrWhiteSpace(paragraph.Contents)) { paragraphList.Add(new ParagraphItem { Type = "Text", Content = paragraph.Contents }); } IEnumerable <ResourceFilesModels> files = paragraph.GetFiles(); foreach (var file in files) { paragraphList.Add(new ParagraphFile { Type = "File", Content = uploadUrl + file.FileInfo, Name = (string.IsNullOrWhiteSpace(file.ShowName) ? System.Text.RegularExpressions.Regex.Replace(file.FileInfo, @"\.[^\.]*$", string.Empty) : file.ShowName) }); } } else if (matchType == "link") { if (!string.IsNullOrWhiteSpace(paragraph.Title)) { paragraphList.Add(new ParagraphItem { Type = "Title", Content = paragraph.Title }); } if (!string.IsNullOrWhiteSpace(paragraph.Contents)) { paragraphList.Add(new ParagraphItem { Type = "Text", Content = paragraph.Contents }); } IEnumerable <ResourceLinksModels> links = paragraph.GetLinks(); foreach (var link in links) { paragraphList.Add(new ParagraphFile { Type = "Link", Content = link.LinkInfo, Name = link.Descriptions }); } } else if (matchType == "voice") { if (!string.IsNullOrWhiteSpace(paragraph.Title)) { paragraphList.Add(new ParagraphItem { Type = "Title", Content = paragraph.Title }); } if (!string.IsNullOrWhiteSpace(paragraph.Contents)) { paragraphList.Add(new ParagraphItem { Type = "Text", Content = paragraph.Contents }); } IEnumerable <ResourceVoicesModels> voices = paragraph.GetVoices(); foreach (var voice in voices) { paragraphList.Add(new ParagraphItem { Type = "Voice", Content = uploadUrl + voice.Path }); } } else if (string.IsNullOrWhiteSpace(matchType)) { if (!string.IsNullOrWhiteSpace(paragraph.Title)) { paragraphList.Add(new ParagraphItem { Type = "Title", Content = paragraph.Title }); } if (!string.IsNullOrWhiteSpace(paragraph.Contents)) { paragraphList.Add(new ParagraphItem { Type = "Text", Content = paragraph.Contents }); } } } return(paragraphList); }