private void RadButton3Click(object sender, EventArgs e) { bool allRemoved = false; if (ddlPortfolios.SelectedItem != null) { DialogResult dialogResult = Telerik.WinControls.RadMessageBox.Show(Program.LanguageDefault.DictionaryPortfolio["ConfirmDeletePortfolio"], "", MessageBoxButtons.OKCancel, Telerik.WinControls.RadMessageIcon.Question); if (dialogResult == DialogResult.OK) { //Update portfolio "All": bool remove = true; List <string> SymbolsNew = ParentControl.UserPortfolios.First(p => p.Name == ddlPortfolios.Text).Symbols.Split(new char[] { ',' }).ToList(); for (int i = 0; i < SymbolsNew.Count(); i++) { // This symbol exists in another portfolio? foreach (SymbolGroup port in ParentControl.UserPortfolios.GetRange(1, ParentControl.UserPortfolios.Count() - 1)) { if (port.Name == ddlPortfolios.Text) { 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); allRemoved = true; } } ParentControl.RemovePortfolio(ddlPortfolios.Text); if (allRemoved) { frmMain2.ReloadStockListPortfolios(); //Update PortfolioView1 ParentControl.LoadPortfolios(new List <string>() { "All" }); } LoadPortfolioSelection(); } } PreviewPortfolio = ""; foreach (RadListDataItem r in radListControl1.Items.Where(r => r.Text.ToUpper() == ddlFilter.SelectedItem.Text.ToUpper())) { radListControl1.SelectedItem = r; } foreach (RadListDataItem r in radListControl2.Items) { if (r.Text.ToUpper() == ddlFilter.SelectedItem.Text.ToUpper()) { radListControl2.SelectedItem = r; } } }
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; }