//XML File Every time a user enters a transaction id that exists in the xml file and the "used" value is 0, he will be redirected to the next page and the XML file must be updated accordingly i.e that corresponding used value must change to 0 and be saved.
<?xml version="1.0" encoding="utf-8" ?>
<purchase>
<transaction>
<id>KIDCL3001</id>
<used>0</used>
</transaction>
<transaction>
<id>KIDCL3002</id>
<used>0</used>
</transaction>
<transaction>
<id>KIDCL3003</id>
<used>0</used>
</transaction>
<transaction>
<id>KIDCL3004</id>
<used>0</used>
</transaction>
</purchase>
//C# code:
private void Button_Click_1(object sender, RoutedEventArgs e)
{
int i = 0;
XDocument xdoc = XDocument.Load("XMLFile1.xml");
var data = from query in xdoc.Descendants("transaction")
select new
{
Id = (string)query.Element("id"),
used = (int)query.Element("used")
};
foreach (var unit in data)
{
if (tid.Text.Equals(unit.Id) && (unit.used == 0))
{
i need to change the value of "used" element from 0 to 1 and save the xml file
this.Frame.Navigate(typeof(BlankPage1));
i = 1;
}
}
No comments:
Post a Comment