예제 #1
0
        private void Button_Click_2(object sender, RoutedEventArgs e)
        {
            try
            {
                Goods   selectedGood = (Goods)dataGrid1.SelectedItem;
                Goods   findGood     = Autho.Goods.First(p => p.Article == selectedGood.Article);
                AddGood editGood     = new AddGood("Изменение продукта");

                editGood.goodArticle.Text = findGood.Article;
                editGood.goodName.Text    = findGood.Name;
                editGood.goodPrice.Text   = Convert.ToString(findGood.Price);
                if (editGood.ShowDialog() != false)
                {
                    selectedGood.Name    = editGood.goodName.Text;
                    selectedGood.Article = editGood.goodArticle.Text;
                    selectedGood.Price   = Convert.ToInt32(editGood.goodPrice.Text);
                    Autho.SubmitChanges();
                    dataGrid1.Items.Refresh();
                    MessageBox.Show("Информация по товару успешно изменена");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
예제 #2
0
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            AddGood addGood = new AddGood("Добавить товар");

            if (addGood.ShowDialog() != false)
            {
                if (addGood.goodName.Text != null && addGood.goodArticle.Text != null && addGood.goodPrice != null)
                {
                    Goods NewGood = new Goods
                    {
                        Article = addGood.goodArticle.Text,
                        Name    = addGood.goodName.Text,
                        Price   = Convert.ToInt32(addGood.goodPrice)
                    };
                    Autho.Goods.InsertOnSubmit(NewGood);
                    Autho.SubmitChanges();
                }
                else
                {
                    MessageBox.Show("Все поля должны быть заполненны!");
                }
            }
            dataGrid1.Items.Refresh();
        }