private void FormProduct_Load(object sender, EventArgs e) { if (id.HasValue) { try { CommodityViewModel view = service.GetElement(id.Value); if (view != null) { textBoxName.Text = view.CommodityName; textBoxPrice.Text = view.Price.ToString(); productComponents = view.CommodityIngridients; LoadData(); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { productComponents = new List <ProductComponentView>(); } }
private void CalcSum() { if (comboBoxCommodity.SelectedValue != null && !string.IsNullOrEmpty(textBoxCount.Text)) { try { int id = Convert.ToInt32(comboBoxCommodity.SelectedValue); CommodityViewModel commodity = serviceP.GetElement(id); int count = Convert.ToInt32(textBoxCount.Text); textBoxSum.Text = (count * commodity.Price).ToString(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }