Beispiel #1
0
        public RegFisIcmsGpoTribPessoa PesquisarRegFisIcmsGpoTribPessoa(long CodigoRegra, int CodigoGrupo)
        {
            try
            {
                AbrirConexao();

                strSQL = "Select * from [REGRA_FISCAL_ICMS_GRUPO_PESSOA] Where [CD_REGRA_FISCAL_ICMS] = @v1 and [CD_GPO_TRIB_PESSOA] = @v2 ";
                Cmd    = new SqlCommand(strSQL, Con);
                Cmd.Parameters.AddWithValue("@v1", CodigoRegra);
                Cmd.Parameters.AddWithValue("@v2", CodigoGrupo);
                Dr = Cmd.ExecuteReader();

                RegFisIcmsGpoTribPessoa p = null;

                if (Dr.Read())
                {
                    p = new RegFisIcmsGpoTribPessoa
                    {
                        CodGpoTribPessoa = Convert.ToInt32(Dr["CD_GPO_TRIB_PESSOA"]),
                        CodigoRegFisIcms = Convert.ToInt64(Dr["CD_REGRA_FISCAL_ICMS"])
                    };
                }

                return(p);
            }
            catch (Exception ex)
            {
                throw new Exception("Erro ao Pesquisar Regra Fiscal Icms Gpo Trib Pessoa: " + ex.Message.ToString());
            }
            finally
            {
                FecharConexao();
            }
        }
Beispiel #2
0
        public void Inserir(RegFisIcmsGpoTribPessoa p)
        {
            try
            {
                Excluir(p.CodigoRegFisIcms, p.CodGpoTribPessoa);

                AbrirConexao();


                strSQL = "insert into [REGRA_FISCAL_ICMS_GRUPO_PESSOA] (CD_REGRA_FISCAL_ICMS, CD_GPO_TRIB_PESSOA) values (@v1, @v2)";
                Cmd    = new SqlCommand(strSQL, Con);
                Cmd.Parameters.AddWithValue("@v1", p.CodigoRegFisIcms);
                Cmd.Parameters.AddWithValue("@v2", p.CodGpoTribPessoa);

                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 Incluir Regra Fiscal Icms Gpo Trib Pessoa: " + ex.Message.ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Erro ao gravar Fiscal Icms Gpo Trib Pessoa: " + ex.Message.ToString());
            }
            finally
            {
                FecharConexao();
            }
        }