Exemplo n.º 1
0
        private void portfolioTabControl_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            if (portfolioTabControl.SelectedTab.Name != ADD_PORTFOLIO)
            {
                // delete/rename new portfolio

                PortfolioCtrlForm portfolioCtrlForm = new PortfolioCtrlForm(this, PortfolioCtrlForm.PortfolioCtrlModeT.MODE_RENAME_DELETE);
                portfolioCtrlForm.PortfolioName = portfolioTabControl.SelectedTab.Name;
                portfolioCtrlForm.ShowDialog();

                if (portfolioCtrlForm.PortfolioOperation == PortfolioCtrlForm.PortfolioCtrlOperT.OPER_DELETE && portfolioTabControl.TabCount > 2)
                {
                    // delete portfolio from list
                    Config.Local.DeletePortfolio(portfolioTabControl.SelectedTab.Name);
                    Config.Local.Save();

                    // update tabs
                    portfolioTabControl.TabPages.RemoveByKey(portfolioTabControl.SelectedTab.Name);
                }
                else if (portfolioCtrlForm.PortfolioOperation == PortfolioCtrlForm.PortfolioCtrlOperT.OPER_RENAME)
                {
                    if (portfolioCtrlForm.PortfolioName == "" || (portfolioTabControl.TabPages.ContainsKey(portfolioCtrlForm.PortfolioName) && portfolioTabControl.SelectedTab.Name.ToLower() != portfolioCtrlForm.PortfolioName.ToLower()))
                    {
                        MessageBox.Show("Portfolio name must be non-empty and unique.    ", "Invalid portfolio name", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                    else
                    {
                        string name = portfolioCtrlForm.PortfolioName.Replace(",", ".");

                        // rename porfolio in configuration
                        Config.Local.RenamePortfolio(portfolioTabControl.SelectedTab.Name, name);
                        Config.Local.Save();

                        // rename portfolio in dataset
                        ps.ReanamePortfolio(portfolioTabControl.SelectedTab.Name, name);

                        // update tabs
                        portfolioTabControl.SelectedTab.Name = name;
                        portfolioTabControl.SelectedTab.Text = name;
                    }
                }
            }

            // update portfolio summery
            ps.UpdateSummary(portfolioTabControl.SelectedTab.Name);

            // update view
            portfolioDataGridView_UpdateView();
        }
Exemplo n.º 2
0
        private void portfolioTabControl_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (portfolioTabControl.SelectedTab.Name == ADD_PORTFOLIO)
            {
                // create a new portfolio

                PortfolioCtrlForm portfolioCtrlForm = new PortfolioCtrlForm(this, PortfolioCtrlForm.PortfolioCtrlModeT.MODE_CREATE);
                portfolioCtrlForm.ShowDialog();

                bool aborted = true;

                if (portfolioCtrlForm.PortfolioOperation == PortfolioCtrlForm.PortfolioCtrlOperT.OPER_CREATE)
                {
                    if (portfolioCtrlForm.PortfolioName == "" || portfolioTabControl.TabPages.ContainsKey(portfolioCtrlForm.PortfolioName))
                    {
                        MessageBox.Show("Portfolio name must be non-empty and unique.    ", "Invalid portfolio name", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                    else
                    {
                        string name = portfolioCtrlForm.PortfolioName.Replace(",", ".");

                        // add new portfolio to list
                        Config.Local.SetPortfolio(name, "");
                        Config.Local.Save();

                        // update tabs
                        portfolioTabControl.SelectedTab.Name = name;
                        portfolioTabControl.SelectedTab.Text = name;
                        portfolioTabControl.TabPages.Add(ADD_PORTFOLIO, ADD_PORTFOLIO);

                        aborted = false;
                    }
                }

                if (aborted)
                {
                    portfolioTabControl.SelectedIndex = 0;
                }
            }

            // update portfolio summery
            ps.UpdateSummary(portfolioTabControl.SelectedTab.Name);

            // update view
            portfolioDataGridView_UpdateView();
        }