Hello,
I've enountered a problem whith saving to an XML file. My app receives user input in several text boxes and when the user hits the OK button it checks if the text boxes are empty. If they are not empty it saves the input to an XML file and closes the window, but if they aren't, it returns a message box with explanations on which text box is empty. Every text box si checked individually.
If a text box is empty the message box is opened as intended, but when confirming the message box it continues to save the input to the XML file and because it is empty and it has nothing to save it returns an error. I want it to stop executing the code when it finds an empty text box, display the message and simply return to the window to allow the user to enter the data.
Source code bellow. (just the start... as it continues the same for each text box and save)
private void btnOK_Click(object sender, EventArgs e)
{
checkIfEmpty();
XmlDocument maindoc = new XmlDocument();
maindoc.Load(@"C:\\Windows\Temp\SessionsTotal.xml");
foreach (XmlNode node in maindoc.SelectNodes("//X1"))
{
node.InnerText = (XmlConvert.ToDouble(node.InnerText) + XmlConvert.ToDouble(X1.Text)).ToString();
}
foreach (XmlNode node in maindoc.SelectNodes("//X2"))
{
node.InnerText = (XmlConvert.ToDouble(node.InnerText) + XmlConvert.ToDouble(X2.Text)).ToString();
}
public void checkIfEmpty()
{
if (X1.Text == String.Empty)
{
MessageBox.Show("The number of Products must be entered", "Products number not entered", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
else if (X2.Text == String.Empty)
{
MessageBox.Show("The Surface Area must be entered", "Surface Area not entered", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
else if (X3.Text == String.Empty)
{
MessageBox.Show("The number of Persons must be entered", "Persons number not entered", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
Thank you.