Пример #1
0
        private void Insert()
        {
            //插入数据
            UserLoginLog ull = new UserLoginLog {
                User_ID   = "a100",
                UserName  = "******",
                IP        = "20190312",
                TimeStamp = Guid.NewGuid().ToString("N").Substring(0, 12)
            };

            ctx.UserLoginLogs.InsertOnSubmit(ull);
            ctx.SubmitChanges();
        }
        private void button3_Click(object sender, RoutedEventArgs e)
        {
            MessageBoxResult m = MessageBox.Show("Удалить?", "", MessageBoxButton.OKCancel);

            if (m == MessageBoxResult.OK)
            {
                Action a = null;
                if (listBox1.SelectedIndex >= 0)
                {
                    a = l[listBox1.SelectedIndex];
                }
                if (listBox2.SelectedIndex >= 0)
                {
                    a = l[listBox1.SelectedIndex];
                }

                using (MyDataContext Db = new MyDataContext(MainPage.strConnectionString))
                {
                    if (a != null)
                    {
                        var s1 = from Action in Db.Actions
                                 where Action.ActionID == a.ActionID
                                 select Action;
                        Db.Actions.DeleteOnSubmit(s1.FirstOrDefault());
                        Db.SubmitChanges();
                    }
                }
                init();
            }
        }
Пример #3
0
    static void Main()
    {
        MyDataContext ctx   = new MyDataContext();
        BindingSource custs = new BindingSource()
        {
            DataSource = ctx.Customers
        };

        BindingSource orders = new BindingSource {
            DataMember = "Orders", DataSource = custs
        };

        Button btn;

        using (Form form = new Form
        {
            Controls =
            {
                new DataGridView()
                {
                    DataSource = orders, DataMember = "Order_Details",
                    Dock = DockStyle.Fill
                },
                new ComboBox()
                {
                    DataSource = orders, DisplayMember = "OrderID",
                    Dock = DockStyle.Top
                },
                new ComboBox()
                {
                    DataSource = custs, DisplayMember = "CompanyName",
                    Dock = DockStyle.Top
                },
                (btn = new Button()
                {
                    Text = "Save", Dock = DockStyle.Bottom
                }),     // **edit here re textbox etc**
                new TextBox {
                    DataBindings ={        { "Text", orders, "ShipAddress"  } },
                    Dock = DockStyle.Bottom
                },
                new Label   {
                    DataBindings ={        { "Text", custs,  "ContactName"  } },
                    Dock = DockStyle.Top
                },
                new Label   {
                    DataBindings ={        { "Text", orders, "RequiredDate" } },
                    Dock = DockStyle.Bottom
                }
            }
        })
        {
            btn.Click += delegate {
                form.Text = "Saving...";
                ctx.SubmitChanges();
                form.Text = "Saved";
            };
            Application.Run(form);
        }
    }
Пример #4
0
 private void textBox1_TextChanged(object sender, TextChangedEventArgs e)
 {
     using (MyDataContext Db = new MyDataContext(MainPage.strConnectionString))
     {
         IQueryable <Diet> q = from Diet in Db.Diets where Diet.DietID == dietId select Diet;
         d          = q.FirstOrDefault();
         d.Duration = Convert.ToInt32(textBox1.Text);
         Db.SubmitChanges();
     }
 }
Пример #5
0
 private void name_TextChanged(object sender, TextChangedEventArgs e)
 {
     using (MyDataContext Db = new MyDataContext(MainPage.strConnectionString))
     {
         IQueryable <Diet> q = from Diet in Db.Diets where Diet.DietID == dietId select Diet;
         d      = q.FirstOrDefault();
         d.Name = name.Text;
         Db.SubmitChanges();
     }
 }
 private void button1_Click(object sender, RoutedEventArgs e)
 {
     using (MyDataContext Db = new MyDataContext(MainPage.strConnectionString))
     {
         Action a = new Action {
             Name = name.Text, Energy = Convert.ToDouble(energy.Text)
         };
         NavigationService.Navigate(new Uri("/ActionList.xaml", UriKind.Relative));
         Db.Actions.InsertOnSubmit(a);
         Db.SubmitChanges();
     }
 }
 private void button2_Click(object sender, RoutedEventArgs e)
 {
     using (MyDataContext Db = new MyDataContext(MainPage.strConnectionString))
     {
         Schedule s = new Schedule {
             DayWeek = dayIdx, Duration = Convert.ToInt32(duration.Text), Time = time.Text, Action = l[listBox1.SelectedIndex]
         };
         Db.Schedules.InsertOnSubmit(s);
         Db.SubmitChanges();
     }
     NavigationService.Navigate(new Uri("/Schedule.xaml", UriKind.Relative));
 }
Пример #8
0
 private void button2_Click(object sender, RoutedEventArgs e)
 {
     using (MyDataContext Db = new MyDataContext(MainPage.strConnectionString))
     {
         IQueryable <Diet> q = from Diet in Db.Diets where Diet.DietID == dietId select Diet;
         d          = q.FirstOrDefault();
         d.Name     = name.Text;
         d.Duration = Convert.ToInt32(textBox1.Text);
         Db.SubmitChanges();
         NavigationService.Navigate(new Uri("/InfoPage.xaml", UriKind.Relative));
     }
 }
 private void button1_Click(object sender, RoutedEventArgs e)
 {
     using (MyDataContext Db = new MyDataContext(MainPage.strConnectionString))
     {
         IQueryable <Dish> RationQuery = from Dish in Db.Dishes where Dish.DishID == l[listBox2.SelectedIndex].DishID select Dish;
         Dish   d = RationQuery.FirstOrDefault();
         Ration r = new Ration {
             DayWeek = listBox1.SelectedIndex, Dish = d, Time = textBox1.Text, WeightDish = Convert.ToInt32(textBox2.Text)
         };
         Db.Rations.InsertOnSubmit(r);
         Db.SubmitChanges();
         NavigationService.Navigate(new Uri("/RationPage.xaml", UriKind.Relative));
     }
 }
