<table border="0" cellpadding="0" cellspacing="0" class="panel_tb"> <tr> <td class="left1"> 标题: </td> <td class="left2"> <input type="text" runat="server" style="width: 98%" id='txt_PMD_Title' /> </td> </tr> <tr> <td class="left1"> 密码: </td> <td class="left2"> <asp:TextBox ID="txt_PM_Password" CssClass="large_box" TextMode="Password" runat="server" Style="width: 90%"></asp:TextBox> <asp:RequiredFieldValidator ID="rfv_txt_PM_Password" runat="server" ControlToValidate="txt_PM_Password" ErrorMessage="*"></asp:RequiredFieldValidator> </td> </tr> <tr> <td class="left1"> 关键词: </td> <td class="left2"> <input type="text" runat="server" style="width: 70%" id='txt_PMD_Keyword' /> <font color="red">(*请用英文逗号分割关键词)</font> </td> </tr> <tr> <td colspan="2"> <asp:HiddenField runat="server" ID="hidProdcutModelDetailID" /> <asp:HiddenField runat="server" ID="hidDetailTypeID" Value='<%=PMDTypeID%>' /> <textarea runat="server" name="txt_PMD_Contents" style="width: 100%; padding: 4px;" rows="15" id='txt_PMD_Contents'></textarea> </td> </tr> <tr> <td class="left1"> 附件上传: </td> <td class="left2" colspan="3"> <div id="fileQueue"> </div> <input type="file" name='uploadify' id='uploadify_<%=PMDTypeID%>' /> <input type="button" id='uploadsubmit' name="uploadsubmit" class="uploadify-button" value="上传" onclick='upload(uploadify_<%=PMDTypeID%>)' style="width: 80px; height: 25px; border: none; cursor: pointer;" /> </td> </tr> <tr> <td class="left1"> 已上传附件列表: </td> <td class="left2" colspan="3"> <div class="tb_upload"> <table id='tb_upload_<%=PMDTypeID%>' cellpadding="0" cellspacing="0"> <tr> <th> 名称 </th> <th> 操作 </th> </tr> </table> </div> </td> </tr> </table>
JS
<script type="text/javascript"> // <!---------------------富文本编辑器相关------------------------------begin----------> KindEditor.ready(function (K) { window.onload = function () { $.each($("input[id^='uploadify_']"), function (i, row) { var item_uploadify = $(this); var _sametable = item_uploadify.parent().parent().parent(); var PMD_Contents = _sametable.find("textarea[id$='txt_PMD_Contents']"); editor3 = K.create(PMD_Contents); init_uploadify(item_uploadify); }); } }); // <!---------------------附件上传相关------------------------------begin----------> var _InfoID = '<%=ParentInfoID%>'; var _UserID = $("#hid_CreateUserID").val(); var _EngineeringType = '<%=EngineeringType%>'; $.each($("table[id^='tb_upload_']"), function (i, row) { var _table = $(this); var id_table = _table[0].id; var _tb = id_table.substring(id_table.length - (id_table.indexOf("tb_upload_") + 1)); $.getJSON('/Ajax/uploadify.ashx', { actiontype: 'list', IsMultiple: 1, EngineeringType: _EngineeringType, tb: _tb, id: _InfoID, IsOnlyContract: _IsOnlyContract, r: Math.random() }, function (data) { _table.find("tr").remove(); var edit = ''; if (data) { _table.append("<tr><th>名称</th> <th>上传日期</th><th>创建人</th>" + (_IsShow ? "<th>操作</th>" : "") + "</tr>"); $.each(data, function (i, row) { edit = '<tr><td class="left1"><a href="/SystemManage/UploadFiles/DownLoad.aspx?id=' + row.FileID + '" title="' + row.FileName + '" target="_blank" >' + row.FileName + '</a></td>'; edit += ' <td class="left2">' + JSONTOstring(row.UploadTime) + '</td><td class="left2">' + row.UploadUserName + '</td>' if (_IsShow) { edit += '<td class="left2"><span style="color:red"> <a href="javascript:;" οnclick="return delInfo(\'' + row.FileID + '\',\'' + row.FileType + '\')" >删除</a> </span></td></tr>'; } edit += '</tr>'; _table.append(edit); }); } }); }); //确定保存 function showMessage(message, isRefresh) { if (isRefresh) { art.dialog.tips(message, 2).lock(); var win = art.dialog.open.origin; //来源页面 if (win) { art.dialog.close(); win.reRefresh(); } } else { art.dialog.tips(message, 2).lock(); } } </script>
MultipleUploadify.js
var _IsShow = true; //是否显示操作 var _IsContract = false; //是否上传合同 var _IsOnlyContract = false; //是否仅显示合同 var _IsFirstUpload = false; //是否第一次上传 var _tablelistid = ""; //对应表格ID var _tb = ""; //对应附件类型 $(document).ready(function () { //清除cookies $.post('/Ajax/uploadify.ashx', { actiontype: 'clearcookies' }); }); //附件上传初始化 //window.onload = function () { function init_uploadify(item_uploadify) { item_uploadify.uploadify({ 'swf': '/Scripts/uploadify/uploadify.swf?var=' + (new Date()).getTime(), 'uploader': '/Ajax/uploadify.ashx', 'debug': false, 'queueSizeLimit ': 5, 'auto': false, //选中文件后,自动上传 'multi': true, //允许上传多个文件 'fileTypeExts': '*', 'fileSizeLimit': '100MB', 'buttonText': '选择', 'method': 'get', 'progressData': 'percentage', 'width': 127, 'height': 30, 'onUploadSuccess': function (file, data, response) { if (data && parseInt(data) > 0) { $.post('/Ajax/uploadify.ashx', { actiontype: 'filecookies', id: data }, function (data) { _IsFirstUpload = true; MultipleFilelist(); art.dialog.tips('上传成功'); }); //更新cookies } else if (_InfoID && data == "True") { _IsFirstUpload = true; MultipleFilelist(); art.dialog.tips('上传成功', 2); } else { art.dialog.tips('上传失败', 2); } }, 'onUploadError': function (file, errorCode, errorMsg) { art.dialog.tips(errorMsg, 3); } }); } //} //上传附件 function upload(id_uploadify) { var item_uploadify = $(id_uploadify); var _sametable = item_uploadify.parent().parent().parent(); _tablelistid = _sametable.find("table[id^='tb_upload_']"); var id_table = _tablelistid[0].id; _tb = id_table.substring(id_table.length - (id_table.indexOf("tb_upload_") + 1)); if (_InfoID) { $(item_uploadify).uploadify("settings", 'uploader', '/Ajax/uploadify.ashx?actiontype=MultipleAddFileByID&EngineeringType=' + _EngineeringType + '&tb=' + _tb + '&id=' + _InfoID + '&UserID=' + _UserID); } else { $(item_uploadify).uploadify("settings", 'uploader', '/Ajax/uploadify.ashx?actiontype=addfile&UserID=' + _UserID + '&EngineeringType=' + _EngineeringType + '&tb=' + _tb); } $(item_uploadify).uploadify("upload", "*"); } //附件列表 function MultipleFilelist() { if (_InfoID != '0') _IsFirstUpload = false; if (!_IsFirstUpload) { $.getJSON('/Ajax/uploadify.ashx', { actiontype: 'list', IsMultiple: 1, EngineeringType: _EngineeringType, tb: _tb, id: _InfoID, IsOnlyContract: _IsOnlyContract, r: Math.random() }, function (data) { _tablelistid.find("tr").remove(); var edit = ''; if (data) { _tablelistid.append("<tr><th>名称</th> <th>上传日期</th><th>创建人</th>" + (_IsShow ? "<th>操作</th>" : "") + "</tr>"); $.each(data, function (i, row) { edit = '<tr><td class="left1"><a href="/SystemManage/UploadFiles/DownLoad.aspx?id=' + row.FileID + '" title="' + row.FileName + '" target="_blank" >' + row.FileName + '</a></td>'; edit += ' <td class="left2">' + JSONTOstring(row.UploadTime) + '</td><td class="left2">' + row.UploadUserName + '</td>' if (_IsShow) { edit += '<td class="left2"><span style="color:red"> <a href="javascript:;" οnclick="return delInfo(\'' + row.FileID + '\',\'' + row.SrcName + '\')" >删除</a> </span></td></tr>'; } edit += '</tr>'; _tablelistid.append(edit); }); } }); } else { $.getJSON('/Ajax/uploadify.ashx', { actiontype: 'listbycookies', tb: _tb, r: Math.random() }, function (data) { _tablelistid.find("tr").remove(); var edit = ''; if (data) { _tablelistid.append("<tr><th>名称</th> <th>上传日期</th><th>创建人</th>" + (_IsShow ? "<th>操作</th>" : "") + "</tr>"); $.each(data, function (i, row) { edit = '<tr><td class="left1"><a href="/SystemManage/UploadFiles/DownLoad.aspx?id=' + row.FileID + '" title="' + row.FileName + '" target="_blank" >' + row.FileName + '</a></td>' + ' <td class="left2">' + JSONTOstring(row.UploadTime) + '</td><td class="left2">' + row.UploadUserName + '</td>' + '<td class="left2"><span style="color:red"> <a href="javascript:;" οnclick="return delInfo(\'' + row.FileID + '\',\'' + row.FileType + '\')" >删除</a> </span></td></tr>'; _tablelistid.append(edit); }); } }); } } //删除附件(获取要删除的表格刷新) function delInfo(idlist, FileType) { _tablelistid = $("#tb_upload_" + FileType + ""); art.dialog.confirm('您确认删除操作?', function () { $.post('/Ajax/uploadify.ashx', { actiontype: 'delete', id: idlist }, function (msg) { if (msg == "True") { art.dialog.tips('删除成功'); } else { art.dialog.tips('删除失败').lock(); } _tb = FileType; MultipleFilelist(); }, "text"); }, function () { art.dialog.tips('您取消了操作'); }); } //转化时间 function JSONTOstring(jsondate) { if (!jsondate) return ""; var date = new Date(parseInt(jsondate.replace("/Date(", "").replace(")/", ""), 10)); var year = date.getFullYear(); var month = date.getMonth() + 1; var day = date.getDate(); return year + "-" + month + "-" + day; }
后台处理ashx
//要绑定的信息id string tb = context.Request["tb"]; if (string.IsNullOrEmpty(tb)) return; //要绑定的信息id string id = context.Request["id"]; if (string.IsNullOrEmpty(id)) return; //附件 HttpPostedFile file = context.Request.Files["Filedata"]; if (file == null) { return; } //操作人id int UserID = Convert.ToInt32(context.Request["UserID"]); if (UserID < 1) { return; } ///工程资料类型 string EngineeringType = context.Request["EngineeringType"]; context.Response.Charset = "utf-8"; context.Response.Write(AddFile(file, UserID, id, tb, EngineeringType, true));
/// <summary> /// 信息编辑时,上传附件 /// </summary> /// <param name="file"></param> /// <param name="UserID"></param> /// <param name="infoid"></param> /// <param name="tb"></param> /// <param name="srcname"></param> /// <param name="IsMultiple">是否页面内多上传控件</param> /// <returns></returns> private int AddFile(HttpPostedFile file, int UserID, string infoid, string tb, string srcname, bool IsMultiple) { if (file != null && !string.IsNullOrEmpty(file.FileName)) { //上传图片 string FilePath = "/UploadFiles/"; string strFileName = System.IO.Path.GetFileName(file.FileName); string strNewName = bell0769.Common.StringPlus.GetKEY("File_"); string FileName = strFileName.Substring(0, strFileName.IndexOf(".")) + ""; string FileType = System.IO.Path.GetExtension(strFileName); Double FileSize = file.ContentLength / 1024; string strFileSize = string.Empty; if (FileSize > 1024) { strFileSize = (FileSize / 1024).ToString() + "MB"; } else { strFileSize = FileSize.ToString() + "KB"; } string strFileSavePath = FilePath + strNewName + FileType; string strFilePathAndName = System.Web.HttpContext.Current.Server.MapPath(strFileSavePath); while (System.IO.File.Exists(strFilePathAndName)) { strNewName = bell0769.Common.StringPlus.GetKEY("File_"); strFileSavePath = FilePath + strNewName + FileType; strFilePathAndName = System.Web.HttpContext.Current.Server.MapPath(strFileSavePath); } string strFile = System.Web.HttpContext.Current.Server.MapPath(FilePath + strNewName + FileType);//原图 file.SaveAs(strFile); //添加数据 Bms_UploadFilesModel info = new Bms_UploadFilesModel(); info.FileExt = FileType; info.FileName = strFileName; info.FilePath = strFileSavePath; info.FileSize = strFileSize; info.FileCode = strNewName; info.UploadUser = UserID; info.UploadUserName = new Bms_UserInfoBLL().Get(UserID).UserName; info.DataKey = infoid; ///上传附件类型 if (!IsMultiple) info.FileType = CommonBLL.GetOperateInfoID(tb); else info.FileType = int.Parse(string.IsNullOrEmpty(tb) ? "-97" : tb); info.SrcName = srcname;//(附件、合同) 或(工程资料类型) int id = new Bms_UploadFilesBLL().Create(info, UserID); return id; } else { return 0; } }