Exemplo n.º 1
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     = (DateTime)iWin.textBox4.SelectedDate,
                    Channel     = (Channel)iWin.comboBox1.SelectedItem
                };
                _itemRep.Create(item);
                UpdateDb();
                MessageBox.Show("Новая статья добавлена");
            }
            else
            {
                return;
            }
        }
Exemplo n.º 2
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.ToString() },
             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     = (DateTime)iWin.textBox4.SelectedDate;
             item.Channel     = (Channel)iWin.comboBox1.SelectedItem;
             _itemRep.Update(item);
             UpdateDb();
             MessageBox.Show("Статья редактирована");
         }
         else
         {
             return;
         }
     }
 }