Ejemplo n.º 1
0
        protected void gvFechamento_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "Exportar")
            {
                try
                {
                    int   index  = int.Parse(e.CommandArgument.ToString());
                    int   esc_id = Convert.ToInt32(gvFechamento.DataKeys[index]["esc_id"]);
                    int   uni_id = Convert.ToInt32(gvFechamento.DataKeys[index]["uni_id"]);
                    int   cal_id = Convert.ToInt32(gvFechamento.DataKeys[index]["cal_id"]);
                    int   tpc_id = Convert.ToInt32(gvFechamento.DataKeys[index]["tpc_id"]);
                    Int64 tur_id = Convert.ToInt64(gvFechamento.DataKeys[index]["tur_id"]);

                    string ordemAluno = ACA_ParametroAcademicoBO.ParametroValorPorEntidade(eChaveAcademico.ORDENACAO_COMBO_ALUNO, __SessionWEB.__UsuarioWEB.Usuario.ent_id);

                    ordemAluno = string.IsNullOrEmpty(ordemAluno) ? "1" : ordemAluno;
                    DataTable dt = CLS_ArquivoEfetivacaoBO.ExportacaoAlunosFechamento(esc_id, uni_id, cal_id, tur_id, tpc_id,
                                                                                      GestaoEscolarUtilBO.nomePadraoPeriodo_Calendario(__SessionWEB.__UsuarioWEB.Usuario.ent_id),
                                                                                      GetGlobalResourceObject("Mensagens", "MSG_DISCIPLINA_PLURAL").ToString(),
                                                                                      Convert.ToInt16(ordemAluno));
                    if (dt.Rows.Count == 0)
                    {
                        throw new ValidationException("Não existem itens para essa turma");
                    }

                    CLS_ArquivoEfetivacao entity = new CLS_ArquivoEfetivacao
                    {
                        aef_id            = -1,
                        esc_id            = esc_id,
                        uni_id            = uni_id,
                        cal_id            = cal_id,
                        tpc_id            = tpc_id,
                        tur_id            = tur_id,
                        aef_dataCriacao   = DateTime.Now,
                        aef_dataAlteracao = DateTime.Now,
                        aef_tipo          = (short)CLS_ArquivoEfetivacaoBO.eTipoArquivoEfetivacao.Exportacao,
                        aef_situacao      = (short)CLS_ArquivoEfetivacaoBO.eSituacao.Ativo,
                        IsNew             = true
                    };

                    if (CLS_ArquivoEfetivacaoBO.Save(entity))
                    {
                        VS_NomeArquivoCSV     = dt.Rows[0][0] + "_" + dt.Rows[0][1] + "_" + dt.Rows[0][2] + "-" + dt.Rows[0][3] + "_" + entity.aef_id + ".csv";
                        VS_ConteudoArquivoCSV = GestaoEscolarUtilBO.ConverterTabelaParaArquivoCSV(dt).ToString();

                        ApplicationWEB._GravaLogSistema(LOG_SistemaTipo.Insert, "aef_id: " + entity.aef_id);
                        lblMsgDownload.Text = UtilBO.GetErroMessage("Arquivo gerado com sucesso.", UtilBO.TipoMensagem.Sucesso);// +
                        //UtilBO.GetErroMessage("O nome do arquivo será utilizado para importação, portanto não deve ser alterado.", UtilBO.TipoMensagem.Alerta);
                        Pesquisar();
                        ScriptManager.RegisterStartupScript(Page, typeof(Page), "Donwload", "$(document).ready(function() { $('#divDownload').dialog({title: 'Download do arquivo do fechamento do bimestre'}).dialog('open'); });", true);
                    }
                }
                catch (ValidationException ex)
                {
                    _lblMessage.Text = UtilBO.GetErroMessage(ex.Message, UtilBO.TipoMensagem.Alerta);
                }
                catch (Exception ex)
                {
                    ApplicationWEB._GravaErro(ex);
                    _lblMessage.Text = UtilBO.GetErroMessage("Erro ao tentar gerar o arquivo.", UtilBO.TipoMensagem.Erro);
                }
            }

            if (e.CommandName == "Importar")
            {
                try
                {
                    gvFechamento.EditIndex = int.Parse(e.CommandArgument.ToString());
                }
                catch (Exception ex)
                {
                    ApplicationWEB._GravaErro(ex);
                    _lblMessage.Text = UtilBO.GetErroMessage("Erro ao tentar carregar o sistema.", UtilBO.TipoMensagem.Erro);
                }
            }
        }