}     //ShowSupliersWindow

        private void AddContactTextBlock_MouseDown(object sender, MouseButtonEventArgs e)
        {
            Suppliers supplier = SuppliersDataGrid.SelectedItem as Suppliers;

            if (supplier == null)
            {
                return;
            }
            AddContactWindow scw = new AddContactWindow(supplier);

            if (scw.ShowDialog() == true)
            {
                try {
                    using (SmallBusinessDBEntities context = new SmallBusinessDBEntities()) {
                        Contacts newContacts = new Contacts();
                        newContacts.contact       = scw.newContact.contact;
                        newContacts.ContactTypeID = scw.newContact.ContactTypeID;
                        newContacts.description   = scw.newContact.description;
                        newContacts.employeeID    = scw.newContact.employeeID;
                        newContacts.supplierID    = scw.newContact.supplierID;
                        context.Contacts.Add(newContacts);
                        context.SaveChanges();
                        MessageBox.Show("Контакт добавлен");
                    }
                }
                catch (Exception ex) {
                    MessageBox.Show(ex.Message);
                }
            }
        }
        }//SerchByCompanyNameTextBox_TextChanged

        private void ChengeTextBlock_MouseDown(object sender, MouseButtonEventArgs e)
        {
            Suppliers item = (SuppliersDataGrid.SelectedItem as Suppliers);

            if (item != null)
            {
                AddSuppliersWindow asw = new AddSuppliersWindow(item);
                if (asw.ShowDialog() == true)
                {
                    Suppliers temp = asw.sup;

                    if (item.companyName != temp.companyName || item.contactName != temp.contactName)
                    {
                        try {
                            using (SmallBusinessDBEntities context = new SmallBusinessDBEntities()) {
                                var ppp = context.Suppliers.FirstOrDefault(s => s.supplierID == temp.supplierID);
                                //context.Groups.FirstOrDefault(s => s.groupID == temp.groupID).groupDescription = temp.groupDescription;
                                ppp.companyName = temp.companyName;
                                ppp.contactName = temp.contactName;

                                context.SaveChanges();
                                MessageBox.Show("Изменения сохранены");
                                ppp             = suppList.FirstOrDefault(s => s.supplierID == temp.supplierID);
                                ppp.companyName = temp.companyName;
                                ppp.contactName = temp.contactName;
                                SuppliersDataGrid.Items.Refresh();
                            }
                        }
                        catch (Exception ex) {
                            MessageBox.Show(ex.Message);
                        }
                    } //if
                }     //if
            }         //if
        }             //ChengeTextBlock_MouseDown
        }             //ChengeTextBlock_MouseDown

        private void MainSupDockPanel_KeyDown(object sender, KeyEventArgs e)
        {
            switch (e.Key)
            {
            case Key.F2: {
                AddSuppliersWindow adsw = new AddSuppliersWindow();
                if (adsw.ShowDialog() == true)
                {
                    Suppliers temp = adsw.sup;
                    try {
                        using (SmallBusinessDBEntities context = new SmallBusinessDBEntities()) {
                            context.Suppliers.Add(temp);
                            context.SaveChanges();
                            MessageBox.Show("Изменения сохранены");
                            suppList.Add(temp);
                            SuppliersDataGrid.Items.Refresh();
                        }    //using
                    }        //try
                    catch (Exception ex) {
                        MessageBox.Show(ex.Message);
                    } //catch
                }     //if
            }         //case Key.F2
            break;

            default:
                break;
            } //switch
        }     //MainSupDockPanel_KeyDown
        private void SaveInvoiceButton_Click(object sender, RoutedEventArgs e)
        {
            try {
                using (SmallBusinessDBEntities context = new SmallBusinessDBEntities()) {
                    this.detailsList.ForEach(d => {
                        InvoiceDetails dummy = new InvoiceDetails {
                            invoiceID = d.InvoiceID,
                            productID = d.ProductID,
                            quantity  = d.Quantity,
                            price     = d.Price
                        };

                        context.InvoiceDetails.Add(dummy);
                    });

                    context.SaveChanges();

                    this.detailsList.Clear();

                    this.LoadInvoices(this.newInvoice.date);

                    this.MainOrdersShowRow.Height = this.AddNewOrderRow.Height;
                    this.AddNewOrderRow.Height    = new GridLength(0);
                    AddNewProductRow.Height       = new GridLength(0);
                }//using
            }
            catch (Exception ex) {
                MessageBox.Show(ex.Message);
            }//catch
        }
        private void ChengeTextBlock_MouseDown(object sender, MouseButtonEventArgs e)
        {
            Groups item = (GroupDataGrid.SelectedItem as Groups);

            if (item != null)
            {
                AddGroupWindow agw = new AddGroupWindow(item);
                if (agw.ShowDialog() == true)
                {
                    Groups temp = agw.group;

                    if (item.groupTitle != temp.groupTitle || item.groupDescription != temp.groupDescription)
                    {
                        try {
                            using (SmallBusinessDBEntities context = new SmallBusinessDBEntities()) {
                                var ppp = context.Groups.FirstOrDefault(s => s.groupID == temp.groupID);
                                //context.Groups.FirstOrDefault(s => s.groupID == temp.groupID).groupDescription = temp.groupDescription;
                                ppp.groupTitle       = temp.groupTitle;
                                ppp.groupDescription = temp.groupDescription;

                                context.SaveChanges();
                                MessageBox.Show("Изменения сохранены");
                                ppp                  = groupList.FirstOrDefault(s => s.groupID == temp.groupID);
                                ppp.groupTitle       = temp.groupTitle;
                                ppp.groupDescription = temp.groupDescription;
                                GroupDataGrid.Items.Refresh();
                            }
                        }
                        catch (Exception ex) {
                            MessageBox.Show(ex.Message);
                        }
                    } //if
                }     //if
            }         //if
        }
        private void MainDockPanel_KeyDown(object sender, KeyEventArgs e)
        {
            switch (e.Key)
            {
            case Key.F2: {
                AddGroupWindow ad = new AddGroupWindow();
                if (ad.ShowDialog() == true)
                {
                    Groups temp = ad.group;
                    try {
                        using (SmallBusinessDBEntities context = new SmallBusinessDBEntities()) {
                            context.Groups.Add(temp);
                            context.SaveChanges();
                            MessageBox.Show("Изменения сохранены");
                            groupList.Add(temp);
                            GroupDataGrid.Items.Refresh();
                        }    //using
                    }        //try
                    catch (Exception ex) {
                        MessageBox.Show(ex.Message);
                    } //catch
                }     //if
            }         //case Key.F2
            break;

            case Key.Escape: {
                this.Content = null;
            }        //case Key.Escape
            break;

            default:
                break;
            }
        }
        }     //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;
            }
        }
        }     //SerchByContactVelueTextBox_TextChanged

        private void ChengeContactTextBlock_MouseDown(object sender, MouseButtonEventArgs e)
        {
            if (ContactsDataGrid.SelectedItem is SimpleContact contact)
            {
                AddContactWindow acw = new AddContactWindow(contact);
                if (acw.ShowDialog() == true)
                {
                    Contacts newcont = acw.newContact;
                    if (newcont.contact != contact.contact || newcont.description != contact.description)
                    {
                        try {
                            using (SmallBusinessDBEntities context = new SmallBusinessDBEntities()) {
                                var ppp = context.Contacts.FirstOrDefault(s => s.ContactID == contact.ContactID);

                                ppp.contact     = newcont.contact;
                                ppp.description = newcont.description;

                                context.SaveChanges();
                                MessageBox.Show("Изменения сохранены");

                                contact.contact     = newcont.contact;;
                                contact.description = newcont.description;

                                ContactsDataGrid.Items.Refresh();
                            }
                        }
                        catch (Exception ex) {
                            MessageBox.Show(ex.Message);
                        }
                    } //if
                }     //if
            }         //if
        }
        private void MainDockPanel_KeyDown(object sender, KeyEventArgs e)
        {
            switch (e.Key)
            {
            case Key.F2: {
                CreateNewInvoiceWindow cniw = new CreateNewInvoiceWindow(this.currentEmployeer);
                if (cniw.ShowDialog() == true)
                {
                    this.detailsList.Clear();
                    this.InvoiceNewDataGrid.Items.Refresh();

                    this.newInvoice = cniw.newInvoice;
                    try {
                        using (SmallBusinessDBEntities context = new SmallBusinessDBEntities()) {
                            context.Invoices.Add(newInvoice);
                            context.SaveChanges();
                            this.newInvoice           = context.Invoices.OrderByDescending(inv => inv.invoiceID).First();
                            this.newInvoice.Suppliers = context.Suppliers.FirstOrDefault(s => s.supplierID == this.newInvoice.supplierID);
                            FillInvoiceFields();
                            this.AddNewOrderRow.Height          = this.MainOrdersShowRow.Height;
                            this.MainOrdersShowRow.Height       = new GridLength(0);
                            AddNewProductRow.Height             = new GridLength(130);
                            this.InvoiceNewDataGrid.ItemsSource = this.detailsList;
                        }        //using
                    }
                    catch (Exception ex) {
                        MessageBox.Show(ex.Message);
                    } //catch
                }     //if
            }         //case Key.F2
            break;

            default:
                break;
            }
        }
        }         //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
        }