分享

Extjs上传文件

 若生安饶 2017-12-26
/* ***********************************************
 * author :GH
 * function: 次要诊断(手术)替换主诊断(手术)信息view
 * history:created by GH 2017/7/25
 * ***********************************************/
Ext.define('CisApp.view.DRG.DiseaseChange.DiseaseChangeList', {
    extend: 'CisApp.base.Grid',
    requires: [
        'CisApp.view.DRG.DiseaseChange.DiseaseChangeListController',
        'CisApp.view.DRG.DiseaseChange.DiseaseChangeListModel',
        'CisApp.view.common.DiseaseOpr.DiseaseOprSearch',
        'CisApp.ux.form.ComboGrid',
         'CisApp.view.common.CommonDataSelSingle.CommonDataSelContainer',
        'CisApp.view.common.CommonDataSelSingle.CommonDataSelSearch'
    ],
    controller: 'DiseaseChangeList',
    viewModel: {
        type: 'DiseaseChangeList'
    },

    bind: {
        store: '{gridstore}',
        selection: '{focusItem}'
    },
    columns: CisApp.Common.Factory.Config.getShowItems("DRG.DiseaseChangeList.DiseaseChangeListItem"),
    tbar: [{
        xtype: 'toolbar',
        width: '100%',
        height: 30,
        margin: CisApp.Design.SearchZone.TopGauge + ' 10',
        items: [
        { xtype: 'textfield', fieldLabel: '诊断(手术)编码', bind: '{searchModel.ICD_CODE}', width: 250, labelWidth: 120, labelAlign: 'right' },
        { xtype: 'textfield', fieldLabel: '诊断(手术)名称', bind: '{searchModel.ICD_NAME}', width: 250, labelWidth: 120, labelAlign: 'right' },
        { xtype: 'button', text: '检索', handler: "search", margin: '0 20px', width: 60 },
        '->',
            {
                text: '新增',
                handler: 'Add',
                width: 50,
                hidden: !CisApp.Common.Service.Sys.isPermission('311101')
            },
            {
                text: '修改',
                handler: 'Edit',
                width: 50,
                hidden: !CisApp.Common.Service.Sys.isPermission('311102')
            },
            {
                text: '删除',
                handler: 'Delete',
                width: 50,
                hidden: !CisApp.Common.Service.Sys.isPermission('311103')
            },
            {
                xtype: "form",
                frame: false,
                anchor: '100%',
                header: false,
                layout: 'hbox',
                defaults: {
                    anchor: '100%',
                    allowBlank: false,
                    msgTarget: 'side',
                    labelWidth: 60,
                },
                resuiltTpl: new Ext.XTemplate(
                    '文件{fileName}上传成功!<br />',
                    '共更新{rowNum}条数据'
                ),
                items: [{
                    xtype: 'filefield',
                    id:'dclfile',
                    emptyText: '请选择要上传的文件',
                    name: 'fileUpName',
                    buttonText: '浏览…',
                    width: 180
                },
                    {
                        xtype: 'button',
                        text: '批量导入',
                        handler: function () {
                            var that = this.up('form');
                            var form = that.getForm();
                            var fileName = Ext.getCmp("dclfile").lastValue;
                            debugger;
                            if (form.isValid()) {
                                form.submit({
                                    url: "/File/UpLoadFile",
                                    waitMsg: '数据上传中...',
                                    success: function (fp, o) {
                                        Ext.Msg.show({
                                            title: '成功',
                                            msg: that.resuiltTpl.apply(o.result),
                                            minWidth: 200,
                                            modal: true,
                                            icon: Ext.Msg.INFO,
                                            buttons: Ext.Msg.OK,
                                            fn: function (btn) {
                                                var grid = that.up('grid');
                                                grid.getStore().reload();
                                            }
                                        });
                                    },
                                    failure: function () {
                                        Ext.Msg.alert("失败", Ext.JSON.decode(this.response.responseText).message);
                                    }
                                });
                            }
                        }
                    },
                    {
                        xtype: 'button',
                        text: '清除',
                        handler: function () {
                            this.up('form').getForm().reset();
                        }
                    }]
            }
        ]
    }],
    bbar: [{
        xtype: 'cispagingtoolbar',
        width: '100%',
        border: 0,
        bind: {
            store: '{gridstore}'
        }
    }]
});



using Microsoft.AspNet.Mvc;
using System.IO;
using System.Web;
using System;
using FileHelper;
using Cis.Mr.Model.DTO.DRG;
using System.Collections.Generic;
using Cis.Mr.Service.DRG;
using Microsoft.AspNet.Hosting;

namespace Cis.CISWorkeload.Web.Controllers
{
    public class FileController : Controller
    {
        #region 变量声明

        private readonly DiseaseChangeService _fileService;
        private IHostingEnvironment HostEnv;
        #endregion 变量声明

        #region 初始化
        public FileController(IHostingEnvironment env)
        {
            HostEnv = env;
            _fileService = new DiseaseChangeService();
        }
        #endregion 初始化

        #region 上传文件
        /// <summary>
        /// 上传附件
        /// </summary>
        /// <param name="filType">附件类型</param>
        /// <param name="fileRelationId">附件关系id</param>
        /// <returns></returns>
        [HttpPost]
        public ActionResult UpLoadFile()
        {
            try
            {
                var files = Request.Form.Files;
                if (files == null || files.Count < 1)
                {
                    return Json(new { success = false, message = "没有选择文件!", errors = new { fileUpName = "上传数据出错!" } });
                }
                foreach (var file in files)
                {
                    var filename = System.Net.Http.Headers.ContentDispositionHeaderValue
                                    .Parse(file.ContentDisposition)
                                     .FileName.Trim('"');
                    if (!filename.Contains(".xlsx") && !filename.Contains(".xls"))
                    {
                        return Json(new { success = false, message = "文件格式不正确,只能上传Excel文件!", errors = new { fileUpName = "上传数据出错!" } });
                    }
                    string name = filename;
                    string guId = Guid.NewGuid().ToString("N");
                    var path = HostEnv.WebRootPath;
                    filename = path+ "\\UplodaTemp" + $@"\{guId}{filename}";
                    using (FileStream fs = System.IO.File.Create(filename))
                    {
                        Stream st = file.OpenReadStream();
                        st.CopyTo(fs);
                        fs.Flush();
                    }
                    string sysAreCode = CurrentRequest.GetAeroCode(this.Context);
                    string projectCode = CurrentRequest.GetProjectCode(this.Context);
                    string projectVer = CurrentRequest.GetProjectVer(this.Context);
                    string createUserId = CurrentRequest.GetUserId(this.Context);
                    //从Excel文档读取数据
                    List<DiseaseChangeListResult> list = ExcelHelper<DiseaseChangeListResult>.ImportExcelToList(filename);
                    int count = _fileService.ExcelAdd(list, sysAreCode, projectCode, projectVer, createUserId).Result;
                    return Json(new { success = true, fileName = name, rowNum = count });
                }
                return Json(new { success = true, fileName = "", rowNum = 1 });
            }
            catch (System.Exception ex)
            {
                return Json(new { success = false, message = ex.Message, errors = new { fileUpName = "上传数据出错!" } });
            }
        }
        #endregion

    }
}


    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多