private void AddHoiNghi()
        {
            if (!ValidateInput())
            {
                return;
            }

            try
            {
                using (DBQuanLiHoiNghiEntities db = new DBQuanLiHoiNghiEntities())
                {
                    int id = db.HOINGHIs.Max(hn => hn.IDHN) + 1;

                    HOINGHI HoiNghi = new HOINGHI();
                    HoiNghi.IDHN            = id;
                    HoiNghi.IDDD            = ListDiaDiem[IndexDiaDiem].IDDD;
                    HoiNghi.TENHN           = TenHoiNghi;
                    HoiNghi.MOTACHITIETHN   = NoiDungHoiNghi;
                    HoiNghi.THOIGIANBATDAU  = NgayBatDau;
                    HoiNghi.THOIGIANKETTHUC = NgayKetThuc;
                    String path = SaveImage(ImagePathHoiNghi);
                    HoiNghi.HINHANH    = path;
                    HoiNghi.MOTANGANHN = MoTa;
                    HoiNghi.SOLUONG    = int.Parse(SoLuong);

                    db.HOINGHIs.Add(HoiNghi);
                    db.SaveChanges();

                    CHITIETADMIN ChiTietAdmin = new CHITIETADMIN();
                    ChiTietAdmin.IDHN      = id;
                    ChiTietAdmin.IDUSER    = DangNhapViewModel.User.IDUSER;
                    ChiTietAdmin.LOAIADMIN = "0";
                    db.CHITIETADMINs.Add(ChiTietAdmin);
                    db.SaveChanges();

                    IsSaved = true;
                    SavedId = id;
                    MessageBox.Show("Đã thêm hội nghị.");
                }
            }
            catch
            {
                MessageBox.Show("Đã có lỗi xảy ra.");
                return;
            }
        }
Esempio n. 2
0
            private void CapQuyen()
            {
                this.IsCapQuyen = !this.IsCapQuyen;

                try
                {
                    if (this.IsCapQuyen)
                    {
                        using (DBQuanLiHoiNghiEntities db = new DBQuanLiHoiNghiEntities())
                        {
                            CHITIETADMIN chiTiet = new CHITIETADMIN();
                            chiTiet.IDHN      = IdHN;
                            chiTiet.IDUSER    = User.IDUSER;
                            chiTiet.LOAIADMIN = LoaiAdmin;
                            db.CHITIETADMINs.Add(chiTiet);
                            db.SaveChanges();
                        }
                    }
                    else
                    {
                        using (DBQuanLiHoiNghiEntities db = new DBQuanLiHoiNghiEntities())
                        {
                            CHITIETADMIN chiTiet = (from ct in db.CHITIETADMINs
                                                    where ct.IDHN == IdHN && ct.IDUSER == User.IDUSER
                                                    select ct).ToList().FirstOrDefault();

                            db.CHITIETADMINs.Remove(chiTiet);
                            db.SaveChanges();
                        }
                    }
                }
                catch
                {
                    this.IsCapQuyen = !this.IsCapQuyen;
                    MessageBox.Show("Đã có lỗi xảy ra.");
                }
            }