Exemplo n.º 1
0
        private void btnThem_Click(object sender, RoutedEventArgs e)
        {
            var phim = new Phim
            {
                Ten           = txtTenPhim.Text,
                NgayKhoiChieu = DateTime.Parse(ngayKhoiChieu.Text),
                theloai       = new TheLoai {
                    TenTheLoai = txtTheLoai.Text
                },
                ThoiLuong = int.Parse(txtThoiLuong.Text),
                NgonNgu   = txtNgonNgu.Text,
                Rated     = float.Parse(txtRated.Text)
            };

            if (Phim.KiemTraInputHopLe(phim).Item1)
            {
                try
                {
                    using (var context = new QlyRapPhimContext())
                    {
                        context.Phims.Add(phim);
                        context.SaveChanges();
                        MessageBox.Show(Phim.KiemTraInputHopLe(phim).Item2, "Success");
                    }
                }
                catch
                {
                    // .......
                }
            }
            else
            {
                MessageBox.Show(Phim.KiemTraInputHopLe(phim).Item2, "Error");
            }
        }
Exemplo n.º 2
0
 private void btnDangNhap_Click(object sender, RoutedEventArgs e)
 {
     using (var context = new QlyRapPhimContext())
     {
         if (IsValidUser(txtTenDangNhap.Text, txtMatKhau.Password))
         {
             MainWindow wd = new MainWindow();
             wd.Show();
             this.Close();
         }
         else
         {
             MessageBox.Show("Sai ten dang nhap hoac mat khau");
         }
     }
 }
Exemplo n.º 3
0
 private bool IsValidUser(string username, string password)
 {
     using (var context = new QlyRapPhimContext())
     {
         var user = from u in context.Users
                    where u.TenDangNhap == txtTenDangNhap.Text && u.MatKhau == txtMatKhau.Password
                    select u;
         if (user.Any())
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
 }
        private void btnDangKy_Click(object sender, RoutedEventArgs e)
        {
            var user = new User
            {
                TenDangNhap = txtTenDangNhap.Text,
                MatKhau     = txtMatKhau.Password
            };

            if (User.KiemTraInput(user).Item1)
            {
                try
                {
                    using (var context = new QlyRapPhimContext())
                    {
                        // Kiểm tra tên đăng nhập có tồn tại trong hệ thống hay chưa ?
                        var username =
                            from u in context.Users
                            where u.TenDangNhap == user.TenDangNhap
                            select u;
                        if (username.Count() > 0)
                        {
                            MessageBox.Show("Ten dang nhap da ton tai", "Error");
                            return;
                        }

                        context.Users.Add(user);
                        context.SaveChanges();
                        MessageBox.Show(User.KiemTraInput(user).Item2, "Success");
                    }
                }
                // Lỗi với MaxLength(10), MaxLength(50)
                catch (DbEntityValidationException)
                {
                    MessageBox.Show("Loi~");
                }
            }
            else
            {
                MessageBox.Show(User.KiemTraInput(user).Item2, "Error");
            }
        }