コード例 #1
0
        public void SaveChanges()
        {
            if (String.IsNullOrEmpty(txtPortfolio.Text))
            {
                Telerik.WinControls.RadMessageBox.Show(Program.LanguageDefault.DictionaryPortfolio["fieldEmptyPortfolio"]);
                return;
            }

            SymbolGroup portChanged = new SymbolGroup()
            {
                Name    = txtPortfolio.Text,
                Type    = (int)GroupType.Portfolio,
                Index   = ParentControl.GetPortfolioNewIndex(),
                Symbols = ""
            };

            UpdatePortfolios = new List <string> {
                txtPortfolio.Text
            };

            SqlConnection _connection = DBlocalSQL.Connect();

            List <SymbolGroup> listpoPortfolios = DBlocalSQL.LoadGroups(GroupType.Index, _connection);

            listpoPortfolios.AddRange(DBlocalSQL.LoadGroups(GroupType.Portfolio, _connection));
            DBlocalSQL.Disconnect(_connection);

            foreach (var listpoPortfolio in listpoPortfolios)
            {
                if (listpoPortfolio.Name.ToUpper() == portChanged.Name.ToUpper() || Program.LanguageDefault.DictionaryTabAssets["tabAll"] == portChanged.Name.ToUpper())
                {
                    Telerik.WinControls.RadMessageBox.Show(String.Format(Program.LanguageDefault.DictionaryPortfolio["portfolioExisted"], txtPortfolio.Text));
                    return;
                }

                UpdatePortfolios.Add(listpoPortfolio.Name);
            }

            listpoPortfolios.Add(portChanged);

            SqlConnection _connection2 = DBlocalSQL.Connect();

            DBlocalSQL.SaveGroups(listpoPortfolios, _connection2);
            DBlocalSQL.Disconnect(_connection2);

            PortFolio = txtPortfolio.Text;

            DialogResult = DialogResult.OK;
            Close();
        }
コード例 #2
0
ファイル: EditPortfolio.cs プロジェクト: Ales999/plena
        public void SaveChanges()
        {
            List <string> updatePortfolios = new List <string>();

            SymbolGroup portChanged;

            if (ddlPortfolios.SelectedItem != null)
            {
                //Create a new portfolio
                portChanged = new SymbolGroup()
                {
                    Name  = ddlPortfolios.SelectedItem.Text == Program.LanguageDefault.DictionaryTabAssets["tabAll"] ? "All" : ddlPortfolios.SelectedItem.Text,
                    Type  = (int)DataServer.Interface.GroupType.Portfolio,
                    Index = ParentControl.GetPortfolioNewIndex()
                };
                List <string> Symbols = new List <string>();
                foreach (var r in radListControl2.Items)
                {
                    string[] codeParse = r.Text.Split(new[] { ' ' });
                    string   newAsset  = codeParse[0];
                    Symbols.Add(newAsset);
                }
                portChanged.Symbols = string.Join(",", Symbols.ToArray());
                //Replace it on User's Portfolios
                List <string> SymbolsNew = new List <string>();

                foreach (var p in ParentControl.UserPortfolios)
                {
                    if (p.Name != portChanged.Name)
                    {
                        continue;
                    }

                    // if (UnorderedEqual(p.Symbols, portChanged.Symbols))
                    //  continue;
                    SymbolsNew = p.Symbols.Split(new char[] { ',' }).ToList();
                    //Remove os simbolos removidos
                    if (!UnorderedEqual(SymbolsNew, Symbols.ToArray()))
                    {
                        for (int i = 0; i < SymbolsNew.Count; i++)
                        {
                            if (!Symbols.Any(s => s == SymbolsNew[i]))
                            {
                                //Update portfolio "All":
                                bool remove = true;
                                // This symbol exists in another portfolio?
                                foreach (SymbolGroup port in ParentControl.UserPortfolios.GetRange(1, ParentControl.UserPortfolios.Count() - 1))
                                {
                                    if (port.Name == portChanged.Name)
                                    {
                                        continue;
                                    }
                                    if (port.Symbols.Split(new char[] { ',' }).ToList().Exists(s => s == SymbolsNew[i]))
                                    {
                                        remove = false;
                                    }
                                }
                                if (remove)
                                {
                                    List <string> userSymbols = ParentControl.UserPortfolios[0].Symbols.Split(new char[] { ',' }).ToList();
                                    if (userSymbols.Remove(SymbolsNew[i]))
                                    {
                                        ParentControl.UserPortfolios[0].Symbols = string.Join(",", userSymbols.ToArray());
                                    }
                                    ParentControl.UserPortfolios[0].Symbols = string.Join(",", userSymbols.ToArray());
                                    List <Symbol> updateSync = new List <Symbol>();
                                    foreach (string s in userSymbols)
                                    {
                                        updateSync.Add(new Symbol()
                                        {
                                            Code = s
                                        });
                                    }
                                    SqlConnection _con = DBlocalSQL.Connect();
                                    DBlocalSQL.SaveSymbols(updateSync, _con, true);
                                    DBlocalSQL.Disconnect(_con);
                                    if (!updatePortfolios.Exists(s => s == "All"))
                                    {
                                        updatePortfolios.Insert(0, "All");
                                    }
                                }

                                SymbolsNew.Remove(SymbolsNew[i]);
                                i--;
                            }
                        }
                    }
                    List <string> symbolsRequest = new List <string>();
                    //insere os simbolos inseridos
                    foreach (string symbol in Symbols)
                    {
                        if (!SymbolsNew.Any(s => s == symbol))
                        {
                            SymbolsNew.Add(symbol);
                            //Update portfolio "All":
                            if (!ParentControl.UserPortfolios[0].Symbols.Split(new char[] { ',' }).ToList().Exists(s => s == symbol))
                            {
                                ParentControl.UserPortfolios[0].Symbols += "," + symbol;

                                //Add request to list:
                                symbolsRequest.Add(symbol);

                                List <Symbol> updateSync = new List <Symbol>();
                                foreach (string s in SymbolsNew)
                                {
                                    updateSync.Add(new Symbol()
                                    {
                                        Code = s
                                    });
                                }
                                SqlConnection _con = DBlocalSQL.Connect();
                                DBlocalSQL.SaveSymbols(updateSync, _con, true);
                                DBlocalSQL.Disconnect(_con);
                                if (!updatePortfolios.Exists(s => s == "All"))
                                {
                                    updatePortfolios.Insert(0, "All");
                                }
                            }
                        }
                    }
                    if (symbolsRequest.Count() > 0)
                    {
                        //Sync new symbol with HUB:
                        MessageService.SubmitRequest(new MSRequest("INSERT SYMBOL m" + ParentControl.MFrmMain2._messageRequestID, MSRequestStatus.Pending,
                                                                   MSRequestType.GetHistoricalData,
                                                                   MSRequestOwner.M4,
                                                                   new object[] { symbolsRequest, (int)BaseType.Days }));
                        ParentControl.MFrmMain2.AddRequestedOperation(new Operations("m" + ParentControl.MFrmMain2._messageRequestID, M4Core.Enums.TypeOperations.LoadSelectView,
                                                                                     new object[] { }));
                    }

                    updatePortfolios.Add(p.Name);

                    p.Symbols = string.Join(",", SymbolsNew.ToArray());
                    break;
                }

                if (updatePortfolios.Count > 0)
                {
                    frmMain2.SaveUserPortfolios(ParentControl.UserPortfolios.GetRange(1, ParentControl.UserPortfolios.Count() - 1));
                    frmMain2.ReloadStockListPortfolios();
                    //Update PortfolioView1
                    ParentControl.LoadPortfolios(updatePortfolios);
                }
            }
            Changes = false;
        }