Beispiel #1
0
        public Error UpdateItemStatus(ItemViewModel item, LendingTransaction transaction)
        {
            DebugWrite("PeopleService.UpdateItemStatus(...)");

            Error error = Error.None;

            if (null != item)
            {
                if (null == transaction)
                {
                    item.Status = string.Empty;
                }
                //else if (!transaction.ReturnDate.HasValue && transaction.ExpectedDate.HasValue && DateTime.Now > transaction.ExpectedDate.Value)
                //    item.Status = "late";
                else if (!transaction.ReturnDate.HasValue)
                {
                    item.Status = "out";
                }
                else
                {
                    item.Status = "in";
                }
            }

            return(error);
        }
Beispiel #2
0
        public Error UpdatePersonStatus(PersonViewModel person, LendingTransaction transaction)
        {
            DebugWrite("PeopleService.UpdatePersonStatus(...)");

            Error error = Error.None;

            if (null != person)
            {
                if (null != transaction)
                {
                    if (!transaction.ReturnDate.HasValue)
                    {
                        person.BorrowedItemsCount += 1;
                    }
                    else
                    {
                        person.BorrowedItemsCount = person.BorrowedItemsCount.HasValue ? (int?)(person.BorrowedItemsCount.Value - 1) : null;
                    }

                    //if (!transaction.ReturnDate.HasValue && transaction.ExpectedDate.HasValue && DateTime.Now > transaction.ExpectedDate.Value)
                    //    person.IsLate = true;
                }
            }

            return(error);
        }
Beispiel #3
0
        private void btnDeleteItem_Click(object sender, EventArgs e)
        {
            DebugWriteLine("Deleting item.");

            ItemViewModel selectedItem = dataGridLibrary.GetSelectedItem();

            if (null != selectedItem)
            {
                if (MessageBox.Show(string.Format("You are about to delete {0}. All transactions pertaining to this item will also be deleted.  Are you sure?", selectedItem.Title), "Confirm delete", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    LendingTransaction trans = ServiceTransactions.GetItemCurrentTransaction(Transactions, selectedItem.Id);

                    if (null != trans)
                    {
                        trans.ReturnDate = DateTime.Now;
                        ServicePeople.UpdatePersonStatus(ServicePeople.GetPeoplePerson(People, trans.Borrower), trans);
                    }

                    Transactions.LendingTransactions.RemoveAll(x => x.Item == selectedItem.Id);
                    Transactions.IsModified = true;
                    Library.Items.Remove(selectedItem);
                    Library.IsModified = true;
                    DataBindLibrary();
                    DebugWriteLine(string.Format("{0} deleted.", selectedItem.Title));
                }
                else
                {
                    DebugWriteLine(string.Format("{0} NOT deleted.", selectedItem.Title));
                }
            }
        }
Beispiel #4
0
        protected void ShowInfo(LendingTransaction transaction)
        {
            TransactionInfo transInfo = new TransactionInfo(transaction, People);

            panelBorrow.Controls.Add(transInfo);
            panelBorrow.Enabled = false;
            dtpReturnDate.Value = transaction.ReturnDate.HasValue ? transaction.ReturnDate.Value : DateTime.Now;
        }
Beispiel #5
0
        protected override void btnSave_Click(object sender, EventArgs e)
        {
            LendingTransaction transaction = (LendingTransaction)Model;

            transaction.ReturnDate = dtpReturnDate.Value;

            base.btnSave_Click(sender, e);
        }
Beispiel #6
0
        protected override void btnSave_Click(object sender, EventArgs e)
        {
            LendingTransaction transaction = (LendingTransaction)Model;

            if (null != _transInfo)
            {
                transaction = _transInfo.GetTransaction();
            }

            base.btnSave_Click(sender, e);
        }
Beispiel #7
0
        public TransactionInfo(LendingTransaction transaction, People people) : base()
        {
            InitializeComponent();
            People       = people;
            _transaction = transaction;

            if (null == _transaction)
            {
                _transaction = new LendingTransaction();
            }

            ShowInfo(_transaction);
        }
Beispiel #8
0
        public LendingTransaction GetItemCurrentTransaction(Transactions transactions, string itemId)
        {
            DebugWrite("TransactionService.GetItemCurrentTransaction(...)");

            LendingTransaction transaction = null;

            if (null != transactions && !string.IsNullOrWhiteSpace(itemId))
            {
                transaction = (from trans in GetItemTransactions(transactions, itemId)
                               where !trans.ReturnDate.HasValue
                               select trans).FirstOrDefault();
            }

            return(transaction);
        }
Beispiel #9
0
        public Error UpdateLendingTransactions(Transactions transactions, LendingTransaction lendingTransaction)
        {
            Error error = Error.None;

            DebugWrite("TransactionService.UpdateLendingTransactions(...)");

            if (null == transactions || null == lendingTransaction)
            {
                error = Error.EmptyArgument;
            }
            else if (lendingTransaction.IsModified /*&&
                                                    * !string.IsNullOrWhiteSpace(lendingTransaction.Item) &&
                                                    * !string.IsNullOrWhiteSpace(lendingTransaction.Borrower) &&
                                                    * lendingTransaction.LendingDate.HasValue*/)
            {
                if (string.IsNullOrWhiteSpace(lendingTransaction.Id))
                {
                    lendingTransaction.Id = Guid.NewGuid().ToString(); //string.Format("{0}_{1}_{2}", lendingTransaction.Item.Trim().ToLowerInvariant(), lendingTransaction.Borrower.Trim().ToLowerInvariant(), lendingTransaction.LendingDate.Value.ToString("yyyy-MM-dd")).Replace(' ', '_');
                    transactions.LendingTransactions.Add(lendingTransaction);

                    //if (0 < (from lendingTransactions in transactions.LendingTransactions where lendingTransactions.Id == lendingTransaction.Id select lendingTransactions.Id).Count())
                    //    error = Error.CollectionItemAlreadyExists;
                    //else
                    //    transactions.LendingTransactions.Add(lendingTransaction);
                }
                else
                {
                    foreach (LendingTransaction currentTransaction in transactions.LendingTransactions)
                    {
                        if (lendingTransaction.Id == currentTransaction.Id)
                        {
                            currentTransaction.Borrower    = lendingTransaction.Borrower;
                            currentTransaction.Item        = lendingTransaction.Item;
                            currentTransaction.LendingDate = lendingTransaction.LendingDate;
                            currentTransaction.ReturnDate  = lendingTransaction.ReturnDate;
                            currentTransaction.Note        = lendingTransaction.Note;
                            currentTransaction.IsModified  = lendingTransaction.IsModified;
                        }
                    }
                }
            }

            return(error);
        }
Beispiel #10
0
        public EditTransaction(LendingTransaction transaction, Transactions transactions, People people, Library library)
            : base()
        {
            InitializeComponent();
            btnSave.Click   += new System.EventHandler(btnSave_Click);
            btnCancel.Click += new System.EventHandler(btnCancel_Click);
            Transactions     = transactions;
            People           = people;
            Library          = library;

            if (null == transaction)
            {
                Model = new LendingTransaction();
            }
            else
            {
                Model = transaction;
            }

            ShowInfo((LendingTransaction)Model);
        }
Beispiel #11
0
        protected void ShowInfo(LendingTransaction transaction)
        {
            txtNote.Text            = !string.IsNullOrWhiteSpace(transaction.Note) ? transaction.Note : string.Empty;
            transaction.LendingDate = transaction.LendingDate.HasValue ? transaction.LendingDate.Value : DateTime.Now;
            dtpDate.Value           = transaction.LendingDate.Value;

            if (null != People)
            {
                cbxPersons.DataSource    = People.Persons;
                cbxPersons.DisplayMember = "Name";
                cbxPersons.ValueMember   = "Id";

                if (!string.IsNullOrWhiteSpace(transaction.Borrower))
                {
                    cbxPersons.SelectedValue = transaction.Borrower;
                }
                else
                {
                    cbxPersons.SelectedIndex = 0;
                }
            }
        }
Beispiel #12
0
 protected void ShowInfo(LendingTransaction transaction)
 {
     _transInfo = new TransactionInfo(transaction, People);
     panelBorrow.Controls.Add(_transInfo);
 }