flash上传附件

// 引用JS
<script src= " ../../../Scripts/upload/jquery.uploadify.js " type= " text/javascript "></script>
    <script src= " ../../../Scripts/upload/jquery.uploadify.min.js " type= " text/javascript "></script>
    <script src= " ../../../Scripts/upload/swfobject.js " type= " text/javascript "></script>
    <link href= " ../../../Scripts/upload/uploadify.css " rel= " stylesheet " type= " text/css " />

// JS方法
<script type= " text/javascript ">
        $(document).ready(function () {
            $( " #uploadify ").uploadify({
                 ' uploader '' /Scripts/upload/uploadify.swf ',
                 ' script '' Uploads.ashx ',
                 ' scriptData ': {  ' lyh '' <%=Request.QueryString["lyh"] %> '' lc '' <%=Request.QueryString["lc"] %> '' HandlerType '' file ' },
                 ' method '' Get ',
                 ' cancelImg '' /Scripts/upload/cancel.png ',
                 ' buttonImg '' /Scripts/upload/uploadbtn.png ',
                 ' buttonText ''',
                 ' width '120,
                 ' height '28,
                 ' queueID '' fileQueue ',
                 ' auto 'false,
                 ' multi 'true,
                 ' queueSizeLimit '10,
                 ' simUploadLimit '1,
                 ' onInit ': function () {
                },
                 ' onSelect ': function (e, queueId, fileObj) {
                },
                 ' onComplete ': function ( event, queueId, fileObj, response, data) {
                     if (response ==  " null ") {
                        $.messager.alert( " 系统提示 "" 未选择需要上传的文件。 "" error ");
                    }  else  if (response ==  " error ") {
                        $.messager.alert( " 系统提示 "" 上传文件时发生错误。 "" 附件格式不对 ");
                    }  else {
                        $.messager.alert( " 系统提示 "" 上传成功 ");
                    }
                }
            });
        });

         // 获取附件信息
        function getAttachment() {
            $.ajax({
                type:  " GET ",
                dataType:  " text ",
                 asyncfalse,
                url:  ' <%=ResolveUrl("/Ajax/Common/Attachment.ashx")%> ',
                data:  " HandlerType=getequipment&lyh= " +  ' <%=Request.QueryString["lyh"] %> ' +  " &lc= " +  ' <%=Request.QueryString["lc"] %> ' +  " &rand= " + newCommon.atrand( 10000000),
                success: function (msg) {
                     var table =  "";
                     if (msg !=  "") {
                        table =  " <table class='list' style='width:460px; margin-top:10px;margin-bottom:10px; margin-left:10px'> ";
                        table +=  " <thead> ";
                        table +=  " <tr style='height:28px;'> ";
                        table +=  " <th align='left' style='border-left:1px solid #5f89c6'>&nbsp;&nbsp;楼宇号</th> ";
                        table +=  " <th align='center' style='width:15%'>楼层</th> ";
                        table +=  " <th align='center' style='width:15%;'>上传上传人</th> ";
                        table +=  " <th style='width:20%;' align='center'>操作</th> ";
                        table +=  " </tr> ";
                        table +=  " </thead> ";
                        table +=  " <tbody> ";
                         var info = msg.split( ' | ');
                         for ( var i =  0; i < info.length; i++) {
                             var name = info[i].split( ' , ');
                            table +=  " <tr style='height:28px;'><td align='left' style='border-left:1px solid #5f89c6'>&nbsp;&nbsp; " + name[ 1] +  " </td> ";
                            table +=  " <td align='center'>&nbsp;&nbsp; " + name[ 2] +  " </td> ";
                            table +=  " <td align='center'>&nbsp;&nbsp; " + name[ 3] +  " </td> ";
                            table +=  " <td align='center'><a class='abtn2' style='cursor:pointer; width:40px' href='/Ajax/Common/Attachment.ashx?HandlerType=download&id= " + name[ 0] +  " ' target='frm'>下载</a> ";
                            table +=  " &nbsp;&nbsp;&nbsp;<a class='abtn2' style='cursor:pointer; width:40px' οnclick='deldata(\" " + name[ 0] +  " \")'>删除</a> ";
                            table +=  " </td></tr> ";
                        }
                        table +=  " </tbody> ";
                        table +=  " </table> ";
                    }
                    $( " #divattachment ").html(table);
                }
            });
        }

         // 删除
        function deldata(attid) {
            $.messager.confirm( ' 系统提示 '' 确定要删除该附件 ', function (r) {
                 if (r) {
                    $.ajax({
                        type:  " GET ",
                        dataType:  " json ",
                         asyncfalse,
                        url:  ' <%=ResolveUrl("../../../Ajax/Common/Attachment.ashx")%> ',
                        data:  " HandlerType=delattinfo&id= " + attid +  " &rand= " + newCommon.atrand( 10000000),
                        success: function (data) {
                             if (data.State ==  " 1 ")
                                getAttachment();
                             else
                                $.messager.alert( " 系统提示 ", data.Message,  " error ");
                        }
                    });
                }
            });
        }
    </script>


