public IActionResult AddTesteNatura(string codRelease, [FromServices] NaturaDAO naturaDAO) { _logger.LogInformation("Natura- [HttpGet] Adicionar Teste a release cod: {0}/ User: {1}", codRelease, User.Identity.Name); List <NaturaTeste> naturaTestes = naturaDAO.ListaTestes_Natura(codRelease); ViewBag.CodRelease = (from x in naturaTestes select x.cod_release).First(); ViewBag.Cenario = (from x in naturaTestes select x.numero_teste).Max() + 1; return(View()); }
public IActionResult TestesNatura(string codRelease, [FromServices] NaturaDAO naturaDAO) { _logger.LogInformation("Natura- Lista de testes da Release cod: {0}/ User: {1}", codRelease, User.Identity.Name); NaturaRelease naturaRelease = naturaDAO.GetRelease(codRelease); List <NaturaTeste> naturaTestes = naturaDAO.ListaTestes_Natura(codRelease); ViewBag.Ambiente = naturaRelease.sistema; ViewBag.CodRelease = (from x in naturaTestes select x.cod_release).First(); return(View(naturaTestes)); }
public IActionResult AddTesteNatura(NaturaTeste naturaTeste, [FromServices] NaturaDAO naturaDAO) { if (!ModelState.IsValid) { List <NaturaTeste> naturaTestes = naturaDAO.ListaTestes_Natura(naturaTeste.cod_release); ViewBag.CodRelease = (from x in naturaTestes select x.cod_release).First(); ViewBag.Cenario = (from x in naturaTestes select x.numero_teste).Max() + 1; return(View()); } naturaTeste.execucao_status = 0; naturaTeste.chamado_status = 0; _logger.LogInformation("Natura- [HttpPost] Adicionar Teste a release cod: {0}/ User: {1}", naturaTeste.cod_release, User.Identity.Name); naturaDAO.AddTest_Natura(naturaTeste); return(RedirectToAction("TestesNatura", "Natura", new { codRelease = naturaTeste.cod_release })); }
public IActionResult InsertTestesNatura(string codRelease, int qtdTeste, IFormFile file, [FromServices] NaturaDAO naturaDAO) { if (qtdTeste < 1) { ModelState.AddModelError("", "Informe a quantidade de testes!"); return(View()); } else { if (file is null) { ModelState.AddModelError("", "Planilha não encontrada!"); return(View()); } List <NaturaTeste> naturaTestes = naturaDAO.ListaTestes_Natura(codRelease); ViewBag.CodRelease = codRelease; int nTeste = (from x in naturaTestes select x.numero_teste).Max() + 1; string webRootPath = _hostingEnvironment.WebRootPath; StringBuilder sb = new StringBuilder(); if (file.Length > 0) { List <NaturaTeste> lista = new List <NaturaTeste>(); string sFileExtension = Path.GetExtension(file.FileName).ToLower(); ISheet sheet; string fullPath = Path.Combine(webRootPath, file.FileName); using (var stream = new FileStream(fullPath, FileMode.Create)) { file.CopyTo(stream); stream.Position = 0; if (sFileExtension == ".xls") { HSSFWorkbook hssfwb = new HSSFWorkbook(stream); //This will read the Excel 97-2000 formats sheet = hssfwb.GetSheetAt(0); //get first sheet from workbook } else { XSSFWorkbook hssfwb = new XSSFWorkbook(stream); //This will read 2007 Excel format sheet = hssfwb.GetSheetAt(0); //get first sheet from workbook } IRow headerRow = sheet.GetRow(0); //Get Header Row int cellCount = headerRow.LastCellNum; for (int i = (sheet.FirstRowNum + 1); i <= qtdTeste; i++) //Read Excel File { IRow row = sheet.GetRow(i); var dataExec = row.GetCell(12)?.ToString(); DateTime?data = null; if (dataExec == "" || dataExec is null) { } else { data = Convert.ToDateTime(dataExec); } NaturaTeste naturaTeste = new NaturaTeste { cod_release = codRelease, numero_teste = nTeste, sistema = row.GetCell(1)?.ToString(), funcionalidade = row.GetCell(2)?.ToString(), cenario = row.GetCell(3)?.ToString(), pre_condicao = row.GetCell(4)?.ToString(), passos = row.GetCell(5)?.ToString(), result_esperado = row.GetCell(6)?.ToString(), pos_condicao = row.GetCell(7)?.ToString(), executor = row.GetCell(8)?.ToString(), massa = row.GetCell(9)?.ToString(), observacao = row.GetCell(10)?.ToString(), url_doc = row.GetCell(11)?.ToString(), data_execucao = data, prioridade = Convert.ToUInt16(row.GetCell(13)?.ToString()), cn_login = row.GetCell(14)?.ToString(), cn_senha = row.GetCell(15)?.ToString(), gr_login = row.GetCell(16)?.ToString(), gr_senha = row.GetCell(17)?.ToString(), lider_login = row.GetCell(18)?.ToString(), lider_senha = row.GetCell(19)?.ToString(), browser = row.GetCell(20)?.ToString(), execucao_status = 0, chamado_status = 0 }; lista.Add(naturaTeste); nTeste += 1; } } //Add Testes foreach (NaturaTeste teste in lista) { naturaDAO.AddTest_Natura(teste); } //Deleta arquivo criado FileInfo fileInfo = new FileInfo(Path.Combine(webRootPath, file.FileName)); fileInfo.Delete(); } } return(RedirectToAction("TestesNatura", "Natura", new { codRelease })); }
public async Task <IActionResult> ExportarReleaseNatura(string codRelease, [FromServices] NaturaDAO naturaDAO) { _logger.LogInformation("Natura- Exporta Release cod: {0} / User: {1}", codRelease, User.Identity.Name); List <NaturaTeste> testes = naturaDAO.ListaTestes_Natura(codRelease); string sWebRootFolder = _hostingEnvironment.WebRootPath; string sFileName = @"Release_Natura.xlsx"; string URL = string.Format("{0}://{1}/{2}", Request.Scheme, Request.Host, sFileName); FileInfo file = new FileInfo(Path.Combine(sWebRootFolder, sFileName)); if (file.Exists) { file.Delete(); //file.Create(); } var memory = new MemoryStream(); using (var fs = new FileStream(Path.Combine(sWebRootFolder, sFileName), FileMode.Create, FileAccess.Write)) { IWorkbook workbook; workbook = new XSSFWorkbook(); ISheet excelSheet = workbook.CreateSheet("Testes"); IRow row = excelSheet.CreateRow(0); row.CreateCell(0).SetCellValue("Numero Teste"); row.CreateCell(1).SetCellValue("Sistema"); row.CreateCell(2).SetCellValue("Funcionalidade"); row.CreateCell(3).SetCellValue("Cenario"); row.CreateCell(4).SetCellValue("Pre condicao"); row.CreateCell(5).SetCellValue("Passos"); row.CreateCell(6).SetCellValue("Result Esperado"); row.CreateCell(7).SetCellValue("Pos condicao"); row.CreateCell(8).SetCellValue("Executor"); row.CreateCell(9).SetCellValue("Massa"); row.CreateCell(10).SetCellValue("Observacao"); row.CreateCell(11).SetCellValue("Link doc"); row.CreateCell(12).SetCellValue("Data prevista"); row.CreateCell(13).SetCellValue("Prioridade"); row.CreateCell(14).SetCellValue("Data executado"); row.CreateCell(16).SetCellValue("Status teste"); row.CreateCell(16).SetCellValue("Status chamado"); int count = 1; string statusTeste = ""; string statusChamado = ""; foreach (var item in testes) { row = excelSheet.CreateRow(count); switch (item.execucao_status) { case 0: statusTeste = "Não Executado"; break; case 1: statusTeste = "Em execução"; break; case 2: statusTeste = "Bloqueado"; break; case 3: statusTeste = "Teste Falhou"; break; case 4: statusTeste = "Teste com sucesso"; break; } switch (item.chamado_status) { case 0: statusChamado = "N/A"; break; case 1: statusChamado = "Aberto"; break; case 2: statusChamado = "Em correção"; break; case 3: statusChamado = "Liberado para teste"; break; case 4: statusChamado = "Em teste"; break; case 5: statusChamado = "Fechado"; break; } row.CreateCell(0).SetCellValue(item.numero_teste); row.CreateCell(1).SetCellValue(item.sistema); row.CreateCell(2).SetCellValue(item.funcionalidade); row.CreateCell(3).SetCellValue(item.cenario); row.CreateCell(4).SetCellValue(item.pre_condicao); row.CreateCell(5).SetCellValue(item.passos); row.CreateCell(6).SetCellValue(item.result_esperado); row.CreateCell(7).SetCellValue(item.pos_condicao); row.CreateCell(8).SetCellValue(item.executor); row.CreateCell(9).SetCellValue(item.massa); row.CreateCell(10).SetCellValue(item.observacao); row.CreateCell(11).SetCellValue(item.url_doc); row.CreateCell(12).SetCellValue(item.data_execucao.Value.ToString("dd/MM/yyyy")); row.CreateCell(13).SetCellValue(item.prioridade); row.CreateCell(14).SetCellValue(item.data_executado.ToString("dd/MM/yyyy")); row.CreateCell(15).SetCellValue(statusTeste); row.CreateCell(16).SetCellValue(statusChamado); count += 1; } workbook.Write(fs); } using (var stream = new FileStream(Path.Combine(sWebRootFolder, sFileName), FileMode.Open)) { await stream.CopyToAsync(memory); } memory.Position = 0; file.Delete(); return(File(memory, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", sFileName)); }