public Int32 GerarDigito(string chave)
{
int i, j, Digito;
const string PESO = "4329876543298765432987654329876543298765432";
chave = chave.Replace("NFe", "");
if (chave.Length != 43)
{
this.cMensagemErro += string.Format("Erro na composição da chave [{0}] para obter o DV", chave) + Environment.NewLine;
return 0;
}
else
{
// Manual Integracao Contribuinte v2.02a - Página: 70 //
j = 0;
Digito = -1;
try
{
for (i = 0; i < 43; ++i)
j += Convert.ToInt32(chave.Substring(i, 1)) * Convert.ToInt32(PESO.Substring(i, 1));
Digito = 11 - (j % 11);
if ((j % 11) < 2)
Digito = 0;
}
catch
{
Digito = -1;
}
if (Digito == -1)
this.cMensagemErro += string.Format("Erro no cálculo do DV da chave [{0}]", chave) + Environment.NewLine;
return Digito;
}
}