Ejemplo n.º 1
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Module.Students stud = new Module.Students();

            stud.IdStudent   = Int32.Parse(StudIdText.Text);
            stud.NameStudent = StudNameText.Text;
            stud.YearStudy   = StudYearText.Text;
            stud.Branch      = StudBranchText.Text;



            try
            {
                db.Students.Add(stud);
                db.SaveChanges();

                Userslist.ItemsSource = db.Students.Select(s => new
                {
                    s.IdStudent,
                    s.NameStudent,
                    s.Branch,
                    s.YearStudy
                }).ToList();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Ejemplo n.º 2
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            int fromtextbox            = Int32.Parse(AssignBookId.Text);
            int fromtexboxAssignstudid = Int32.Parse(AssignStudId.Text);

            book             = db.books.Where(w => w.Idbook == fromtextbox).FirstOrDefault();
            assign.BookId    = book.Idbook;
            stud             = db.Students.Where(w => w.IdStudent == fromtexboxAssignstudid).FirstOrDefault();
            assign.StudentId = stud.IdStudent;
            assign.StartDate = DateTime.Now;
            assign.EndDate   = DateTime.Now.AddDays(30);
            // assign.Penality = (assign.EndDate - DateTime.Now) * 5 ;

            db.AssignBooks.Add(assign);

            db.SaveChanges();
            MessageBox.Show(string.Format("student id:{0} assign to ", assign.StudentId.ToString()));
        }