コード例 #1
0
 private void button1_Click(object sender, RoutedEventArgs e)
 {
     using (MyDataContext Db = new MyDataContext(MainPage.strConnectionString))
     {
         DietProduct dp = new DietProduct()
         {
             DId = AddDiet.d.DietID, Product = l[SelectedIndex]
         };
         Db.DietProducts.InsertOnSubmit(dp);
         AddDiet.d.DietProducts.Add(dp);
         Db.SubmitChanges();
         NavigationService.Navigate(new Uri("/AddDiet.xaml", UriKind.Relative));
     }
 }
コード例 #2
0
        private void button3_Click(object sender, RoutedEventArgs e)
        {
            MessageBoxResult m = MessageBox.Show("Удалить?", "", MessageBoxButton.OKCancel);

            if (m == MessageBoxResult.OK)
            {
                DietProduct s = null;
                if (listBox1.SelectedIndex >= 0)
                {
                    s = list[listBox1.SelectedIndex];
                }
                else if (listBox2.SelectedIndex >= 0)
                {
                    s = list[listBox2.SelectedIndex];
                }
                else if (listBox3.SelectedIndex >= 0)
                {
                    s = list[listBox3.SelectedIndex];
                }
                else if (listBox3.SelectedIndex >= 0)
                {
                    s = list[listBox3.SelectedIndex];
                }
                else if (listBox4.SelectedIndex >= 0)
                {
                    s = list[listBox4.SelectedIndex];
                }
                else if (listBox5.SelectedIndex >= 0)
                {
                    s = list[listBox5.SelectedIndex];
                }
                using (MyDataContext Db = new MyDataContext(MainPage.strConnectionString))
                {
                    if (s != null)
                    {
                        var s1 = from DietProduct in Db.DietProducts
                                 where DietProduct.DPID == s.DPID
                                 select DietProduct;
                        Db.DietProducts.DeleteOnSubmit(s1.FirstOrDefault());
                        Db.SubmitChanges();
                    }
                }
                init();
            }
        }