Exemplo n.º 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();
     }
 }
Exemplo n.º 2
0
 private void UpdateGridView()
 {
     using (var db = new ThuVien())
     {
         gridControl.DataSource = db.TacGia.ToList();
     }
 }
Exemplo n.º 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();
     }
 }
Exemplo n.º 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();
     }
 }
Exemplo n.º 5
0
 private void btnThem_Click(object sender, EventArgs e)
 {
     using (var db = new ThuVien())
     {
         db.Sach.Add(Current);
         db.SaveChanges();
     }
     LoadGrid();
 }
Exemplo n.º 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;
     }
 }
Exemplo n.º 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();
 }
Exemplo n.º 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();
 }
Exemplo n.º 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");
            }
        }
Exemplo n.º 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();
 }
Exemplo n.º 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();
     }
 }
Exemplo n.º 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);
         }
     }
 }
Exemplo n.º 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();
 }
Exemplo n.º 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();
     }
 }
Exemplo n.º 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();
        }
Exemplo n.º 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();
     }
 }
Exemplo n.º 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();
        }
Exemplo n.º 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();
         }
     }
 }
Exemplo n.º 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();
        }
Exemplo n.º 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();
        }
Exemplo n.º 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();
        }
Exemplo n.º 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();
        }
Exemplo n.º 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();
        }
Exemplo n.º 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);
            }
        }