Example #1
0
        private void ReturnBookButton_Click(object sender, EventArgs e)
        {
            string id;

            try
            {
                id = CopyListView.SelectedItems[0].SubItems[0].Text;
            }
            catch (ArgumentOutOfRangeException ex)
            {
                MessageManager.ShowMessageBox("Please select a book ID", "Error");
                return;
            }

            string[] columns    = { "Reader", "Borrowed" };
            string[] values     = { "NULL", "NULL" };
            string[] conditions = { $"{userId} = Reader", $"{id} = ID" };
            database.UpdateTable(ControllerDB.Table.Copy, columns, values, conditions);

            PopulateTable();
        }
        private void CheckoutButton_Click(object sender, EventArgs e)
        {
            try
            {
                string isbn = CopyListView.SelectedItems[0].SubItems[0].Text;
                if (CopyListView.SelectedItems[0].SubItems[3].Text == "0")
                {
                    MessageManager.ShowMessageBox("There are no copies left", "Error");
                    return;
                }

                string[] columns    = { "Reader", "Borrowed" };
                string[] values     = { String.Format("{0:D7}", previousWindow.userId), "GETDATE()" };
                string[] conditions = { ("ID in (SELECT TOP 1 id from db_owner.Copy " +
                                         $"WHERE READER IS NULL AND ISBN = {isbn} ORDER BY NEWID())") };
                database.UpdateTable(ControllerDB.Table.Copy, columns, values, conditions);

                this.Hide();
            }
            catch (System.ArgumentOutOfRangeException ex)
            {
                MessageManager.ShowMessageBox("Please select a book ISBN", "Error");
            }
        }