Exemple #1
0
        public ActionResult ImportPersonData()
        {
            string UnitID = RequestHelper.GetStrByName("UnitID"),
                   RowID  = RequestHelper.GetStrByName("RowID");

            if (string.IsNullOrEmpty(UnitID) || string.IsNullOrEmpty(RowID))
            {
                return(operateContext.RedirectAjax(1, "参数异常~", "", ""));
            }
            var files = Request.Files;

            if (files == null || files.Count <= 0)
            {
                return(null);
            }
            string file_name  = "工资模板" + operateContext.Usr.login_name;
            string pathServer = "~/UpFile/WageManager";
            string path       = Server.MapPath(pathServer);

            if (!Directory.Exists(path.ToString()))
            {
                Directory.CreateDirectory(path.ToString());//文件夹不存在则创建
            }
            HttpPostedFileBase file = Request.Files["filePerson"];
            //1.上传文档
            string sreUrl = Server.MapPath(pathServer + "/" + file_name + "." + file.FileName.Split('.')[1]);

            file.SaveAs(sreUrl);//上传文件
            System.Data.DataTable dt = NpoiHelper.ImportExcelToDataTable(sreUrl);
            if (null == dt || dt.Rows.Count <= 0)
            {
                return(operateContext.RedirectAjax(1, "导入数据为空~", "", ""));
            }
            bool mark = operateContext.bllSession.WGJG02_Template.ImportPersonData(dt, UnitID, RowID);

            if (mark)
            {
                return(operateContext.RedirectAjax(0, "导入成功~", "", ""));
            }
            return(operateContext.RedirectAjax(1, "导入失败~", "", ""));
        }