| 12
 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
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 
 | using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Mail;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
 
public partial class defaultPage : System.Web.UI.Page
{
    string sRefTrasaction;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            int[] aValues = new int[91];
            int iValue = 10;
            for (int i = 0; i < 91 ; i++)
            {
                aValues[i] = iValue++;
            }
            montantDD.DataSource = aValues;
            montantDD.DataBind();
            //focus sur les champs formualaire
            montantDD.Attributes.Add("onchange", "updateMessage()");
            emailTB.Attributes.Add("onblur", "updateMessage()");
            libre.Attributes.Add("onclick", "getChoice(this)");
            libre.Attributes.Add("value", "usage libre");
            restreint.Attributes.Add("onclick", "getChoice(this)");
            restreint.Attributes.Add("value", "usage restreint");
        }
        IDmessage.Text = "";
 
    }
 
 
    protected void submit_change_Click (object sender, EventArgs e) 
    {
        //Création d'un nouvelle transaction
        sRefTrasaction = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString("D2");
        if (Page.IsValid)
        {
            // Création de la transaction
            createTransaction_Web();
        }
 
    }
    // //////////////////////////////////////////////
    // Création d'un nouvelle transaction 
    // Table: Transaction_Web
    /// /////////////////////////////////////////////
    private void createTransaction_Web()
    {
       ConnectionStringSettings settings;
       Int32 newProdID = 0;
       settings = ConfigurationManager.ConnectionStrings["DatabaseConnection"];
       string sRq1 = "INSERT INTO ********************"
               + "(****)"
               + "VALUES('" + DateTime.Now.ToString() + "','', '0','0','0','','','');"
               + "SELECT CAST(scope_identity() AS int)";
        if (settings != null)
        {
            using (SqlConnection conn = new SqlConnection(settings.ConnectionString))
            {
                SqlCommand cmd = new SqlCommand(sRq1, conn);
                try
                {
                    conn.Open();
                    // Création d'une nouvelle transaction vide
                    newProdID = (Int32)cmd.ExecuteScalar();
                    sRefTrasaction = "g"+sRefTrasaction+"FR"+newProdID.ToString();
                    ************************
                    string sType = "0";
                    if (libre.Checked)
                    {
                        sType = "1";
                    }else
                    {
                        sType ="0";
                    }
                    //Modifier la transation
                    string sRq2 = "UPDATE ******"
                                  + " SET RefExpay ='" + sRefTrasaction + "',"
                                  + "Montant='" + montantDD.SelectedValue + "',"
                                  + "AccesRestreint='" + sType + "',"
                                  + "AdresseEmail='" + emailTB.Text + "',"
                                  + "ClePerso='" + clefTB.Text + "',"
                                  + "AdresseIP='" + Session["IP"] + "'";
                    cmd.CommandText = sRq2;
                    cmd.ExecuteNonQuery();
                    // Si Paybox Retour OK
                    if (true)
                    {
                        Session["email"] = emailTB.Text;
                        Session["montant"] = montantDD.SelectedValue;
                        Session["type"] = sType;
                        // Affiche la page de confirmation
                        Response.Redirect("confirmation.aspx");
                    }
                    else
                    {
                        // Affiche la page d'erreur
                        Response.Redirect("erreur_PayBox.aspx");
                    }
                    //
                    //Ferme la connection
                    conn.Close();
                }
                catch (Exception e)
                {
                    sendExection(e.Message);
                }
            }
        }
    }
 
    // //////////////////////////////////////////////
    // Envoyer un message avec l'erreur 
    // Table: Transaction_Web
    /// /////////////////////////////////////////////
 
    protected void sendExection(string sMessage)
    {
        MailMessage oEmail = new MailMessage();
        string sUtilisateur = ConfigurationSettings.AppSettings["SmtpUtilisateur"];
        string sPassword = ConfigurationSettings.AppSettings["SmtpPassword"];
        string sServeur = ConfigurationSettings.AppSettings["SmtpServeur"];
 
        oEmail.From = sUtilisateur;
        oEmail.To = sUtilisateur;
        oEmail.Subject = "Erreur du Site Guichet";
        oEmail.Body = sMessage;
        SmtpMail.SmtpServer = sServeur;
 
        oEmail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
        oEmail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", sUtilisateur);
        oEmail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", sPassword);
 
        try
        {
            SmtpMail.Send(oEmail);
        }
        catch (Exception e)
        {
            IDmessage.Text = e.Message;
        }
    }
} | 
Partager