internal static int Mod11_NossoNumero(string value, int Base) { int Digito, Soma = 0, Peso = 2; for (int i = value.Length; i > 0; i--) { Soma = Soma + (Convert.ToInt32(value.Mid(i, 1)) * Peso); if (Peso == Base) { Peso = 2; } else { Peso = Peso + 1; } } if ((Soma % 11) > 1) { Digito = 11 - (Soma % 11); } else if ((Soma % 11) == 1) { int d1 = Utils.ToInt32(Strings.Mid(value, value.Length, value.Length - 1)); d1 += 1; if (d1 == 10) { d1 = 0; } Digito = Banco_BRB.Mod11_NossoNumero(Strings.Mid(value, 1, value.Length - 1) + d1, 7); Digito += 20; } else { Digito = (Soma % 11); } return(Digito); }
public void FormataChave(Boleto boleto) { string zeros = "000"; string agencia = boleto.Cedente.ContaBancaria.Agencia; string conta = boleto.Cedente.ContaBancaria.Conta + boleto.Cedente.ContaBancaria.DigitoConta; int categoria = 1; boleto.Categoria = categoria; string nossonumero = boleto.NossoNumero; string banco = Utils.FormatCode(Codigo.ToString(), 3); //Mod10 dentro da classe Banco_BRB pelas particularidades que ela tem. int d1 = Banco_BRB.Mod10(zeros + agencia + conta + categoria + nossonumero + banco); int d2 = Banco_BRB.Mod11_NossoNumero(zeros + agencia + conta + categoria + nossonumero + banco + d1, 7); if (d2 > 10) { d1 += 1; d2 -= 20; } boleto.CodigoBarra.Chave = zeros + agencia + conta + categoria + nossonumero + banco + d1 + d2; }