123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.Mvc;
- using AirWheel.Cycling.Domain;
- using AirWheel.Cycling.Common;
- using AirWheel.Cycling.Service.IService;
- using AirWheel.Cycling.Common.Enums;
- using AirWheel.Cycling.WebPage.Controllers;
- namespace AirWheel.Cycling.WebPage.Areas.ComManage.Controllers
- {
- public class DownloadController : BaseController
- {
- #region 声明容器
- /// <summary>
- /// 下载管理
- /// </summary>
- IDownloadManage DownloadManage { get; set; }
- /// <summary>
- /// 上传的文件记录
- /// </summary>
- IUploadManage UploadManage { get; set; }
- #endregion
- #region 公共变量
- //文件ID
- string fileid = string.Empty;
- #endregion
- #region 基本视图
- /// <summary>
- /// 加载首页
- /// </summary>
- [UserAuthorizeAttribute(ModuleAlias = "Download", OperaAction = "View")]
- public ActionResult Index()
- {
- ViewBag.Search = base.keywords;
- return View(BindList());
- }
- /// <summary>
- /// 查询列表方法
- /// </summary>
- private PageInfo BindList()
- {
- var config = this.DownloadManage.Config;
- var query = (from r in config.COM_DOWNLOAD
- join u in config.COM_UPLOAD on r.FK_UPID equals u.ID
- select new
- {
- r.ID,
- r.DLDATE,
- r.DLIP,
- r.DLNUM,
- r.DLOPERATOR,
- r.FK_UPID,
- r.FK_USERID,
- FILENAME = u.UPOLDNAME,
- u.UPFILEPATH
- });
- if (!string.IsNullOrEmpty(base.keywords))
- {
- query = query.Where(p => p.DLOPERATOR.Contains(keywords));
- }
- return this.DownloadManage.Query(query, base.page, base.pagesize);
- }
- /// <summary>
- /// 加载详情
- /// </summary>
- [UserAuthorizeAttribute(ModuleAlias = "Download", OperaAction = "Detail")]
- public ActionResult Detail(string id)
- {
- var entity = this.DownloadManage.Get(p => p.ID == id) ?? new COM_DOWNLOAD();
- return View(entity);
- }
- #endregion
- #region 其他调用
- /// <summary>
- /// 用户下载功能
- /// </summary>
- [UserAuthorizeAttribute(ModuleAlias = "Download", OperaAction = "Download")]
- public ActionResult DownLoadFile()
- {
- fileid = Request.QueryString["file"];
- //文件ID
- if (string.IsNullOrEmpty(fileid))
- {
- Response.Write("<script>alert('^未找到要下载的文件');window.opener=null;window.open('', '_self', ''); window.close();</script>");
- Response.End();
- }
- //查找文件ID是否存在
- var file = this.UploadManage.Get(p => p.ID == fileid);
- if (file == null)
- {
- Response.Write("<script>alert('未找到要下载的文件');window.opener=null;window.open('', '_self', ''); window.close();</script>");
- Response.End();
- }
- //根据文件路径判断文件是否存在
- if (!System.IO.File.Exists(Server.MapPath(file.UPFILEPATH)))
- {
- Response.Write("<script>alert('下载的文件不存在');window.opener=null;window.open('', '_self', ''); window.close();</script>");
- //记录日志,文件缺失
- WriteLog(enumOperator.Files, "文件丢失,文件原始名称:" + file.UPOLDNAME + "路径" + file.UPFILEPATH,enumLog4net.ERROR);
- Response.End();
- }
- //记录下载数据
- this.DownloadManage.Save(new COM_DOWNLOAD()
- {
- ID = Guid.NewGuid().ToString(),
- FK_UPID = fileid,
- FK_USERID = this.CurrentUser.Id,
- DLDATE = DateTime.Now,
- DLIP = Utils.GetIP(),
- DLOPERATOR = this.CurrentUser.Name,
- DLNUM = 1
- });
- //跳转文件路径,进行浏览器下载
- Response.Redirect(file.UPFILEURL + file.UPFILEPATH, true);
- return new EmptyResult();
- }
- #endregion
- }
- }
|