Exemplo n.º 1
0
        private void Change_Click(object sender, EventArgs e)
        {
            if (DataGrid1.SelectedItems.Count > 0)
            {
                for (int i = 0; i < DataGrid1.SelectedItems.Count; i++)
                {
                    Channel channel = DataGrid1.SelectedItems[i] as Channel;
                    if (channel != null)
                    {
                        ChannelWin cWin = new ChannelWin();

                        cWin.textBox1.Text = channel.Title;
                        cWin.textBox2.Text = channel.Description;
                        cWin.textBox3.Text = channel.Link;
                        cWin.textBox4.Text = channel.Copyright;

                        if (cWin.ShowDialog() == true)
                        {
                            channel.Title       = cWin.textBox1.Text;
                            channel.Description = cWin.textBox2.Text;
                            channel.Link        = cWin.textBox3.Text;
                            channel.Copyright   = cWin.textBox4.Text;

                            chRep.Update(channel);
                            UpdateDB();

                            //db.Entry(channel).State = EntityState.Modified;
                            //db.SaveChanges();

                            MessageBox.Show("Статья редактирована");
                        }
                        else
                        {
                            return;
                        }
                        //DataGrid1.ItemsSource = null;

                        // DataGrid1.ItemsSource = db.Channels.Local.ToBindingList();
                    }
                }
            }
        }
Exemplo n.º 2
0
        private void Add_Click(object sender, RoutedEventArgs e)
        {
            ChannelWin cWin = new ChannelWin();

            if (cWin.ShowDialog() == true)
            {
                Channel channel = new Channel();
                channel.Title       = cWin.textBox1.Text;
                channel.Description = cWin.textBox2.Text;
                channel.Link        = cWin.textBox3.Text;
                channel.Copyright   = cWin.textBox4.Text;

                chRep.Create(channel);
                UpdateDB();
                // db.Channels.Add(channel);
                // db.SaveChanges();

                MessageBox.Show("Новый канал добавлен");
            }
            else
            {
                return;
            }
        }