예제 #1
0
        private void Add_Click(object sender, RoutedEventArgs e)
        {
            ItemWindow iWin = new ItemWindow();

            // из команд в бд формируем список
            List <Channel> channels = db.Channels.ToList();

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

            //ComboBox.ItemsSource = DS.Tables["TypeUser"].DefaultView;
            //ComboBox.DisplayMemberPath = "Name";

            if (iWin.ShowDialog() == true)
            {
                Item item = new Item();
                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.Items.Add(item);
                db.SaveChanges();

                MessageBox.Show("Новая статья добавлена");
            }
            else
            {
                return;
            }
        }
예제 #2
0
        private void Add_Click(object sender, RoutedEventArgs e)
        {
            var iWin = new ItemWindow
            {
                comboBox1 =
                {
                    ItemsSource       = _chRep.Get(),
                    DisplayMemberPath = "Title"
                }
            };

            if (iWin.ShowDialog() == true)
            {
                var item = new Item
                {
                    Title       = iWin.textBox1.Text,
                    Description = iWin.textBox2.Text,
                    Link        = iWin.textBox3.Text,
                    PubDate     = iWin.textBox4.Text,
                    Channel     = (Channel)iWin.comboBox1.SelectedItem
                };
                _itemRep.Create(item);
                UpdateDb();
                MessageBox.Show("Новая статья добавлена");
            }
            else
            {
                return;
            }
        }
예제 #3
0
        //private void MainWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        //{
        //    db.Dispose();
        //}

        private void Add_Click(object sender, RoutedEventArgs e)
        {
            ItemWindow iWin = new ItemWindow();

            // из команд в бд формируем список

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


            //iWin.comboBox1.ItemsSource = db.Channels.Local.ToBindingList();
            iWin.comboBox1.ItemsSource = chRep.Get();

            iWin.comboBox1.DisplayMemberPath = "Title";

            if (iWin.ShowDialog() == true)
            {
                Item item = new Item();
                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;

                itemRep.Create(item);
                UpdateDB();

                MessageBox.Show("Новая статья добавлена");
            }
            else
            {
                return;
            }
        }
예제 #4
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.ItemsSource = chRep.Get();

                        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;

                            itemRep.Update(item);
                            UpdateDB();
                            //db.Entry(item).State = EntityState.Modified;
                            //db.SaveChanges();

                            MessageBox.Show("Статья редактирована");
                        }
                        else
                        {
                            return;
                        }
                        //DataGrid1.ItemsSource = null;
                        //DataGrid1.ItemsSource = db.Items.Local.ToBindingList();
                    }
                }
            }
        }
예제 #5
0
 private void Change_Click(object sender, EventArgs e)
 {
     if (DataGrid1.SelectedItems.Count <= 0)
     {
         return;
     }
     foreach (var t in DataGrid1.SelectedItems)
     {
         if (!(t is Item item))
         {
             continue;
         }
         var iWin = new ItemWindow
         {
             textBox1  = { Text = item.Title },
             textBox2  = { Text = item.Description },
             textBox3  = { Text = item.Link },
             textBox4  = { Text = item.PubDate },
             comboBox1 =
             {
                 ItemsSource       = _chRep.Get(),
                 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;
             _itemRep.Update(item);
             UpdateDb();
             MessageBox.Show("Статья редактирована");
         }
         else
         {
             return;
         }
     }
 }