/// <summary> /// Parse option having crude option, string or HtmlMode. Is a variable-argument method. /// </summary> public OptionParseResult Parse(string str, HtmlNode node) { bool strFormalMode = str != null; bool nodeFormalMode = node != null; if (strFormalMode == nodeFormalMode) { throw new InvalidOperationException("This is a two-mode method, please provide only single desired parameter."); } if (PriceAmount == null) { throw new NullReferenceException($"Price extraction is not defined."); } #region Option Info Parsing var newOptionParse = new OptionParseResult(); // Details try { if (Code != null) { newOptionParse.Code = Code.ExtractSingle(str, node); } } catch (NullReferenceException nrex) { Logger.Log(nrex.Message + " @ Option Code Parsing"); } try { if (PropertyA != null) { newOptionParse.PropertyA = PropertyA.ExtractSingle(str, node); } } catch (NullReferenceException nrex) { Logger.Log(nrex.Message + " @ Option PropertyA Parsing"); } try { if (PropertyB != null) { newOptionParse.PropertyB = PropertyB.ExtractSingle(str, node); } } catch (NullReferenceException nrex) { Logger.Log(nrex.Message + " @ Option PropertyB Parsing"); } try { if (PropertyC != null) { newOptionParse.PropertyC = PropertyC.ExtractSingle(str, node); } } catch (NullReferenceException nrex) { Logger.Log(nrex.Message + " @ Option PropertyC Parsing"); } #endregion Option Info Parsing #region Snapshot Info Parsing var snapshot = new Snapshot(newOptionParse) { Timestamp = DateTime.Now }; try { if (Stock != null) { newOptionParse.StockStatus = Stock.ExtractSingle(str, node); } } catch (NullReferenceException nrex) { Logger.Log(nrex.Message + " @ Option Snapshot Stock Parsing"); } //Price try { var extracted = PriceAmount.ExtractSingle(str, node); decimal.TryParse(extracted, NumberStyles.Any, CultureInfo.InvariantCulture, out decimal parsedDouble); newOptionParse.Price = new Money(parsedDouble, PriceCurrency); } catch (NullReferenceException nrex) { Logger.Log(nrex.Message + " @ Option Snapshot Price Parsing"); } #endregion Snapshot Info Parsing return(newOptionParse); }
private void updateGrid() { var priceAmounts = container.PriceAmounts; dataGrid.Rows.Clear(); dataGrid.Columns.Clear(); if (priceAmounts.Count > 0) { if (container.IsSingleType()) { dataGrid.ColumnCount = 3; int priceNumber = priceAmounts.Count; dataGrid.RowCount = priceNumber + 1; dataGrid.Columns[0].HeaderCell.Value = "Покупка"; dataGrid.Columns[1].HeaderCell.Value = "Продажа"; dataGrid.Columns[2].HeaderCell.Value = "Разница"; dataGrid.Columns[0].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight; dataGrid.Columns[1].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight; dataGrid.Columns[2].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight; int i = 0; foreach (double price in priceAmounts.Keys) { dataGrid.Rows[priceNumber - i - 1].HeaderCell.Value = price.ToString(); PriceAmount priceAmount = priceAmounts[price]; var row = dataGrid.Rows[priceNumber - i - 1]; row.HeaderCell.Style.Font = new Font(dataGrid.Font, FontStyle.Bold); row.Cells[0].Value = priceAmount.Buy.ToString("N0", CultureInfo.InvariantCulture); row.Cells[1].Value = priceAmount.Sell.ToString("N0", CultureInfo.InvariantCulture); row.Cells[2].Value = priceAmount.Difference.ToString("N0", CultureInfo.InvariantCulture); row.Cells[0].Style.Font = new Font(dataGrid.Font, FontStyle.Bold); row.Cells[0].Style.ForeColor = Color.Green; row.Cells[1].Style.Font = new Font(dataGrid.Font, FontStyle.Bold); row.Cells[1].Style.ForeColor = Color.Red; row.Cells[2].Style.Font = new Font(dataGrid.Font, FontStyle.Bold); if (priceAmount.Difference >= 0) { row.Cells[2].Style.ForeColor = Color.Green; } else { row.Cells[2].Style.ForeColor = Color.Red; } i++; } var totalRow = dataGrid.Rows[dataGrid.Rows.Count - 1]; totalRow.HeaderCell.Value = "Всего:"; totalRow.Cells[0].Value = priceAmounts.Sum(x => x.Value.Buy).ToString("N0", CultureInfo.InvariantCulture); totalRow.Cells[1].Value = priceAmounts.Sum(x => x.Value.Sell).ToString("N0", CultureInfo.InvariantCulture); double totalDiff = priceAmounts.Sum(x => x.Value.Difference); totalRow.Cells[2].Value = totalDiff.ToString("N0", CultureInfo.InvariantCulture); totalRow.Cells[0].Style.Font = new Font(dataGrid.Font, FontStyle.Bold); totalRow.Cells[0].Style.ForeColor = Color.Green; totalRow.Cells[1].Style.Font = new Font(dataGrid.Font, FontStyle.Bold); totalRow.Cells[1].Style.ForeColor = Color.Red; totalRow.Cells[2].Style.Font = new Font(dataGrid.Font, FontStyle.Bold); if (totalDiff >= 0) { totalRow.Cells[2].Style.ForeColor = Color.Green; } else { totalRow.Cells[2].Style.ForeColor = Color.Red; } } else { MessageBox.Show("Были загружены данные о разных акциях", "Предупреждение", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }