예제 #1
0
        //下载员工二维码 新



        #region 导入用户
        public string ImportUser()
        {
            var         responseData = new ResponseData();
            var         userService  = new cUserService(CurrentUserInfo);
            ExcelHelper excelHelper  = new ExcelHelper();

            if (Request("filePath") != null && Request("filePath").ToString() != "")
            {
                try
                {
                    var     rp          = new ImportRP();
                    string  strPath     = Request("filePath").ToString();
                    string  strFileName = string.Empty;
                    DataSet ds          = userService.ExcelToDb(HttpContext.Current.Server.MapPath(strPath), CurrentUserInfo);
                    if (ds != null && ds.Tables.Count > 1 && ds.Tables[0] != null && ds.Tables[0].Rows.Count > 0)
                    {
                        Workbook wb       = JIT.Utility.DataTableExporter.WriteXLS(ds.Tables[0], 0);
                        string   savePath = HttpContext.Current.Server.MapPath(@"~/File/ErrFile/User");
                        if (!System.IO.Directory.Exists(savePath))
                        {
                            System.IO.Directory.CreateDirectory(savePath);
                        }
                        strFileName = "\\用户错误信息导出" + DateTime.Now.ToFileTime() + ".xls";
                        savePath    = savePath + strFileName;
                        wb.Save(savePath);//保存Excel文件
                        rp = new ImportRP()
                        {
                            Url        = "/File/ErrFile/User" + strFileName,
                            TotalCount = Convert.ToInt32(ds.Tables[1].Rows[0]["TotalCount"].ToString()),
                            ErrCount   = Convert.ToInt32(ds.Tables[1].Rows[0]["ErrCount"].ToString())
                        };
                    }
                    else
                    {
                        rp = new ImportRP()
                        {
                            Url        = "",
                            TotalCount = Convert.ToInt32(ds.Tables[1].Rows[0]["TotalCount"].ToString()),
                            ErrCount   = Convert.ToInt32(ds.Tables[1].Rows[0]["ErrCount"].ToString())
                        };

                        responseData.success = true;
                    }
                    responseData.success = true;
                    responseData.data    = rp;
                }
                catch (Exception err)
                {
                    responseData.success = false;
                    responseData.msg     = err.Message.ToString();
                }
            }
            return(responseData.ToJSON());
        }