• 上传文件


    一.页面数据

    @using System.Data
    @using Adf.App.Interface.Entity
    @using Adf.App.Service.Service
    @using Adf.Core.Database
    @using Adf.Core.Util
    @using Adf.Core.Web
    @{
        /****************系统定义 开始 **************************/
        Layout = "~/Views/Shared/AdminDefaultLayout.cshtml";

        //相关属性
        User sysUserLoginInfo = ViewBag.GlobalUserLoginInfo;
        Module sysCurrentModuleInfo = ViewBag.GlobalModule;
        String curShowType = ViewBag.ShowType;
        String curDoCmd = ViewBag.DoCmd;


        String curControlName = "/manage/basemodule";
        //功能点
        String curMainSysFuncId = "PaOAsspExecuteContractFile";
        //curControlName = StringHelper.SubString(curControlName, "?");
        RoleModuleParam sysRoleModuleParam = new RoleModuleParam();
        //数据源集合

        //详细页数据集
        DataTable curMainDetailEntity = null;

        //列表页数据集编码
        String curListDsCode = "dsPaOAContractFileList";
        /**自定义部分 -- 开始 --*/

        if (curShowType == "detail")
        {
            String dsCode = curListDsCode;
            String strWhere = "ContractFilesCode='" + RequestHelper.GetQueryString("ContractFilesCode") + "'";
            String strOrderBy = "";
            curMainDetailEntity = AppService.Instance().SysDataset().QueryDataTable(dsCode, "", strWhere, strOrderBy, 1);

        }

        /**自定义部分 -- 结束 --*/

    }
    @section ScriptMain
    {
        @{
            if (curShowType == "list")
            {
            <script type="text/javascript">

                //var sysExecuteUrl = "";


                $(document).ready(function () {

                    //定义行点击获取记录集数据
                    $("#myData tbody tr").live('click', function (e) {//得到选中行
                        //获取点击当前行
                        var aData = oTable.fnGetData(this); //得到选中行的数据
                        if (null != aData) {
                            rowDataInfo = aData;
                        }
                    });

                    //定义全选以及反选事件
                    $("#cbSel").click(function () {
                        if ($("#cbSel").attr("checked") == true) {
                            setFormSelect("", "cblInfo", 1);
                        } else {
                            setFormSelect("", "cblInfo", 2);
                        }

                    });

                    /****定义表格显示部门**/

                    //step 定义表格显示列
                    var columns = [
               {
                   "sName": "ContractFilesCode", "sTitle": "<input type='checkbox' name='cbSel' id='cbSel' value='1'  />选择", "mDataProp": "ContractFilesCode", "sWidth": "50", "mRender": function (data, type, row) {
                       return "<input type='checkbox' name='cblInfo' value='" + data + "' />";
                   }
               }
               , { "sName": "FilesDate", "sTitle": "档案日期", "sWidth": "100", "mDataProp": "FilesDate" }
               , { "sName": "HouseCode", "sTitle": "房源地址", "sWidth": "100", "mDataProp": "HouseCode" }
               , { "sName": "UserName", "sTitle": "提交人", "sWidth": "100", "mDataProp": "UserName" }
               , { "sName": "FilesName", "sTitle": "文件名称", "sWidth": "100", "mDataProp": "FilesName" }
               , { "sName": "FilesRoad", "sTitle": "附件下载", "sWidth": "", "mDataProp": "FilesRoad", "mRender": function (data, type, row) {
                   if (data == "") {
                       return "未上传";
                   } else {
                       return "<a href='" + data + "'>附件</a>";
                   }
               }
               }
               , { "sName": "IsCheck", "sTitle": "审核状态", "sWidth": "", "mDataProp": "IsCheck", "mRender": function (data, type, row) {
                   if (data == '') {
                       return "未审核";
                   } else if (data == '未审核') {
                       return "未审核";
                   } else if (data == null) {
                       return "未审核";
                   } else {
                       return "已审核";
                   }
               }
               }
               ];

                    //step 显示数据
                    var strWhere = " where 1=1";
                    var strOrderby = " InfoId desc";
                    var strModuleCode = "@sysCurrentModuleInfo.ModuleCode";
                    var strDs = "@curListDsCode";

                    ShowGridForBaseModule("myData", columns, strModuleCode, strDs, strWhere, strOrderby);

                    /***定义操作按钮事件**/

                    //增加
                    $("#btnAdd").click(function () {
                        var sUrl = "@curControlName/index?showtype=detail&doCmd=add&mc=@sysCurrentModuleInfo.ModuleCode";
                        goUrl(sUrl);
                    });

                    //修改
                    $("#btnModify").click(function () {
                        if (getCheckboxLength("cblInfo") != 1) {
                            alert('修改时请选择一条记录.');
                            return;
                        }
                        var infoCode = getCheckboxFirstValue("cblInfo");
                        var sUrl = "@curControlName/index?showtype=detail&doCmd=modify&mc=@sysCurrentModuleInfo.ModuleCode&ContractFilesCode=" + infoCode;
                        goUrl(sUrl);
                    });
                    //删除
                    $("#btnDelete").click(function () {
                        if (getCheckboxLength("cblInfo") != 1) {
                            alert('请选择一条记录.');
                            return false;
                        }
                        if (confirm("确认要删除吗?") == false) {
                            return false;
                        }
                        var infoCode = getCheckboxFirstValue("cblInfo");
                        var sUrl = "@curControlName/ExecutePost";
                        var sParam = {
                            Action: "delete",
                            ContractFilesCode: infoCode,
                            SysFuncId: "@curMainSysFuncId"
                        };
                        var retData = sysDoAjaxPost(sUrl, sParam);
                        alert(retData.RetValue);
                        if (retData.RetStatus = 100) {
                            DefaultGridRefresh();
                        }
                    });
                    $("#btnRfresh").click(function () {
                        DefaultGridRefresh();
                    });
                });
            </script>
                   

            }

            if (curShowType == "detail")
            {
            <script type="text/javascript">
                $(document).ready(function () {
                    //设置表格样式
                    setTableTrBgColor('myTable', "even", "old");

                    //保存
                    $("#btnSave").click(function () {
                        var doAction = "@curDoCmd";
                        SetHiddenInputValue("curForm", "Action", "@curDoCmd");
                        SetHiddenInputValue("curForm", "ContractFilesCode", "@DbService.DtV(curMainDetailEntity, "ContractFilesCode")");
                        SetHiddenInputValue("curForm", "SysFuncId", "@curMainSysFuncId");
                        var retInfo = doSubmitForm("curForm", "@curControlName/executepost");
                        alert(retInfo.RetValue);
                        if (retInfo.RetStatus == 101) {
                            goUrl("@Html.Raw(RequestHelper.GetUrlReferrer())");
                        } else if (retInfo.RetStatus == 100) {

                        }
                    });

                    //返回
                    $("#btnReturn").click(function () {
                        goUrl("@Html.Raw(RequestHelper.GetUrlReferrer())");
                    });

                });
                
                 //上传文件

                function DoUploadFile2(ctrlId) {
                    var newFile = window.showModalDialog("/Res/Upload/UploadFiles.aspx","newWin", "dialogWidth:420px; dialogHeight:100px;status:no;help:yes");
                    //alert(newFile);
                    if   (typeof(SomeVar) == 'undefined ')
                    {
                        newFile = "";
                    }
                    var objCtrl = document.getElementById(ctrlId);
                    objCtrl.value = newFile;
                    return false;
                }
            </script>

            }


        }
    }
    @section tbMainToolBar
    {
        <div class="buttons">
            @{
                //列表页功能定义
                if (curShowType == "list")
                {
                    if (PermissionService.HasParamValue(ViewBag.RoleModuleParams, "add", "1", ref sysRoleModuleParam))
                    {
                @UIHelper.SetButton(sysRoleModuleParam.ParamCode, sysRoleModuleParam.ParamName);
                    }
                    if (PermissionService.HasParamValue(ViewBag.RoleModuleParams, "modify", "1", ref sysRoleModuleParam))
                    {
                @UIHelper.SetButton(sysRoleModuleParam.ParamCode, sysRoleModuleParam.ParamName);
                    }
                    if (PermissionService.HasParamValue(ViewBag.RoleModuleParams, "delete", "1", ref sysRoleModuleParam))
                    {
                @UIHelper.SetButton(sysRoleModuleParam.ParamCode, sysRoleModuleParam.ParamName);
                    }


                @UIHelper.SetButton("Rfresh", "刷 新");
                }

                //详细页功能定义
                if (curShowType == "detail")
                {
                <button type="button" class="positive" name="btnSave" id="btnSave">
                    保 存
                </button>
                    <button type="button" class="positive" name="btnReturn" id="btnReturn">
                        返 回
                    </button>
               
                }
            }
        </div>
    }
    @section tbMainCondition
    {
        @{
            if (curShowType == "list")
            {

            }
        }
    }
    @section tbMain
    {
        @{
            //列表页
            if (curShowType == "list")
            {
            <table id="myData" class="display">
            </table>
            }

            //详细页
            if (curShowType == "detail")
            {
            <form id="curForm" action="" method="post">
            <table id="myTable" class="detailTable">
                <tr>
                    <td class="fieldCaption">
                        房源地址:
                    </td>
                    <td>
                        @StringHelper.ToMvcString(HtmlControlHelper.GetText("HouseCode", DbService.DtV(curMainDetailEntity, "HouseCode"), 40, false, false))
                    </td>
                </tr>
                <tr>
                    <td class="fieldCaption">
                        合同编号:
                    </td>
                    <td>
                        @StringHelper.ToMvcString(HtmlControlHelper.GetText("ContractCode", DbService.DtV(curMainDetailEntity, "ContractCode"), 40, false, false))
                    </td>
                </tr>
                <tr>
                    <td class="fieldCaption">
                        文件名称:
                    </td>
                    <td>
                        @StringHelper.ToMvcString(HtmlControlHelper.GetText("FilesName", DbService.DtV(curMainDetailEntity, "FilesName"), 40, false, false))
                    </td>
                </tr>
                <tr>
                    <td class="fieldCaption">
                        上传附件:
                    </td>
                    <td>
                        @StringHelper.ToMvcString(HtmlControlHelper.GetText("FilesRoad", DbService.DtV(curMainDetailEntity, "FilesRoad"), 40, false, false))
                        <a href="javascript:void(0);" onclick="DoUploadFile2('FilesRoad');"class="toolMenu">上传</a>
                    </td>
                </tr>
                <tr>
                    <td class="fieldCaption">
                        文件日期:
                    </td>
                    <td>
                        @StringHelper.ToMvcString(HtmlControlHelper.GetDateTime("FilesDate", DbService.DtV(curMainDetailEntity, "FilesDate"), "", ""))
                    </td>
                </tr>
              
                <tr>
                    <td class="fieldCaption">
                        提交人:
                    </td>
                    @if(curDoCmd=="add")
                    {
                        <td>
                            @StringHelper.ToMvcString(HtmlControlHelper.GetText("UserName", sysUserLoginInfo.UserName, 40, false, false))
                        </td>
                    }
                    else
                    {
                        <td>
                            @StringHelper.ToMvcString(HtmlControlHelper.GetText("UserName", DbService.DtV(curMainDetailEntity, "UserName"), 40, false, false))
                        </td>
                    }
                   
                </tr>
                <tr>
                    @if(curDoCmd=="modify")
                    {
                    <td class="fieldCaption">
                        审核:
                    </td>
                    <td>
                                @StringHelper.ToMvcString(HtmlControlHelper.GetDropDownList("IsCheck", DbService.DtV(curMainDetailEntity, "IsCheck"), "", "未审核|已审核", "未审核|已审核"))
                    </td>
                    }
                   
                </tr>
            </table>

            </form>

            }
        }
    }
    @section tbMemo
    {
        @{
            //列表页
            if (curShowType == "list")
            {

            }

            //详细页
            if (curShowType == "detail")
            {

            } 
           

           
       
        }
    }

    二.调用页面

    a.UploadFiles.aspx

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="UploadFiles.aspx.cs" Inherits="AgileCorp.AppWeb.Res.Upload.UploadFiles" %>


    <!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 id="Head1" runat="server">
        <title></title>
        <base target="_self" />
    </head>
    <body style="background-color:#f1f1f1;">
        <form id="form1" runat="server">
        <div>
        <table style="100%; font-size:12px; margin-top:20px;">
            <tr>
                <td align="center">
                        <asp:FileUpload ID="FileUploadMain" runat="server" Width="300px" />
            <asp:Button ID="btnUpload" runat="server" onclick="btnUpload_Click" Text="上传" />

                </td>
            </tr>
        </table>
           
       
        </div>
        </form>
    </body>
    </html>

    b.UploadFiles.aspx.cs

    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Adf.Core.File;
    using Adf.Core.Util;


    namespace AgileCorp.AppWeb.Res.Upload
    {
        public partial class UploadFiles : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                Response.Expires = -1;
            }

            protected void btnUpload_Click(object sender, EventArgs e)
            {
                String sMsg = "上传失败";
                String rValue = UploadFileForSave();
                //Response.Write(rValue);
                if(rValue.Trim().Length > 2)
                {
                    sMsg = "上传成功";   
                }

                CloseWinAndReturnValue(sMsg, rValue);
            }

            /// <summary>
            /// 保存附件
            /// </summary>
            /// <returns></returns>
            private String UploadFileForSave()
            {
                String rValue = String.Empty;
                //
                String uploadPath = ConfigHelper.ReadWebConfig("UploadFilePath1", "~/UploadFiles/");
                String physicalUploadPath = Server.MapPath(uploadPath);
                FileHelper.CreateDir(physicalUploadPath, "");

                String fileExtName = String.Empty;
                String curFileName = String.Empty;
                String sNewFileName = String.Empty;

                String saveFilePath = String.Empty;

                if (FileUploadMain.HasFile)
                {
                    try
                    {
                        curFileName = FileUploadMain.FileName;
                        int intExt = curFileName.LastIndexOf(".");
                        fileExtName = curFileName.Substring(intExt);

                        sNewFileName = DateTime.Now.ToString("yyyy-MM-dd-hhmmss") + fileExtName;
                        fileExtName = fileExtName.ToLower();
                        saveFilePath = physicalUploadPath + sNewFileName;
                        FileUploadMain.SaveAs(saveFilePath);
                        rValue = ResolveUrl(uploadPath + sNewFileName);
                    }
                    catch (Exception ex)
                    {
                        LogHelper.WriteLog(ex.Message);
                        //
                        rValue = "";
                    }
                }
                return rValue;
            }

            private void CloseWinAndReturnValue(String sMsg, String sContent)
            {
                StringBuilder sbScript = new StringBuilder();
                sbScript.Append("<script> ");
                sbScript.Append("alert('" + sMsg + "'); ");
                sbScript.Append("this.returnValue = '" + sContent.Trim() + "'; ");
                sbScript.Append("window.close(); ");
                sbScript.Append("</script>");

                if (!IsClientScriptBlockRegistered("AgilecloseWin"))
                {
                    RegisterClientScriptBlock("AgilecloseWin", sbScript.ToString());
                }
            }


        }
    }

  • 相关阅读:
    angularjs学习笔记—事件指令
    JS编写点击页面弹出被点击的标签名
    对数据进行排序
    springBoot集成seata
    maven打包时根据不同的环境生成不同的jar包名称
    单列模式-双重锁校验解析
    hashmap原理简述
    Linux搭建disconf(二)
    Linux搭建dubbo-admin 分布式服务监控中心
    Linux安装zookeeper
  • 原文地址:https://www.cnblogs.com/howie/p/3727788.html
Copyright © 2020-2023  润新知