Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public partial class selectPOSReports : Form
- {
- XmlDocument doc = new XmlDocument();
- public selectPOSReports()
- {
- InitializeComponent();
- if (!File.Exists(@"C:UsersPublicMECposReportList.xml"))
- {
- Directory.CreateDirectory(@"C:UsersPublicMEC");
- doc.LoadXml("<?xml version="1.0" encoding="utf-8"?><Reports count="0"></Reports>");
- doc.Save(@"C:UsersPublicMECposReportList.xml");
- }
- else
- {
- doc.Load(@"C:UsersPublicMECposReportList.xml");
- }
- XmlNodeList excelReportList = doc.SelectNodes("//Workbook");
- foreach (XmlNode excelReport in excelReportList)
- {
- reportList.Items.Add(excelReport.InnerText);
- }
- }
- private void addButton_Click(object sender, EventArgs e)
- {
- int newIndex = 0;
- if ( selectReportDialog.ShowDialog() == DialogResult.OK ) {
- doc.Save(@"C:UsersPublicMECposReportList.xml");
- string fileName = selectReportDialog.FileName;
- string filePath = Path.GetPathRoot(fileName);
- XDocument xd = XDocument.Load(XmlReader.Create(@"C:UsersPublicMECposReportList.xml"));
- xd.Element("Reports").Add(
- new XElement("Report", new XAttribute("id", newIndex),
- new XElement("Workbook", fileName),
- new XElement("Filepath", filePath)));
- xd.Save(@"C:UsersPublicMECposReportList.xml");
- reportList.Items.Add(fileName);
- }
- }
- private void removeButton_Click(object sender, EventArgs e)
- {
- DialogResult result = MessageBox.Show("Are you sure you want to remove " + reportList.SelectedItems.ToString() + " from the list?",
- "Remove Excel Report",
- MessageBoxButtons.YesNo,
- MessageBoxIcon.Warning);
- if (result == DialogResult.Yes)
- {
- int index = reportList.SelectedIndex;
- string sindex = index.ToString();
- XmlNode deleteNode = doc.GetElementById(sindex);
- deleteNode.ParentNode.RemoveChild(deleteNode);
- doc.Save("posReportList.xml");
- reportList.Items.RemoveAt(index);
- }
- }
- }
- <Reports count="1"><!--Count will be updated as items are added-->
- <Report id="1">
- <Workbook>SomeBook.xlsx</Workbook>
- <Filepath>C:/SomePath</FilePath>
- </Report>
- </Reports>
- doc.Save(@"C:UsersPublicMECposReportList.xml");
- xd.Save(@"C:UsersPublicMECposReportList.xml");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement