源码下载地址:http://www.yealuo.com/Sccnn/Detail?KeyValue=c891ffae-7441-4afb-9a75-c5fe000e3d1c
本项目主要是一个素材的分享网站,所以在设计网站前端的时候,我们尽量的切合这一主题,在设计上更多的是素材的预览及下载,首页设计为所见即所得的形式,用瀑布流的分页形式来设计,下面可以先欣赏一下页面效果:
(1)下面我们开始罗列代码,首先,我们需要改造表现层中的布局页_Layout.cshtml:
@using Bobo.Utilities.Membership @using IA.Business @using IA.Entity <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width" /> <title>@ViewBag.Title</title> <meta name="keywords" content="jQuery特效,网站模板,商城模板,网页特效,手机模板,前端UI,网站源码,网页部落,素材部落,网页素材网,手机素材网" /> <meta name="description" content="页落网,页落素材网!靠谱的前端网页部落网站,主要收集最新、最前沿的前端技术和jQuery网页特效、jQuery网页代码、网站模板、网页模板、企业模板、商城模板、图标、移动手机端UI等素材,为致力于前端艺术开发的UED提供良好的素材平台!" /> <meta name="author" content="页落网" /> <meta name="renderer" content="webkit" /> <meta name="360-site-verification" content="7d7a9207bd598c307b2710a8403ba645" /> <meta name="baidu-site-verification" content="djx4WgYUWt" /> <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" media="screen" /> <link href="~/Content/Styles/base.css" rel="stylesheet" /> <link href="~/Content/Web/css/web.css" rel="stylesheet" /> <script src="~/Content/Scripts/jquery/jquery-1.8.2.min.js"></script> </head> <body> <script> (function () { //360推送 var src = (document.location.protocol == "http:") ? "http://js.passport.qihucdn.com/11.0.1.js?004e54cc11817ced2ae8cd0b01c5d60b" : "https://jspassport.ssl.qhimg.com/11.0.1.js?004e54cc11817ced2ae8cd0b01c5d60b"; document.write('<script src="' + src + '" id="sozz"><\/script>'); //百度推送 var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })(); </script> <!-- herder S --> <div id="header"> <div class="header-nav"> <div class="header-menu"> <div class="logo"> <a href="/"><img src="~/Content/Web/img/logo.png" style="width:100px;" /></a> </div> <ul class="header-nav-ul"> <li class="header-nav-li indexKey"> <a class="header-nav-li-a" href="/Sccnn/Index">首页</a> </li> <li class="header-nav-li"> <a class="header-nav-li-a" href="/Sccnn/Index?FileType=WEB">网站模板</a> <div class="header-nav-li-child"> <div class="webPage WEB"> </div> </div> </li> <li class="header-nav-li"> <a class="header-nav-li-a" href="/Sccnn/Index?FileType=WAP">手机端</a> <div class="header-nav-li-child"> <div class="webPage WAP"> </div> </div> </li> <li class="header-nav-li"> <a class="header-nav-li-a" href="/Sccnn/Index?FileType=H5C3">HTML5 CSS3</a> <div class="header-nav-li-child"> <div class="webPage H5C3"> </div> </div> </li> <li class="header-nav-li"> <a class="header-nav-li-a" href="/Sccnn/Index?FileType=WJS">网页特效</a> <div class="header-nav-li-child"> <div class="webPage WJS"> </div> </div> </li> <li class="header-nav-li"> <a class="header-nav-li-a" href="/Sccnn/Index?FileType=FLASH">flash素材</a> <div class="header-nav-li-child"> <div class="webPage FLASH"> </div> </div> </li> <li class="header-nav-li"> <a class="header-nav-li-a" href="/Sccnn/Index?FileType=PIC">网页素材</a> <div class="header-nav-li-child"> <div class="webPage PIC"> </div> </div> </li> <li class="header-nav-li"> <a class="header-nav-li-a" href="/Sccnn/Index?FileType=SYS">网站源码</a> <div class="header-nav-li-child"> <div class="webPage SYS"> </div> </div> </li> <li class="header-nav-li"> <a href="/WebArticle/Index?ArticleType=zw" target="_blank" class="header-nav-li-a">轻博客</a> @*<div class="header-nav-li-child"> <div class="webPage MoreSeach"> </div> </div>*@ </li> </ul> @if (ManageProvider.Provider.IsOverdue()) { <div class="header-tip text-right"> <a href="/MemberCenterModule/MemberSystem/Index"> 用户中心</a> | <a href="javscript:;" οnclick="LoginOut()"> 退出登录</a> </div> } else { <div class="header-tip text-right"> <a href="/MemberCenterModule/MemberRegLogin/Registered"><i class="icon glyphicon-user"></i>注册</a> | <a href="/MemberCenterModule/MemberRegLogin/login">登录</a> </div> } </div> </div> <div class="header-search"> <input type="text" name="search" id="tip_search_input" class="seach-text"> <a οnclick="seachFrom()" title="搜索" class="seach-btn"><img src="~/Content/Web/img/icon-search-01.png" /></a> </div> </div> <!-- header E --> @RenderBody() <!-- 友情链接 --> @*footer S*@ <div id="footer"> <div class="foot-tip"> <div class="webPage text-center"> 页落素材网是网页特效下载社区,以提高效率、分享经验的理念,提供高品质实用、简单、易懂的Web页面特效。 <script type="text/javascript">var cnzz_protocol = (("https:" == document.location.protocol) ? " https://" : " http://"); document.write(unescape("%3Cspan id='cnzz_stat_icon_1274673375'%3E%3C/span%3E%3Cscript src='" + cnzz_protocol + "s22.cnzz.com/z_stat.php%3Fid%3D1274673375%26show%3Dpic1' type='text/javascript'%3E%3C/script%3E"));</script> </div> </div> </div> @*footer E*@ <a target="_blank" href="http://wpa.qq.com/msgrd?v=3&uin=470797533&site=qq&menu=yes" style="position:fixed;top:45%;right:10px;"> <img border="0" src="http://wpa.qq.com/pa?p=2:470797533:53" alt="在线咨询" title="在线咨询" /> </a> <script type="text/javascript"> function LoginOut() { AjaxJson("/MemberCenterModule/MemberRegLogin/LoginOut", {}, function (data) { layer.msg("您已退出登录,欢迎再来哦 ^_^", { icon: 6, shade: [0.3, '#000'] }, function () { location.href = "/Sccnn/Index"; }); }); } //回车键 document.onkeydown = function (e) { if (!e) e = window.event; //火狐中是 window.event if ((e.keyCode || e.which) == 13) { seachFrom(); } } function seachFrom() { window.location.href = '/Sccnn/Index?FileTitle=' + $('#tip_search_input').val(); } $(function () { $(".header-nav-li").hover(function () { $(this).siblings(".header-nav-li").find(".header-nav-li-child").hide(); $(this).addClass("on"); $(this).find(".header-nav-li-child").show(); }, function () { $(this).removeClass("on"); $(this).find(".header-nav-li-child").hide(); }); GetContentKeyByType(); }) //获取导航关键字 function GetContentKeyByType() { $.post("/Sccnn/GetContentKeyByType", {}, function (data) { for (var i = 0; i < data.length; i++) { $("." + data[i].Code).append('<a href="/Sccnn/Index?FileType=' + data[i].Code + '&ContentKey=' + data[i].DataDictionaryTitle + '" title="' + data[i].DataDictionaryTitle + '"> ' + data[i].DataDictionaryTitle + '</a>'); } }, "json") } </script> </body> </html>
(2)然后在最外层(注意跟区域层区分)的Controller文件中添加SccnnController.cs控制器:
using Bobo.Utilities; using Bobo.Utilities.Membership; using IA.Business; using IA.Business.SystemBusiness; using IA.Entity; using IA.WebApp.SystemExtension; using System; using System.Collections.Generic; using System.Data.Common; using System.Linq; using System.Web; using System.Web.Mvc; using Insus.NET; namespace IA.WebApp.Controllers { /// <summary> /// 网站首页控制器 /// </summary> public class SccnnController : Controller { // // GET: /Sccnn/ /// <summary> /// 首页 /// </summary> /// <returns></returns> public ActionResult Index(string FileTitle, string FileType, string ContentKey, int p = 1) { Com_BannerBll bll = new Com_BannerBll(); ViewBag.Banner = bll.GetBannerList("Index");//获取广告 ViewBag.GetContentKey = new Base_DataDictionaryDetailBll().GetDataDictionaryList("", "ContentKey");//获取关键字 JqGridParam jgp = new JqGridParam(); jgp.page = p; jgp.rows = 15; jgp.records = 0; jgp.sidx = "CreateDate"; jgp.sord = "DESC"; var seachStr = ""; if (!StringHelper.IsNullOrEmpty(FileTitle)) { FileTitle = FileTitle.Replace(" ", ""); seachStr += "&FileTitle=" + FileTitle; } if (!StringHelper.IsNullOrEmpty(FileType)) { FileType = FileType.Replace(" ", ""); seachStr += "&FileType=" + FileType; } if (!StringHelper.IsNullOrEmpty(ContentKey)) { ContentKey = ContentKey.Replace(" ", ""); seachStr += "&ContentKey=" + ContentKey; } ViewBag.seachStr = seachStr; Com_AttachmentBll all = new Com_AttachmentBll(); ViewBag.model = all.GetWebTablePage(FileTitle, FileType, ContentKey, ref jgp); ViewBag.pageData = jgp; return View(); } /// <summary> /// 获取导航关键字 /// </summary> /// <returns></returns> public ActionResult GetContentKeyByType() { Base_DataDictionaryDetailBll bll = new Base_DataDictionaryDetailBll(); List<Base_DataDictionaryDetail> dlist = new List<Base_DataDictionaryDetail>(); dlist.AddRange(bll.GetContentKeyList("WEB")); dlist.AddRange(bll.GetContentKeyList("WAP")); dlist.AddRange(bll.GetContentKeyList("H5C3")); dlist.AddRange(bll.GetContentKeyList("WJS")); dlist.AddRange(bll.GetContentKeyList("FLASH")); dlist.AddRange(bll.GetContentKeyList("PIC")); dlist.AddRange(bll.GetContentKeyList("SYS")); return Content(dlist.ToJson()); } /// <summary> /// 详情页 /// </summary> /// <returns></returns> public ActionResult Detail(string KeyValue) { Com_AttachmentBll bll = new Com_AttachmentBll(); Com_Attachment entity = new Com_Attachment(); if (!StringHelper.IsNullOrEmpty(KeyValue)) { entity = bll.Factory.FindEntity(KeyValue); } ViewBag.NewGetAttachment = bll.GetAttachmentList(null, 6, "CreateDate"); ViewBag.HotGetAttachment = bll.GetAttachmentList(null, 6, "CollectionNum"); ViewBag.dwCount = new Com_DownloadLogBll().Factory.FindCount("DataID", KeyValue); ViewBag.GetContentKey = new Base_DataDictionaryDetailBll().GetDataDictionaryList("", "ContentKey");//获取关键字 return View(entity); } /// <summary> /// 模板预览 /// </summary> /// <returns></returns> public ActionResult DemoShow(string KeyValue) { Com_Attachment entity = new Com_Attachment(); if (!StringHelper.IsNullOrEmpty(KeyValue)) { entity = new Com_AttachmentBll().Factory.FindEntity(KeyValue); } ViewBag.FileID = entity.FileID; ViewBag.FileTitle = entity.FileTitle; ViewBag.FileIndexUrl = entity.FileIndexUrl; return View(); } [LoginAuthorize("~/MemberCenterModule/MemberRegLogin/login")] /// <summary> /// 下载界面 /// </summary> /// <param name="KeyValue"></param> /// <returns></returns> public ActionResult DownloadView(string KeyValue) { Com_Attachment entity = new Com_Attachment(); string MemeberID = ManageProvider.Provider.Current().UserId; if (!StringHelper.IsNullOrEmpty(KeyValue)) { entity = new Com_AttachmentBll().Factory.FindEntity(KeyValue); } Com_Member mentity = new Com_MemberBll().Factory.FindEntity(MemeberID); ViewBag.UserName = mentity.RealName; ViewBag.Integral = mentity.Integral; ViewBag.FileID = entity.FileID; ViewBag.FileTitle = entity.FileTitle; ViewBag.FileCover = entity.FileCover; ViewBag.NeedIntegral = entity.Integral; return View(); } /// <summary> /// 设置浏览量 /// </summary> /// <param name="KeyValue"></param> /// <returns></returns> public ActionResult SubSetBrwColNum(string KeyValue, int CollectionNum = 0, int BrowseNum = 0) { Com_AttachmentBll bll = new Com_AttachmentBll(); Com_ApproveBll all = new Com_ApproveBll(); DbTransaction transaction = bll.Factory.BeginTrans(); try { int IsOk = 0; string Message = "操作失败。"; if (!StringHelper.IsNullOrEmpty(KeyValue)) { Com_Attachment enity = bll.Factory.FindEntity(KeyValue); enity.BrowseNum = enity.BrowseNum + BrowseNum; enity.CollectionNum = enity.CollectionNum + CollectionNum; enity.Modify(KeyValue, false); IsOk = bll.Factory.Update(enity, transaction); if (ManageProvider.Provider.IsOverdue() && CollectionNum > 0) { List<Com_Approve> bList = all.GetApproveList(KeyValue, "Collection", ManageProvider.Provider.Current().UserId); if (bList.Count > 0) { return Content(new JsonMessage { Success = false, Code = "-1", Message = "您已收藏该素材!" }.ToString()); } else { IsOk = all.SubmitApproveData(KeyValue, "Collection", "收藏", null, transaction);//插入收藏 } } bll.Factory.Commit(); Message = IsOk > 0 ? "操作成功。" : "操作失败"; } return Content(new JsonMessage { Success = true, Code = IsOk.ToString(), Message = Message }.ToString()); } catch (Exception ex) { return Content(new JsonMessage { Success = false, Code = "-1", Message = "操作失败:" + ex.Message }.ToString()); } } //[LoginAuthorize("~/MemberCenterModule/MemberRegLogin/login")] /// <summary> /// 下载附件 /// </summary> /// <param name="KeyValue"></param> /// <returns></returns> public ActionResult DownloadFile(string KeyValue) { Com_DownloadLogBll bll = new Com_DownloadLogBll(); Com_MemberBll mll = new Com_MemberBll(); InsusIOUtility file = new InsusIOUtility(); string MemeberID = ManageProvider.Provider.Current().UserId; if (!StringHelper.IsNullOrEmpty(KeyValue)) { List<Com_DownloadLog> logList = bll.Factory.FindList("DataID", KeyValue); Com_Attachment entity = new Com_AttachmentBll().Factory.FindEntity(KeyValue); Com_Member mentity = mll.Factory.FindEntity(MemeberID); if ((mentity.Integral >= entity.Integral) || mentity.MemberType == 1) { string updir = Server.MapPath(entity.FileUrl); DbTransaction transaction = bll.Factory.BeginTrans(); if (file.IsExistFile(updir)) { if (logList.Count == 0 && mentity.MemberType != 1) { mentity.Integral = (mentity.Integral - entity.Integral);//非VIP会员,扣除下载积分 mentity.Modify(MemeberID); mll.Factory.Update(mentity, transaction); } bll.SubDownloadLog(KeyValue, entity.Integral, transaction);//生成下载日志 file.Download(updir); bll.Factory.Commit(); return Content("1"); } else { return PartialView("_NoFile"); } } else { return Content("<script>if (confirm('你当前余额为:" + mentity.Integral + " 金币,请前往充值!')) { window.location.href = '/MemberCenterModule/MemberSystem/RechargeView';} else {history.go(-1) }</script>"); } } else { return PartialView("_NoFile"); } } /// <summary> /// 获取关键字 /// </summary> /// <param name="title"></param> /// <returns></returns> public ActionResult GetContentKey() { Base_DataDictionaryDetailBll bll = new Base_DataDictionaryDetailBll(); List<Base_DataDictionaryDetail> dlist = bll.GetDataDictionaryList("", "ContentKey"); return Content(dlist.ToJson()); } } }
在这个控制器中写了很多方法,有的是没用到的,大家可忽略。其次在这里面的方法需要调用到业务层中的方法,下面就罗列出需要在业务层中创建业务方法的业务文件。
(1)Com_BannerBll.cs
using Bobo.DataAccess; using Bobo.Repository; using Bobo.Utilities; using IA.Entity; using System; using System.Collections.Generic; using System.Data; using System.Data.Common; using System.Linq; using System.Text; using System.Threading.Tasks; namespace IA.Business { // <summary> /// 广告信息表 /// <author> /// <name>YHB</name> /// <date>2018.10.18</date> /// </author> /// </summary> public class Com_BannerBll : RepositoryFactory<Com_Banner> { /// <summary> /// 获取分页数据 /// </summary> /// <param name="jgp"></param> /// <returns></returns> public DataTable GetTablePage(string BannerTitle, ref JqGridParam jgp) { StringBuilder whereSql = new StringBuilder(); List<DbParameter> param = new List<DbParameter>(); whereSql.Append(@" AND DeleteMark<>1"); if (!StringHelper.IsNullOrEmpty(BannerTitle)) { whereSql.Append(@" AND BannerTitle like @BannerTitle"); param.Add(DbFactory.CreateDbParameter("@BannerTitle", '%' + BannerTitle + '%')); } return Factory.FindTablePage(whereSql.ToString(), param.ToArray(), ref jgp); } /// <summary> /// 获取 /// </summary> /// <returns></returns> public List<Com_Banner> GetBannerList(string BannerType) { StringBuilder whereSql = new StringBuilder(); List<DbParameter> param = new List<DbParameter>(); whereSql.Append(@" AND DeleteMark<>1 AND State=1"); if (!StringHelper.IsNullOrEmpty(BannerType)) { whereSql.Append(@" AND BannerType=@BannerType"); param.Add(DbFactory.CreateDbParameter("@BannerType", BannerType)); } return Factory.FindList(whereSql.ToString(), param.ToArray()); } } }
(2)Base_DataDictionaryDetailBll.cs
using Bobo.DataAccess; using Bobo.Repository; using Bobo.Utilities; using IA.Entity; using System; using System.Collections.Generic; using System.Data; using System.Data.Common; using System.Linq; using System.Text; using System.Threading.Tasks; namespace IA.Business.SystemBusiness { // <summary> /// 数据字典表 /// <author> /// <name>YHB</name> /// <date>2018.10.18</date> /// </author> /// </summary> public class Base_DataDictionaryDetailBll : RepositoryFactory<Base_DataDictionaryDetail> { /// <summary> /// 根据字典类型和编码获取字典详细 /// </summary> /// <param name="DataDictionaryType"></param> /// <param name="Code"></param> /// <returns></returns> public List<Base_DataDictionaryDetail> GetDataducListByTypeCode(string DataDictionaryType, string Code) { StringBuilder Sql = new StringBuilder(); List<DbParameter> param = new List<DbParameter>(); Sql.Append(@"SELECT * FROM Base_DataDictionaryDetail WHERE DeleteMark<>1"); if (!StringHelper.IsNullOrEmpty(DataDictionaryType)) { Sql.Append(@" AND DataDictionaryType=@DataDictionaryType"); param.Add(DbFactory.CreateDbParameter("@DataDictionaryType", DataDictionaryType)); } if (!StringHelper.IsNullOrEmpty(Code)) { Sql.Append(@" AND Code=@Code"); param.Add(DbFactory.CreateDbParameter("@Code", Code)); } return Factory.FindListBySql(Sql.ToString(), param.ToArray()); } /// <summary> /// 获取类型关键字 /// </summary> /// <param name="DataDictionaryTitle"></param> /// <param name="DataDictionaryType"></param> /// <returns></returns> public List<Base_DataDictionaryDetail> GetDataDictionaryList(string DataDictionaryTitle, string DataDictionaryType) { StringBuilder Sql = new StringBuilder(); List<DbParameter> param = new List<DbParameter>(); Sql.Append(@"SELECT * FROM Base_DataDictionaryDetail WHERE DeleteMark<>1"); if (!StringHelper.IsNullOrEmpty(DataDictionaryType)) { Sql.Append(@" AND DataDictionaryType=@DataDictionaryType"); param.Add(DbFactory.CreateDbParameter("@DataDictionaryType", DataDictionaryType)); } if (!StringHelper.IsNullOrEmpty(DataDictionaryTitle)) { Sql.Append(@" AND DataDictionaryTitle like @DataDictionaryTitle"); param.Add(DbFactory.CreateDbParameter("@DataDictionaryTitle", '%' + DataDictionaryTitle + '%')); } return Factory.FindListBySql(Sql.ToString(), param.ToArray()); } /// <summary> /// 获取关于协会分页数据 /// </summary> /// <param name="ArticleTitle"></param> /// <param name="jgp"></param> /// <returns></returns> public DataTable GetAboutTablePage(ref JqGridParam jgp) { StringBuilder Sql = new StringBuilder(); List<DbParameter> param = new List<DbParameter>(); Sql.Append(@"SELECT * FROM( SELECT X1.DataDictionaryTitle,X1.Code,X1.SortCode,X2.* from (SELECT * FROM dbo.Base_DataDictionaryDetail WHERE DeleteMark<>1 AND DataDictionaryType='About') X1 LEFT JOIN (SELECT * FROM Com_Article WHERE DeleteMark<>1 AND State=1) X2 ON X1.Code=x2.ArticleType) TT WHERE 1=1 "); return Factory.FindTablePageBySql(Sql.ToString(), param.ToArray(), ref jgp); } /// <summary> /// /// </summary> /// <param name="jgp"></param> /// <returns></returns> public DataTable GetAboutTableAllPage(ref JqGridParam jgp) { StringBuilder Sql = new StringBuilder(); List<DbParameter> param = new List<DbParameter>(); Sql.Append(@"SELECT * FROM( SELECT X1.DataDictionaryTitle,X1.Code,X1.SortCode,X2.* from (SELECT * FROM dbo.Base_DataDictionaryDetail WHERE DeleteMark<>1 AND DataDictionaryType='About') X1 LEFT JOIN (SELECT * FROM Com_Article WHERE DeleteMark<>1) X2 ON X1.Code=x2.ArticleType) TT WHERE 1=1 "); return Factory.FindTablePageBySql(Sql.ToString(), param.ToArray(), ref jgp); } /// <summary> /// 添加关键字 /// </summary> /// <param name="ContentKey"></param> /// <returns></returns> public int SubContentKey(string ContentKey) { List<DbParameter> param = new List<DbParameter>(); string[] ContentKeyArr = ContentKey.Split(','); int num = 0; try { if (ContentKeyArr.Length > 0) { foreach (var item in ContentKeyArr) { StringBuilder Sql = new StringBuilder(); Sql.Append(@"DELETE Base_DataDictionaryDetail WHERE DeleteMark<>1 AND DataDictionaryType='ContentKey' AND DataDictionaryTitle='" + item + "'"); Factory.ExecuteBySql(Sql); Base_DataDictionaryDetail entiy = new Base_DataDictionaryDetail(); entiy.DataDictionaryTitle = item; entiy.DataDictionaryType = "ContentKey"; entiy.Create(); Factory.Insert(entiy); } num = 1; } else { num = 0; } } catch { num= 0; } return num; } /// <summary> /// 获取有数据的关键字 /// </summary> /// <param name="Type">关键字类型</param> /// <returns></returns> public List<Base_DataDictionaryDetail> GetContentKeyList(string Type) { StringBuilder Sql = new StringBuilder(); List<DbParameter> param = new List<DbParameter>(); if (!StringHelper.IsNullOrEmpty(Type)) { Sql.Append(@"SELECT * FROM( SELECT (SELECT COUNT(FileID) FROM dbo.Com_Attachment WHERE DeleteMark<>1 AND ContentKey like '%'+x.DataDictionaryTitle+'%' AND FileType=@FileType) FileCount, x.DataDictionaryTitle, x.DataDictionaryType, '"+Type+@"' Code, x.DeleteMark FROM dbo.Base_DataDictionaryDetail x) T WHERE DataDictionaryType='ContentKey' AND DeleteMark<>1 AND FileCount>0"); param.Add(DbFactory.CreateDbParameter("@FileType", Type)); } return Factory.FindListBySql(Sql.ToString(), param.ToArray()); } } }
(3)Com_AttachmentBll.cs
using Bobo.DataAccess; using Bobo.Repository; using Bobo.Utilities; using IA.Entity; using System; using System.Collections.Generic; using System.Data; using System.Data.Common; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Web; namespace IA.Business {// <summary> /// 素材表 /// <author> /// <name>YHB</name> /// <date>2018.10.18</date> /// </author> /// </summary> public class Com_AttachmentBll : RepositoryFactory<Com_Attachment> { /// <summary> /// 获取网站分页数据 /// </summary> /// <param name="FileTitle"></param> /// <param name="FileType"></param> /// <param name="ContentKey"></param> /// <param name="jgp"></param> /// <returns></returns> public List<Com_Attachment> GetWebTablePage(string FileTitle, string FileType, string ContentKey, ref JqGridParam jgp) { StringBuilder whereSql = new StringBuilder(); List<DbParameter> param = new List<DbParameter>(); whereSql.Append(@" AND DeleteMark<>1"); if (!StringHelper.IsNullOrEmpty(FileTitle)) { whereSql.Append(@" AND (FileTitle LIKE @FileTitle OR ContentKey LIKE @ContentKey OR Remarks LIKE @Remarks)"); param.Add(DbFactory.CreateDbParameter("@FileTitle", '%' + FileTitle + '%')); param.Add(DbFactory.CreateDbParameter("@ContentKey", '%' + FileTitle + '%')); param.Add(DbFactory.CreateDbParameter("@Remarks", '%' + FileTitle + '%')); } if (!StringHelper.IsNullOrEmpty(ContentKey)) { whereSql.Append(@" AND ContentKey LIKE @ContentKey"); param.Add(DbFactory.CreateDbParameter("@ContentKey", '%' + ContentKey + '%')); } if (!StringHelper.IsNullOrEmpty(FileType)) { whereSql.Append(@" AND FileType=@FileType"); param.Add(DbFactory.CreateDbParameter("@FileType", FileType)); } return Factory.FindListPage(whereSql.ToString(), param.ToArray(), ref jgp); } /// <summary> /// 获取附件数据 /// </summary> /// <param name="ArticleTitle"></param> /// <param name="jgp"></param> /// <returns></returns> public DataTable GetTablePage(string FileTitle, ref JqGridParam jgp) { StringBuilder whereSql = new StringBuilder(); List<DbParameter> param = new List<DbParameter>(); whereSql.Append(@" AND DeleteMark<>1"); if (!StringHelper.IsNullOrEmpty(FileTitle)) { whereSql.Append(@" AND FileTitle LIKE @FileTitle"); param.Add(DbFactory.CreateDbParameter("@FileTitle", '%' + FileTitle + '%')); } return Factory.FindTablePage(whereSql.ToString(), param.ToArray(), ref jgp); } /// <summary> /// 获取附件列表 /// </summary> /// <param name="DataID"></param> /// <returns></returns> public List<Com_Attachment> GetAttachmentList(string DataID, int? topNum, string ByType) { StringBuilder Sql = new StringBuilder(); List<DbParameter> param = new List<DbParameter>(); string where = "*"; if (!StringHelper.IsNullOrEmpty(topNum) && topNum > 0) { where = "TOP(" + topNum + ") *"; } Sql.Append(@"SELECT " + where + " FROM Com_Attachment WHERE DeleteMark<>1"); if (!StringHelper.IsNullOrEmpty(DataID)) { Sql.Append(@" AND DataID=@DataID"); param.Add(DbFactory.CreateDbParameter("@DataID", DataID)); } if (!StringHelper.IsNullOrEmpty(ByType)) { Sql.Append(@" ORDER BY " + ByType + " DESC"); } return Factory.FindListBySql(Sql.ToString(), param.ToArray()); } } }
(4)Com_DownloadLogBll.cs
using Bobo.DataAccess; using Bobo.Repository; using Bobo.Utilities; using IA.Entity; using System; using System.Collections.Generic; using System.Data; using System.Data.Common; using System.Linq; using System.Text; using System.Threading.Tasks; namespace IA.Business { // <summary> /// 下载日志表 /// <author> /// <name>YHB</name> /// <date>2018.10.18</date> /// </author> /// </summary> public class Com_DownloadLogBll : RepositoryFactory<Com_DownloadLog> { /// <summary> /// 添加下载日志 /// </summary> /// <param name="DataID"></param> /// <param name="Integral"></param> /// <param name="transaction"></param> /// <returns></returns> public int SubDownloadLog(string DataID, int? Integral, DbTransaction transaction) { try { Com_DownloadLog entity = new Com_DownloadLog(); entity.DataID = DataID; entity.Integral = Integral; entity.Create(); Factory.Insert(entity); return 1; } catch { return 0; } } /// <summary> /// 获取下载日志 /// </summary> /// <param name="MemeberID"></param> /// <param name="jgp"></param> /// <returns></returns> public DataTable GetTablePage(string MemeberID, ref JqGridParam jgp) { StringBuilder Sql = new StringBuilder(); List<DbParameter> param = new List<DbParameter>(); Sql.Append(@"SELECT * FROM( SELECT x2.FileTitle,x2.FileID,x1.* FROM dbo.Com_DownloadLog x1 INNER JOIN dbo.Com_Attachment x2 ON x2.FileID=x1.DataID AND x1.DeleteMark<>1 AND x2.DeleteMark<>1 ) T WHERE 1=1"); if (!StringHelper.IsNullOrEmpty(MemeberID)) { Sql.Append(@" AND CreateUserId=@MemeberID"); param.Add(DbFactory.CreateDbParameter("@MemeberID", MemeberID)); } return Factory.FindTablePageBySql(Sql.ToString(), param.ToArray(), ref jgp); } } }
后台的业务方法创建好后,我们需要创建几个视图(首页、详情页,预览页,下载页),这些视图都放在同一个控制器的视图Sccnn文件下。
(1)首页Index.cshtml
@using System.Data @using Bobo.Utilities @{ ViewBag.Title = "页落网_YEALUO_页落素材网_jQuery网页特效最全网页模板和网站模板jQuery代码素材网站!靠谱的前端网页素材网站"; Layout = "~/Views/Shared/_Layout.cshtml"; } @*center S*@ <div id="center"> <!-- 幻灯 --> @if (ViewBag.Banner.Count > 0) { <div class="webPage"> <div id="mainSile"> <div class="bd"> <ul> @foreach (var item in ViewBag.Banner) { <li> <div class="mainSileImg"><img src="@item.BannerImg" style="width:100%;height:auto" title="@item.BannerTitle" /></div> <div class="mainSileCom"> <div class="mainSileTit"><a href="@item.BannerLink" target="_blank" title="@item.BannerTitle">@item.BannerTitle</a></div> <div class="mainSileTxt"> @StringHelper.ClipString(StringHelper.ClearHtml(item.BannerCenter), 100) <a href="@item.BannerLink" target="_blank" title="@item.BannerTitle">详细</a> </div> </div> </li> } </ul> </div> <ul class="ticker"> <li class="prev"></li> <li class="next"></li> </ul> </div> </div> } <!-- 幻灯end --> <div style="display:none;" class="hideKey"> @foreach (var item in ViewBag.GetContentKey) { <a href="/Sccnn/Index?ContentKey=@item.DataDictionaryTitle" title="@item.DataDictionaryTitle"> @StringHelper.ClipString(StringHelper.ClearHtml(item.DataDictionaryTitle), 10)</a> } </div> @*<div class="center-key webPage"> <div class="center-key-title">热门标签 </div> <div class="center-key-txt"> @foreach (var item in ViewBag.GetContentKey) { <a href="/Sccnn/Index?ContentKey=@item.DataDictionaryTitle" title="@item.DataDictionaryTitle"> @StringHelper.Out(StringHelper.ClearHTML(item.DataDictionaryTitle), 10)</a> } </div> </div>*@ <ul class="webPage center-ul" id="dataBody"> @foreach (var item in ViewBag.model) { <li class="center-ul-li" > <a href="/Sccnn/Detail?KeyValue=@item.FileID" target="_blank" class="ul-li-img" title="@item.FileTitle"><img class="indImg" src="@(item.FileMinCover)" width="260" alt="@item.FileTitle"></a> <a href="/Sccnn/Detail?KeyValue=@item.FileID" target="_blank" class="ul-li-tit" title="@item.FileTitle">@item.FileTitle</a> <div class="ul-li-foot"><span title="浏览"><i class="icon glyphicon-eye-open"></i>@item.BrowseNum</span><span title="收藏"><i class="icon glyphicon-star-empty"></i> @item.CollectionNum</span></div> <div class="ul-li-tip" style="display: none;"> @if (item.FileType != "FLASH" && item.FileType != "PIC" && item.FileType != "SYS") { <a href="/Sccnn/DemoShow?KeyValue=@item.FileID" target="_blank" class="L" title="预览"><i class="icon glyphicon-eye-open"></i> 预览</a> } else { <a href="/Sccnn/Detail?KeyValue=@item.FileID" target="_blank" class="L" title="预览"> <i class="icon glyphicon-eye-open"></i> 预览</a> } <a href="/Sccnn/DownloadView?KeyValue=@item.FileID" target="_blank" class="R" title="下载"> <i class="icon glyphicon-download-alt"></i> 下载</a> </div> </li> } </ul> <div class="tcdPageCode"></div> </div> @*center E*@ <script src="~/Content/Web/js/masonry.js"></script> <script src="~/Content/Web/js/scrollLoading.js"></script> <script src="~/Content/Scripts/layer/layer.js"></script> <script src="~/Content/Scripts/boboui-jshelp.js"></script> <script src="~/Content/Web/js/jquery.SuperSlide.js"></script> <script src="~/Content/Scripts/Juicer/juicer.js"></script> <script src="~/Content/Web/js/jquery.page.js"></script> <script type="text/javascript"> $(function () { SetMoreKey(); jaxscroll(); SetMoust(); }); $(".tcdPageCode").createPage({ pageCount: @ViewBag.pageData.total, current: @ViewBag.pageData.page, backFn: function (p) { location.href = "/Sccnn/Index?p=" + p + "@ViewBag.seachStr"; } }); function jaxscroll() { //瀑布流代码 var $container = $('.center-ul'); $container.masonry(); $(".indImg").scrollLoading({ callback: function () { $container.imagesLoaded(function () { $container.masonry('reload'); }); } }); $container.imagesLoaded(function () { $container.masonry({ itemSelector: '.center-ul-li', columnWidth: 0 //每两列之间的间隙为5像素 }); }); } //鼠标移过 function SetMoust() { $(".center-ul-li").each(function(){ $(this).hover(function(){ if($(this).hasClass("on")){ $(this).removeClass("on"); $(this).find(".ul-li-tip").slideUp(300) } else{ $(this).addClass("on"); $(this).find(".ul-li-tip").slideDown(300) } }) }) } //幻灯设置 $("#mainSile").slide({ mainCell: ".bd ul", autoPage: true, effect: "leftLoop", autoPlay: true, interTime: 3000, delayTime: 500 }); function SetMoreKey(){ var str='<div class="header-nav-li-child"><div class="webPage indexKey">'; str+=$(".hideKey").html(); str+='</div></div>'; $(".indexKey").append(str); } </script>
(2)详情页Detail.cshtml:
@using IA.Entity @using Bobo.Utilities @using Bobo.Utilities.Membership @model Com_Attachment @{ ViewBag.Title = "页落网_YEALUO_" + Model.FileTitle + "_页落素材网!靠谱的前端网页素材网站"; Layout = "~/Views/Shared/_LayoutMember.cshtml"; } @*center S*@ <div id="center" style="padding-top:90px;"> <div class="webPage"> <div class="web-map"> <span>当前位置:</span> <a href="/">首页 ></a> <a href="">@Model.FileTitle</a> </div> <div class="detail-com L"> <h1 class="detail-title">@Model.FileTitle</h1> <div class="detail-img"> <img src="@Model.FileCover" style="width:100%;height:auto" alt="@Model.FileTitle" /> </div> <div class="detail-content"> @Model.Remarks </div> <div class="detail-key"> @if (!StringHelper.IsNullOrEmpty(Model.ContentKey)) { var ContentKeyArr = Model.ContentKey.Split(','); if (ContentKeyArr.Length > 0) { foreach (var item in ContentKeyArr) { <a href="/Sccnn?ContentKey=@item" title="@item"><i class="icon glyphicon-link"></i> @item</a> } } } </div> <div class="detail-czbtn"> @if (Model.FileType != "FLASH" && Model.FileType != "PIC" && Model.FileType != "SYS") { <a href="/Sccnn/DemoShow?KeyValue=@Model.FileID" target="_blank" class="detail-btn detail-btn1"><i class="icon glyphicon-eye-open"></i>查看演示</a> } else{ <span style="padding-left:185px;" class="L"> </span> } @if (ManageProvider.Provider.IsOverdue()) { <a href="javascript:;" class="detail-btn detail-btn2" οnclick="addColl(1)"><i class="icon glyphicon-eye-open"></i> 加入收藏</a> } else { <a href="javascript:;" class="detail-btn detail-btn2" οnclick="addColl(0)"><i class="icon glyphicon-star-empty"></i> 加入收藏</a> } <a href="/Sccnn/DownloadView?KeyValue=@Model.FileID" class="detail-btn detail-btn3"><i class="icon glyphicon-download-alt"></i> 下载资源</a> <div class='clear'><span class="detail-btn"><i class="icon glyphicon-eye-open"></i> @Model.BrowseNum</span> <span class="detail-btn"><i class="icon glyphicon-star-empty"></i> @Model.CollectionNum</span> <span class="detail-btn"><i class="icon glyphicon-download-alt"></i> @ViewBag.dwCount</span> </div> </div> </div> <div class="detail-side R"> <div class="detail-side-title">最新发布</div> <div class="detail-side-com"> @foreach (var item in ViewBag.NewGetAttachment) { <a href="/Sccnn/Detail?KeyValue=@item.FileID" title="@item.FileTitle" class="detail-side-item"> <img src="@item.FileMinCover" width="80" height="100" alt="@item.FileTitle" /> <span>@StringHelper.ClipString(item.FileTitle, 10)</span> </a> } </div> <div class="detail-side-title">热门标签</div> <div class="detail-side-key"> @foreach (var item in ViewBag.GetContentKey) { <a href="/Sccnn/Index?ContentKey=@item.DataDictionaryTitle" title="@item.DataDictionaryTitle">@item.DataDictionaryTitle</a> } </div> <div class="detail-side-title">热门推荐</div> <div class="detail-side-com"> @foreach (var item in ViewBag.HotGetAttachment) { <a href="/Sccnn/Detail?KeyValue=@item.FileID" title="@item.FileTitle" class="detail-side-item"> <img src="@item.FileMinCover" width="80" height="100" alt="@item.FileTitle" /> <span>@StringHelper.ClipString(item.FileTitle, 10)</span> </a> } </div> </div> </div> </div> @*center E*@ <script type="text/javascript"> var KeyValue = GetQuery('KeyValue').replace("null", ""); $(function () { SetBrwCol(); }) //设置cookie function setCookie(cname, cvalue, exdays) { var d = new Date(); d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));//24小时 var expires = "expires=" + d.toUTCString(); document.cookie = cname + "=" + cvalue + "; " + expires; } //获取cookie function getCookie(cname) { var name = cname + "="; var ca = document.cookie.split(';'); for (var i = 0; i < ca.length; i++) { var c = ca[i]; while (c.charAt(0) == ' ') c = c.substring(1); if (c.indexOf(name) != -1) return c.substring(name.length, c.length); } return ""; } //浏览量 function SetBrwCol() { if (getCookie(KeyValue + "Brw") == "") { SubSetBrwColNum(0, 1, "Brw"); } return false; } //加入收藏 function addColl(num) { if (num > 0) { SubSetBrwColNum(1, 0, "Coll"); } else { if (getCookie(KeyValue + "Coll") == "") { SubSetBrwColNum(1, 0, "Coll"); addFavorite(window.location, document.title); } else { layer.msg('请登录后再继续收藏', { icon: -1, time: 2000 }); } } return false; } //设置收藏浏览 function SubSetBrwColNum(CollectionNum, BrowseNum, type) { $.post("/Sccnn/SubSetBrwColNum", { KeyValue: KeyValue, CollectionNum: CollectionNum, BrowseNum: BrowseNum }, function (data) { if (data.Code > 0) { setCookie(KeyValue + type, KeyValue + type, 1); } else if (CollectionNum>0) { layer.alert(data.Message, { icon: data.Code }); } }, "json"); } </script>
(3)预览页DemoShow.cshtml:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>页落网_YEALUO_@ViewBag.FileTitle _页落素材网!靠谱的前端网页素材网站</title> <link href="~/Content/Web/css/demo.css" rel="stylesheet" /> <!--[if IE]> <style type="text/css"> li.remove_frame a { padding-top: 5px; background-position: 0px -3px; } </style> <![endif]--> <script src="~/Content/Scripts/jquery/jquery-1.8.2.min.js"></script> <script src="~/Content/Web/js/jquery.qrcode.min.js"></script> <script type="text/javascript"> $(document).ready(function () { function fixHeight() { var headerHeight = $("#switcher").height(); $("#iframe").attr("height", $(window).height() - 54 + "px"); } $(window).resize(function () { fixHeight(); }).resize(); $('.icon-monitor').addClass('active'); $(".icon-mobile-3").click(function () { $("#by").css("overflow-y", "auto"); $('#iframe-wrap').removeClass().addClass('mobile-width-3'); $('.icon-tablet,.icon-mobile-1,.icon-monitor,.icon-mobile-2,.icon-mobile-3').removeClass('active'); $(this).addClass('active'); return false; }); $(".icon-mobile-2").click(function () { $("#by").css("overflow-y", "auto"); $('#iframe-wrap').removeClass().addClass('mobile-width-2'); $('.icon-tablet,.icon-mobile-1,.icon-monitor,.icon-mobile-2,.icon-mobile-3').removeClass('active'); $(this).addClass('active'); return false; }); $(".icon-mobile-1").click(function () { $("#by").css("overflow-y", "auto"); $('#iframe-wrap').removeClass().addClass('mobile-width'); $('.icon-tablet,.icon-mobile,.icon-monitor,.icon-mobile-2,.icon-mobile-3').removeClass('active'); $(this).addClass('active'); return false; }); $(".icon-tablet").click(function () { $("#by").css("overflow-y", "auto"); $('#iframe-wrap').removeClass().addClass('tablet-width'); $('.icon-tablet,.icon-mobile-1,.icon-monitor,.icon-mobile-2,.icon-mobile-3').removeClass('active'); $(this).addClass('active'); return false; }); $(".icon-monitor").click(function () { $("#by").css("overflow-y", "hidden"); $('#iframe-wrap').removeClass().addClass('full-width'); $('.icon-tablet,.icon-mobile-1,.icon-monitor,.icon-mobile-2,.icon-mobile-3').removeClass('active'); $(this).addClass('active'); return false; }); }); </script> <script type="text/javascript"> function Responsive($a) { if ($a == true) $("#Device").css("opacity", "100"); if ($a == false) $("#Device").css("opacity", "0"); $('#iframe-wrap').removeClass().addClass('full-width'); $('.icon-tablet,.icon-mobile-1,.icon-monitor,.icon-mobile-2,.icon-mobile-3').removeClass('active'); $(this).addClass('active'); return false; }; </script> </head> <body id="by"> <div id="switcher"> <div class="center"> <ul> <div id="Device"> <li class="device-monitor"><a href="javascript:"><div class="icon-monitor"></div></a></li> <li class="device-mobile"><a href="javascript:"><div class="icon-tablet"></div></a></li> <li class="device-mobile"><a href="javascript:"><div class="icon-mobile-1"></div></a></li> <li class="device-mobile-2"><a href="javascript:"><div class="icon-mobile-2"></div></a></li> <li class="device-mobile-3"><a href="javascript:"><div class="icon-mobile-3"></div></a></li> </div> <li class="top2"> <a href="#">手机二维码预览</a> <div class="vm"> <div id="output"></div> <p style="color:#808080;margin:10px 0 0 0;">扫一扫,直接在手机上打开</p> </div> </li> <li class="logoTop"> <a href="/Sccnn/Detail?KeyValue=@ViewBag.FileID">@ViewBag.FileTitle</a> <script type="text/javascript"> jQuery('#output').qrcode({ width: 150, height: 150, text: window.location.href }); </script> <li class="remove_frame"><a href="@ViewBag.FileIndexUrl" title="移除框架"></a></li> </ul> </div> </div> <div id="iframe-wrap"> <iframe id="iframe" src="@ViewBag.FileIndexUrl" frameborder="0" width="100%"></iframe> </div> </body> </html>
(4)下载页DownloadView.cshtml
@{ ViewBag.Title = "页落网_YEALUO_" + ViewBag.FileTitle + "_页落素材网!靠谱的前端网页素材网站"; Layout = "~/Views/Shared/_LayoutMember.cshtml"; } <div id="center" style="padding-top:90px;"> <div class="down-com"> <a href="/Sccnn/Detail?KeyValue=@ViewBag.FileID" class="down-img L"><img src="@ViewBag.FileCover" alt="@ViewBag.FileTitle" style="width:100%;"></a> <div class="down-txt R"> <a href="/Sccnn/Detail?KeyValue=@ViewBag.FileID" class="down-title" title="@ViewBag.FileTitle">@ViewBag.FileTitle</a> <div class="down-user"> <a href="/MemberCenterModule/MemberSystem/Index" class="pth-img"><img src="~/Content/Images/slice/pht.png" width="38" height="38" alt="@ViewBag.UserName"> <span>@ViewBag.UserName</span></a> 当前金币:<em>@ViewBag.Integral</em> <a class="green" href="/MemberCenterModule/MemberSystem/RechargeView" target="_blank">充值金币</a> </div> <div class="detail-czbtn" style="width:100%; clear:both;"> <a href="/MemberCenterModule/MemberSystem/RechargeView" class="detail-btn detail-btn2" target="_blank">VIP无限下载</a> <a href="/Sccnn/DownloadFile?KeyValue=@ViewBag.FileID" class="detail-btn detail-btn3">下载资源</a> </div> <div class="down-tip"> 下载扣除:<b>@ViewBag.NeedIntegral</b>金币 @if (ViewBag.Integral < ViewBag.NeedIntegral) { <span>您的金币不足以下载本素材!</span> } <a href="" target="_blank">下载须知</a> </div> </div> </div> </div>
下面预览效果图: