Пример #1
0
 private void LoadGridView()
 {
     using (var db = new ThuVien())
     {
         gridControl.DataSource = db.PhieuMuon.Select(x => new { maphieumuon = x.maphieumuon, nguoimuon = x.DocGia.hoten, ngaymuon = x.ngaymuon, soluong = x.Sach.Count }).ToList();
     }
 }
Пример #2
0
 private void UpdateGridView()
 {
     using (var db = new ThuVien())
     {
         gridControl.DataSource = db.TacGia.ToList();
     }
 }
Пример #3
0
 private void LoadGrid()
 {
     using (var db = new ThuVien())
     {
         gridControl1.DataSource = db.Sach.Select(s => new { masach = s.masach, tensach = s.tensach, gioithieu = s.gioithieu, theloai = s.TheLoai.tentheloai, tacgia = s.TacGia.tentacgia }).ToList();
     }
 }
Пример #4
0
 private void FormPhieuMuon_Load(object sender, EventArgs e)
 {
     LoadGridView();
     using (var db = new ThuVien())
     {
         luDocGia.Properties.DataSource = db.DocGia.Select(dg => new { ID = dg.madocgia, Name = dg.hoten }).ToList();
     }
 }
Пример #5
0
 private void btnThem_Click(object sender, EventArgs e)
 {
     using (var db = new ThuVien())
     {
         db.Sach.Add(Current);
         db.SaveChanges();
     }
     LoadGrid();
 }
Пример #6
0
 public FormMenu(int userID)
 {
     InitializeComponent();
     this.userID = userID;
     using (var db = new ThuVien())
     {
         statusLabel.Caption = "Xin chào, " + db.User.First(u => u.id == userID).hoten;
     }
 }
Пример #7
0
 private void simpleButton1_Click(object sender, EventArgs e)
 {
     using (var db = new ThuVien())
     {
         db.DocGia.Add(new DocGia {
             madocgia = txtID.Text, hoten = txtName.Text, diachi = txtAddr.Text, sodienthoai = txtSDT.Text
         });
         db.SaveChanges();
     }
     UpdateGridView();
 }
Пример #8
0
 private void barButtonItem1_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
 {
     // Them
     using (var db = new ThuVien()) {
         db.PhieuMuon.Add(new PhieuMuon {
             maphieumuon = txtMaPhieu.Text, nguoimuon = luDocGia.EditValue as string, ngaymuon = (DateTime)calendar.EditValue
         });
         db.SaveChanges();
     }
     LoadGridView();
 }
Пример #9
0
        private void Init()
        {
            LoadGrid();

            // Load combo boxes
            using (var db = new ThuVien())
            {
                ApplyComboBox(cbTacGia, db.TacGia.ToList(), "tentacgia", "matacgia");
                ApplyComboBox(cbTheLoai, db.TheLoai.ToList(), "tentheloai", "matheloai");
            }
        }
Пример #10
0
 private void simpleButton1_Click(object sender, EventArgs e)
 {
     using (var db = new ThuVien())
     {
         db.TheLoai.Add(new TheLoai {
             matheloai = txtID.Text, tentheloai = txtName.Text
         });
         db.SaveChanges();
     }
     UpdateGridView();
 }
Пример #11
0
 public void LoadData()
 {
     using (var db = new ThuVien())
     {
         var phieu = db.PhieuMuon.First(pm => pm.maphieumuon == id);
         var list  = phieu.Sach.ToList();
         var hashs = new HashSet <int>(list.Select(x => x.masach).ToList());
         listMuon.DataSource = list.Select(s => new { ID = s.masach, Name = s.tensach }).ToList();
         listKho.DataSource  = db.Sach.Where(s => !hashs.Contains(s.masach)).Select(s => new { ID = s.masach, Name = s.tensach }).ToList();
     }
 }
Пример #12
0
 private void gridView_DoubleClick(object sender, EventArgs e)
 {
     if (gridView1.GetFocusedRow() != null)
     {
         using (var db = new ThuVien())
         {
             var id = (int)gridView1.GetFocusedRowCellValue("masach");
             Current = db.Sach.First(s => s.masach == id);
         }
     }
 }
Пример #13
0
 private void simpleButton1_Click(object sender, EventArgs e)
 {
     using (var db = new ThuVien())
     {
         db.TacGia.Add(new TacGia {
             matacgia = txtID.Text, tentacgia = txtName.Text, gioithieu = txtGioiThieu.Text
         });
         db.SaveChanges();
     }
     UpdateGridView();
 }
Пример #14
0
 private void btnXoa_Click(object sender, EventArgs e)
 {
     if (gridView1.GetFocusedRow() != null)
     {
         using (var db = new ThuVien())
         {
             var id = (int)gridView1.GetFocusedRowCellValue("masach");
             db.Sach.Remove(db.Sach.First(s => s.masach == id));
             db.SaveChanges();
         }
         LoadGrid();
     }
 }
Пример #15
0
        private void simpleButton1_Click(object sender, EventArgs e)
        {
            if (listMuon.SelectedValue == null)
            {
                return;
            }
            var selected = (int)listMuon.SelectedValue;

            using (var db = new ThuVien())
            {
                var phieu = db.PhieuMuon.First(pm => pm.maphieumuon == id);
                phieu.Sach.Remove(db.Sach.First(s => s.masach == selected));
                db.SaveChanges();
            }
            LoadData();
        }
Пример #16
0
 private void btnSua_Click(object sender, EventArgs e)
 {
     if (gridView1.GetFocusedRow() != null)
     {
         using (var db = new ThuVien())
         {
             var id = (int)gridView1.GetFocusedRowCellValue("masach");
             var s  = Current;
             s.masach = id;
             db.Sach.Attach(s);
             db.Entry(s).State = System.Data.Entity.EntityState.Modified;
             db.SaveChanges();
         }
         LoadGrid();
     }
 }
Пример #17
0
        private void simpleButton3_Click(object sender, EventArgs e)
        {
            GridView gridView = gridControl.MainView as GridView;

            if (gridView.GetFocusedRow() == null)
            {
                return;
            }
            string id = (gridView.GetFocusedRow() as TacGia).matacgia;

            using (var db = new ThuVien())
            {
                db.TacGia.Remove(db.TacGia.First(x => x.matacgia == id));
                db.SaveChanges();
            }
            UpdateGridView();
        }
Пример #18
0
 private void btnLogin_Click(object sender, EventArgs e)
 {
     using (var db = new ThuVien())
     {
         if (!db.User.Any(u => u.username == txtUsername.Text && u.password == txtPassword.Text))
         {
             MessageBox.Show("Đăng nhập không thành công !", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
         }
         else
         {
             var user = db.User.First(u => u.username == txtUsername.Text && u.password == txtPassword.Text);
             Hide();
             MessageBox.Show(String.Format("Đăng nhập thành công!\nXin chào {0}", user.hoten), "Thành công", MessageBoxButtons.OK, MessageBoxIcon.Information);
             (new FormMenu(user.id)).Show();
         }
     }
 }
Пример #19
0
        private void barButtonItem3_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            // Xoa
            var gridview = (GridView)gridControl.MainView;
            var id       = gridview.GetFocusedRowCellValue("maphieumuon") as string;

            if (id == null)
            {
                return;
            }
            using (var db = new ThuVien())
            {
                var phieumuon = db.PhieuMuon.First(pm => pm.maphieumuon == id);
                db.PhieuMuon.Remove(phieumuon);
                db.SaveChanges();
            }
            LoadGridView();
        }
Пример #20
0
        private void simpleButton2_Click(object sender, EventArgs e)
        {
            GridView gridView = gridControl.MainView as GridView;

            if (gridView.GetFocusedRow() == null)
            {
                return;
            }
            string id = (gridView.GetFocusedRow() as TheLoai).matheloai;

            using (var db = new ThuVien())
            {
                var tl = db.TheLoai.First(x => x.matheloai == id);
                tl.tentheloai = txtName.Text;
                db.SaveChanges();
            }
            UpdateGridView();
        }
Пример #21
0
        private void simpleButton2_Click(object sender, EventArgs e)
        {
            GridView gridView = gridControl.MainView as GridView;

            if (gridView.GetFocusedRow() == null)
            {
                return;
            }
            string id = (gridView.GetFocusedRow() as TacGia).matacgia;

            using (var db = new ThuVien())
            {
                var tg = db.TacGia.First(x => x.matacgia == id);
                tg.tentacgia = txtName.Text;
                tg.gioithieu = txtGioiThieu.Text;
                db.SaveChanges();
            }
            UpdateGridView();
        }
Пример #22
0
        private void barButtonItem2_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            // Cap nhat
            var gridview = (GridView)gridControl.MainView;
            var id       = gridview.GetFocusedRowCellValue("maphieumuon") as string;

            if (id == null)
            {
                return;
            }

            using (var db = new ThuVien())
            {
                var phieumuon = db.PhieuMuon.First(pm => pm.maphieumuon == id);
                phieumuon.ngaymuon  = (DateTime)calendar.EditValue;
                phieumuon.nguoimuon = (string)luDocGia.EditValue;
                db.SaveChanges();
            }
            LoadGridView();
        }
Пример #23
0
        private void simpleButton2_Click(object sender, EventArgs e)
        {
            GridView gridView = gridControl.MainView as GridView;

            if (gridView.GetFocusedRow() == null)
            {
                return;
            }
            string id = (gridView.GetFocusedRow() as DocGia).madocgia;

            using (var db = new ThuVien())
            {
                var dg = db.DocGia.First(x => x.madocgia == id);
                dg.hoten       = txtName.Text;
                dg.sodienthoai = txtSDT.Text;
                dg.diachi      = txtAddr.Text;
                db.SaveChanges();
            }
            UpdateGridView();
        }
Пример #24
0
        private void simpleButton1_Click(object sender, EventArgs e)
        {
            string s1 = txt1.EditValue as string;
            string s2 = txt1.EditValue as string;

            if (!s1.Equals(s2))
            {
                XtraMessageBox.Show(this, "Mật khẩu nhập lại không chính xác!", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }
            else if (s1.Length < 6)
            {
                XtraMessageBox.Show(this, "Mật khẩu tối thiểu 6 ký tự!", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            using (var db = new ThuVien())
            {
                db.User.First(u => u.id == userID).password = s1;
                db.SaveChanges();
                XtraMessageBox.Show(this, "Đổi mật khẩu thành công", "Succes", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }