1-06-04-2021-Calculatrice-Changment Color: Rachid Tounsy
1-06-04-2021-Calculatrice-Changment Color: Rachid Tounsy
1-06-04-2021-Calculatrice-changment color
TP-1 : changment color- ListItem
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style>
#Panel1
{
height:200px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
</asp:RadioButtonList>
</div>
</form>
</body>
</html>
-------
namespace WebApplication_TP2
{
public partial class WebForm2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
1
protected void Button1_Click(object sender, EventArgs e)
{
if(RadioButtonList1.SelectedIndex==0)
{
Panel1.BackColor = Color.Red;
}
if (RadioButtonList1.SelectedIndex == 1)
{
Panel1.BackColor = Color.Blue;
}
if (RadioButtonList1.SelectedIndex == 2)
{
Panel1.BackColor = Color.Green;
}
}
}
}
}
TP2 : Calculatrice
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style>
.c1{
background-color:aqua;
width:80%;
}
.c2{
font-size:20px;
font-weight:bold:
}
.auto-style1 {
2
width: 100%;
}
.auto-style2 {
width: 331px;
}
.auto-style3 {
width: 331px;
height: 22px;
}
.auto-style4 {
height: 22px;
}
.auto-style5 {
width: 331px;
height: 23px;
}
.auto-style6 {
height: 23px;
}
.auto-style7 {
width: 331px;
height: 25px;
}
.auto-style8 {
height: 25px;
}
.auto-style9 {
width: 331px;
height: 24px;
}
.auto-style10 {
height: 24px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<h1> Calculatrice</h1>
<div class="c1">
<table class="auto-style1">
<tr>
<td class="auto-style2">
<asp:Label ID="Label1" runat="server" Text="Donner a"></asp:Label>
</td>
<td>
<asp:TextBox ID="TextBox1" runat="server" style="margin-bottom:
0px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="auto-style2">
<asp:Label ID="Label2" runat="server" Text="Donner b"></asp:Label>
</td>
<td>
<asp:TextBox ID="TextBox2" runat="server" style="margin-bottom:
0px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="auto-style5"></td>
<td class="auto-style6">
3
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" Width="84px" />
</td>
</tr>
<tr>
<td class="auto-style3">
<asp:Label ID="Label3" runat="server" CssClass="c2" Text="+"></asp:Label>
</td>
<td class="auto-style4">
<asp:Label ID="Label7" runat="server" Text="Rersultat"></asp:Label>
</td>
</tr>
<tr>
<td class="auto-style9">
<asp:Label ID="Label4" runat="server" BorderStyle="None" ForeColor="Black" CssClass="c2" Text="-"
Width="60px" Height="19px"></asp:Label>
</td>
<td class="auto-style10">
<asp:Label ID="Label8" runat="server" Text="Rersultat"></asp:Label>
</td>
</tr>
<tr>
<td class="auto-style7">
<asp:Label ID="Label5" runat="server" BorderStyle="None" ForeColor="Black"
CssClass="c2" Text="*" Width="60px" Height="19px"></asp:Label>
</td>
<td class="auto-style8">
<asp:Label ID="Label9" runat="server" Text="Rersultat"></asp:Label>
</td>
</tr>
<tr>
<td class="auto-style2">
<asp:Label ID="Label6" runat="server" BorderStyle="None" ForeColor="Black"
CssClass="c2" Text="/" Width="60px" Height="19px"></asp:Label>
</td>
<td>
<asp:Label ID="Label10" runat="server" Text="Rersultat"></asp:Label>
</td>
</tr>
<tr>
<td class="auto-style2"> </td>
<td>
<asp:Label ID="Label11" runat="server" Text="Label"></asp:Label>
</td>
</tr>
<tr>
<td class="auto-style2"> </td>
<td> </td>
</tr>
<tr>
<td class="auto-style2"> </td>
<td> </td>
</tr>
</table>
</div>
</form>
</body>
</html>
namespace WebApplication1
{
public partial class WebForm2 : System.Web.UI.Page
4
{
protected void Page_Load(object sender, EventArgs e)
{
int M = a * b;
int S = a - b;
Label7.Text = "Somme est " + Sum.ToString();
Label8.Text = "Soustraction est " + S.ToString();
Label9.Text = "Multiplicatin est " + M.ToString();
Label10.Text = "Division est " + D.ToString();
}
catch(Exception ex)
{
Label11.Text= ex.Message;
}
}
3-07-04-2021-Activity_Apprentissage_2_asp.net
Exercices 1
5
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Exercices1.aspx.cs"
Inherits="Exercices1.Exercices1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.auto-style1 {
width: 100%;
}
.auto-style2 {
height: 26px;
}
.auto-style3 {
height: 25px;
}
.auto-style4 {
height: 27px;
}
table
{
background-color:aqua;
}
#Button1
{
width:200px;
height:30px;
color:black;
background-color:darkgreen;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<h1> Text </h1>
<table class="auto-style1">
<tr>
<td class="auto-style3">
<asp:Label ID="Label1" runat="server" Text="Tapez u texte
(AutoPostBack=False)"></asp:Label>
</td>
6
<td class="auto-style3">
<asp:TextBox ID="TextBox1" runat="server" Height="22px"
OnTextChanged="TextBox1_TextChanged"></asp:TextBox>
</td>
<td class="auto-style3">
<asp:Label ID="Label5" runat="server" Text="Label"></asp:Label>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label2" runat="server" Text="Tapez u texte
(AutoPostBack=True)"></asp:Label>
</td>
<td>
<asp:TextBox ID="TextBox2" runat="server" AutoPostBack="True"
OnTextChanged="TextBox2_TextChanged"></asp:TextBox>
</td>
<td>
<asp:Label ID="Label6" runat="server" Text="Label"></asp:Label>
</td>
</tr>
<tr>
<td class="auto-style4">
<asp:Label ID="Label3" runat="server" Text="Mod de passe"></asp:Label>
</td>
<td class="auto-style4">
<asp:TextBox ID="TextBox3" runat="server" AutoPostBack="True"
TextMode="Password"></asp:TextBox>
</td>
<td class="auto-style4"></td>
</tr>
<tr>
<td class="auto-style2">
<asp:Label ID="Label4" runat="server" Text="Plusieurs Lignes"></asp:Label>
</td>
<td class="auto-style2">
<asp:TextBox ID="TextBox4" runat="server" AutoPostBack="True"
TextMode="MultiLine" Height="78px" OnTextChanged="TextBox4_TextChanged"></asp:TextBox>
</td>
<td class="auto-style2">
<asp:CheckBox ID="CheckBox1" runat="server"
OnCheckedChanged="CheckBox1_CheckedChanged" Text="Wrap" />
<br />
<asp:CheckBox ID="CheckBox2" runat="server" Text="ReadOnly"
OnCheckedChanged="CheckBox2_CheckedChanged" />
</td>
</tr>
</table>
<div>
<asp:Button ID="Button1" runat="server" Text="OK" Width="782px" />
</div>
</form>
</body>
</html>
protected void Page_Load(object sender, EventArgs e)
{
if(this.IsPostBack==false)
{
CheckBox1.Checked = TextBox4.ReadOnly;
CheckBox2.Checked = TextBox4.Wrap;
}
7
}
TP_dropdwonlist_manipulation
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="Ville"></asp:Label>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"
OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" style="margin-bottom: 0px">
</asp:DropDownList>
</div>
8
<br />
<asp:Button ID="Button1" runat="server" Text="Afficher la valeur selectionner"
OnClick="Button1_Click" />
</form>
</body>
</html>
protected void Page_Load(object sender, EventArgs e)
{if(this.IsPostBack==false) {
ListItem x = new ListItem("Rabat", "1");
ListItem y = new ListItem("Beni Mellal", "2");
ListItem z = new ListItem("Casa", "3");
ListItem E = new ListItem("Azillal", "4");
DropDownList1.Items.Add(x);
DropDownList1.Items.Add(y);
DropDownList1.Items.Add(z);
DropDownList1.Items.Add(E); }
}
protected void Button1_Click(object sender, EventArgs e)
{
int i = DropDownList1.SelectedIndex;
string ville = DropDownList1.Items[i].Text;
string Valauer_ville = DropDownList1.Items[i].Value;
Response.Write("indice selectionner : " + i.ToString() + " " + ville + " " +
Valauer_ville);
}
9
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Exercice_2_les_controles_DropDownList_et_Button
{
public partial class Exercice_2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
DropDownList1.Items.Add(new ListItem("Euros", "0,7436"));
DropDownList1.Items.Add(new ListItem("Yen Japonais ", "81,0"));
DropDownList1.Items.Add(new ListItem("Dollars Canadien", "0,9996"));
Image1.Visible = false;
}
}
TextBox1.BackColor = Color.White;
int i = DropDownList1.SelectedIndex;
decimal valuesMonnaie = decimal.Parse(DropDownList1.Items[i].Value);
decimal MontantTotale = montantUs * valuesMonnaie;
string nomMonnaie = DropDownList1.Items[i].Text;
ListItem element = DropDownList1.Items[DropDownList1.SelectedIndex];
Label3.Text = montantUs.ToString() + " Dollars U.S= ";
Label3.Text += MontantTotale.ToString() + " " + element.Text;
}
else
{
TextBox1.BackColor = Color.Red;
throw new Exception("montant ne doit pas etre negatifs");
}
}
catch(Exception ex)
{
Label3.Text = ex.Message;
}
} }}
10
5-13-04-2021 DropdowList ville –carier
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="Ville"></asp:Label>
<asp:DropDownList ID="DropDownList1" runat="server" Height="16px"
OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" style="margin-bottom: 0px"
AutoPostBack="True">
</asp:DropDownList>
<br />
<br />
<asp:Label ID="Label2" runat="server" Text="Quartier"></asp:Label>
<asp:DropDownList ID="DropDownList2" runat="server"
OnSelectedIndexChanged="DropDownList2_SelectedIndexChanged" style="margin-bottom: 0px">
</asp:DropDownList>
<br />
<br />
<asp:Button ID="Button1" runat="server" Text="Envoyer" OnClick="Button1_Click" />
<br />
<br />
<asp:Label ID="Label3" runat="server" Text="message"></asp:Label>
<br />
</div>
</form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
11
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace TP1_DropdowList
{
public partial class TP1_DropdowList : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if(this.IsPostBack==false)
{
ListItem a = new ListItem("Choisir une Ville", "0");
DropDownList1.Items.Add(x);
DropDownList1.Items.Add(y);
DropDownList1.Items.Add(z);
DropDownList1.Items.Add(K);
}
}
int i = DropDownList1.SelectedIndex;
if(i==1)
{
DropDownList2.Items.Clear();
ListItem x1 = new ListItem("Takadom", "1");
ListItem x2 = new ListItem("ELHoda", "2");
ListItem x3= new ListItem("Riyad salam", "4");
DropDownList2.Items.Add(x1);
DropDownList2.Items.Add(x2);
DropDownList2.Items.Add(x3);
}
if (i == 2)
{
DropDownList2.Items.Clear();
ListItem a1 = new ListItem("Agdal", "1");
ListItem a2 = new ListItem("Hassan 6", "2");
ListItem a3 = new ListItem("Souissi", "3");
DropDownList2.Items.Add(a1);
DropDownList2.Items.Add(a2);
DropDownList2.Items.Add(a3);
}
if (i == 3)
{
DropDownList2.Items.Clear();
ListItem z1 = new ListItem("Hassan 2", "1");
ListItem z2 = new ListItem("Riyad", "2");
DropDownList2.Items.Add(z1);
DropDownList2.Items.Add(z2);
12
}
if (i == 4)
{
DropDownList2.Items.Clear();
ListItem K1 = new ListItem("Elsaada", "1");
ListItem K2 = new ListItem("Hawziya", "2");
ListItem K3 = new ListItem("Narjis", "3");
DropDownList2.Items.Add(K1);
DropDownList2.Items.Add(K2);
DropDownList2.Items.Add(K3);
}
}
}
}
}
6-14-04-2021-Controle de Validation
13
RegularExpressionValidator
7-20-04-2021- Cookies
Page 1
Page 2
14
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TP1.aspx.cs" Inherits="TP_Cookie.TP1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style>
.Panel1
{
height:250px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace TP_Cookie
{
public partial class TP1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
15
{
if (!IsPostBack) {
RadioButtonList1.Items.Add(new ListItem("Red", "0"));
RadioButtonList1.Items.Add(new ListItem("Blue", "1"));
RadioButtonList1.Items.Add(new ListItem("Green", "2"));
}
}
}
}
}
Page 2 afficherCookies
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;
namespace TP_Cookie
{
public partial class afficherCokies : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if ( Request.Cookies["c2"]!=null)
{
Label1.Text =Request.Cookies["c1"].Value.ToString();
Label2.Text = Request.Cookies["c2"].Value.ToString();
}
else
{
Response.Redirect("TP1.aspx");
}
16
}
}
}
}
8-21-04-2021 Request_QueryString
TP1
Page 1
protected void Button1_Click(object sender, EventArgs e)
{
string url = "page2.aspx?nom=" + TextBox1.Text+
"&tel1="+TextBox3.Text+"&prenom="+TextBox2.Text;
Response.Redirect(url);
}
}
Page2
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Request_QueryString
{
public partial class page2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
17
if (Request.QueryString["tel1"] != null)
{
string telFrompage1 = Request.QueryString["nom"].ToString();
string prenom = Request.QueryString["prenom"].ToString();
string tel = Request.QueryString["tel1"].ToString();
}
else
{
Response.Redirect("page1.aspx");
}
}
}
}
TP2 : cookie_couleur
Page 1
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace cookie_couleur
{
public partial class page1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
18
if (RadioButton3.Checked)
{
couleur = "B";
}
if (couleur == "")
{
Response.Write("veullez cocher une couleur");
}
else
{
Page 2
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;
namespace cookie_couleur
{
public partial class page2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Request.Cookies["cookie_couleur"] != null)
{
if (couleur == "R")
{
Panel1.BackColor = Color.Red;
}
if (couleur == "G")
{
Panel1.BackColor = Color.Green;
}
if (couleur == "B")
{
Panel1.BackColor = Color.Blue;
}
}
else
{
Panel1.BackColor = Color.DarkRed;
}
19
{
}
}
}
9-23-04-2021 session_et_database_table_aspnet_
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace TP1_session
{
public partial class TP_2_login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if(Request.QueryString["message"]!=null)
{
Label4.Text = Request.QueryString["message"];
}
}
20
}
}
}
}
Page menu
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace TP1_session
{
public partial class Menu : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Session["nom"]!=null)
{
Label1.Text = Session["nom"].ToString();
Label2.Text = "Bonjour "+ Session["nom"].ToString()+",si mon TP Session 24-04-2021";
}
else
{
//Response.Redirect("TP_2_login.aspx");
Response.Redirect("TP_2_login.aspx?message= pas autorise d'entre dans menu !!");
}
}
}
21
10-24-04-2021 session_et_database_table
Page login
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
namespace TP1_session
{
public partial class TP_2_login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if(Request.QueryString["message"]!=null)
{
Label4.Text = Request.QueryString["message"];
}
}
22
cmd.Parameters.Add(P2);
SqlDataReader dr = cmd.ExecuteReader();
if(dr.Read()==true)
{
string code = dr.GetValue(0).ToString();
string nom = dr.GetValue(1).ToString();
string password = dr.GetValue(2).ToString();
Session["code"] = code;
Session["nom"] = nom;
Session["password"] = password;
Response.Redirect("Menu.aspx");
}
else
{
//aucun lign dans la table client (base de donnee TP_ASP)
Label3.Text = "erreur de nom ou password";
}
con.Close();
}
catch(Exception ex )
{
Label4.Text = ex.Message;
}
}
}
}
}
Page inscription
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
namespace TP1_session
{
public partial class iscription : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
23
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = "insert into client values(@code,@nom,@password)";
cmd.Parameters.Clear();
cmd.Parameters.AddWithValue("@code", SqlDbType.Int).Value = TextBox1.Text;
cmd.Parameters.AddWithValue("@nom", SqlDbType.VarChar).Value = TextBox2.Text;
cmd.Parameters.AddWithValue("@password", SqlDbType.VarChar).Value = TextBox3.Text;
int dr = cmd.ExecuteNonQuery();
if(dr==0)
{
Label5.Text = " Atansion !!!!";
Response.Redirect("iscription.aspx");
}
else
{
Label5.Text = " bien Ajouter ";
Response.Redirect("Menu.aspx");
}
con.Close();
}
catch(Exception ex)
{
Label5.Text = ex.Message;
}
}
}
}
Page Menu
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace TP1_session
{
public partial class Menu : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Session["nom"]!=null)
{
Label1.Text = " " +Session["nom"].ToString();
24
}
}
}
}
Page Rechercher
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
namespace TP1_session
{
public partial class rechercheclient : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
cmd.Parameters.Clear();
cmd.Parameters.AddWithValue("@code", SqlDbType.Int).Value = TextBox1.Text;
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read()==true)
{
TextBox1.Text = "";
TextBox2.Text = "";
TextBox3.Text = "";
TextBox2.Text = dr.GetValue(0).ToString();
TextBox3.Text = dr.GetValue(1).ToString();
TextBox4.Text = dr.GetValue(2).ToString();
25
}
else
{
Label2.Text = " ce client nexiste pas";
}
dr.Close();
con.Close();
}
catch (Exception ex)
{
Label2.Text = ex.Message;
}
}
}
}
Base de donnee
create database TP_ASP
USE TP_ASP
go
/*TP 1 23-04-2021*/
GO
create table client(code int primary key,nom varchar(20),password varchar(30))
GO
insert into client values(1,'ahmed','123'),
(2,'amine','456'),
(3,'khalid','789'),
(4,'fouad','4546'),
(5,'khadiga','756'),
(6,'aicha','897'),
(7,'ahmed','123'),
(8,'nabila','123')
11-27-04-2021
26
Page Rechercherparnom
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
namespace TP1_session
{
public partial class Rechercherparnom : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if(this.IsPostBack==false)
{
string chain = "Data Source=DESKTOP-R59K5PE\\SQLEXPRESS01;Initial
Catalog=TP_ASP;Integrated Security=True";
string sql = " SELECT * FROM client";
SqlConnection con = new SqlConnection(chain);
con.Open();
SqlCommand cmd = new SqlCommand(sql,con);
SqlDataReader dr = cmd.ExecuteReader();
DataTable t = new DataTable();
t.Load(dr);
DropDownList1.DataTextField = "nom";
DropDownList1.DataValueField = "code";
DropDownList1.DataSource = t;
DropDownList1.DataBind();
con.Close();
}
}
27
{
try
{
string chainecon = "Data Source=DESKTOP-R59K5PE\\SQLEXPRESS01;Initial
Catalog=TP_ASP;Integrated Security=True";
string sql = "SELECT * FROM client where code = @code";
SqlConnection con = new SqlConnection(chainecon);
con.Open();
SqlCommand cmd = new SqlCommand(sql, con);
SqlParameter p1 = new SqlParameter("@code",int.Parse(DropDownList1.SelectedValue));
cmd.Parameters.Add(p1);
SqlDataReader dr = cmd.ExecuteReader();
DataTable t = new DataTable();
t.Load(dr);
GridView1.DataSource = t;
GridView1.DataBind();
con.Close();
}
catch (Exception ex)
{
Label3.Text = ex.Message;
}
}
}
}
11-27-04-2021
Rechercherparnom
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
namespace TP1_session
{
public partial class Rechercherparnom : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if(this.IsPostBack==false)
{
string chain = "Data Source=DESKTOP-R59K5PE\\SQLEXPRESS01;Initial
Catalog=TP_ASP;Integrated Security=True";
string sql = " SELECT * FROM client";
28
SqlConnection con = new SqlConnection(chain);
con.Open();
SqlCommand cmd = new SqlCommand(sql,con);
SqlDataReader dr = cmd.ExecuteReader();
DataTable t = new DataTable();
t.Load(dr);
DropDownList1.DataTextField = "nom";
DropDownList1.DataValueField = "code";
DropDownList1.DataSource = t;
DropDownList1.DataBind();
con.Close();
}
}
}
catch (Exception ex)
{
Label3.Text = ex.Message;
}
}
}
}
29
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
namespace TP1_session
{
public partial class SupprimerClient : System.Web.UI.Page
{
void DropDownList()
{
if (this.IsPostBack == false)
{
string chain = "Data Source=DESKTOP-R59K5PE\\SQLEXPRESS01;Initial
Catalog=TP_ASP;Integrated Security=True";
string sql = " SELECT * FROM client";
SqlConnection con = new SqlConnection(chain);
con.Open();
SqlCommand cmd = new SqlCommand(sql, con);
SqlDataReader dr = cmd.ExecuteReader();
DataTable t = new DataTable();
t.Load(dr);
DropDownList1.DataTextField = "nom";
DropDownList1.DataValueField = "code";
DropDownList1.DataSource = t;
DropDownList1.DataBind();
charger();
//Response.Redirect("SupprimerClient.aspx");
}
}
void charger()
{
string chainecon = "Data Source=DESKTOP-R59K5PE\\SQLEXPRESS01;Initial
Catalog=TP_ASP;Integrated Security=True";
string sql = "SELECT * FROM client";
SqlConnection con = new SqlConnection(chainecon);
con.Open();
30
SqlCommand cmd = new SqlCommand(sql, con);
SqlDataReader dr = cmd.ExecuteReader();
DataTable t = new DataTable();
t.Load(dr);
GridView1.DataSource = t;
GridView1.DataBind();
con.Close();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
Panel1.Visible = true;
}
con.Close();
charger();
DropDownList();
Response.Redirect("SupprimerClient.aspx");
}
catch (Exception ex)
{
Label3.Text = ex.Message;
}
}
31
}
}
}
TP 2 : site master
Page SupprimerClient
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
namespace TP_site_master
{
public partial class SupprimerClient : System.Web.UI.Page
{
private void charger_les_clients()
{
string chaincon = "Data Source=DESKTOP-R59K5PE\\SQLEXPRESS01;Initial
Catalog=TP_ASP;Integrated Security=True";
string sql = " SELECT * FROM client";
SqlConnection cone = new SqlConnection(chaincon);
cone.Open();
SqlCommand comande = new SqlCommand(sql, cone);
SqlDataReader dr = comande.ExecuteReader();
DataTable t = new DataTable();
t.Load(dr);
GridView1.DataSource = t;
GridView1.DataBind();
cone.Close();
}
protected void Page_Load(object sender, EventArgs e)
{
charger_les_clients();
}
private bool existteClient( int code)
{
bool test = false;
string chaincon = "Data Source=DESKTOP-R59K5PE\\SQLEXPRESS01;Initial
Catalog=TP_ASP;Integrated Security=True";
string sql = " SELECT * FROM client where code=@code";
32
SqlConnection cone = new SqlConnection(chaincon);
cone.Open();
SqlCommand comande = new SqlCommand(sql, cone);
SqlParameter parcod = new SqlParameter("@code", code);
comande.Parameters.Add(parcod);
SqlDataReader dr = comande.ExecuteReader();
if(dr.Read()==true)
{
test = true;
}
cone.Close();
return test;
}
private void supprimerparcode(int code)
{
string chaincon = "Data Source=DESKTOP-R59K5PE\\SQLEXPRESS01;Initial
Catalog=TP_ASP;Integrated Security=True";
string sql = " DELETE FROM client where code=@code";
SqlConnection cone = new SqlConnection(chaincon);
cone.Open();
SqlCommand comande = new SqlCommand(sql, cone);
SqlParameter parcod = new SqlParameter("@code", code);
comande.Parameters.Add(parcod);
SqlDataReader dr = comande.ExecuteReader();
charger_les_clients();
}
protected void Button1_Click(object sender, EventArgs e)
{
try
{
int code = int.Parse(TextBox1.Text);
bool test = existteClient(code);
if(test==false)
{
Label2.Text = "Client avec le code " + code.ToString() + " n existe pas";
}
else
{
supprimerparcode(code);
}
}
catch(Exception ex)
{
Response.Write(ex.Message);
}
}
}
}
33
Page listClient
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
namespace TP_site_master
{
public partial class listClient : System.Web.UI.Page
{
private void charger_les_clients()
{
string chaincon = "Data Source=DESKTOP-R59K5PE\\SQLEXPRESS01;Initial
Catalog=TP_ASP;Integrated Security=True";
string sql= " SELECT code,nom,len(nom) as 'nomber caractere' FROM client";
SqlConnection cone= new SqlConnection(chaincon);
cone.Open();
SqlCommand comande = new SqlCommand(sql, cone);
SqlDataReader dr = comande.ExecuteReader();
DataTable t = new DataTable();
t.Load(dr);
GridView1.DataSource = t;
GridView1.DataBind();
cone.Close();
34
12-28-04-2021-Mercredi_seance__control_utilisateur_ (à distance)
using System;
35
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;
namespace Exercices_1_controle_Utilisateur_web
{
public partial class MenuCtrl : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
AddMenuItem("Facebook", "http://www.facebook.com");
AddMenuItem("github.", "https://github.com/Rachidtounsy");
AddMenuItem("ofppt", "http://ofppt.info/");
AddMenuItem("Page Ajouter Client", "AjouterClient.aspx");
}
private void AddMenuItem(string linkName, string linkURL)
{
TableRow menuRow = new TableRow();
Table1.Rows.Add(menuRow);
TableCell menuCell = new TableCell();
BuildLink(menuCell, linkName, linkURL);
menuRow.Cells.Add(menuCell);
}
private void BuildLink(TableCell menuCell, string linkCaption, string
linkHRef)
{
HyperLink menuLink = new HyperLink();
menuLink.Text = linkCaption;
menuLink.NavigateUrl = linkHRef;
menuCell.Controls.Add(menuLink);
}
public Color BackGroundColor
{
get
{
return Table1.BackColor;
}
set
{
Table1.BackColor = value;
}
}
public string cssStyle
{
get
{ return Table1.BackColor; }
set
{ Table1.BackColor = value; }
}
}
}
----
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
36
using System.Web.UI.WebControls;
using System.Drawing;
namespace Exercices_1_controle_Utilisateur_web
{
public partial class AjouterClient : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
// MenuCtrl1.couleurDuTableau = Color.Aqua;
MenuCtrl1.BackGroundColor = Color.Azure;
MenuCtrl1.cssStyle = "c1";
}
}
}
13-29-04-2021-TP_procedure (à distance)
Page ApppeProc
using System;
using System.Data;
using System.Data.SqlClient;
namespace TP_procedure
{
37
public partial class ApppeProc : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
catch (Exception ex)
{
Label2.Text = ex.Message;
}
}
}
}
14-04-05-2021-TP_procedure2 (à distance)
Appel de procedure stockee en c#(windowsform+webform)
1-procedure PC2
exec pc2 5
38
webform a realise
Code button
con.Close();
2-procedure PC3
39
select * from client
where nom=@nomclient
set @n = @@Rowcount
--nombre de ligne de la derniere requete
return convert(int ,getdate())
end
declare @x int
declare @r int
exec @r=pc3 'fouad',@x output
print @x
print @r
Code button :
//output
SqlParameter p2 = new SqlParameter("@n", SqlDbType.Int);
p2.Direction = ParameterDirection.Output;
//retvalue
SqlParameter valeurRetparametre= new SqlParameter("RetVal", SqlDbType.Int);
valeurRetparametre.Direction = ParameterDirection.ReturnValue;
cmd.Parameters.Add(p1);
cmd.Parameters.Add(p2);
cmd.Parameters.Add(valeurRetparametre);
SqlDataReader dr=cmd.ExecuteReader();
40
con.Close();
15-19-05-2021 : XML
TP 1 :
--19-05-2021
create table city (
id int primary key identity,
nameC varchar(50),
countryCode varchar(50),
poopulation float
)
16-26-05-2021
TP 1 :
41
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
namespace appGridViewSimple
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (this.IsPostBack == false)
{
chargegrid();
}
}
public void chargegrid()
{
String sql = "SELECT * FROM client ";
42
String ch = "Data Source=DESKTOP-R59K5PE\\SQLEXPRESS01;Initial
Catalog=Db_client_ParGeidViewSimple;Integrated Security=True";
SqlConnection con = new SqlConnection(ch);
SqlDataAdapter dt = new SqlDataAdapter(sql, con);
DataSet ds = new DataSet();
dt.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
TextBox1.Text = GridView1.SelectedRow.Cells[3].Text;
TextBox2.Text = GridView1.SelectedRow.Cells[4].Text;
TextBox3.Text = GridView1.SelectedRow.Cells[5].Text;
TextBox4.Text = GridView1.SelectedRow.Cells[6].Text;
chargegrid();
}
chargegrid();
}
43
String ch = "Data Source=DESKTOP-R59K5PE\\SQLEXPRESS01;Initial
Catalog=Db_client_ParGeidViewSimple;Integrated Security=True";
String sql = "update client set nom=@nom , prenom=@prenom ,salaire=@salaire where code
=@code ";
SqlConnection con = new SqlConnection(ch);
con.Open();
SqlCommand cmd = new SqlCommand(sql, con);
SqlParameter p1 = new SqlParameter("@nom",texNom.Text);
SqlParameter p2 = new SqlParameter("@prenom", texPrenom.Text);
SqlParameter p3 = new SqlParameter("@salaire", float.Parse(texsalaire.Text));
SqlParameter p4 = new SqlParameter("@code", int.Parse(texCode.Text));
cmd.Parameters.Add(p1);
cmd.Parameters.Add(p2);
cmd.Parameters.Add(p3);
cmd.Parameters.Add(p4);
cmd.ExecuteNonQuery();
con.Close();
//
GridView1.EditIndex = -1;
chargegrid();
}
catch (Exception mess)
{
Label5.Text = mess.Message;
}
}
int dr = cmd.ExecuteNonQuery();
if (dr == 0)
{
Label5.Text = " Atansion !!!!";
}
else
{
Label5.Text = " bien Ajouter ";
chargegrid();
}
con.Close();
}
catch (Exception ex)
44
{
Label5.Text = ex.Message;
}
}
}
}
45