Пример #1
0
 private void btnLend_Click(object sender, EventArgs e)
 {
     if ((Convert.ToInt32(Program.userSekarang.fine) <= 0))
     {
         if ((Convert.ToInt32(dgvBooks.SelectedCells[5].Value) > 0))
         {
             Peminjaman lend   = new Peminjaman();
             Random     rand   = new Random();
             string     user   = Program.userSekarang.user,
                        idBuku = dgvBooks.SelectedCells[0].Value.ToString();
             bool success      = false;
             lend.lendId   = randomDigit();
             lend.username = user;
             lend.bookId   = idBuku;
             lend.addLendDate();
             lend.addDueDate();
             lend.convertToString();
             koneksiSql koneksi = new koneksiSql();
             do
             {
                 try
                 {
                     koneksi.makeLend(lend.lendId, lend.username, lend.bookId, lend.strLendDate, lend.strDueDate);
                     koneksi.updateStock(idBuku, dgvBooks.SelectedCells[5].Value.ToString(), "remove");
                     success = true;
                 }
                 catch
                 {
                     lend.lendId = randomDigit();
                 }
             } while (!success);
         }
         else
         {
             DialogNormal dialog = new DialogNormal("Notice", "The stock currently Empty", 70, 85);
             dialog.ShowDialog();
         }
     }
     else
     {
         DialogNormal dialog = new DialogNormal("Notice", "You have unpaid Fine \n Please pay your fine first!", 70, 65);
         dialog.ShowDialog();
     }
     isiDgv(txtSearch.Text);
 }