Esempio 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++)
                {
                    Item item = DataGrid1.SelectedItems[i] as Item;
                    if (item != null)
                    {
                        ItemWindow iWin = new ItemWindow();

                        iWin.textBox1.Text = item.Title;
                        iWin.textBox2.Text = item.Description;
                        iWin.textBox3.Text = item.Link;
                        iWin.textBox4.Text = item.PubDate;

                        List <Channel> channels = db.Channels.ToList();

                        iWin.comboBox1.ItemsSource       = db.Channels.Local.ToBindingList();
                        iWin.comboBox1.DisplayMemberPath = "Title";

                        if (item.Channel != null)
                        {
                            iWin.comboBox1.SelectedValue = item.Channel.Id;
                        }

                        if (iWin.ShowDialog() == true)
                        {
                            item.Title       = iWin.textBox1.Text;
                            item.Description = iWin.textBox2.Text;
                            item.Link        = iWin.textBox3.Text;
                            item.PubDate     = iWin.textBox4.Text;
                            item.Channel     = (Channel)iWin.comboBox1.SelectedItem;

                            db.Entry(item).State = EntityState.Modified;
                            db.SaveChanges();

                            MessageBox.Show("Статья редактирована");
                        }
                        else
                        {
                            return;
                        }
                        DataGrid1.ItemsSource = null;
                        DataGrid1.ItemsSource = db.Items.Local.ToBindingList();
                    }
                }
            }
        }
Esempio n. 2
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;

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

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

                        DataGrid1.ItemsSource = db.Channels.Local.ToBindingList();
                    }
                }
            }
        }