public object AddMulitDeparment(IFormCollection files) { string[] colName = new string[] { "公司名称", "部门经理", "部门名称", "员工数量", "部门代码" }; var result = new object(); if (files != null && files.Files.Count > 0) { for (int i = 0; i < files.Files.Count; i++) { var file = files.Files[i]; try { object path = _importExcelUtil.SaveExcel(file); FileInfo fileInfo = new FileInfo((string)path); using (FileStream fs = new FileStream(fileInfo.ToString(), FileMode.Create)) { file.CopyTo(fs); fs.Flush(); } using (ExcelPackage package = new ExcelPackage(fileInfo)) { ExcelWorksheet worksheet = package.Workbook.Worksheets[1]; List <Deparment> successDeparments; if (_importExcelUtil.JudgeCol(worksheet, colName)) { result = new { data = _importExcelUtil.SaveDepToDB(worksheet, out successDeparments) }; System.IO.File.Delete((string)path); foreach (var item in successDeparments) { TransferWorkerDto transferWorkerDto = new TransferWorkerDto { WorkerId = (int)item.ManagerId, DeparmentId = item.Id, StateId = _commonAppService.GetManagerState(item.CompanyId), PositionId = _commonAppService.GetManagerPosition(item.CompanyId) }; _dangAnAppService.TransferWorker(transferWorkerDto); } } } } catch (Exception ex) { result = new { data = ex.Message, fileError = true }; } } } return(result); }
public object AddMulitWorker(IFormCollection files) { string[] colName = new string[] { "公司", "部门", "职位", "姓名", "性别", "电话号码", "地址", "证件类型", "证件号码", "状态", "入职时间", "电子邮箱" }; var result = new object(); string message = ""; if (files != null && files.Files.Count > 0) { for (int i = 0; i < files.Files.Count; i++) { var file = files.Files[i]; try { object path = _importExcelUtil.SaveExcel(file); FileInfo fileInfo = new FileInfo((string)path); using (FileStream fs = new FileStream(fileInfo.ToString(), FileMode.Create)) { file.CopyTo(fs); fs.Flush(); } using (ExcelPackage package = new ExcelPackage(fileInfo)) { ExcelWorksheet worksheet = package.Workbook.Worksheets[1]; if (_importExcelUtil.JudgeCol(worksheet, colName)) { result = new { data = _importExcelUtil.SaveWorkerToDB(worksheet, worksheet.Dimension.Rows, worksheet.Dimension.Columns) }; System.IO.File.Delete((string)path); } } } catch (Exception ex) { result = new { data = ex.Message, fileError = true }; } } } return(result); }
public object AddMulitDeparment(IFormCollection files) { string[] colName = new string[] { "公司名称", "部门经理", "部门名称", "员工数量", "部门代码" }; var result = new object(); string message = ""; if (files != null && files.Files.Count > 0) { for (int i = 0; i < files.Files.Count; i++) { var file = files.Files[i]; try { object path = _importExcelUtil.SaveExcel(file); FileInfo fileInfo = new FileInfo((string)path); using (FileStream fs = new FileStream(fileInfo.ToString(), FileMode.Create)) { file.CopyTo(fs); fs.Flush(); } using (ExcelPackage package = new ExcelPackage(fileInfo)) { ExcelWorksheet worksheet = package.Workbook.Worksheets[1]; if (_importExcelUtil.JudgeCol(worksheet, colName)) { result = new { data = _importExcelUtil.SaveDepToDB(worksheet) }; System.IO.File.Delete((string)path); } } } catch (Exception ex) { message = ex.Message; } } } return(result); }