// HTML代码
// 显示进度条
<div style= " padding: 1px; ">
        <div id= " fileQueue ">
        </div>
    </div>
    <table cellpadding= " 0 " cellspacing= " 0 ">
        <tr>
            <td style= " border: 0px; ">
                <input type= " file " name= " uploadify " id= " uploadify " />
            </td>
            <td style= " border: 0px; ">
                <a id= " btnUpload " plain= " true "  class= " easyui-linkbutton " iconcls= " icon-ok " οnclick= "  javascript:$('#uploadify').uploadifyUpload();  ">
                    上传文件</a>
            </td>
            <td style= " border: 0px; ">
                <a id= " btnCancle " plain= " true "  class= " easyui-linkbutton " iconcls= " icon-cancel " οnclick= "  javascript:$('#uploadify').uploadifyClearQueue();  ">
                    取消上传</a>
            </td>
        </tr>
    </table>
// 显示附件列表
    <div id= " divattachment ">
    </div>



// 一般处理程序代码

public  override  void OnRequest(HttpContext context)
        {
            context.Response.ContentType =  " text/plain ";
             string HandleType = context.Request[ " HandlerType "].ToLower();
             switch (HandleType)
            {
                 case  " file "// 获取自定义树形结构
                    GetFIle(context);
                     break;
            }
        }

         #region 获取设备树
         ///   <summary>
        
///  附件处理
        
///   </summary>
        
///   <param name="context"></param>
        
///   <returns></returns>
         private  void GetFIle(HttpContext context)
        {
            Mes oMes =  new Mes();
            context.Response.ContentType =  " text/plain ";
             try
            {
                 string basePath = Hzjg.Common.Config.ConfigManage.fGetAppConfig( " SaveFilePath ");
                HttpPostedFile file = context.Request.Files[ " FileData "];
                 string extension = Path.GetExtension(file.FileName).ToUpper();
                 if (extension !=  " .PDF " && extension !=  " .PNG " && extension !=  " .GIF " && extension !=  " .JPEG " && extension !=  " .JPG ")
                {
                    context.Response.Write( " 格式不对 ");
                }
                 else
                {

                     if (file !=  null)
                    {
                         #region 执行文件上传
                         string documentPath =  @" \files\ " + context.Request[ " lyh "] +  @" \消防设备图纸\ ";
                         if (!Directory.Exists(basePath + documentPath))
                            Directory.CreateDirectory(basePath + documentPath);
                         if (!File.Exists(basePath + documentPath))
                        {
                            file.SaveAs(basePath + documentPath + file.FileName);
                            Model.LOGISTICS_BUILDINGEQUIPMENTPIC model =  new Model.LOGISTICS_BUILDINGEQUIPMENTPIC();
                            model = cBll.GetList( "  where t.LYH=' " + context.Request[ " lyh "] +  " ' and t.LC=' " + context.Request[ " lc "] +  " ' """).FirstOrDefault();
                             if (model !=  null)
                            {
                                model.PICTUREPATH = documentPath.Replace( " \\ "" / ") + file.FileName;
                                oMes =  new BLL.LOGISTICS_BUILDINGEQUIPMENTPIC().Update(model);
                            }
                             else
                            {
                                model =  new Model.LOGISTICS_BUILDINGEQUIPMENTPIC();
                                model.ID = Guid.NewGuid().ToString();
                                model.LYH = context.Request[ " lyh "];
                                model.LC =  decimal.Parse(context.Request[ " lc "]);
                                model.PICTUREPATH = documentPath.Replace( " \\ "" / ") + file.FileName;
                                model.INPUTTIME = DateTime.Now;
                                model.INPUTCODE = JG.Base.Portal.AppCode.Data.CurrentUserInfo.UserCode;
                                oMes =  new BLL.LOGISTICS_BUILDINGEQUIPMENTPIC().Add(model);
                            }
                        }
                         #endregion
                    }
                }
            }
             catch (Exception ex)
            {
                Hzjg.Common.Utility.Log.fWriterLog( " 上传发文附件异常: " + ex.Message, ex);
            }
            context.Response.Write( " Succeed ");
        }

         #endregion

转载于:https://www.cnblogs.com/zecVip/p/4506441.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值