示例#1
0
 private void FormProduct_Load(object sender, EventArgs e)
 {
     if (id.HasValue)
     {
         try
         {
             CandyViewModel view = service.GetElement(id.Value);
             if (view != null)
             {
                 textBoxName.Text  = view.CandyName;
                 textBoxPrice.Text = view.Price.ToString();
                 candyIngredients  = view.CandyIngredients;
                 LoadData();
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
     else
     {
         candyIngredients = new List <CandyIngredientViewModel>();
     }
 }
 private void CalcSum()
 {
     if (comboBoxProduct.SelectedValue != null && !string.IsNullOrEmpty(textBoxCount.Text))
     {
         try
         {
             int            id      = Convert.ToInt32(comboBoxProduct.SelectedValue);
             CandyViewModel product = serviceP.GetElement(id);
             int            count   = Convert.ToInt32(textBoxCount.Text);
             textBoxSum.Text = (count * product.Price).ToString();
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
 }