Exemplo n.º 1
0
        //导入
        public ActionResult ImportUser()
        {
            string strErrorPath = null;

            HttpFileCollectionBase httfiles = Request.Files;

            if (httfiles.Count > 0)
            {
                HttpPostedFileBase httpfile = httfiles[0];
                try
                {
                    List <string[]> arrstrmapplst = new List <string[]> {
                        new string[] { "用户编号", "UserCode" },
                        new string[] { "用户名称", "FullName" },
                        new string[] { "手机号", "PhoneNumber" },
                        new string[] { "邮箱", "Email" },
                        new string[] { "角色", "RoleNamestr" },
                        new string[] { "经销商", "DistributorNamestr" },
                        new string[] { "到期日", "StopTime" },
                        new string[] { "检测情况", "CheckInfo" }
                    };
                    string           strGenarateDir  = Server.MapPath(@"~/TempFile");
                    string           strGenarateFile = Guid.NewGuid().ToString("N") + ".xlsx";
                    string           strExportFile   = strGenarateDir + "\\" + strGenarateFile;
                    List <ExcelUser> rplst           = ExcelHelper.Import <ExcelUser>(httpfile.InputStream, "Sheet1", arrstrmapplst, CheckUserInfo, strExportFile);
                    if (rplst == null)
                    {
                        strErrorPath = strGenarateFile;
                    }
                    else
                    {
                        var boolD = UserAuthorityProvider.ImportUser(rplst);
                        if (!boolD.SubmitResult)
                        {
                            Logger.WriteLog(boolD.Message.ToString());
                            strErrorPath = "导入失败";
                        }
                    }
                }
                catch (Exception ex)
                {
                    Logger.WriteLog(ex.ToString());
                    strErrorPath = "导入失败";
                }
            }

            return(Json(strErrorPath));
        }