private void buttonNext_Click(object sender, EventArgs e) { if (comboBoxCategory.Text != "" && textBoxTheme.Text != "" && textBoxAuthor.Text != "") { try { testWriter = new XmlTextWriter("Tests\\" + comboBoxCategory.Text + "\\" + textBoxAuthor.Text + ".xml", Encoding.UTF8); } catch (DirectoryNotFoundException) { Directory.CreateDirectory("Tests\\" + comboBoxCategory.Text); testWriter = new XmlTextWriter("Tests\\" + comboBoxCategory.Text + "\\" + textBoxTheme.Text + ".xml", Encoding.UTF8); } testWriter.Formatting = Formatting.Indented; testWriter.WriteStartDocument(); testWriter.WriteStartElement("test"); testWriter.WriteStartElement("Category"); testWriter.WriteString(comboBoxCategory.Text); testWriter.WriteEndElement(); testWriter.WriteStartElement("Author"); testWriter.WriteString(textBoxAuthor.Text); testWriter.WriteEndElement(); testWriter.WriteStartElement("Theme"); testWriter.WriteString(textBoxTheme.Text); testWriter.WriteEndElement(); testWriter.WriteStartElement("NumberOfQuestions"); testWriter.WriteStartAttribute("numbers"); testWriter.WriteString(numericNQuestions.Value.ToString()); testWriter.WriteEndAttribute(); for (int i = 1; i <= numericNQuestions.Value; i++) { QuestionsForm QF = new QuestionsForm(i, testWriter); QF.ShowDialog(); this.Visible = false; } testWriter.WriteEndElement(); testWriter.WriteEndElement(); testWriter.WriteEndDocument(); testWriter.Close(); MessageBox.Show("All questions are created"); Application.Exit(); } else { MessageBox.Show("Fill all data"); } }
private void buttonNext_Click(object sender, EventArgs e) { filePath = "Tests\\" + comboBoxCategory.Text + "\\" + textBoxTheme.Text + ".xml"; if (comboBoxCategory.Text != "" && textBoxTheme.Text != "" && comboBoxAuthor.Text != "") { try { if (File.Exists(filePath)) { MessageBox.Show("The file is already exists, please change theme"); textBoxTheme.Text = ""; return; } else { testWriter = new XmlTextWriter(filePath, Encoding.ASCII); } } catch (DirectoryNotFoundException) { Directory.CreateDirectory("Tests\\" + comboBoxCategory.Text); testWriter = new XmlTextWriter(filePath, Encoding.ASCII); } testWriter.Formatting = Formatting.Indented; testWriter.WriteStartDocument(); testWriter.WriteStartElement("test"); testWriter.WriteStartElement("path"); testWriter.WriteString(comboBoxCategory.Text + "\\" + textBoxTheme.Text + ".xml"); testWriter.WriteEndElement(); testWriter.WriteStartElement("fileName"); testWriter.WriteString(textBoxTheme.Text + ".xml"); testWriter.WriteEndElement(); testWriter.WriteStartElement("Category"); testWriter.WriteString(comboBoxCategory.Text); testWriter.WriteEndElement(); testWriter.WriteStartElement("Author"); testWriter.WriteString(comboBoxAuthor.Text); testWriter.WriteEndElement(); testWriter.WriteStartElement("Theme"); testWriter.WriteString(textBoxTheme.Text); testWriter.WriteEndElement(); testWriter.WriteStartElement("NumberOfQuestions"); testWriter.WriteStartAttribute("numbers"); testWriter.WriteString(numericNQuestions.Value.ToString()); testWriter.WriteEndAttribute(); for (int i = 1; i <= numericNQuestions.Value; i++) { QuestionsForm QF = new QuestionsForm(i, testWriter); QF.ShowDialog(); } testWriter.WriteEndElement(); testWriter.WriteEndElement(); testWriter.WriteEndDocument(); testWriter.Close(); SendXML(); MessageBox.Show("All questions are created and sent to server"); //Application.Exit(); } else { MessageBox.Show("Fill all data"); } }