Example #1
0
        }     //Button_Click

        // Обработка нажатия кнопок
        private void DockPanel_KeyDown(object sender, KeyEventArgs e)
        {
            switch (e.Key)
            {
            //Добавить новый продукт
            case Key.F2: {
                CreateProductWindow cpw = new CreateProductWindow();
                if (cpw.ShowDialog() == true)
                {
                    try {
                        using (SmallBusinessDBEntities context = new SmallBusinessDBEntities()) {
                            Products prod = new Products();
                            prod.barcode      = cpw.product.barcode;
                            prod.groupID      = cpw.product.groupID;
                            prod.productTitle = cpw.product.productTitle;

                            context.Products.Add(prod);
                            context.SaveChanges();
                            MessageBox.Show("Продукт добавлен!");
                            this.productLict.Add(prod);
                            ProductDataGrid.Items.Refresh();
                        }        //using
                    }
                    catch (Exception ex) {
                        MessageBox.Show(ex.Message);
                    }        //catch
                }
            }
            break;

            default:
                break;
            }
        }
Example #2
0
        }         //ShowProducts

        //Контекстное меню изменение продукта
        private void ChengeProductTextBlock_MouseDown(object sender, MouseButtonEventArgs e)
        {
            Products item = (ProductDataGrid.SelectedItem as Products);

            if (item != null)
            {
                CreateProductWindow agw = new CreateProductWindow(item);
                if (agw.ShowDialog() == true)
                {
                    Products temp = agw.product;

                    if (item.barcode != temp.barcode || item.groupID != temp.groupID || item.productTitle != temp.productTitle)
                    {
                        try {
                            using (SmallBusinessDBEntities context = new SmallBusinessDBEntities()) {
                                var ppp = context.Products.FirstOrDefault(s => s.productID == temp.productID);

                                ppp.barcode      = temp.barcode;
                                ppp.groupID      = temp.groupID;
                                ppp.productTitle = temp.productTitle;
                                context.SaveChanges();
                                MessageBox.Show("Изменения сохранены");
                                ppp              = productLict.FirstOrDefault(s => s.productID == temp.productID);
                                ppp.barcode      = temp.barcode;
                                ppp.groupID      = temp.groupID;
                                ppp.productTitle = temp.productTitle;
                                ProductDataGrid.Items.Refresh();
                            }
                        }
                        catch (Exception ex) {
                            MessageBox.Show(ex.Message);
                        }
                    } //if
                }     //if
            }         //if
        }