예제 #1
0
        public void DeleteLeases()
        {
            int count = this.leaseView.SelectedItems.Count;

            if (count > 0)
            {
                if (MessageBox.Show("Are you sure to delete " + count.ToString() + " entries?\nIt cannot be undone.",
                                    "Deleting Leases", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                {
                    List <Lease> todel = new List <Lease>();
                    foreach (ListViewItem lvi in this.leaseView.SelectedItems)
                    {
                        Lease l = Lease.FromListView(lvi, db_handler);
                        todel.Add(l);
                    }

                    if (db_handler.DeleteLeases(todel))
                    {
                        MessageBox.Show(count.ToString() + " entries deleted successfully.", "Deleting Leases",
                                        MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        MessageBox.Show("An error occured.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }

                    PopulateLeaseView();
                    PopulateBookView();
                }
            }
        }
예제 #2
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();
                }
            }
        }