Esempio n. 1
0
        public async Task StudentInfoAndPaymentLogImporter_Test()
        {
            var filePath  = Path.Combine(Directory.GetCurrentDirectory(), "TestFiles", "Import", "学生基础数据及缴费流水号导入.xlsx");
            var importDic = await Importer.ImportMultipleSheet <ImportStudentAndPaymentLogDto>(filePath);

            foreach (var item in importDic)
            {
                var import = item.Value;
                import.ShouldNotBeNull();
                if (import.Exception != null)
                {
                    _testOutputHelper.WriteLine(import.Exception.ToString());
                }

                if (import.RowErrors.Count > 0)
                {
                    _testOutputHelper.WriteLine(JsonConvert.SerializeObject(import.RowErrors));
                }
                import.HasError.ShouldBeTrue();
                import.Data.ShouldNotBeNull();
                if (item.Key == "1班导入数据")
                {
                    import.Data.Count.ShouldBe(16);
                    ImportStudentDto dto = (ImportStudentDto)import.Data.ElementAt(0);
                    dto.Name.ShouldBe("杨圣超");
                }
                if (item.Key == "缴费数据")
                {
                    import.Data.Count.ShouldBe(20);
                    ImportPaymentLogDto dto = (ImportPaymentLogDto)import.Data.ElementAt(0);
                    dto.Name.ShouldBe("刘茵");
                }
            }
        }
Esempio n. 2
0
        public async Task <object> Export([FromBody] ImportStudentDto model)
        {
            Dictionary <string, string> columnNames = new Dictionary <string, string>();
            List <string> lists = new List <string>();

            lists.Add("IdCard");

            var properties = typeof(ImportStudentDto).GetProperties();

            foreach (var property in properties)
            {
                var name = property.GetCustomAttribute <DisplayAttribute>()?.Name;
                if (!string.IsNullOrWhiteSpace(name))
                {
                    foreach (var list in lists)
                    {
                        if (list == property.Name)
                        {
                            columnNames.Add(property.Name, name);
                        }
                    }
                }
            }
            var students = await db.ImportStudentDtos.ToListAsync();

            var sc = await ExportExcelHelper.GetByteToExportExcel(students, columnNames, lists, "sheet1", "测试");

            return(File(sc, "application/octet-stream", "测试.xlsx"));
            //columnNames.Add("SerialNumber", "序号");
            //columnNames.Add("StudentCode", "学籍号");
            //columnNames.Add("Name", "姓名");
            //columnNames.Add("Gender", "性别");
            //columnNames.Add("IdCard", "身份证号");
        }
        public async Task ClassStudentInfoImporter_SaveLabelingError_Test()
        {
            var filePath = Path.Combine(Directory.GetCurrentDirectory(), "TestFiles", "Import",
                                        "学生基础数据及缴费流水号导入_标注错误.xlsx");

            var importDic = await Importer.ImportMultipleSheet <ImportStudentAndPaymentLogDto>(filePath);

            foreach (var item in importDic)
            {
                var import = item.Value;
                import.ShouldNotBeNull();
                if (import.Exception != null)
                {
                    _testOutputHelper.WriteLine(import.Exception.ToString());
                }

                if (import.RowErrors.Count > 0)
                {
                    _testOutputHelper.WriteLine(JsonConvert.SerializeObject(import.RowErrors));
                }

                import.Data.ShouldNotBeNull();
                if (item.Key == "1班导入数据")
                {
                    import.Data.Count.ShouldBe(16);
                    ImportStudentDto dto = (ImportStudentDto)import.Data.ElementAt(0);
                    dto.Name.ShouldBe("杨圣超");
                }

                if (item.Key == "缴费数据")
                {
                    import.HasError.ShouldBeTrue();
                    import.Data.Count.ShouldBe(20);
                    ImportPaymentLogDto dto = (ImportPaymentLogDto)import.Data.ElementAt(0);
                    dto.Name.ShouldBe("刘茵");
                }
            }

            var ext = Path.GetExtension(filePath);
            var labelingErrorExcelPath = filePath.Replace(ext, "_" + ext);

            if (File.Exists(labelingErrorExcelPath))
            {
                _testOutputHelper.WriteLine($"保存标注错误Excel文件已生成,路径:{labelingErrorExcelPath}");
            }
        }
Esempio n. 4
0
        public async Task <object> Add([FromBody] ImportStudentDto model)
        {
            var student = new ImportStudentDto
            {
                Gender       = Genders.男,
                IdCard       = "421087199211027016",
                Name         = "贺扬明",
                SerialNumber = 0,
                StudentCode  = "2222",
            };
            await db.ImportStudentDtos.AddAsync(student);

            if (await db.SaveChangesAsync() > 0)
            {
                return(student.SerialNumber);
            }
            return(BadRequest("坏的"));
        }