private void UpdateCurrentPricesGridFromDatabase() { m_currentPrices.Clear(); var connectionString = ConfigurationManager.ConnectionStrings["LiveDb"].ConnectionString; using (var conn = new SqlConnection(connectionString)) { conn.Open(); using (var cmd = new SqlCommand()) { cmd.Connection = conn; cmd.CommandText = "SELECT ProductId, TillDescription, RegularPrice, OfferPrice, Barcode FROM Products"; var reader = cmd.ExecuteReader(); while (reader.Read()) { var item = new ShoppingItem { ProductId = (int)reader["ProductId"], Barcode = (string)reader["Barcode"], RegularPrice = (Decimal)reader["RegularPrice"], OfferPrice = reader["OfferPrice"] == DBNull.Value ? null : (Decimal?)reader["OfferPrice"], TillDescription = (string)reader["TillDescription"] }; m_currentPrices.Add(item); } UpdateCurrentPricesGrid(); } } }
private void AddItemToCurrentPricingTable(ShoppingItem item) { RichTextBox description = GetRichTextBoxForItemList(false); description.Text = item.TillDescription; RichTextBox regularPrice = GetRichTextBoxForItemList(false); regularPrice.Text = item.RegularPrice.ToString("C"); RichTextBox offerPrice = GetRichTextBoxForItemList(false); offerPrice.Text = item.OfferPrice.HasValue ? item.OfferPrice.Value.ToString("C") : String.Empty; RichTextBox barcode = GetRichTextBoxForItemList(false); barcode.Text = item.Barcode; Button updatePrice = new Button { Text = "Edit", Width = 60 }; tableLayoutPanelCurrentPricing.RowCount++; int nextRow = tableLayoutPanelCurrentPricing.RowCount - 1; tableLayoutPanelCurrentPricing.Controls.Add(description, 0, nextRow); tableLayoutPanelCurrentPricing.Controls.Add(regularPrice, 1, nextRow); tableLayoutPanelCurrentPricing.Controls.Add(offerPrice, 2, nextRow); tableLayoutPanelCurrentPricing.Controls.Add(updatePrice, 3, nextRow); }