private void button1_Click(object sender, EventArgs e) { List <String> bnums = new List <String>(); Boolean copies_flag = false, ownership_flag = false; for (int i = 0; i < dt.Rows.Count; i++) { if (Convert.ToBoolean(dataGridView1.Rows[i].Cells[0].Value) == true) { if (Convert.ToInt32(dt.Rows[i].ItemArray[3].ToString()) > 0) { foreach (Book value in user.BOOKS) { if (value.BNUM == Convert.ToInt32(dt.Rows[i].ItemArray[0])) { ownership_flag = true; } } bnums.Add(dt.Rows[i].ItemArray[0].ToString()); } else { copies_flag = true; } } } if (copies_flag == true) { MessageBox.Show("One or more of the selected books is not in stock!", "Message"); return; } if (ownership_flag == true) { MessageBox.Show("You already have one or more of the selected books!", "Message"); return; } int num; dataGridView1.Columns[4].ReadOnly = false; for (int i = 0; i < dt.Rows.Count; i++) { if (bnums.Contains(dt.Rows[i].ItemArray[0].ToString())) { num = Convert.ToInt32(dt.Rows[i].ItemArray[3].ToString()) - 1; dataGridView1.Rows[i].Cells[4].Value = num; dt.Rows[i].ItemArray[3] = num; } } dataGridView1.Columns[4].ReadOnly = true; dt = db.UpdateTable(db.TLIBRARY, "Book_Number, Book_Count", "Department = 0 OR Department = " + (int)user.DEPT, dt); foreach (Book value in user.BOOKS) { bnums.Add(value.BNUM.ToString()); } String book_code = user.encrypt_books(bnums); db.SimpleUpdate(db.TSTUDENT, "Books = '" + book_code + "'", "id = " + user.ID); user.decrypt_books(book_code); MessageBox.Show("You have successfully taken all the selected books!", "Message"); foreach (DataGridViewRow value in dataGridView1.Rows) { DataGridViewCheckBoxCell chk = (DataGridViewCheckBoxCell)value.Cells[0]; chk.Value = false; } }