initProject

This commit is contained in:
2024-05-08 11:01:54 +08:00
commit e7cea71567
4078 changed files with 579425 additions and 0 deletions
@@ -0,0 +1 @@
<%@ WebHandler Language="C#" CodeBehind="fileupload.ashx.cs" Class="FineUIPro.Web.AttachFile.fileupload" %>
@@ -0,0 +1,128 @@
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.IO;
using System.Web;
using System.Web.SessionState;
namespace FineUIPro.Web.AttachFile
{
/// <summary>
/// fileupload 的摘要说明
/// </summary>
public class fileupload : IHttpHandler, IRequiresSessionState
{
private void ResponseError(HttpContext context)
{
// 出错了
context.Response.StatusCode = 500;
context.Response.Write("No file");
}
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
string owner = context.Request.Form["owner"];
string sessionName = owner.Split('|')[0];
string attachPath = owner.Split('|')[1];
string initFullPath = BLL.Funs.RootPath + attachPath;
if (!Directory.Exists(initFullPath))
{
Directory.CreateDirectory(initFullPath);
}
if (context.Request.Files.Count == 0)
{
ResponseError(context);
return;
}
if (String.IsNullOrEmpty(owner))
{
ResponseError(context);
return;
}
HttpPostedFile postedFile = context.Request.Files[0];
// 文件名完整路径
string fileName = postedFile.FileName;
// 文件名保存的服务器路径
string savedFileName = GetSavedFileName(fileName);
postedFile.SaveAs(context.Server.MapPath("~/" + attachPath + "/" + savedFileName));
string shortFileName = GetFileName(fileName);
string fileType = GetFileType(fileName);
int fileSize = postedFile.ContentLength;
JObject fileObj = new JObject();
string fileId = Guid.NewGuid().ToString();
fileObj.Add("name", shortFileName);
fileObj.Add("type", fileType);
fileObj.Add("savedName", savedFileName);
fileObj.Add("size", fileSize);
fileObj.Add("id", fileId);
SaveToDatabase(context, sessionName, fileObj);
context.Response.Write("Success");
}
private void SaveToDatabase(HttpContext context, string sessionName, JObject fileObj)
{
if (context.Session[sessionName] == null)
{
context.Session[sessionName] = new JArray();
}
JArray source = context.Session[sessionName] as JArray;
source.Add(fileObj);
context.Session[sessionName] = source;
}
private string GetFileType(string fileName)
{
string fileType = String.Empty;
int lastDotIndex = fileName.LastIndexOf(".");
if (lastDotIndex >= 0)
{
fileType = fileName.Substring(lastDotIndex + 1).ToLower();
}
return fileType;
}
private string GetFileName(string fileName)
{
string shortFileName = fileName;
int lastSlashIndex = shortFileName.LastIndexOf("\\");
if (lastSlashIndex >= 0)
{
shortFileName = shortFileName.Substring(lastSlashIndex + 1);
}
return shortFileName;
}
private string GetSavedFileName(string fileName)
{
fileName = fileName.Replace(":", "_").Replace(" ", "_").Replace("\\", "_").Replace("/", "_");
fileName = DateTime.Now.Ticks.ToString() + "_" + fileName;
return fileName;
}
public bool IsReusable
{
get
{
return false;
}
}
}
}
File diff suppressed because it is too large Load Diff
File diff suppressed because one or more lines are too long
@@ -0,0 +1,193 @@
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="webuploader.aspx.cs" Inherits="FineUIPro.Web.AttachFile.webuploader" %>
<!DOCTYPE html>
<html>
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<link href="../../res/css/common.css" rel="stylesheet" type="text/css" />
<meta name="sourcefiles" content="~/AttachFile/fileupload.ashx" />
<style>
.webuploader-element-invisible {
position: absolute !important;
clip: rect(1px,1px,1px,1px);
}
.webuploader-pick-disable {
opacity: 0.6;
pointer-events: none;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<f:PageManager ID="PageManager1" runat="server" />
<f:Grid ID="Grid1" runat="server" ShowHeader="false" ShowBorder="true" Title="文件上传"
Width="650px" Height="360px"
EnableCollapse="false" EnableCheckBoxSelect="false" EmptyText="尚未上传文件"
DataIDField="id" OnRowCommand="Grid1_RowCommand">
<Toolbars>
<f:Toolbar ID="toolBar1" runat="server">
<Items>
<f:Button ID="btnSelectFiles" Text="选择文件上传" IconFont="Plus" runat="server" EnablePostBack="false">
</f:Button>
<f:ToolbarSeparator runat="server"></f:ToolbarSeparator>
<f:Button ID="btnDelete" Text="删除选中文件" IconFont="Remove" runat="server" OnClick="btnDelete_Click">
</f:Button>
<f:Button ID="btnSave" Text="保存" Icon="Add" runat="server" OnClick="btnSave_Click">
</f:Button>
<f:Button ID="Button1" Text="转化" Icon="Add" runat="server" OnClick="btnChange_Click" Hidden="true">
</f:Button>
</Items>
</f:Toolbar>
</Toolbars>
<Columns>
<f:LinkButtonField ColumnID="FileName" DataTextField="name" DataToolTipField="name" HeaderText="文件名" ExpandUnusedSpace="True" CommandName="Attach"/>
<f:BoundField ColumnID="FileType" DataField="type" HeaderText="类型" Width="80px" />
<f:RenderField ColumnID="FileSize" DataField="size" HeaderText="大小" Renderer="FileSize" Width="90px" />
<f:BoundField ColumnID='FileStatus' DataField="status" NullDisplayText="已完成" HeaderText="状态" Width="90px" />
<f:LinkButtonField Width="60px" ConfirmText="你确定要删除这个文件吗?" ConfirmTarget="Top" ToolTip="删除"
HeaderText="删除" CommandName="Delete" IconUrl="~/res/icon/delete.png" />
</Columns>
</f:Grid>
<br />
注:本多附件上传支持的浏览器版本为:Chrome、Firefox、Safari、IE10+ 。
</form>
<script src="res/webuploader/webuploader.nolog.min.js" type="text/javascript"></script>
<script type="text/javascript">
var btnDeleteClientID = '<%= btnDelete.ClientID %>';
var btnSelectFilesClientID = '<%= btnSelectFiles.ClientID %>';
var gridClientID = '<%= Grid1.ClientID %>';
var BASE_URL = '<%= ResolveUrl("~/") %>';
var SERVER_URL = BASE_URL + 'AttachFile/fileupload.ashx';
// sizeLimit 单个文件大小限制,单位为MB
function initUploader(gridId, pickerId, ownerId, accept, sizeLimit, success) {
var grid = F(gridId);
var uploaderOptions = {
// swf文件路径
swf: BASE_URL + 'AttachFile/res/webuploader/Uploader.swf',
// 文件接收服务端。
server: SERVER_URL,
// 选择文件的按钮。可选。
// 内部根据当前运行是创建,可能是input元素,也可能是flash.
pick: '#' + pickerId,
// 不压缩image, 默认如果是jpeg,文件上传前会压缩一把再上传!
resize: false,
// 自动上传
auto: true,
// 文件上传参数表,用来标记文件的所有者(如果是一篇文章的附件,就是文章的ID)
formData: {
owner: ownerId
},
// 单个文件大小限制(单位:byte),这里限制为 10M
fileSingleSizeLimit: sizeLimit * 1024 * 1024
};
if (accept) {
$.extend(uploaderOptions, {
accept: accept
});
}
var uploader = WebUploader.create(uploaderOptions);
// 添加到上传队列
uploader.on('fileQueued', function (file) {
grid.addNewRecord(file.id, {
'FileName': file.name,
'FileSize': file.size,
'FileStatus': '等待上传'
}, true);
});
uploader.on('uploadProgress', function (file, percentage) {
var cellEl = grid.getCellEl(file.id, 'FileStatus').find('.f-grid-cell-inner');
var barEl = cellEl.find('.ui-progressbar-value');
// 避免重复创建
if (!barEl.length) {
cellEl.html('<div class="ui-progressbar ui-widget ui-widget-content ui-corner-all" style="height:12px;">' +
'<div class="ui-progressbar-value ui-widget-header ui-corner-left" style="width:0%">' +
'</div></div>');
barEl = cellEl.find('.ui-progressbar-value');
}
barEl.css('width', percentage * 100 + '%');
});
uploader.on('uploadSuccess', function (file) {
var cellEl = grid.getCellEl(file.id, 'FileStatus').find('.f-grid-cell-inner');
cellEl.text('上传成功');
});
uploader.on('uploadError', function (file) {
var cellEl = grid.getCellEl(file.id, 'FileStatus').find('.f-grid-cell-inner');
cellEl.text('上传出错');
});
// 不管上传成功还是失败,都会触发 uploadComplete 事件
uploader.on('uploadComplete', function (file) {
uploader.removeFile(file, true);
});
// 所有文件上传成功
uploader.on('uploadFinished', function () {
if (success) {
success.call(uploader);
}
});
uploader.on('error', function (type, arg, file) {
if (type === 'F_EXCEED_SIZE') {
F.alert('文件[' + file.name + ']大小超出限制值(' + F.format.fileSize(arg) + '');
}
});
}
F.ready(function () {
if ('<%= FileType%>' == '1') {
initUploader(gridClientID, btnSelectFilesClientID, '<%= ParamStr%>', {
extensions: 'gif,jpg,jpeg,bmp,png',
mimeTypes: 'image/*'
}, 100, function () {
__doPostBack('', 'RebindGrid');
});
}
else if ('<%= FileType%>' == '2') {
initUploader(gridClientID, btnSelectFilesClientID, '<%= ParamStr%>', {
extensions: 'doc,docx',
mimeTypes: '.doc,.docx'
}, 100, function () {
__doPostBack('', 'RebindGrid');
});
}
else {
initUploader(gridClientID, btnSelectFilesClientID, '<%= ParamStr%>',
{
extensions: 'gif,jpg,jpeg,bmp,png,doc,docx,xls,xlsx,csv,ppt,pptx,pdf,txt,dwg,zip,rar,mp3,mp4,rm,rmvb,mpeg1-4,mov,mtv,dat,wmv,avi,3gp,amv,dmv ',
mimeTypes: '.gif,.jpg,.jpeg,.bmp,.png,.doc,.docx,.xls,.xlsx,.csv,.ppt,.pptx,.pdf,.txt,.dwg,.zip,.rar,.mp3,.mp4,.rm,.rmvb,.mpeg1-4,.mov,.mtv,.dat,.wmv,.avi,.3gp,.amv,.dmv'
}, 100, function () {
__doPostBack('', 'RebindGrid');
});
}
});
</script>
</body>
</html>
@@ -0,0 +1,414 @@
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
namespace FineUIPro.Web.AttachFile
{
public partial class webuploader : PageBase
{
public string ToKeyId
{
get
{
return (string)ViewState["ToKeyId"];
}
set
{
ViewState["ToKeyId"] = value;
}
}
public string AttachPath
{
get
{
return (string)ViewState["AttachPath"];
}
set
{
ViewState["AttachPath"] = value;
}
}
public string sessionName
{
get
{
return (string)ViewState["sessionName"];
}
set
{
ViewState["sessionName"] = value;
}
}
public string ParamStr
{
get
{
return (string)ViewState["ParamStr"];
}
set
{
ViewState["ParamStr"] = value;
}
}
public string FileType
{
get
{
return (string)ViewState["FileType"];
}
set
{
ViewState["FileType"] = value;
}
}
public string MenuId
{
get
{
return (string)ViewState["MenuId"];
}
set
{
ViewState["MenuId"] = value;
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
GetButtonPower(Request.QueryString["edit"]);
// 删除选中行
btnDelete.OnClientClick = Grid1.GetNoSelectionAlertReference("请至少选择一项!");
btnDelete.ConfirmText = String.Format("你确定要删除选中的&nbsp;<b><script>{0}</script></b>&nbsp;个文件吗?", Grid1.GetSelectedCountReference());
ToKeyId = Request.QueryString["toKeyId"];
AttachPath = Request.QueryString["path"];
MenuId = Request.QueryString["menuId"];
FileType = Request.QueryString["fileType"];
if (FileType == "1")
{
sessionName = "AttachFile.webuploader1";
}
else if (FileType == "2")
{
sessionName = "AttachFile.webuploader2";
}
else
{
sessionName = "AttachFile.webuploader3";
}
ParamStr = sessionName + "|" + AttachPath;
Session["AttachFile.webuploader1"] = null;
Session["AttachFile.webuploader2"] = null;
Session["AttachFile.webuploader3"] = null;
BindGrid();
}
else
{
if (GetRequestEventArgument() == "RebindGrid")
{
BindGrid();
}
}
}
#region BindGrid
private void BindGrid()
{
Grid1.DataSource = GetSourceData();
Grid1.DataBind();
}
#endregion
#region Events
protected void btnDelete_Click(object sender, EventArgs e)
{
foreach (string rowId in Grid1.SelectedRowIDArray)
{
DeleteRow(rowId);
}
BindGrid();
}
protected void Grid1_RowCommand(object sender, GridCommandEventArgs e)
{
if (e.CommandName == "Delete")
{
if (Request.QueryString["edit"] == "1")
{
DeleteRow(e.RowID);
BindGrid();
}
else
{
ShowNotify("您没有删除附件权限,请与管理员联系!");
}
}
if (e.CommandName == "Attach")
{
JArray source = GetSourceData();
for (int i = 0, count = source.Count; i < count; i++)
{
JObject item = source[i] as JObject;
if (item.Value<string>("id") == e.RowID)
{
try
{
string savedName = item.Value<string>("savedName");
string url = BLL.Funs.RootPath + AttachPath + "\\" + savedName;
FileInfo info = new FileInfo(url);
if (!info.Exists || string.IsNullOrEmpty(savedName))
{
url = BLL.Funs.RootPath + "Images//Null.jpg";
info = new FileInfo(url);
}
string fileName = Path.GetFileName(url);
long fileSize = info.Length;
System.Web.HttpContext.Current.Response.Clear();
System.Web.HttpContext.Current.Response.ContentType = "application/x-zip-compressed";
System.Web.HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
System.Web.HttpContext.Current.Response.AddHeader("Content-Length", fileSize.ToString());
System.Web.HttpContext.Current.Response.TransmitFile(url, 0, fileSize);
System.Web.HttpContext.Current.Response.Flush();
System.Web.HttpContext.Current.Response.Close();
}
catch (Exception)
{
}
}
}
}
}
#endregion
#region GetSourceData
private JArray GetSourceData()
{
if (Session[sessionName] == null)
{
var sour = from x in BLL.Funs.DB.AttachFile where x.ToKeyId == ToKeyId select x;
if (sour.Count() > 0)
{
Session[sessionName] = JArray.Parse(sour.First().AttachSource);
}
else
{
Session[sessionName] = new JArray();
}
}
return (JArray)Session[sessionName];
}
private void DeleteRow(string rowId)
{
JArray source = GetSourceData();
for (int i = 0, count = source.Count; i < count; i++)
{
JObject item = source[i] as JObject;
if (item.Value<string>("id") == rowId)
{
try
{
string savedName = item.Value<string>("savedName");
System.IO.File.Delete(Server.MapPath("~/" + AttachPath + "\\" + savedName));
}
catch (Exception)
{
// 尝试删除物理文件失败,不做处理
}
source.RemoveAt(i);
break;
}
}
Session[sessionName] = source;
}
#endregion
/// <summary>
/// 保存按钮事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnSave_Click(object sender, EventArgs e)
{
Model.EProjectDB db = Funs.DB;
JArray source = GetSourceData();
string attachUrl = string.Empty;
for (int i = 0, count = source.Count; i < count; i++)
{
JObject item = source[i] as JObject;
attachUrl += AttachPath + "\\" + item.Value<string>("savedName") + ",";
}
if (!string.IsNullOrEmpty(attachUrl))
{
attachUrl = attachUrl.Replace('/', '\\');
attachUrl = attachUrl.Substring(0, attachUrl.LastIndexOf(","));
}
var sour = from x in db.AttachFile where x.ToKeyId == ToKeyId select x;
if (sour.Count() == 0)
{
Model.AttachFile att = new Model.AttachFile();
att.ToKeyId = ToKeyId;
att.AttachSource = source.ToString();
att.AttachUrl = attachUrl;
att.MenuId = MenuId;
BLL.AttachFileService.AddAttachFile(att);
}
else
{
Model.AttachFile att = db.AttachFile.FirstOrDefault(x => x.AttachFileId == sour.First().AttachFileId);
if (att != null)
{
att.ToKeyId = ToKeyId;
att.AttachSource = source.ToString();
att.AttachUrl = attachUrl;
att.MenuId = MenuId;
BLL.AttachFileService.updateAttachFile(att);
}
}
ShowNotify("保存成功!");
}
#region
/// <summary>
/// 获取按钮权限
/// </summary>
/// <param name="button"></param>
/// <returns></returns>
private void GetButtonPower(string isEnabelEdit)
{
if (isEnabelEdit == "1")
{
toolBar1.Hidden = false;
}
else
{
toolBar1.Hidden = true;
}
}
#endregion
protected void btnChange_Click(object sender, EventArgs e)
{
//var law = from x in Funs.DB.Common_LawRegulation select x;
//foreach (var q in law)
//{
// InsertAttachFile(q.LawRegulationId, q.AttachUrl, "96DE448F-0629-40BC-2222-3E79686D3343");
//}
//var co = from x in Funs.DB.Common_ConstructionStandardList select x;
//foreach (var q in co)
//{
// InsertAttachFile(q.StandardId, q.AttachUrl, "46EE9F79-64CF-4BF4-2222-67E73B1ECB2F");
//}
//var edu = from x in Funs.DB.HSSE_Train_EduTrainType select x;
//foreach (var q in edu)
//{
// InsertAttachFile(q.EduTrainTypeCode, q.AttachUrl, "9D99A981-7380-4085-3333-8C3B1AFA6202");
//}
}
#region
/// <summary>
/// 多附件转化方法
/// </summary>
/// <param name="ID"></param>
/// <param name="attachUrl"></param>
private void InsertAttachFile(string ID, string attachUrl, string menuId)
{
if (!string.IsNullOrEmpty(attachUrl))
{
var att = Funs.DB.AttachFile.FirstOrDefault(x => x.ToKeyId == ID);
if (att == null)
{
Model.AttachFile newAttachFile = new Model.AttachFile();
newAttachFile.AttachFileId = SQLHelper.GetNewID(typeof(Model.AttachFile));
newAttachFile.ToKeyId = ID;
string attachSource = string.Empty;
int strInt = attachUrl.LastIndexOf("~");
if (strInt < 0)
{
strInt = attachUrl.LastIndexOf("\\");
}
string name = attachUrl.Substring(strInt + 1);
string type = attachUrl.Substring(attachUrl.LastIndexOf(".") + 1);
string savedName = attachUrl.Substring(attachUrl.LastIndexOf("\\") + 1);
string id = SQLHelper.GetNewID(typeof(Model.AttachFile));
attachSource = "[ { \"name\": \"" + name + "\", \"type\": \"" + type + "\", \"savedName\": \"" + savedName
+ "\", \"size\": 100, \"id\": \"" + SQLHelper.GetNewID(typeof(Model.AttachFile)) + "\" }]";
newAttachFile.AttachSource = attachSource;
if (menuId == "9D99A981-7380-4085-3333-8C3B1AFA6202")
{
newAttachFile.AttachUrl = attachUrl.Replace("\\File\\", "FileUpload\\HSSE\\");
}
else
{
newAttachFile.AttachUrl = attachUrl.Replace("\\Law\\", "\\Common\\");
}
newAttachFile.MenuId = menuId;
Funs.DB.AttachFile.InsertOnSubmit(newAttachFile);
Funs.DB.SubmitChanges();
}
else
{
if (string.IsNullOrEmpty(att.MenuId))
{
att.MenuId = menuId;
Funs.DB.SubmitChanges();
}
}
}
}
#endregion
}
}
@@ -0,0 +1,87 @@
//------------------------------------------------------------------------------
// <自动生成>
// 此代码由工具生成。
//
// 对此文件的更改可能导致不正确的行为,如果
// 重新生成代码,则所做更改将丢失。
// </自动生成>
//------------------------------------------------------------------------------
namespace FineUIPro.Web.AttachFile {
public partial class webuploader {
/// <summary>
/// form1 控件。
/// </summary>
/// <remarks>
/// 自动生成的字段。
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::System.Web.UI.HtmlControls.HtmlForm form1;
/// <summary>
/// PageManager1 控件。
/// </summary>
/// <remarks>
/// 自动生成的字段。
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.PageManager PageManager1;
/// <summary>
/// Grid1 控件。
/// </summary>
/// <remarks>
/// 自动生成的字段。
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.Grid Grid1;
/// <summary>
/// toolBar1 控件。
/// </summary>
/// <remarks>
/// 自动生成的字段。
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.Toolbar toolBar1;
/// <summary>
/// btnSelectFiles 控件。
/// </summary>
/// <remarks>
/// 自动生成的字段。
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.Button btnSelectFiles;
/// <summary>
/// btnDelete 控件。
/// </summary>
/// <remarks>
/// 自动生成的字段。
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.Button btnDelete;
/// <summary>
/// btnSave 控件。
/// </summary>
/// <remarks>
/// 自动生成的字段。
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.Button btnSave;
/// <summary>
/// Button1 控件。
/// </summary>
/// <remarks>
/// 自动生成的字段。
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.Button Button1;
}
}
@@ -0,0 +1,162 @@
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="webuploader2.aspx.cs" Inherits="FineUIPro.Web.AttachFile.webuploader2" %>
<!DOCTYPE html>
<html>
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<link href="../../res/css/common.css" rel="stylesheet" type="text/css" />
<meta name="sourcefiles" content="~/AttachFile/fileupload.ashx" />
<style>
.webuploader-element-invisible {
position: absolute !important;
clip: rect(1px,1px,1px,1px);
}
.webuploader-pick-disable {
opacity: 0.6;
pointer-events: none;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<f:PageManager ID="PageManager1" runat="server" />
<f:Grid ID="Grid1" runat="server" ShowHeader="false" ShowBorder="true" Title="文件上传"
Width="650px" Height="360px"
EnableCollapse="false" EnableCheckBoxSelect="false" EmptyText="尚未上传文件"
DataIDField="id" OnRowCommand="Grid1_RowCommand">
<Toolbars>
<f:Toolbar runat="server">
<Items>
<f:Button ID="btnSelectFiles" Text="选择文件上传" IconFont="Plus" runat="server" EnablePostBack="false">
</f:Button>
<f:ToolbarSeparator runat="server"></f:ToolbarSeparator>
<f:Button ID="btnDelete" Text="删除选中文件" IconFont="Remove" runat="server" OnClick="btnDelete_Click">
</f:Button>
<f:Button ID="btnSave" Text="保存" Icon="Add" runat="server" OnClick="btnSave_Click">
</f:Button>
</Items>
</f:Toolbar>
</Toolbars>
<Columns>
<f:LinkButtonField ColumnID="FileName" DataTextField="name" DataToolTipField="name" HeaderText="文件名" ExpandUnusedSpace="True" CommandName="Attach"/>
<f:BoundField ColumnID="FileType" DataField="type" HeaderText="类型" Width="80px" />
<f:RenderField ColumnID="FileSize" DataField="size" HeaderText="大小" Renderer="FileSize" Width="90px" />
<f:BoundField ColumnID='FileStatus' DataField="status" NullDisplayText="已完成" HeaderText="状态" Width="90px" />
<f:LinkButtonField Width="60px" ConfirmText="你确定要删除这个文件吗?" ConfirmTarget="Top" ToolTip="删除"
HeaderText="删除" CommandName="Delete" IconUrl="~/res/icon/delete.png" />
</Columns>
</f:Grid>
<br />
注:本多附件上传支持的浏览器版本为:Chrome、Firefox、Safari、IE10+ 。
</form>
<script src="res/webuploader/webuploader.nolog.js" type="text/javascript"></script>
<script type="text/javascript">
var btnDeleteClientID = '<%= btnDelete.ClientID %>';
var btnSelectFilesClientID = '<%= btnSelectFiles.ClientID %>';
var gridClientID = '<%= Grid1.ClientID %>';
var BASE_URL = '<%= ResolveUrl("~/") %>';
var SERVER_URL = BASE_URL + 'AttachFile/fileupload.ashx';
F.ready(function () {
var grid = F(gridClientID);
var uploader = WebUploader.create({
// swf文件路径
swf: BASE_URL + 'AttachFile/res/webuploader/Uploader.swf',
// 文件接收服务端。
server: SERVER_URL,
// 选择文件的按钮。可选。
// 内部根据当前运行是创建,可能是input元素,也可能是flash.
pick: '#' + btnSelectFilesClientID,
// 不压缩image, 默认如果是jpeg,文件上传前会压缩一把再上传!
resize: false,
// 自动上传
auto: true,
// 文件上传参数表,用来标记文件的所有者(如果是一篇文章的附件,就是文章的ID)
formData: {
owner: '<%= ParamStr%>'
},
// 单个文件大小限制(单位:byte),这里限制为 10M
fileSingleSizeLimit: 100 * 1024 * 1024
});
// 添加到上传队列
uploader.on('fileQueued', function (file) {
grid.addNewRecord(file.id, {
'FileName': file.name,
'FileType': file.ext,
'FileSize': file.size,
'FileStatus': '等待上传'
}, true);
});
uploader.on('uploadProgress', function (file, percentage) {
var cellEl = grid.getCellEl(file.id, 'FileStatus').find('.f-grid-cell-inner');
var barEl = cellEl.find('.ui-progressbar-value');
// 避免重复创建
if (!barEl.length) {
cellEl.html('<div class="ui-progressbar ui-widget ui-widget-content ui-corner-all" style="height:12px;">' +
'<div class="ui-progressbar-value ui-widget-header ui-corner-left" style="width:0%">' +
'</div></div>');
barEl = cellEl.find('.ui-progressbar-value');
}
barEl.css('width', percentage * 100 + '%');
});
uploader.on('uploadSuccess', function (file) {
var cellEl = grid.getCellEl(file.id, 'FileStatus').find('.f-grid-cell-inner');
cellEl.text('上传成功');
});
uploader.on('uploadError', function (file) {
var cellEl = grid.getCellEl(file.id, 'FileStatus').find('.f-grid-cell-inner');
cellEl.text('上传出错');
});
// 不管上传成功还是失败,都会触发 uploadComplete 事件
uploader.on('uploadComplete', function (file) {
uploader.removeFile(file, true);
});
// 当开始上传流程时触发
uploader.on('startUpload', function () {
// 禁用删除按钮
F(btnDeleteClientID).disable();
});
// 当所有文件上传结束时触发
uploader.on('uploadFinished', function () {
// 启用删除按钮
F(btnDeleteClientID).enable();
// 回发页面,重新绑定表格数据
__doPostBack('', 'RebindGrid');
});
uploader.on('error', function (type, arg, file) {
if (type === 'F_EXCEED_SIZE') {
F.alert('文件[' + file.name + ']大小超出限制值(' + F.format.fileSize(arg) + '');
}
});
});
</script>
</body>
</html>
@@ -0,0 +1,280 @@
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
namespace FineUIPro.Web.AttachFile
{
public partial class webuploader2 : PageBase
{
private static readonly string sessionName = "AttachFile.webuploader";
protected string ParamStr;
public string ToKeyId
{
get
{
return (string)ViewState["ToKeyId"];
}
set
{
ViewState["ToKeyId"] = value;
}
}
public string AttachPath
{
get
{
return (string)ViewState["AttachPath"];
}
set
{
ViewState["AttachPath"] = value;
}
}
public string MenuId
{
get
{
return (string)ViewState["MenuId"];
}
set
{
ViewState["MenuId"] = value;
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
// 删除选中行
btnDelete.OnClientClick = Grid1.GetNoSelectionAlertReference("请至少选择一项!");
btnDelete.ConfirmText = String.Format("你确定要删除选中的&nbsp;<b><script>{0}</script></b>&nbsp;个文件吗?", Grid1.GetSelectedCountReference());
Session[sessionName] = null;
ToKeyId = Request.QueryString["toKeyId"];
AttachPath = Request.QueryString["path"];
ParamStr = sessionName + "|" + AttachPath;
MenuId = Request.QueryString["menuId"];
BindGrid();
}
else
{
if (GetRequestEventArgument() == "RebindGrid")
{
BindGrid();
}
}
}
#region BindGrid
private void BindGrid()
{
Grid1.DataSource = GetSourceData();
Grid1.DataBind();
}
#endregion
#region Events
protected void btnDelete_Click(object sender, EventArgs e)
{
foreach (string rowId in Grid1.SelectedRowIDArray)
{
DeleteRow(rowId);
}
BindGrid();
}
protected void Grid1_RowCommand(object sender, GridCommandEventArgs e)
{
if (e.CommandName == "Delete")
{
DeleteRow(e.RowID);
BindGrid();
}
if (e.CommandName == "Attach")
{
JArray source = GetSourceData();
for (int i = 0, count = source.Count; i < count; i++)
{
JObject item = source[i] as JObject;
if (item.Value<string>("id") == e.RowID)
{
try
{
string savedName = item.Value<string>("savedName");
string url = BLL.Funs.RootPath + AttachPath + "\\" + savedName;
FileInfo info = new FileInfo(url);
if (!info.Exists || string.IsNullOrEmpty(savedName))
{
url = BLL.Funs.RootPath + "Images//Null.jpg";
info = new FileInfo(url);
}
string fileName = Path.GetFileName(url);
long fileSize = info.Length;
System.Web.HttpContext.Current.Response.Clear();
System.Web.HttpContext.Current.Response.ContentType = "application/x-zip-compressed";
System.Web.HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
System.Web.HttpContext.Current.Response.AddHeader("Content-Length", fileSize.ToString());
System.Web.HttpContext.Current.Response.TransmitFile(url, 0, fileSize);
System.Web.HttpContext.Current.Response.Flush();
System.Web.HttpContext.Current.Response.Close();
}
catch (Exception)
{
}
}
}
}
}
#endregion
#region GetSourceData
private JArray GetSourceData()
{
if (Session[sessionName] == null)
{
var sour = from x in BLL.Funs.DB.AttachFile where x.ToKeyId == ToKeyId select x;
if (sour.Count() > 0)
{
Session[sessionName] = JArray.Parse(sour.First().AttachSource);
}
else
{
Session[sessionName] = new JArray();
}
}
return (JArray)Session[sessionName];
}
private void DeleteRow(string rowId)
{
JArray source = GetSourceData();
for (int i = 0, count = source.Count; i < count; i++)
{
JObject item = source[i] as JObject;
if (item.Value<string>("id") == rowId)
{
try
{
string savedName = item.Value<string>("savedName");
System.IO.File.Delete(Server.MapPath("~/" + AttachPath + "\\" + savedName));
}
catch (Exception)
{
// 尝试删除物理文件失败,不做处理
}
source.RemoveAt(i);
break;
}
}
Session[sessionName] = source;
}
#endregion
/// <summary>
/// 保存按钮事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnSave_Click(object sender, EventArgs e)
{
Model.EProjectDB db = Funs.DB;
JArray source = GetSourceData();
string attachUrl = string.Empty;
for (int i = 0, count = source.Count; i < count; i++)
{
JObject item = source[i] as JObject;
attachUrl += AttachPath + "\\" + item.Value<string>("savedName") + ",";
}
if (!string.IsNullOrEmpty(attachUrl))
{
attachUrl = attachUrl.Replace('/', '\\');
attachUrl = attachUrl.Substring(0, attachUrl.LastIndexOf(","));
}
var sour = from x in db.AttachFile where x.ToKeyId == ToKeyId select x;
if (sour.Count() == 0)
{
Model.AttachFile att = new Model.AttachFile();
att.AttachFileId = BLL.SQLHelper.GetNewID(typeof(Model.AttachFile));
att.ToKeyId = ToKeyId;
att.AttachSource = source.ToString();
att.AttachUrl = attachUrl;
att.MenuId = MenuId;
db.AttachFile.InsertOnSubmit(att);
db.SubmitChanges();
}
else
{
Model.AttachFile att = db.AttachFile.FirstOrDefault(x => x.AttachFileId == sour.First().AttachFileId);
if (att != null)
{
att.ToKeyId = ToKeyId;
att.AttachSource = source.ToString();
att.AttachUrl = attachUrl;
att.MenuId = MenuId;
db.SubmitChanges();
}
}
ShowNotify("保存成功!");
}
#region
/// <summary>
/// 获取按钮权限
/// </summary>
/// <param name="button"></param>
/// <returns></returns>
private void GetButtonPower()
{
//var buttonList = BLL.CommonService.GetAllButtonList(this.CurrUser.UserId, MenuId);
//if (buttonList.Count > 0)
//{
// if (!buttonList.Contains(BLL.Const.BtnSave))
// {
// this.btnSelectFiles.Hidden = true;
// this.btnDelete.Hidden = true;
// this.btnSave.Hidden = true;
// }
//}
}
#endregion
}
}
@@ -0,0 +1,69 @@
//------------------------------------------------------------------------------
// <自动生成>
// 此代码由工具生成。
//
// 对此文件的更改可能导致不正确的行为,如果
// 重新生成代码,则所做更改将丢失。
// </自动生成>
//------------------------------------------------------------------------------
namespace FineUIPro.Web.AttachFile {
public partial class webuploader2 {
/// <summary>
/// form1 控件。
/// </summary>
/// <remarks>
/// 自动生成的字段。
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::System.Web.UI.HtmlControls.HtmlForm form1;
/// <summary>
/// PageManager1 控件。
/// </summary>
/// <remarks>
/// 自动生成的字段。
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.PageManager PageManager1;
/// <summary>
/// Grid1 控件。
/// </summary>
/// <remarks>
/// 自动生成的字段。
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.Grid Grid1;
/// <summary>
/// btnSelectFiles 控件。
/// </summary>
/// <remarks>
/// 自动生成的字段。
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.Button btnSelectFiles;
/// <summary>
/// btnDelete 控件。
/// </summary>
/// <remarks>
/// 自动生成的字段。
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.Button btnDelete;
/// <summary>
/// btnSave 控件。
/// </summary>
/// <remarks>
/// 自动生成的字段。
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.Button btnSave;
}
}