/// <summary> /// 通过ID获取作品信息 /// </summary> /// <param name="worksId">作品ID</param> /// <returns></returns> public Works GetWorksSubmitById(string worksId) { long workId = long.Parse(worksId); Works ds = db.Works.SingleOrDefault(p => p.WorksID == workId); return(ds); }
/// <summary> /// 图片文件的显示:相册 /// </summary> /// <param name="serviceWorks"></param> /// <param name="worksId"></param> /// <returns></returns> private void ShowImages(IServiceWorks serviceWorks, long worksId) { StringBuilder htmlContent = new StringBuilder(); List <VAWcfService.WorksFile> imagesList = serviceWorks.GetWorksFile(worksId.ToString(), "2"); if (imagesList.Count > 0) { VAWcfService.Works works = serviceWorks.GetWorksSubmitById(worksId.ToString()); string periodId = works.PeriodID.ToString(); Periods period = serviceWorks.GetPeriodsById(periodId).FirstOrDefault(); string courseId = period.CourseID.ToString(); Course course = serviceWorks.GetCourseById(courseId).FirstOrDefault(); string siteUrl = "http://va.neu.edu.cn"; if (course != null) { siteUrl += course.Url; } htmlContent.AppendLine("<fieldset><legend>作品图片</legend>"); htmlContent.AppendLine("<div class='box'>"); htmlContent.AppendLine("<div id ='imgs' class='imgs'>"); foreach (var file in imagesList) { htmlContent.AppendLine("<img src='" + siteUrl + file.FilePath + "' onClick='$(this).ImgZoomIn();' height='200'>"); } htmlContent.AppendLine("</div>"); htmlContent.AppendLine("</div>"); htmlContent.AppendLine("</fieldset>"); ImagesDiv.InnerHtml = htmlContent.ToString(); } else { ImagesDiv.Visible = false; } }
/// <summary> /// 更新作品 /// </summary> /// <param name="works"></param> public void Update(Works works) { Works worksEntity = db.Works.SingleOrDefault(w => w.WorksID == works.WorksID); if (worksEntity != null) { worksEntity.WorksCode = works.WorksCode; } db.SaveChanges(); }
/// <summary> /// 删除作品 /// </summary> /// <param name="worksId"></param> public void Delete(string worksId) { long lWorksId = long.Parse(worksId); Works worksEntity = db.Works.SingleOrDefault(w => w.WorksID == lWorksId); if (worksEntity != null) { worksEntity.Flag = 0; } db.SaveChanges(); }
/// <summary> /// 删除作品 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void BtnDelete_Click(object sender, ImageClickEventArgs e) { string worksId = WorksId.ToString(); using (ChannelFactory <IServiceWorks> channelFactory = new ChannelFactory <IServiceWorks>("ServiceWorks")) { IServiceWorks serviceWorks = channelFactory.CreateChannel(); VAWcfService.Works wks = serviceWorks.GetWorksSubmitById(worksId); wks.Flag = 0; serviceWorks.Update(wks); } }
/// <summary> /// 多媒体文件(包括音视频)的显示:播放窗口 /// </summary> /// <param name="serviceWorks">数据服务层接口</param> /// <param name="worksId">作品ID</param> /// <param name="typeId"></param> /// <returns></returns> private void ShowMedias(IServiceWorks serviceWorks, long worksId, int typeId) { StringBuilder htmlContent = new StringBuilder(); List <VAWcfService.WorksFile> mediaFiles = serviceWorks.GetWorksFile(worksId.ToString(), typeId.ToString()); if (mediaFiles.Count > 0) { VAWcfService.WorksFile mediaFile = mediaFiles.OrderByDescending(wf => wf.WorksFileID).FirstOrDefault();//因为可能有多个文档重复上传,所以此处先处理成该作品最后一次上传的文档为作品文档。 VAWcfService.Works works = serviceWorks.GetWorksSubmitById(worksId.ToString()); string periodId = works.PeriodID.ToString(); Periods period = serviceWorks.GetPeriodsById(periodId).FirstOrDefault(); string siteUrl = "http://va.neu.edu.cn"; if (period != null) { string courseId = period.CourseID.ToString(); Course course = serviceWorks.GetCourseById(courseId).FirstOrDefault(); if (course != null) { siteUrl += course.Url; } } if (mediaFile != null) { MediaDiv.Visible = true; //string mediaHtml = "<iframe type='text/html' width='640' height='360'"; //mediaHtml += "src='"+ siteUrl + "/_layouts/15/videoembedplayer.aspx?site=" + mediaFile.FilePath + "title=1'></iframe>"; htmlContent.AppendLine("<div class='plist'>"); htmlContent.AppendLine("<a href='" + siteUrl + mediaFile.FilePath + "' name='" + mediaFile.FileName + "'"); htmlContent.AppendLine("<img class='listpic' src='images/start.jpg' alt='" + mediaFile.FileName + "' width='200' height='150'>"); string txtExtend = mediaFile.FileName.Substring(mediaFile.FileName.LastIndexOf(".", StringComparison.Ordinal) + 1).ToLower(); if (txtExtend == "mp3") { htmlContent.AppendLine("<span class='v_bq_hong'>讲解音频</span><span class='v_bg'></span>"); } else { htmlContent.AppendLine("<span class='v_bq_lan'>讲解视频</span><span class='v_bg'></span>"); } htmlContent.AppendLine("<span class='v_bq_vico'></span></a>"); htmlContent.AppendLine("<h2><a href='" + siteUrl + mediaFile.FilePath + "' name='" + mediaFile.FileName + "'>" + mediaFile.FileName + "</a></h2><p>" + mediaFile.Created + "</p>"); htmlContent.AppendLine("</div>"); } //} MediaList.InnerHtml = htmlContent.ToString(); } else { MediaDiv.Visible = false; } //return htmlContent; }
/// <summary> /// 文档文件的显示:在线浏览 /// </summary> /// <param name="serviceWorks"></param> /// <param name="worksId"></param> /// <returns></returns> private void ShowDocuments(IServiceWorks serviceWorks, long worksId) { StringBuilder htmlContent = new StringBuilder(); List <VAWcfService.WorksFile> docFiles = serviceWorks.GetWorksFile(worksId.ToString(), "1"); if (docFiles.Count > 0) { SPSite spsite = SPContext.Current.Site; VAWcfService.Works works = serviceWorks.GetWorksSubmitById(worksId.ToString()); string periodId = works.PeriodID.ToString(); Periods period = serviceWorks.GetPeriodsById(periodId).FirstOrDefault(); if (period != null) { string courseId = period.CourseID.ToString(); Course course = serviceWorks.GetCourseById(courseId).FirstOrDefault(); string siteUrl = "http://va.neu.edu.cn"; string cUrl = ""; if (course != null) { cUrl = course.Url.Substring(0, course.Url.Length - 1); } siteUrl += cUrl; var docFile = docFiles.OrderByDescending(f => f.WorksFileID).FirstOrDefault();//因为可能有多个文档重复上传,所以此处先处理成该作品最后一次上传的文档为作品文档。 //if (docFiles.Count ==1) //{ //var file = docFiles[0]; if (docFile != null) { htmlContent.AppendLine("<fieldset><legend>作品文档:<a href='" + siteUrl + docFile.FilePath + "'>" + docFile.FileName + "</a></legend>"); htmlContent.AppendLine("<div style='width:100%;text-align:center'><iframe src='" + siteUrl + "/_layouts/15/WopiFrame.aspx?sourcedoc=" + cUrl + HttpUtility.UrlEncode(docFile.FilePath) + "&action=embedview' width='600px' height='400px' frameborder='0'></iframe></div>"); htmlContent.AppendLine("</fieldset>"); } //} //else //{ // htmlContent.AppendLine("<div>作品文档:</div>"); // htmlContent.AppendLine("<table style='border:1px solid #666666'>"); // htmlContent.AppendLine("<tr><td valign='top'>"); // htmlContent.AppendLine("<fieldset><legend>文档列表</legend>"); // foreach (var file in docFiles) // { // string url = siteUrl + "/_layouts/15/WopiFrame.aspx?sourcedoc= " + cUrl + HttpUtility.UrlEncode(docFiles[0].FilePath) + "&action=embedview"; // htmlContent.AppendLine("<dt onClick='return showframe('" + url + "')' style='cursor: pointer;'>"+ file.FileName+ "</dt>"); // } // htmlContent.AppendLine("</fieldset>"); // htmlContent.AppendLine("</td><td>"); // htmlContent.AppendLine("<fieldset style='border:1px solid #444444'><legend>文档预览</legend>"); // htmlContent.AppendLine("<iframe id='myIframe' src='"+ siteUrl + "/_layouts/15/WopiFrame.aspx?sourcedoc=" + cUrl + HttpUtility.UrlEncode(docFiles[0].FilePath) + "&action=embedview' width='400px' height='300px' frameborder='0'></iframe>"); // htmlContent.AppendLine("</fieldset>"); // htmlContent.AppendLine("</td></tr>"); // htmlContent.AppendLine("</table>"); //} } DocsDiv.InnerHtml = htmlContent.ToString(); } else { DocsDiv.Visible = false; } }
/// <summary> /// 初始化作品信息显示控件 /// </summary> /// <param name="userId">当前用户ID</param> /// <param name="worksId">当前作品ID</param> private void InitControl(long userId, long worksId) { if (worksId != 0) { using (ChannelFactory <IServiceWorks> channelFactory = new ChannelFactory <IServiceWorks>("ServiceWorks")) { IServiceWorks proxy = channelFactory.CreateChannel(); //getall VAWcfService.Works works = proxy.GetWorksSubmitById(worksId.ToString()); LbWorksName.Text = works.WorksName; LbWorksCode.Text = works.WorksCode; LbInstallationGuide.Text = works.InstallationGuide; LbComment.Text = works.Comment; LbSubmitProfile.Text = works.SubmitProfile; //LblDemoUrl.Text = works.DemoURL; //VAWcfService.WorksType worksType=proxy. DivDesignIdeas.Controls.Clear(); DivDesignIdeas.InnerText = works.DesignIdeas; DivKeyPoints.InnerText = works.KeyPoints; DivScore.InnerText = works.Score.ToString(); if (works.WorksTypeID != null) { VAWcfService.WorksType worksType = proxy.GetWorksTypeById(works.WorksTypeID.ToString()); LbWorksType.Text = worksType.WorksTypeName.ToString(); } //作品附件 ShowDocuments(proxy, worksId); //ShowMedias(proxy, worksId, 3); ShowMedias(proxy, worksId, 4); ShowImages(proxy, worksId); ShowOthers(proxy, worksId); //上下文导航 List <VAWcfService.Works> worksList = proxy.GetWorks(); int currentIndex = worksList.FindIndex(w => w.WorksID == worksId); //string worksNavhtml = ""; if (currentIndex == 0)//第一条 { LeftLayer.InnerHtml = "<a class='nvWorksLnk' href='WorksShow.aspx?wid=" + worksList[worksList.Count - 1].WorksID + "' title='上一作品:" + worksList[worksList.Count - 1].WorksName + "'><img src='images//Prev.png' alt=''/></a>"; RightLayer.InnerHtml = "<a class='nvWorksLnk' href='WorksShow.aspx?wid=" + worksList[currentIndex + 1].WorksID + "' title='下一作品:" + worksList[currentIndex + 1].WorksName + "'><img src='images/Next.png' alt=''/></a>"; lnkPre.Text = "上一作品:" + worksList[worksList.Count - 1].WorksName; lnkPre.NavigateUrl = "WorksShow.aspx?wid=" + worksList[worksList.Count - 1].WorksID; lnkNext.Text = "下一作品:" + worksList[currentIndex + 1].WorksName; lnkNext.NavigateUrl = "WorksShow.aspx?wid=" + worksList[currentIndex + 1].WorksID; } else if (currentIndex == worksList.Count - 1)// { LeftLayer.InnerHtml = "<a class='nvWorksLnk' href='WorksShow.aspx?wid=" + worksList[currentIndex - 1].WorksID + "' title='上一作品:" + worksList[currentIndex - 1].WorksName + "'><img src='images/Prev.png' alt=''/></a>"; RightLayer.InnerHtml = "<a class='nvWorksLnk' href='WorksShow.aspx?wid=" + worksList[0].WorksID + "' title='下一作品:" + worksList[0].WorksName + "'><img src='images/Next.png' alt=''/></a>"; lnkPre.Text = "上一作品:" + worksList[currentIndex - 1].WorksName; lnkPre.NavigateUrl = "WorksShow.aspx?wid=" + worksList[currentIndex - 1].WorksID; lnkNext.Text = "下一作品:" + worksList[0].WorksName; lnkNext.NavigateUrl = "WorksShow.aspx?wid=" + worksList[0].WorksID; } else// { LeftLayer.InnerHtml = "<a class='nvWorksLnk' href='WorksShow.aspx?wid=" + worksList[currentIndex - 1].WorksID + "' title='上一作品:" + worksList[currentIndex - 1].WorksName + "'><img src='images/Prev.png' alt=''/></a>"; RightLayer.InnerHtml = "<a class='nvWorksLnk' href='WorksShow.aspx?wid=" + worksList[currentIndex + 1].WorksID + "' title='下一作品:" + worksList[currentIndex + 1].WorksName + "'><img src='images/Next.png' alt=''/></a>"; lnkPre.Text = "上一作品:" + worksList[currentIndex - 1].WorksName; lnkPre.NavigateUrl = "WorksShow.aspx?wid=" + worksList[currentIndex - 1].WorksID; lnkNext.Text = "下一作品:" + worksList[currentIndex + 1].WorksName; lnkNext.NavigateUrl = "WorksShow.aspx?wid=" + worksList[currentIndex + 1].WorksID; } //WorksNavDiv.InnerHtml = worksNavhtml; //if (em.WorksTypeID != null) //{ // LbWorksType.Text = GetWorksTypeName((int)em.WorksTypeID); //} } if (userId != 0) { using (ChannelFactory <IServiceUser> cfUser = new ChannelFactory <IServiceUser>("ServiceUser")) { IServiceUser user = cfUser.CreateChannel(); if (user == null) { throw new ArgumentNullException(nameof(user)); } Favorites favWorks = user.GetUserFavorites(userId.ToString()) .FirstOrDefault(f => f.DomainID == 5 & f.ItemID == worksId); if (favWorks != null) { BtnFav.Visible = false; BtnUnFav.Visible = true; } else { BtnFav.Visible = true; BtnUnFav.Visible = false; } } } } else { LeftLayer.Visible = false; RightLayer.Visible = false; } }
/// <summary> /// 添加作品 /// </summary> /// <param name="worksEntity"></param> /// <returns></returns> public long Create(Works worksEntity) { db.Works.Add(worksEntity); db.SaveChanges(); return(worksEntity.WorksID); }