Exemplo n.º 1
0
        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
        }
Exemplo n.º 2
0
        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;
            }
        }