namespace ASPPlus { using System; using System.Data; using System.Text.RegularExpressions; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; using System.Collections; public class ApplicationController : System.Web.UI.Page { public System.Web.UI.WebControls.DataGrid table_clients; public System.Web.UI.WebControls.DataGrid table_commandes; public System.Web.UI.WebControls.DataGrid table_produits; public System.Web.UI.WebControls.DataGrid table_produit_commande; public System.Web.UI.WebControls.Button ajouterClient; public System.Web.UI.WebControls.Button ajouterProduit; public System.Web.UI.WebControls.Button ajouterCommande; public System.Web.UI.WebControls.Button ajouterProduitACommande; public System.Web.UI.HtmlControls.HtmlInputText nom; public System.Web.UI.HtmlControls.HtmlInputText prenom; public System.Web.UI.HtmlControls.HtmlInputText label; public System.Web.UI.HtmlControls.HtmlInputText prix; public System.Web.UI.HtmlControls.HtmlInputText quantite; public System.Web.UI.WebControls.DropDownList list_clients; public System.Web.UI.WebControls.DropDownList list_produits; public System.Web.UI.WebControls.DropDownList list_commandes; protected void Page_Load(object sender, EventArgs e) { ApplicationModel.Open(); } protected void Page_PreRender(Object sender, EventArgs e) { DataSet ds = ApplicationModel.GetClients(); table_clients.DataSource = ds; table_clients.DataBind(); list_clients.DataSource = ds; list_clients.DataBind(); ds = ApplicationModel.GetProduits(); table_produits.DataSource = ds; table_produits.DataBind(); list_produits.DataSource = ds; list_produits.DataBind(); ds = ApplicationModel.GetCommandes(); table_commandes.DataSource = ds; table_commandes.DataBind(); list_commandes.DataSource = ds; list_commandes.DataBind(); table_produit_commande.DataSource = ApplicationModel.GetProduitCommande(); table_produit_commande.DataBind(); ApplicationModel.Close(); } public void ClientsEditHandler(Object sender, DataGridCommandEventArgs e) { table_clients.EditItemIndex = e.Item.ItemIndex; } public void ClientsCancelHandler(Object sender, DataGridCommandEventArgs e) { table_clients.EditItemIndex = -1; } public void ClientsUpdateHandler(Object sender, DataGridCommandEventArgs e) { String id = ((TextBox)e.Item.Cells[0].Controls[0]).Text; String nom = ((TextBox)e.Item.Cells[1].Controls[0]).Text; String prenom = ((TextBox)e.Item.Cells[2].Controls[0]).Text; if (nom == String.Empty || prenom==String.Empty) return; ApplicationModel.UpdateClient(id,nom,prenom); table_clients.EditItemIndex = -1; } public void ClientsDeleteHandler(Object sender, DataGridCommandEventArgs e) { String id; if(e.Item.Cells[0].Controls.Count>0) id = ((TextBox)e.Item.Cells[0].Controls[0]).Text; else id = e.Item.Cells[0].Text; ApplicationModel.DeleteClient(id); } protected void ClientsAddHandler(object sender, EventArgs events) { if (nom.Value == String.Empty || prenom.Value== String.Empty) return; ApplicationModel.AddClient(nom.Value,prenom.Value); } public void ProduitsEditHandler(Object sender, DataGridCommandEventArgs e) { table_produits.EditItemIndex = e.Item.ItemIndex; } public void ProduitsCancelHandler(Object sender, DataGridCommandEventArgs e) { table_produits.EditItemIndex = -1; } public void ProduitsUpdateHandler(Object sender, DataGridCommandEventArgs e) { String id = ((TextBox)e.Item.Cells[0].Controls[0]).Text; String label = ((TextBox)e.Item.Cells[1].Controls[0]).Text; String prix = ((TextBox)e.Item.Cells[2].Controls[0]).Text; if (label == String.Empty || prix==String.Empty) return; ApplicationModel.UpdateProduit(id,label,prix); table_produits.EditItemIndex = -1; } public void ProduitsDeleteHandler(Object sender, DataGridCommandEventArgs e) { String id; if(e.Item.Cells[0].Controls.Count>0) id = ((TextBox)e.Item.Cells[0].Controls[0]).Text; else id = e.Item.Cells[0].Text; ApplicationModel.DeleteProduit(id); } protected void ProduitsAddHandler(object sender, EventArgs events) { if (label.Value == String.Empty || prix.Value== String.Empty) return; ApplicationModel.AddProduit(label.Value,prix.Value); } public void CommandesEditHandler(Object sender, DataGridCommandEventArgs e) { table_commandes.EditItemIndex = e.Item.ItemIndex; } public void CommandesCancelHandler(Object sender, DataGridCommandEventArgs e) { table_commandes.EditItemIndex = -1; } public void CommandesUpdateHandler(Object sender, DataGridCommandEventArgs e) { String id = ((TextBox)e.Item.Cells[0].Controls[0]).Text; String client_pkey = ((TextBox)e.Item.Cells[1].Controls[0]).Text; String total = ((TextBox)e.Item.Cells[2].Controls[0]).Text; if(client_pkey == String.Empty || total==String.Empty) return; ApplicationModel.UpdateCommande(id,client_pkey,total); table_commandes.EditItemIndex = -1; } public void CommandesDeleteHandler(Object sender, DataGridCommandEventArgs e) { String id; if(e.Item.Cells[0].Controls.Count>0) id = ((TextBox)e.Item.Cells[0].Controls[0]).Text; else id = e.Item.Cells[0].Text; ApplicationModel.DeleteCommande(id); } protected void CommandesAddHandler(object sender, EventArgs events) { string client_pkey = list_clients.SelectedItem.Value; ApplicationModel.AddCommande(client_pkey); } public void Produit_commandeEditHandler(Object sender, DataGridCommandEventArgs e) { table_produit_commande.EditItemIndex = e.Item.ItemIndex; } public void Produit_commandeCancelHandler(Object sender, DataGridCommandEventArgs e) { table_produit_commande.EditItemIndex = -1; } public void Produit_commandeUpdateHandler(Object sender, DataGridCommandEventArgs e) { String commande_pkey = ((TextBox)e.Item.Cells[0].Controls[0]).Text; String produit_pkey = ((TextBox)e.Item.Cells[1].Controls[0]).Text; String quantite = ((TextBox)e.Item.Cells[2].Controls[0]).Text; if(produit_pkey == String.Empty || quantite==String.Empty || commande_pkey==String.Empty ) return; ApplicationModel.UpdateProduitCommande(commande_pkey,produit_pkey,quantite); table_produit_commande.EditItemIndex = -1; } public void Produit_commandeDeleteHandler(Object sender, DataGridCommandEventArgs e) { String commande_pkey; String produit_pkey; if(e.Item.Cells[0].Controls.Count>0) { commande_pkey = ((TextBox)e.Item.Cells[0].Controls[0]).Text; produit_pkey = ((TextBox)e.Item.Cells[1].Controls[0]).Text; } else { commande_pkey = e.Item.Cells[0].Text; produit_pkey = e.Item.Cells[1].Text; } ApplicationModel.DeleteProduitCommande(commande_pkey,produit_pkey); } protected void Produit_commandeAddHandler(object sender, EventArgs events) { string commande_pkey = list_commandes.SelectedItem.Value; string produit_pkey = list_produits.SelectedItem.Value; if (quantite.Value == String.Empty) return; ApplicationModel.AddProduitCommande(commande_pkey,produit_pkey,quantite.Value); } } }