public override void SaveXml(bool confirm) { if (xmlHasChanged) { if (confirm) { if (MessageBox.Show("Do you want to save the changes you made to your worksheet?", "Finance Advisor - Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes) { return; } } if (xmlFilename == "") { mainSaveFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal); mainSaveFileDialog.Filter = "Quote List Files (*.quo)|*.quo|TVM Files (*.tvm)|*.tvm|CFLO Files (*.cfo)|*.cfo|All Files (*.*)|*.*"; if (mainSaveFileDialog.ShowDialog() == DialogResult.OK) { xmlFilename = mainSaveFileDialog.FileName; } else { return; } } using (StreamWriter sw = new StreamWriter(xmlFilename, false, Encoding.Unicode)) { StringBuilder stringb = new StringBuilder(); XmlWriterSettingsLibrary settings = new XmlWriterSettingsLibrary(); using (XmlWriter writer = XmlWriter.Create(stringb, settings.maindocxmlsettings)) { /* * Sample document * * <?xml version="1.0" encoding="utf-16"?> * <FA> * <PE> * <Symbol id="0">YHOO</Symbol> * <Symbol id="1">MSFT</Symbol> * </PE> * </FA> */ // Write XML data. writer.WriteStartElement("FA"); writer.WriteStartElement("PE"); for (int i = 0; i < symbolHistory.Count; i++) { writer.WriteStartElement("Symbol"); string id = i.ToString(); writer.WriteAttributeString("id", id); writer.WriteString(symbolHistory[i].ToString()); writer.WriteEndElement(); } writer.WriteEndElement(); //PE writer.WriteEndElement(); //FA writer.Flush(); } xmloutput = stringb.ToString(); sw.WriteLine(xmloutput); } this.Text = formTitle + " - " + xmlFilename; xmlHasChanged = false; } }
//void textBoxN_KeyDown(object sender, KeyEventArgs e) //{ // toolTip.Hide(textBoxN); //} //void textBoxN_MouseHover(object sender, EventArgs e) //{ // // throw new Exception("The method or operation is not implemented."); // toolTip.ToolTipTitle = "Number of years or periods."; // toolTip.Show("Number of years or total number of periods.\nTotal number of periods = (years x periods/year)", textBoxN, textBoxN.Location.X, textBoxN.Location.Y, 5000); //} //void textBoxPV_KeyDown(object sender, KeyEventArgs e) //{ // toolTip.Hide(textBoxPV); //} //void textBoxPV_MouseHover(object sender, EventArgs e) //{ // // throw new Exception("The method or operation is not implemented."); // toolTip.ToolTipTitle = "Loan amount."; // toolTip.Show("Total loan amount. Present value.", textBoxPV, textBoxPV.Location.X, textBoxPV.Location.Y, 5000); //} //void textBoxPMT_KeyDown(object sender, KeyEventArgs e) //{ // toolTip.Hide(textBoxPMT); //} //void textBoxPMT_MouseHover(object sender, EventArgs e) //{ // // throw new Exception("The method or operation is not implemented."); // toolTip.ToolTipTitle = "Periodic payment amount."; // toolTip.Show("This is the scheduled periodic payment amount.\nThis is a negative number if you are making payments.", textBoxPMT, textBoxPMT.Location.X, textBoxPV.Location.Y, 5000); //} //void textBoxFV_KeyDown(object sender, KeyEventArgs e) //{ // toolTip.Hide(textBoxFV); //} //void textBoxFV_MouseHover(object sender, EventArgs e) //{ // // throw new Exception("The method or operation is not implemented."); // toolTip.ToolTipTitle = "Ending loan balance."; // toolTip.Show("This is the ending balance of the loan.\nUsually you want to leave it at $0.00.", textBoxFV, textBoxFV.Location.X, textBoxPV.Location.Y, 5000); //} public override void SaveXml(bool confirm) { if (xmlHasChanged) { if (confirm) { if (MessageBox.Show("Do you want to save the changes you made to your worksheet?", "Finance Advisor Calculator - Confirm", MessageBoxButtons.YesNo) != DialogResult.Yes) { return; } } if (xmlFilename == "") { mainSaveFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal); mainSaveFileDialog.Filter = "TVM Files (*.tvm)|*.tvm|CFLO Files (*.cfo)|*.cfo|All Files (*.*)|*.*"; if (mainSaveFileDialog.ShowDialog() == DialogResult.OK) { xmlFilename = mainSaveFileDialog.FileName; } else { return; } } using (StreamWriter sw = new StreamWriter(xmlFilename, false, Encoding.Unicode)) { StringBuilder stringb = new StringBuilder(); XmlWriterSettingsLibrary settings = new XmlWriterSettingsLibrary(); using (XmlWriter writer = XmlWriter.Create(stringb, settings.maindocxmlsettings)) { /* * Sample document * * <?xml version="1.0" encoding="utf-16"?> * <FA> * <TVM> * <N isYear="true">30.00</N> * <PV>$600,000.00</PV> * <PMT>($3,597.30)</PMT> * <FV>$0.00</FV> * <I>6.00</I> * <P isEnd="true">12</P> * <FROM>1</FROM> * <TO>12</TO> * </TVM> * </FA> */ // Write XML data. writer.WriteStartElement("FA"); writer.WriteStartElement("TVM"); writer.WriteStartElement("N"); string isYearstring = isYear ? "true" : "false"; writer.WriteAttributeString("isYear", isYearstring); writer.WriteString(textBoxN.Text); writer.WriteEndElement(); writer.WriteStartElement("PV"); writer.WriteString(textBoxPV.Text); writer.WriteEndElement(); writer.WriteStartElement("PMT"); writer.WriteString(textBoxPMT.Text); writer.WriteEndElement(); writer.WriteStartElement("FV"); writer.WriteString(textBoxFV.Text); writer.WriteEndElement(); writer.WriteStartElement("I"); writer.WriteString(textBoxI.Text); writer.WriteEndElement(); writer.WriteStartElement("P"); string isEndstring = isEnd ? "true" : "false"; writer.WriteAttributeString("isEnd", isEndstring); writer.WriteString(textBoxP.Text); writer.WriteEndElement(); writer.WriteStartElement("FROM"); writer.WriteString(numericUpDownFrom.Value.ToString()); writer.WriteEndElement(); writer.WriteStartElement("TO"); writer.WriteString(numericUpDownTo.Value.ToString()); writer.WriteEndElement(); writer.WriteEndElement(); //TVM writer.WriteEndElement(); //FA writer.Flush(); } xmloutput = stringb.ToString(); sw.WriteLine(xmloutput); } this.Text = formTitle + " - " + xmlFilename; xmlHasChanged = false; } }
public override void SaveXml(bool confirm) { if (xmlHasChanged) { if (confirm) { if (MessageBox.Show("Do you want to save the changes you made to your worksheet?", "Finance Advisor - Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes) { return; } } if (xmlFilename == "") { mainSaveFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal); mainSaveFileDialog.Filter = "CFLO Files (*.cfo)|*.cfo|TVM Files (*.tvm)|*.tvm|All Files (*.*)|*.*"; if (mainSaveFileDialog.ShowDialog() == DialogResult.OK) { xmlFilename = mainSaveFileDialog.FileName; } else { return; } } using (StreamWriter sw = new StreamWriter(xmlFilename, false, Encoding.Unicode)) { StringBuilder stringb = new StringBuilder(); XmlWriterSettingsLibrary settings = new XmlWriterSettingsLibrary(); using (XmlWriter writer = XmlWriter.Create(stringb, settings.maindocxmlsettings)) { /* * Sample document * * <?xml version="1.0" encoding="utf-16"?> * <FA> * <CFLO> * <SafeI>5.00</SafeI> * <RiskI>10.00</RiskI> * <CF id="0"> * <C>-100000</C> * <N>1</N> * </CF> * <CF id="1"> * <C>100000</C> * <N>5</N> * </CF> * <CF id="2"> * <C>-100000</C> * <N>5</N> * </CF> * </CFLO> * </FA> */ // Write XML data. writer.WriteStartElement("FA"); writer.WriteStartElement("CFLO"); writer.WriteStartElement("SafeI"); writer.WriteString(S.Text); writer.WriteEndElement(); writer.WriteStartElement("RiskI"); writer.WriteString(R.Text); writer.WriteEndElement(); for (int i = 0; i < MAXC; i++) { writer.WriteStartElement("CF"); writer.WriteAttributeString("id", i.ToString()); writer.WriteStartElement("C"); writer.WriteString(cj[i].Text); writer.WriteEndElement(); writer.WriteStartElement("N"); writer.WriteString(nj[i].Text); writer.WriteEndElement(); writer.WriteEndElement(); //CF } writer.WriteEndElement(); //CFLO writer.WriteEndElement(); //FA writer.Flush(); } xmloutput = stringb.ToString(); sw.WriteLine(xmloutput); } this.Text = formTitle + " - " + xmlFilename; xmlHasChanged = false; } }