Détails de l'exception: System.FormatException: Le format de la chaîne d'entrée est incorrect.
Bonjour,
Ma variable, 'pourcentage_taxe1' et 'pourcentage_taxe2'se trouvent dans plusieurs fichiers.
Ces taux sont variables par semaine et je dois le changer chaque semaine dans plusieurs fichiers.
J'aimerais bien faire de changements, mais dans un seul fichier pour tous les formulaires.
J'essaie de les mettre dans le fichier web.config
Code:
1 2 3 4 5
|
<appSettings>
<add key="pourcentage_taxe1" value="0.05m" />
<add key="pourcentage_taxe2" value="0.07m" />
</appSettings> |
et je change le code en c# :
Code:
1 2 3
| //private decimal pourcentage_taxe1 = 0.05m;
static string string_pourcentage_taxe1 = ConfigurationManager.AppSettings["pourcentage_taxe1"];
private decimal pourcentage_taxe1 = decimal.Parse(string_pourcentage_taxe1); |
Et j'ai le message
Citation:
Détails de l'exception: System.FormatException: Le format de la chaîne d'entrée est incorrect.
Voici mes codes :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
|
namespace Ecom
{
public partial class engregistrement : System.Web.UI.Page
{
//private decimal pourcentage_taxe1 = 0.05m;
static string string_pourcentage_taxe1 = ConfigurationManager.AppSettings["pourcentage_taxe1"];
private decimal pourcentage_taxe1 = decimal.Parse(string_pourcentage_taxe1);
//private decimal pourcentage_taxe2 = 0.07m;
static string string_pourcentage_taxe2 = ConfigurationManager.AppSettings["pourcentage_taxe2"];
private decimal pourcentage_taxe2 = decimal.Parse(string_pourcentage_taxe2);
private void taxeCalculer(string xMontantTotal, string xCuntry, string xState, string xNombre)
{
calculMontant = Convert.ToDecimal(xMontantTotal);
Nombre = Convert.ToDecimal(xNombre);
calculMontant = calculMontant * Nombre;
if (xCuntry == "CA")
{
switch (xState)
{
case "QC":
T1erTaxe = calculMontant * pourcentage_taxe2;
T1erTaxe = decimal.Round(T1erTaxe, 2, MidpointRounding.AwayFromZero);
T2eTaxe = calculMontant * pourcentage_taxe1;
T2eTaxe = decimal.Round(T2eTaxe, 2, MidpointRounding.AwayFromZero);
deuxTaxes = T1erTaxe + T2eTaxe;
Somme = calculMontant + T1erTaxe + T2eTaxe;
break;
default:
T1erTaxe = calculMontant * pourcentage_taxe2;
T1erTaxe = decimal.Round(T1erTaxe, 2, MidpointRounding.AwayFromZero);
deuxTaxes = T1erTaxe;
Somme = calculMontant + T1erTaxe;
break;
}
}
else
{
deuxTaxes = T1erTaxe + T2eTaxe;
Somme = calculMontant;
}
intSomme = Convert.ToInt32(Somme * 100);
}
protected void Button_Click(object sender, System.EventArgs e)
{
object recup_info = Session["paiePrivatePage"];
paiement.paiePrivatePageState paiem = (paiement.nouveau1UtilisateurInscriptionPrivatePageState)recup_info;
CalculTaxe(paiem.PriceAmt.ToString(), paiem.CountryShipping, paiem.StateShipping, paiem.NumberOfCopies.ToString());
string stringDB = ConfigurationManager.AppSettings["stringDB"];
MySqlConnection conn = new MySqlConnection(stringDB);
conn.Open();
string req = ConfigurationManager.AppSettings["reqSql"];
MySqlCommand cmd = new MySqlCommand(req, conn);
MySqlParameter tps = new MySqlParameter("@tps", T1erTaxe);
MySqlParameter tvq = new MySqlParameter("@tvq", T2eTaxe);
//MySqlParameter somme = new MySqlParameter("@somme", Somme.ToString());
MySqlParameter somme = new MySqlParameter("@somme", decimal.Parse(Somme.ToString()));
cmd.Parameters.Add(tps);
cmd.Parameters.Add(tvq);
cmd.Parameters.Add(somme);
cmd.ExecuteNonQuery();
conn.Close();
}
}
} |
Est-ce que vous avez une idée pour régler la 1re partie de mon code où il y a cette erreur ?
Sinon comment je peux la mettre la valeur dans web.config et le récupérer en décimale dans mes formulaires ?
Merci