예제 #1
0
        public List <AnexoDocumento> ObterAnexos(decimal CodDocumento)
        {
            try
            {
                AbrirConexao();
                string comando = "Select * from ANEXO_DO_DOCUMENTO Where CD_DOCUMENTO= @v1 ";

                Cmd = new SqlCommand(comando, Con);

                Cmd.Parameters.AddWithValue("@v1", CodDocumento);

                Dr = Cmd.ExecuteReader();
                List <AnexoDocumento> anexo = new List <AnexoDocumento>();

                while (Dr.Read())
                {
                    AnexoDocumento p = new AnexoDocumento();
                    p.CodigoDocumento    = Convert.ToDecimal(Dr["CD_DOCUMENTO"]);
                    p.CodigoAnexo        = Convert.ToInt32(Dr["CD_ANEXO"]);
                    p.DataHoraLancamento = Convert.ToDateTime(Dr["DT_HR_LANCAMENTO"]);
                    p.CodigoMaquina      = Convert.ToInt32(Dr["CD_MAQUINA"]);
                    p.CodigoUsuario      = Convert.ToInt32(Dr["CD_USUARIO"]);
                    p.NomeArquivo        = Convert.ToString(Dr["NM_ARQUIVO"]);
                    p.ExtensaoArquivo    = Convert.ToString(Dr["EX_ARQUIVO"]);
                    p.Arquivo            = (byte[])(Dr["TX_CONTEUDO"]);
                    p.DescricaoArquivo   = Convert.ToString(Dr["DS_ARQUIVO"]);
                    p.NaoEditavel        = Convert.ToInt32(Dr["IN_NAO_EDITAVEL"]);

                    UsuarioDAL usuarioDAL = new UsuarioDAL();
                    Usuario    usuario    = new Usuario();
                    usuario       = usuarioDAL.PesquisarUsuario(Convert.ToInt32(Dr["CD_USUARIO"]));
                    p.Cpl_Usuario = usuario.NomeUsuario;

                    Habil_EstacaoDAL EstacaoDAL = new Habil_EstacaoDAL();
                    Habil_Estacao    Estacao    = new Habil_Estacao();
                    Estacao       = EstacaoDAL.PesquisarCodigoHabil_Estacao(Convert.ToInt32(Dr["CD_MAQUINA"]));
                    p.Cpl_Maquina = Estacao.NomeEstacao;



                    anexo.Add(p);
                }
                return(anexo);
            }
            catch (Exception ex)
            {
                throw new Exception("Erro ao Pesquisar anexos: " + ex.Message.ToString());
            }
            finally
            {
                FecharConexao();
            }
        }
예제 #2
0
        public void SalvarAnexos(decimal CodigoDocumento, byte[] Arquivo, DateTime data, IntegraDocumentoEletronico integra, string StrDescricao)
        {
            AnexoDocumento    anexo    = new AnexoDocumento();
            AnexoDocumentoDAL anexoDAL = new AnexoDocumentoDAL();

            anexo.CodigoDocumento    = Convert.ToDecimal(CodigoDocumento);
            anexo.CodigoMaquina      = integra.CodigoMaquina;
            anexo.CodigoUsuario      = integra.CodigoUsuario;
            anexo.DataHoraLancamento = data;
            anexo.DescricaoArquivo   = StrDescricao;
            anexo.ExtensaoArquivo    = "XML";
            anexo.Arquivo            = Arquivo;
            anexo.NaoEditavel        = 1;
            anexo.NomeArquivo        = anexoDAL.GerarGUID(anexo.ExtensaoArquivo);
            anexoDAL.InserirXMLDocumento(anexo);
        }
예제 #3
0
        public void InserirXMLDocumento(AnexoDocumento anexo)
        {
            try
            {
                List <AnexoDocumento> listaAnexosExistentes = new List <AnexoDocumento>();
                listaAnexosExistentes = ObterAnexos(anexo.CodigoDocumento);

                int intCttItem = 0;
                if (listaAnexosExistentes.Count != 0)
                {
                    intCttItem = Convert.ToInt32(listaAnexosExistentes.Max(x => x.CodigoAnexo).ToString());
                }

                AbrirConexao();
                Cmd = new SqlCommand("insert into ANEXO_DO_DOCUMENTO (CD_DOCUMENTO, " +
                                     "CD_ANEXO," +
                                     " DT_HR_LANCAMENTO," +
                                     " CD_MAQUINA," +
                                     " CD_USUARIO," +
                                     " NM_ARQUIVO," +
                                     " EX_ARQUIVO," +
                                     " TX_CONTEUDO," +
                                     " DS_ARQUIVO," +
                                     " IN_NAO_EDITAVEL ) " +
                                     "values (@v1,@v2,@v3,@v4, @v5, @v6, @v7, @v8,@v9,@v10);", Con);
                Cmd.Parameters.AddWithValue("@v1", anexo.CodigoDocumento);
                Cmd.Parameters.AddWithValue("@v2", intCttItem + 1);
                Cmd.Parameters.AddWithValue("@v3", anexo.DataHoraLancamento);
                Cmd.Parameters.AddWithValue("@v4", anexo.CodigoMaquina);
                Cmd.Parameters.AddWithValue("@v5", anexo.CodigoUsuario);
                Cmd.Parameters.AddWithValue("@v6", anexo.NomeArquivo);
                Cmd.Parameters.AddWithValue("@v7", anexo.ExtensaoArquivo);
                Cmd.Parameters.AddWithValue("@v8", anexo.Arquivo);
                Cmd.Parameters.AddWithValue("@v9", anexo.DescricaoArquivo);
                Cmd.Parameters.AddWithValue("@v10", anexo.NaoEditavel);


                //Cmd.ExecuteNonQuery();
                Cmd.ExecuteNonQuery();
            }
            catch (SqlException ex)
            {
                if (ex.Errors.Count > 0) // Assume the interesting stuff is in the first error
                {
                    switch (ex.Errors[0].Number)
                    {
                    case 2601:     // Primary key violation
                        throw new DuplicateNameException("Inclusão não Permitida!!! Chave já consta no Banco de Dados. Mensagem :" + ex.Message.ToString(), ex);

                    case 2627:     // Primary key violation
                        throw new DuplicateNameException("Inclusão não Permitida!!! Chave já consta no Banco de Dados. Mensagem :" + ex.Message.ToString(), ex);

                    default:
                        throw new Exception("Erro ao gravar ANEXO 2: " + ex.Message.ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Erro ao gravar ANEXO: " + ex.Message.ToString());
            }
            finally
            {
                FecharConexao();
            }
        }