Example #1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            SinhVienDAO dao  = new SinhVienDAO();
            SinhVien    info = InitSinhVien();

            if (isAdd_)
            {
                if (dao.Add(info))
                {
                    MessageBox.Show("Thêm thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    result_ = true;
                    this.Close();
                }
                else
                {
                    MessageBox.Show("Thêm thất bại!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                if (dao.Edit(info))
                {
                    MessageBox.Show("Sửa thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    result_ = true;
                    this.Close();
                }
                else
                {
                    MessageBox.Show("Sửa thất bại!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Example #2
0
        public void TestXoaSinhV()
        {
            using (MyDbContext db = new MyDbContext())
            {
                SinhVien sv = new SinhVien();
                sv.MaSinhVien  = Helper.getMSSV("CN");
                sv.TenSinhVien = "test";
                sv.NgaySinh    = DateTime.Parse("12/31/1997");
                sv.GioiTinh    = false;
                sv.TruongTHPT  = "test";
                sv.MaNganh     = "CN";
                sv.DiemChuan   = db.Nganh.Find("CN").DiemChuan;
                sv.DiemThi     = db.Nganh.Find("CN").DiemChuan + 1;

                SinhVienDAO dao = new SinhVienDAO();
                Assert.AreEqual(dao.Add(sv), true);
            }
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            SinhVienDAO dao = new SinhVienDAO();

            SinhVien sinhVien = CreateSinhVien();

            if (isAdd_)
            {
                if (dao.Add(sinhVien))
                {
                    MessageBox.Show("Thêm thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);

                    result_ = true;
                }
                else
                {
                    MessageBox.Show("Thêm thất bại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                if (dao.Edit(sinhVien))
                {
                    MessageBox.Show("Cập nhật thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);

                    result_ = true;
                }
                else
                {
                    MessageBox.Show("Cập nhật thất bại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }

            if (result_)
            {
                this.Close();
            }
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            double   diemThi;
            DateTime ngaySinh = DateTime.Parse(txtNgaySinh.ToString());
            int      tuoi     = DateTime.Now.Year - ngaySinh.Year;

            db = new MyDbContext();

            if (String.IsNullOrEmpty(txtHoTen.Text) || String.IsNullOrEmpty(txtTHPT.Text) || String.IsNullOrEmpty(txtDiemThi.Text))
            {
                MessageBox.Show("Vui lòng điền đầy đủ thông tin", "Lỗi", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            else if (tuoi < 19 || tuoi > 30)
            {
                MessageBox.Show("Tuổi không nhỏ hơn 19", "Lỗi", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            else if (double.TryParse(txtDiemThi.Text, out diemThi) == false)
            {
                MessageBox.Show("Vui lòng đúng điểm thi", "Lỗi", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            else if (double.Parse(txtDiemThi.Text) < double.Parse(txtDiemChuan.Text))
            {
                MessageBox.Show("Điểm thi không thể bé hơn điểm chuẩn", "Lỗi", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            else
            {
                if (db.SinhVien.FirstOrDefault(x => x.TenSinhVien == txtHoTen.Text) != null)
                {
                    if (MessageBox.Show("Tên sinh viên đã tồn tại. Bạn có chắc muốn thêm?", "Thông báo", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
                    {
                        try
                        {
                            SinhVienDAO dao = new SinhVienDAO();
                            SinhVien    sv  = new SinhVien();
                            sv.MaSinhVien  = Helper.getMSSV(txtNganh.SelectedValue.ToString());
                            sv.TenSinhVien = txtHoTen.Text;
                            sv.NgaySinh    = DateTime.Parse(txtNgaySinh.Text);
                            if (txtNam.IsChecked == true)
                            {
                                sv.GioiTinh = false;
                            }
                            else
                            {
                                sv.GioiTinh = false;
                            }
                            sv.TruongTHPT = txtTHPT.Text;
                            sv.MaNganh    = txtNganh.SelectedValue.ToString();
                            sv.DiemChuan  = double.Parse(txtDiemChuan.Text);
                            sv.DiemThi    = double.Parse(txtDiemThi.Text);
                            if (dao.Add(sv))
                            {
                                MessageBox.Show("Thêm thành công", "Thông báo", MessageBoxButton.OK, MessageBoxImage.Information);
                                this.Close();
                            }
                        }
                        catch (Exception ex) { }
                    }
                }
                else
                {
                    try
                    {
                        SinhVienDAO dao = new SinhVienDAO();
                        SinhVien    sv  = new SinhVien();
                        sv.MaSinhVien  = Model.DAO.Helper.getMSSV(txtNganh.SelectedValue.ToString());
                        sv.TenSinhVien = txtHoTen.Text;
                        sv.NgaySinh    = DateTime.Parse(txtNgaySinh.Text);
                        if (txtNam.IsChecked == true)
                        {
                            sv.GioiTinh = false;
                        }
                        else
                        {
                            sv.GioiTinh = true;
                        }
                        sv.TruongTHPT = txtTHPT.Text;
                        sv.MaNganh    = txtNganh.SelectedValue.ToString();
                        sv.DiemChuan  = double.Parse(txtDiemChuan.Text);
                        sv.DiemThi    = double.Parse(txtDiemThi.Text);
                        if (dao.Add(sv))
                        {
                            MessageBox.Show("Thêm thành công", "Thông báo", MessageBoxButton.OK, MessageBoxImage.Information);
                            this.Close();
                        }
                    }
                    catch (Exception ex) { }
                }
            }
        }