Ejemplo n.º 1
0
        /// <summary>
        /// O método valida o nome do arquivo selecionado.
        /// </summary>
        /// <returns></returns>
        private bool ValidarNomeArquivo()
        {
            Regex  rgx         = new Regex(@"^\d{6}[_]([A-Z,a-z,0-9,à-ú,À-Ú,-])+[_]\d{4}[-]\d[ºª][A-Z,a-z,-]+[_]\d+$", RegexOptions.IgnoreCase);
            string nomeArquivo = Path.GetFileNameWithoutExtension(fupArquivo.PostedFile.FileName);

            bool valido = rgx.IsMatch(nomeArquivo);

            if (!valido)
            {
                throw new ValidationException("O nome do arquivo é inválido.");
            }

            return(GestaoEscolarUtilBO.VerificarArquivo(fupArquivo.PostedFile) && valido);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// O método analisa os registros do arquivo de fechamento.
        /// </summary>
        private void AnalisarArquivo()
        {
            try
            {
                //if (ValidarNomeArquivo())
                if (GestaoEscolarUtilBO.VerificarArquivo(fupArquivo.PostedFile))
                {
                    int sucesso, erro;

                    string nomeArquivoSemExtensao = Path.GetFileNameWithoutExtension(fupArquivo.PostedFile.FileName);
                    string nomeArquivo            = fupArquivo.PostedFile.FileName;
                    int    tamanhoArquivo         = fupArquivo.PostedFile.ContentLength;
                    string typeMime = fupArquivo.PostedFile.ContentType;

                    Stream arquivo = CopiarArquivo(fupArquivo.PostedFile.InputStream);

                    VS_arquivo = CriarAnexo(arquivo, nomeArquivo, tamanhoArquivo, typeMime);

                    arquivo.Position = 0;

                    VS_listaLoteFechamento = CLS_ArquivoEfetivacaoBO.AnalisarRegistrosLote
                                             (
                        (string)GetGlobalResourceObject("Mensagens", "MSG_DISCIPLINA"),
                        __SessionWEB.__UsuarioWEB.Usuario.ent_id,
                        VS_cal_id, VS_tpc_id, VS_tur_id,
                        arquivo, nomeArquivoSemExtensao,
                        out sucesso, out erro
                                             );

                    if (VS_listaLoteFechamento.Any())
                    {
                        UCComboQtdePaginacao.Valor = 10;
                        grvArquivo.PageIndex       = 0;
                        grvArquivo.PageSize        = UCComboQtdePaginacao.Valor;
                        grvArquivo.DataBind();
                        updArquivo.Update();

                        // Configura análise dos registro do arquivo
                        lblSucesso.Text = sucesso.ToString();
                        lblErro.Text    = erro.ToString();
                        lblTotal.Text   = (sucesso + erro).ToString();

                        ConfigurarPasso(ePasso.AnaliseArquivo);
                    }
                    else
                    {
                        lblMessage.Text = UtilBO.GetErroMessage("Não existem registros para analisar no arquivo enviado.", UtilBO.TipoMensagem.Alerta);
                        updMessage.Update();
                    }
                }
            }
            catch (ValidationException ex)
            {
                lblMessage.Text = UtilBO.GetErroMessage(ex.Message, UtilBO.TipoMensagem.Alerta);
            }
            catch (ArgumentException ex)
            {
                lblMessage.Text = UtilBO.GetErroMessage(ex.Message, UtilBO.TipoMensagem.Alerta);
            }
            catch (Exception ex)
            {
                lblMessage.Text = UtilBO.GetErroMessage("Erro ao realizar a análise dos registros do arquivo.", UtilBO.TipoMensagem.Erro);
                ApplicationWEB._GravaErro(ex);
            }
            finally
            {
                updMessage.Update();
            }
        }