Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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);
        }