Example #1
0
        public void EditLease()
        {
            if (this.leaseView.SelectedItems.Count > 0)
            {
                Lease l = Lease.FromListView(this.leaseView.SelectedItems[0],
                                             db_handler);

                Forms.CreateLease dlg = new CreateLease(db_handler);
                dlg.Text = "Edit Lease";

                dlg.bookid.Text      = l.BookId.ToString();
                dlg.quantity.Value   = l.Quantity;
                dlg.userid.Text      = l.UserId.ToString();
                dlg.from.Value       = l.LeaseDate;
                dlg.to.Value         = l.ReturnDate;
                dlg.remarks.Text     = l.Remarks;
                dlg.returned.Checked = l.Returned;

                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    l.BookId     = Convert.ToInt32(dlg.bookid.Text);
                    l.Quantity   = (int)dlg.quantity.Value;
                    l.UserId     = Convert.ToInt32(dlg.userid.Text);
                    l.LeaseDate  = dlg.from.Value;
                    l.ReturnDate = dlg.to.Value;
                    l.Remarks    = dlg.remarks.Text;
                    l.Returned   = dlg.returned.Checked;


                    db_handler.UpdateLease(l);
                    PopulateLeaseView();
                    PopulateBookView();
                }
            }
        }
Example #2
0
        public void AddLease()
        {
            if (this.bookView.SelectedItems.Count > 0)
            {
                Book b = Book.FromListView(this.bookView.SelectedItems[0]);
                if (b.Borrowed < b.Quantity)
                {
                    Forms.CreateLease dlg = new CreateLease(db_handler);
                    dlg.bookid.Text = b.Id.ToString();

                    int diff = b.Quantity - b.Borrowed;
                    dlg.quantity.Maximum = diff;

                    if (dlg.ShowDialog() == DialogResult.OK)
                    {
                        int bookId = Convert.ToInt32(dlg.bookid.Text);
                        int userId = Convert.ToInt32(dlg.userid.Text);
                        int quant  = (int)dlg.quantity.Value;

                        bool ret = dlg.returned.Checked;

                        Lease l = new Lease(-1, bookId, userId, quant, dlg.from.Value,
                                            dlg.to.Value, ret, dlg.remarks.Text,
                                            "", "", "", "");

                        if (db_handler.InsertLease(l))
                        {
                            MessageBox.Show("Lease successfully creaed.", "Success",
                                            MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        else
                        {
                            MessageBox.Show("An error occured.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }

                        PopulateBookView();
                        PopulateLeaseView();
                    }
                }
                else
                {
                    MessageBox.Show("All books have already been leased.", "Error",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }