public void LoadPortfolio(string fName) { FileStream fStream = null; try { XmlSerializer portInput = new XmlSerializer(typeof(PortFolio)); fStream = new FileStream(fName, FileMode.Open, FileAccess.Read, FileShare.None); portfolio = (PortFolio)portInput.Deserialize(fStream); fStream.Close(); portfolioPath = fName; foreach (Holding hld in portfolio.Positions) { dataList.Add(new TickerData(hld)); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error Loading Portfolio File"); portfolio = null; portfolioPath = ""; } finally { if (fStream != null) fStream.Close(); } }
private void newPortfolioToolStripMenuItem_Click(object sender, EventArgs e) { if (portfolio != null) { if (MessageBox.Show("Are you sure you wish to lose the current portfolio?", "New Portfolio", MessageBoxButtons.OKCancel) != System.Windows.Forms.DialogResult.OK) return; } portfolio = new PortFolio(); TickerListForm frm = new TickerListForm(); frm.TickerList = new List<Holding>(); DialogResult res = frm.ShowDialog(); if (res == System.Windows.Forms.DialogResult.OK) { portfolio.Positions = frm.TickerList.ToArray(); } }