Funções básicas
Iniciando o primeiro post desta categoria mostrando algumas das funções básicas (Mas essenciais) na utilização da NFe com .NET.
Módulo 11 – Para calculo do digito verificado da Chave.
Com certeza esta função pode ser reduzida para menos linhas… se o fizer, por favor deixe um comentário com o código, sugestões são sempre bem vindas
public static int modulo11(string chaveNFE)
{
if (chaveNFE.Length != 43)
throw new Exception("Chave inválida, não é possível calcular o digito verificador");
string baseCalculo = "4329876543298765432987654329876543298765432";
int somaResultados = 0;
for (int i = 0; i <= chaveNFE.Length - 1; i++)
{
int numNF = Convert.ToInt32(chaveNFE[i].ToString());
int numBaseCalculo = Convert.ToInt32(baseCalculo[i].ToString());
somaResultados += (numBaseCalculo * numNF);
}
int restoDivisao = (somaResultados % 11);
int dv = 11 - restoDivisao;
if ((dv == 0) || (dv > 9))
return 0;
else
return dv;
}
Remover Acentos
Esta função não é de minha autoria, peguei no Google um tempo atrás e realmente não lembro mais de onde ela foi retirada.
public static string TirarAcento(string palavra)
{
string palavraSemAcento = "";
string caracterComAcento = "áàãâäéèêëíìîïóòõôöúùûüçÁÀÃÂÄÉÈÊËÍÌÎÏÓÒÕÖÔÚÙÛÜÇ";
string caracterSemAcento = "aaaaaeeeeiiiiooooouuuucAAAAAEEEEIIIIOOOOOUUUUC";
for (int i = 0; i < palavra.Length; i++)
{
if (caracterComAcento.IndexOf(Convert.ToChar(palavra.Substring(i, 1))) >= 0)
{
int car = caracterComAcento.IndexOf(Convert.ToChar(palavra.Substring(i, 1)));
palavraSemAcento += caracterSemAcento.Substring(car, 1);
}
else
{
palavraSemAcento += palavra.Substring(i, 1);
}
}
return palavraSemAcento;
}
Remove formatação
Remove formatação de CNPJ/IE/RG/CPF, entre outros
public static string removeFormatacao(string texto)
{
string txt = "";
txt = texto.Replace(".", "");
txt = txt.Replace("-", "");
txt = txt.Replace("/", "");
txt = txt.Replace("(", "");
txt = txt.Replace(")", "");
txt = txt.Replace(" ", "");
return txt;
}
Por enquanto é isso, em breve (Ainda esta semana acredito eu) estarei postando uma classe para geração de XML, assim como exemplos para conexão com WebService, assinatura digital, cadeias de certificado, utilização de certificados A1 e A3 e etc.
Abraços
You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
Olá Giovanni,
Obrigado pelos exemplos. A função de módulo 11 me economizou alguns minutos ou até horas de trabalho. Eu tenho uma ótima função para remover formatação de uma forma bem mais genérica. Ela remove tudo que não é letra ou número. Se quiser, pode publicá-la.
Abraço, Jimmy.
public static string LimpaTexto(string s)
{
int i = 0;
char ch;
while (i < s.Length)
{
ch = s.ToCharArray()[i];
if (!Char.IsLetterOrDigit(ch))
s = s.Remove(i, 1);
else
i++;
}
return s;
}
mp3…
I adore reading and I believe this website got some truly utilitarian stuff on it!…
dekorasyon…
anybody know of a good theme in which I can put in the full custom header, and make the theme a nice color gold? …
mobilya resimleri…
Very good blog, was happy to learn a lot here, I hope I can often look, thank you very much! …
son model mobilya…
thank you admin,for your great blog . but I think there is still a few steps to the change for blog…….
AlaMarka…
I’ve been visiting your blog for a while now and I always find a gem in your new posts. Thanks for sharing…
ikinci el oto…
Thanks very much for sharing all of the good info!…
masko…
I truly appreciate this post. I have been looking everywhere for this! Thank goodness I found it on Bing. You’ve made my day! Thx again…
oto kiralama …
Great articles & Nice a site.. Hey very nice blog!!…
ozoderm…
Thanks for taking the time to debate this, I feel strongly about it and love studying extra on this topic. If possible, as you acquire expertise, would you mind updating your blog with further information? It is extremely useful for me….
Buy@Coral.Calcium.Online” rel=”nofollow”>……
Buygeneric pills…
Buy@Discount.Coral.Calcium” rel=”nofollow”>.…
Buyit now…
Purchase@Cheap.Coral.Calcium” rel=”nofollow”>..…
Buynow it…
Buy@Abana.Online” rel=”nofollow”>.…
Buynow it…
Order@Discount.Abana” rel=”nofollow”>..…
Buygeneric pills…
Get@Abana.Online” rel=”nofollow”>..…
Buyit now…
Buy@Discount.Abilify” rel=”nofollow”>……
Buywithout prescription…
Order@Discount.Abilify” rel=”nofollow”>..…
Buyno prescription…
Get@Abilify.Online” rel=”nofollow”>..…
Buygeneric drugs…
Order@Generic.Abilify” rel=”nofollow”>……
Buywithout prescription…
Order@Acai.Online” rel=”nofollow”>……
Buynow…
Order@Discount.Acai” rel=”nofollow”>……
Buywithout prescription…
Purchase@Acai.Online” rel=”nofollow”>……
Buynow…
Buy@Generic.Acai” rel=”nofollow”>..…
Buywithout prescription…
Purchase@Generic.Acai” rel=”nofollow”>……
Buygeneric drugs…
Cheap@Acai.Without.Prescription” rel=”nofollow”>..…
Buygeneric meds…
Order@Coral.Calcium.Online” rel=”nofollow”>..…
Buyno prescription…
Buy@Coral.Calcium.Online” rel=”nofollow”>.…
Buygeneric meds…
Buy@Acai.Online” rel=”nofollow”>.…
Buyit now…
Buy@Discount.Coral.Calcium” rel=”nofollow”>.…
Buygeneric meds…
Buy@Acai.Online” rel=”nofollow”>……
Buynow it…
Buy@Acai.Online” rel=”nofollow”>..…
Buygeneric drugs…
where@can.i.purchase.max.acai” rel=”nofollow”>..…
Buynow it…
Order@Acai.Online” rel=”nofollow”>..…
Buydrugs without prescription…
Order@Cheap.Acai” rel=”nofollow”>……
Buyit now…
Order@Discount.Acai” rel=”nofollow”>..…
Buywithout prescription…
Purchase@Acai.Online” rel=”nofollow”>……
Buyit now…
where@can.you.buy.acai.berry” rel=”nofollow”>..…
Buygeneric drugs…
Order@Cheap.Energy.Boost” rel=”nofollow”>.…
Buynow it…
Purchase@Energy.Boost.Online” rel=”nofollow”>.…
Buygeneric drugs…
Cheap@Energy.Boost.Online” rel=”nofollow”>.…
Buynow it…
Get@Energy.Boost.Online” rel=”nofollow”>.…
Buygeneric pills…
Order@Discount.Accupril” rel=”nofollow”>.…
Buygeneric drugs…
Order@Accutane.Online” rel=”nofollow”>.…
Buynow it…
Get@Accutane.Online” rel=”nofollow”>.…
Buygeneric meds…
Buy@Accutane.Without.Prescription” rel=”nofollow”>.…
Buygeneric drugs…
Buy@Aciphex.20mg” rel=”nofollow”>.…
Buygeneric drugs…
Buy@Discount.Acomplia” rel=”nofollow”>.…
Buygeneric meds…
Order@Cheap.Acomplia” rel=”nofollow”>.…
Buyno prescription…
Purchase@Generic.Actonel” rel=”nofollow”>.…
Buygeneric meds…