0
我有一段代碼的提交按鈕被點擊抓鬥選擇的ID從應用程序在C#中的Visual Studio
XmlDocument xml = new XmlDocument();
xml.Load("menu.xml");
XmlNode Quantity = xml.DocumentElement.SelectSingleNode("/MenuInfo/Meal/Quantity");
int qty = Convert.ToInt32(Quantity.InnerText);
// Deducting 1 from orginal quantity, you can use variable instead of quantity 1
Quantity.InnerText = (qty - 1).ToString();
//Finally you can retrieve modified xml from using doc.InnerXml
string modifiedXml = xml.InnerXml;
xml.Save("menu.xml");
MessageBox.Show("The order has been placed.");
Main nf = new Main();
nf.ShowDialog();
this.Close();
這段代碼的作用是,當用戶點擊應用程序提交時將執行的數量元素將在「menu.xml」文件中減1。然而,我的問題是它只是用餐1。我目前在外部「menu.xml」文件中有四種不同的膳食,我希望程序能夠識別哪個餐點被點擊並從該餐點減去數量。例如,如果用戶點擊餐1,則應該將數量減1,如果用戶點擊餐2,則應該從該餐減去數量。我知道需要做什麼,即獲得身份證,但我不知道如何做到這一點,有人可以幫助我嗎?希望這是有道理的。
<?xml version="1.0" encoding="utf-8"?>
<MenuInfo>
<Meal>
<MealID>1</MealID>
<Food>Meal 1 (Fish and Chips)</Food>
<Price>£4.99</Price>
<Time>25 minutes</Time>
<Quantity>12</Quantity>
</Meal>
<Meal>
<MealID>2</MealID>
<Food>Meal 2 (Chicken and Chips)</Food>
<Price>£3.99</Price>
<Time>25 minutes</Time>
<Quantity>12</Quantity>
</Meal>
<Meal>
<MealID>3</MealID>
<Food>Meal 3 (Saussage and Chips)</Food>
<Price>£2.99</Price>
<Time>25 minutes</Time>
<Quantity>12</Quantity>
</Meal>
<Meal>
<MealID>4</MealID>
<Food>Meal 4 (Burger and Chips)</Food>
<Price>£5.99</Price>
<Time>25 minutes</Time>
<Quantity>12</Quantity>
</Meal>
</MenuInfo>