Пример #10
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));
     }
 }
Пример #11
0
    static void Main()
    {
        MyDataContext ctx   = new MyDataContext();
        BindingSource custs = new BindingSource()
        {
            DataSource = ctx.Customers
        };

        BindingSource orders = new BindingSource {
            DataMember = "Orders", DataSource = custs
        };

        Button btn;

        using (Form form = new Form
        {
            Controls =
            {
                new DataGridView()
                {
                    DataSource = orders, DataMember = "Order_Details",
                    Dock = DockStyle.Fill
                },
                new ComboBox()
                {
                    DataSource = orders, DisplayMember = "OrderID",
                    Dock = DockStyle.Top
                },
                new ComboBox()
                {
                    DataSource = custs, DisplayMember = "CompanyName",
                    Dock = DockStyle.Top
                },
                (btn = new Button()
                {
                    Text = "Save", Dock = DockStyle.Bottom
                })
            }
        })
        {
            btn.Click += delegate {
                form.Text = "Saving...";
                ctx.SubmitChanges();
                form.Text = "Saved";
            };
            Application.Run(form);
        }
    }
Пример #12
0
        public ActionResult Edit(int?id, LearningMVCAppln.Models.User userDetails)
        //public ActionResult Edit(int? id)
        {
            TempData["TempData Name"] = "Akhil";

            try
            {
                using (var dbContext = new MyDataContext())
                {
                    var user = dbContext.Users.FirstOrDefault(userId => userId.UserId == id);
                    if (user != null)
                    {
                        user.FirstName   = userDetails.FirstName;
                        user.LastName    = userDetails.LastName;
                        user.Address     = userDetails.Address;
                        user.PhoneNo     = userDetails.PhoneNo;
                        user.EMail       = userDetails.EMail;
                        user.Company     = userDetails.Company;
                        user.Designation = userDetails.Designation;
                        dbContext.SubmitChanges();
                    }
                    return(RedirectToAction(nameof(Index)));
                }
            }
            catch (Exception)
            {
                return(View());
            }


            //try
            //{
            //    Mapper.CreateMap<LearningMVCAppln.Models.User, LearningMVCAppln.User>();
            //    using (var dbContext = new MyDataContext())
            //    {
            //        var userDetails1 = dbContext.Users.FirstOrDefault(userId => userId.UserId == id);
            //        var user = Mapper.Map<LearningMVCAppln.Models.User, LearningMVCAppln.User>(userDetails);
            //        //dbContext.Users.InsertOnSubmit(user);
            //        dbContext.SubmitChanges();
            //        return RedirectToAction(nameof(Index));
            //    }
            //}
            //catch (Exception)
            //{
            //    return View();
            //}
        }
        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();
            }
        }
Пример #14
0
 public ActionResult Create(LearningMVCAppln.Models.User userDetails)
 {
     try
     {
         Mapper.CreateMap <LearningMVCAppln.Models.User, LearningMVCAppln.User>();
         using (var dbContext = new MyDataContext())
         {
             var user = Mapper.Map <LearningMVCAppln.Models.User, LearningMVCAppln.User>(userDetails);
             dbContext.Users.InsertOnSubmit(user);
             dbContext.SubmitChanges();
             return(RedirectToAction(nameof(Index)));
         }
     }
     catch (Exception)
     {
         return(View());
     }
 }
Пример #15
0
        public ActionResult Delete(int?id, Models.User userDetails)
        {
            try
            {
                using (var dbContext = new MyDataContext())
                {
                    var user = dbContext.Users.FirstOrDefault(userId => userId.UserId == id);
                    if (user != null)
                    {
                        dbContext.Users.DeleteOnSubmit(user);
                        dbContext.SubmitChanges();
                    }

                    return(RedirectToAction(nameof(Index)));
                }
            }
            catch (Exception)
            {
                return(View());
            }
        }
Пример #16
0
        public AddDiet()
        {
            InitializeComponent();
            InitializeComponent();
            if (a)
            {
                d = new Diet();
                using (MyDataContext Db = new MyDataContext(MainPage.strConnectionString))
                {
                    d.Name         = "";
                    d.DietProducts = new System.Data.Linq.EntitySet <DietProduct>();
                    Db.Diets.InsertOnSubmit(d);
                    Db.SubmitChanges();
                    dietId = (from Diet in Db.Diets select Diet).Count();
                }
                a = false;
            }
            else
            {
                name.Text     = d.Name;
                textBox1.Text = d.Duration + "";
                using (MyDataContext Db = new MyDataContext(MainPage.strConnectionString))
                {
                    IQueryable <Diet> q = from Diet in Db.Diets where Diet.DietID == dietId select Diet;
                    d = q.FirstOrDefault();

                    var           list1 = d.DietProducts.ToList();
                    List <String> ll    = new List <string>();
                    foreach (var s in list1)
                    {
                        ll.Add(s.Product.Name);
                    }
                    lb1.ItemsSource = ll;
                }
            }
        }
Пример #17
0
 public void Save()
 {
     _dataContext.SubmitChanges();
 }