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 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 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
|
<% @Page Language="C#" Debug="true" %>
<% @Import Namespace="System" %>
<% @Import Namespace="System.Web" %>
<% @Import Namespace="System.Xml" %>
<% @Import Namespace="System.IO" %>
<% @Import Namespace="System.Xml.XPath" %>
<script runat="server">
public String chooseBG()
{
return "Hello";
}
protected void ahrefChooseBackGround_Click(String fond)
{
try
{
//String[] r = { "agence3", "sheira", "fondK.jpg" };
String agence = HttpContext.Current.Request.Params["groupe"];
String prenom = HttpContext.Current.Request.Params["nom"];
String[] r = new String []{ agence, prenom, fond};
String filename = "test.xml";
using (FileStream f = new FileStream(HttpContext.Current.Server.MapPath(filename), FileMode.OpenOrCreate, FileAccess.ReadWrite))
{
if (f.Length != 0)
{
XmlDocument doc = new XmlDocument();
doc.Load(f);
XmlElement racine = doc.DocumentElement;
// on vérifie d'abord que la balise groupe existe
if (racine != null && racine.Name == "groupe")
{
XmlNodeList noeudsAgence = racine.ChildNodes;
if (noeudsAgence.Count > 0)
{
// on vérifie que le noeud n'existe pas avant de le créer
bool agenceExist = false;
bool utilisateurExist = false;
foreach (XmlNode noeudAgence in noeudsAgence)
{
if (noeudAgence.Attributes["nom"].InnerText == r[0])
{
agenceExist = true;
foreach (XmlNode utilisateur in noeudAgence.ChildNodes)
{
Response.Write (utilisateur.InnerText);
if (utilisateur.InnerText == r[1])
{
utilisateurExist = true;
utilisateur.Attributes["fond"].Value = r[2];
break;
}
}
if (!utilisateurExist)
{
XmlElement user = doc.CreateElement("utilisateur");
user.InnerText = r[1];
XmlAttribute attrFond = doc.CreateAttribute("fond");
attrFond.Value = r[2];
user.SetAttributeNode(attrFond);
noeudAgence.AppendChild(user);
}
}
}
if (!agenceExist)
{
XmlElement ag = doc.CreateElement("agence");
XmlAttribute attrNom = doc.CreateAttribute("nom");
attrNom.Value = r[0];
ag.SetAttributeNode(attrNom);
XmlElement user = doc.CreateElement("utilisateur");
user.InnerText = r[1];
XmlAttribute attrFond = doc.CreateAttribute("fond");
attrFond.Value = r[2];
user.SetAttributeNode(attrFond);
ag.AppendChild(user);
racine.AppendChild(ag);
}
f.Close();
doc.Save(HttpContext.Current.Server.MapPath(filename));
}
}
}
else
{
XmlDocument doc = new XmlDocument();
XmlDeclaration declaration = doc.CreateXmlDeclaration("1.0", "Utf-8", null);
doc.AppendChild(declaration);
XmlElement racine = doc.CreateElement("groupe");
XmlElement ag = doc.CreateElement("agence");
XmlAttribute attrNom = doc.CreateAttribute("nom");
attrNom.Value = r[0];
ag.SetAttributeNode(attrNom);
XmlElement user = doc.CreateElement("utilisateur");
user.InnerText = r[1];
XmlAttribute attrFond = doc.CreateAttribute("fond");
attrFond.Value = r[2];
user.SetAttributeNode(attrFond);
ag.AppendChild(user);
racine.AppendChild(ag);
doc.AppendChild(racine);
doc.Save(f);
}
}
}
catch (Exception ex)
{
//Todo:gestion des exceptions
}
}
</script>
<HTML>
<HEAD>
<meta http-equiv="content-type" content="text/html; charset=windows-1252" />
<script language= "Javascript" type= "text/javascript" >
function getVar (nomVariable)
{
var infos = location.href.substring(location.href.indexOf("?")+1, location.href.length)+"&"
if (infos.indexOf("#")!=-1)
infos = infos.substring(0,infos.indexOf("#"))+"&"
var variable=0
{
nomVariable = nomVariable + "="
var taille = nomVariable.length
if (infos.indexOf(nomVariable)!=-1)
variable = infos.substring(infos.indexOf(nomVariable)+taille,infos.length).substring(0,infos.substring(infos.indexOf(nomVariable)+taille,infos.length).indexOf("&"))
}
return variable
}
function setBackGround(strFond)
{
var groupe = getVar('groupe');
var nom = getVar('nom');
var data = [];
data.push(groupe, nom);
data.push(strFond);
//alert (data.join(","));
//alert("<%= chooseBG() %>;
<%
String[] r = { "agence4", "Olivier", "fondO.jpg" };
/*String agence = HttpContext.Current.Request.Params["groupe"];*/
String prenom = HttpContext.Current.Request.Params["nom"];
Response.Write(prenom);
//chooseBackGround(r);
%>
}
</script>
</HEAD>
<BODY>
<form runat="server">
<table width=50 height =50>
<tr width=50 align="center">
<font size="10%" color="#D5CCCD">Définir un nouveau fond d'écran</font>
</tr>
<tr width=25>
<td width=5 height =5><a href = "default.aspx" id="ahrefChooseBackGround" runat = "server" onclick="ahrefChooseBackGround_Click("fond1.jpg")" title = "Cliquer pour choisir ce fond"><img src="../images/fond1.jpg" width=180 height=180></a></td>
<td width=5 height =5><a href = "" id="ahrefChooseBackGround2" runat = "server" onclick="ahrefChooseBackGround_Click("fond1.jpg")" title = "Cliquer pour choisir ce fond"><img src="../images/fond1.jpg" width=180 height=180></a></td>
<td width=5 height =5><a href = "" id="ahrefChooseBackGround3" runat = "server" onclick="ahrefChooseBackGround_Click("fond1.jpg")" title = "Cliquer pour choisir ce fond"><img src="../images/fond1.jpg" width=180 height=180></a></td>
<td width=5 height =5><a href = "" id="ahrefChooseBackGround4" runat = "server" onclick="ahrefChooseBackGround_Click("fond1.jpg")" title = "Cliquer pour choisir ce fond"><img src="../images/fond1.jpg" width=180 height=180></a></td>
</tr>
<tr></tr>
<tr></tr>
<tr width=25>
<td width=5 height =5><a href = "" id="ahrefChooseBackGround5" runat = "server" onclick="ahrefChooseBackGround_Click("fond2.jpg")" title = "Cliquer pour choisir ce fond"><img src="../images/fond2.jpg" width=180 height=180></a></td>
<td width=5 height =5><a href = "" id="ahrefChooseBackGround6" runat = "server" onclick="ahrefChooseBackGround_Click("fond2.jpg")" title = "Cliquer pour choisir ce fond"><img src="../images/fond2.jpg" width=180 height=180></a></td>
<td width=5 height =5><a href = "" id="ahrefChooseBackGround7" runat = "server" onclick="ahrefChooseBackGround_Click("fond2.jpg")" title = "Cliquer pour choisir ce fond"><img src="../images/fond2.jpg" width=180 height=180></a></td>
<td width=5 height =5><a href = "" id="ahrefChooseBackGround8" runat = "server" onclick="ahrefChooseBackGround_Click("fond2.jpg")" title = "Cliquer pour choisir ce fond"><img src="../images/fond2.jpg" width=180 height=180></a></td>
</tr>
</table>
</form>
</BODY>
</HTML> |
Partager