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
| <%@ Page Title="Page d'accueil" Language="C#" AutoEventWireup="true"%>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
Application["id"] = getCount();
//--- Mise en base de donnée
if (Request.Params["n"] != null)
{
Application["id"] = Convert.ToInt32(Application["id"]) + 1;
ajoutBDD(Convert.ToInt32(Application["id"]), Request.Params["n"].ToString(), Request.Params["v"].ToString(), Convert.ToInt32(Request.Params["cp"].ToString()), Request.Params["a"].ToString(), Request.Params["mail"].ToString(), Convert.ToInt32(Request.Params["s"].ToString()), Request.Params["tel"].ToString(), Request.Params["im"].ToString());
}
//--- Affichage de la base de donnée
La.Text += "<br/>";
La.Text += "<br/> Contenu de la base de donnée";
La.Text += "<br/> ----------------------------<br/>";
for (int i = 0; i < Convert.ToInt32(Application["id"]); i++)
{
affBDD(i);
La.Text += "<br/>";
}
La.Text += "<br/> ----------------------------<br/>";
}
protected int getCount()
{
// renvoi le nombre de ligne dans la BDD
}
protected void affBDD(int id)
{
//Affiche le contenu de la base de donnée
}
protected void ajoutBDD(int id, string nom, string ville, int codePostal, string annonce, string email, int surface, string tel, string images)
{
try
{
// Chaine de connexion
string connectString = "XXX; XXX; XXX; XXX";
// Objet connection
System.Data.SqlClient.SqlConnection connection = new System.Data.SqlClient.SqlConnection(connectString);
// Ouverture
connection.Open();
// Objet Command
System.Data.SqlClient.SqlCommand command = new System.Data.SqlClient.SqlCommand
("INSERT INTO immob (\"id\",\"nom\",\"ville\",\"code_postal\" ,\"annonce\" ,\"email\" ,\"surface\" ,\"telephone\" ,\"images\")
values (\'"+id+"\',\'"+nom+"\',\'"+ville+"\',\'"+codePostal+"\',\'"+annonce+"\',\'"+email+"\',\'"+surface+"\',\'"+tel+"',\'"+images+"\')",connection);
// Execution
int affectedrows = command.ExecuteNonQuery();
La.Text += "Nombre de lignes affectées" + affectedrows;
// Fermeture connection
connection.Close();
}
catch (Exception ex)
{
La.Text += ex.ToString();
}
}
public void Check(object sender, EventArgs e) // lors de la validation du formulaire
{
Response.Redirect("Default.aspx?n=" + tbNom.Text + "&cp=" + tbCodePostal.Text+"&v=" + tbVille.Text+"&a=" + tbAnnonce.Text+"&s=" + tbSurface.Text+"&mail=" + tbMail.Text+"&im=" + tbImages.Text+ "&tel="+tbTel.Text);
}
</script> |
Partager