/// <summary> /// Заполнить форму данными /// </summary> /// <param name="getNewInfo">Надо ли загрузить новую информацию об акции с интернета</param> private async Task FillStockForm(bool getNewInfo = true) { if (comboBoxStocks.Text == "" || !comboBoxStocks.Items.Contains(comboBoxStocks.Text)) { return; } m_selectedStock = MainClass.GetStock(true, comboBoxStocks.Text); if (m_selectedStock == null) { ResetStockForm(); return; } panelMain.Visible = panelCommon.Visible = true; checkBoxIsStarred.Enabled = true; // Получим инфу об акции if (getNewInfo) { await MainClass.GetStockData(m_selectedStock); } if (m_selectedStock.Market.Location == StockMarketLocation.Usa) { linkLabel1.Text = string.Format(Web.GetStockDataUrlUsa, m_selectedStock.Symbol); panelUSACoefs.Visible = true; panelRussiaCoefs.Visible = false; } else if (m_selectedStock.Market.Location == StockMarketLocation.Russia) { if (!string.IsNullOrEmpty(m_selectedStock.LinkToGetInfo)) { linkLabel1.Text = Web.GetStockDataUrlRussia + m_selectedStock.LinkToGetInfo; } panelUSACoefs.Visible = false; panelRussiaCoefs.Visible = true; } // Получили labelStockName.Text = m_selectedStock.Name; checkBoxIsStarred.Checked = m_selectedStock.IsStarred; if (m_selectedStock.Market.Currency == StockMarketCurrency.Rub) { textBoxStockPrice.Text = m_selectedStock.Price.ToString(CultureInfo.InvariantCulture); textBoxStockPriceUSD.Text = (m_selectedStock.Price / StockMarket.GetExchangeRates(StockMarketCurrency.Usd)).ToString("F2"); } else if (m_selectedStock.Market.Currency == StockMarketCurrency.Usd) { textBoxStockPriceUSD.Text = m_selectedStock.Price.ToString(CultureInfo.InvariantCulture); textBoxStockPrice.Text = (m_selectedStock.Price * StockMarket.GetExchangeRates(StockMarketCurrency.Usd)).ToString("F2"); } textBoxStockSymbol.Text = m_selectedStock.Symbol; textBoxStockLastUpdated.Text = m_selectedStock.LastUpdate.ToString(CultureInfo.InvariantCulture); foreach (var coef in Coefficient.CoefficientList) { CoefsTextboxes[coef].Text = m_selectedStock[coef].ToCuteStr(); if (m_selectedStock.ListToRatings.ContainsKey(m_selectedList) && m_selectedStock.ListToRatings[m_selectedList].ContainsKey(coef) && Stock.AllStocksInListAnalyzed) { var pos = m_selectedStock.ListToRatings[m_selectedList][coef]; PositionLabels[coef].Text = pos != null ? $@"{100.0 * (Stock.CoefHasValueCount[coef] - pos + 1) / Stock.CoefHasValueCount[coef]:F2}%" : @" "; } } var listCount = m_selectedList.StList.Count(); foreach (var metric in Coefficient.MetricsList) { if (m_selectedStock.MetricsValues.ContainsKey(metric)) { MetricsTextboxes[metric].Text = m_selectedStock.MetricsValues[metric].ToCuteStr(); } if (m_selectedStock.ListToRatings.ContainsKey(m_selectedList) && m_selectedStock.ListToRatings[m_selectedList].ContainsKey(metric) && Stock.AllStocksInListAnalyzed) { var pos = m_selectedStock.ListToRatings[m_selectedList][metric]; PositionLabels[metric].Text = pos != null ? $@"{100.0 * (listCount - pos + 1) / listCount:F2}%" : @" "; } } if (Stock.AllStocksInListAnalyzed) { textBoxRatingAll.Text = $@"{m_selectedStock.AveragePositionAll:F2}"; textBoxRatingCoefs.Text = $@"{m_selectedStock.AveragePositionNormalizedCoefs:F2}"; textBoxRatingMetrics.Text = $@"{m_selectedStock.AveragePositionMetric:F2}"; } if (getNewInfo) { labelDone.Visible = true; } }
private async Task InitializeMainClass() { await Task.Delay(10); LoadStockListsToViewOnInit(); LogWriter.WriteLog( $"Текущие котировки: \r\nUSD: {StockMarket.GetExchangeRates(StockMarketCurrency.Usd):F2}\r\nEUR: {StockMarket.GetExchangeRates(StockMarketCurrency.Eur):F2}"); string path = $"{Const.ToRestoreDirName}/{ViewSettingsFile}"; if (!File.Exists(path)) { m_selectedList = GetList(StockListNamesEnum.Tinkoff); Logger.Log.Warn($"File {path} does not exists."); return; } Serializer ser = new Serializer(path); bool[] checks = ser.Deserialize() as bool[] ?? throw new ArgumentNullException(); if (m_selectedList == null) { m_selectedList = GetList(StockListNamesEnum.Starred); if (checks[0]) { radioButtonAllStocks.Checked = true; m_selectedList = GetList(StockListNamesEnum.All); } else if (checks[1]) { radioButtonRusStocks.Checked = true; m_selectedList = GetList(StockListNamesEnum.Rus); } else if (checks[2]) { radioButtonUSAStocks.Checked = true; m_selectedList = GetList(StockListNamesEnum.Usa); } else if (checks[3]) { radioButtonLondonStocks.Checked = true; m_selectedList = null; } else if (checks[4]) { radioButtonFromTinkoff.Checked = true; m_selectedList = GetList(StockListNamesEnum.Tinkoff); } } }