public static void pinjam(string idbuku) { using (perpustakaanEntities db = new perpustakaanEntities()) { var buku = db.bukus.First(i => i.id == idbuku); buku.dipinjam++; db.SaveChanges(); } }
public static void kembali(string idbuku) { using (perpustakaanEntities db = new perpustakaanEntities()) { var buku = db.bukus.First(i => i.id == idbuku); if (buku.dipinjam != 0) { buku.dipinjam--; db.SaveChanges(); } } }
public void cekPass() { using (perpustakaanEntities db = new perpustakaanEntities()) { var result = db.logins.FirstOrDefault(i => i.username == "admin"); if (result.password == "") { SHA256 sha = new SHA256Managed(); var def_hash = Convert.ToBase64String(sha.ComputeHash(System.Text.Encoding.UTF8.GetBytes("admin" + "qwertyuio@#$&^&%&pQWERTYUIOP"))); result.password = def_hash; db.SaveChanges(); } } }
private void dataGridViewBuku_CellContentClick(object sender, DataGridViewCellEventArgs e) { var grid = (DataGridView)sender; if (e.RowIndex > -1 && grid.Columns[e.ColumnIndex] is DataGridViewCheckBoxColumn) { var cb = grid.Rows[e.RowIndex].Cells[e.ColumnIndex] as DataGridViewCheckBoxCell; var idbuku = grid.Rows[e.RowIndex].Cells[1].Value.ToString(); if ((bool)cb.Value) { //Unchecked //MessageBox.Show("UnChecked :" + grid.Rows[e.RowIndex].Cells[1].Value.ToString()); cb.Value = false; using (perpustakaanEntities db = new perpustakaanEntities()) { var result = db.pinjams.FirstOrDefault(i => i.buku_id == idbuku && i.transaksi_id == idTransaksi && i.user_id == idUser); if (result != null) { db.pinjams.Remove(result); db.SaveChanges(); } } } else { //Checked //MessageBox.Show("Checked :" + grid.Rows[e.RowIndex].Cells[1].Value.ToString()); cb.Value = true; using (perpustakaanEntities db = new perpustakaanEntities()) { pinjam _pinjam = new pinjam() { transaksi_id = idTransaksi, user_id = idUser, buku_id = idbuku }; db.pinjams.Add(_pinjam); db.SaveChanges(); } } } }