/// <summary>
 /// Used to instantiate a new transaction
 /// </summary>
 /// <param name="invoiceID">The invoice the transaction belongs to</param>
 /// <param name="item">The item being sold</param>
 /// <param name="quantity">How many of the item is being sold</param>
 public DBTransaction(int invoiceID, DBItem item, int quantity)
 {
     this.invoiceID   = invoiceID;
     this.ItemID      = item.GetItemID();
     this.Desc        = item.GetDescription();
     this.ItemType    = item.GetItemType();
     this.Edition     = item.GetEdition();
     this.Condition   = item.GetConditionType();
     this.conditionID = item.GetConditionID();
     this.Price       = item.GetPrice();
     this.Quantity    = quantity;
     this.itemStock   = item.GetQuantity();
 }
        public void ShowItem()
        {
            int itemTypeID = DBItem.GetDBItemTypeOfId((int)nudItemID.Value);

            cbxItemType.SelectedValue = itemTypeID;
            DBItem tempItem = null;

            switch (itemTypeID)
            {
            case 1:
                tempItem = DBBook.GetBookOfId((int)nudItemID.Value);
                DBBook tempBook = (tempItem as DBBook);
                this.txtTitle.Text          = tempBook.Title;
                this.txtAuthorFirst.Text    = tempBook.GetAuthorFirst();
                this.txtAuthorLast.Text     = tempBook.GetAuthorLast();
                this.cbxGenre.SelectedValue = tempBook.GetGenreID();
                this.txtPublisher.Text      = tempBook.Publisher;
                this.dtpPublishDate.Value   = tempBook.PublishDate;
                break;

            case 2:
                tempItem = DBMap.GetMapOfId((int)nudItemID.Value);
                DBMap tempMap = (tempItem as DBMap);
                this.txtPublisher.Text = tempMap.Publisher;
                this.txtLocation.Text  = tempMap.Location;
                this.nudYear.Value     = tempMap.Year;
                break;

            case 3:
                tempItem = DBPeriodical.GetPeriodicalOfId((int)nudItemID.Value);
                DBPeriodical tempPeriodical = (tempItem as DBPeriodical);
                this.txtTitle.Text          = tempPeriodical.Title;
                this.cbxGenre.SelectedValue = tempPeriodical.GetGenreID();
                this.txtCompanyName.Text    = tempPeriodical.CompanyName;
                this.dtpPublishDate.Value   = tempPeriodical.PublishDate;
                break;
            }

            if (tempItem != null)
            {
                this.tkbCondition.Value = tempItem.GetConditionID();
                this.nudQuantity.Value  = tempItem.GetQuantity();

                try
                {
                    DBControlHelper.PopulateWithControls <DBTag, CheckBox>(this.tlpTagSelection, DBTag.GetTags(), "Description", "ID", tempItem.GetTags());
                }
                catch (Exception ex)
                {
                    (this.Parent.Parent as MasterForm).SetStatus("Error! Failed to load tags: " + ex.Message);
                }

                this.nudPrice.Value = tempItem.GetRegularPrice();

                //Show the discount
                if (tempItem.HasDiscount())
                {
                    this.nudDiscountPrice.Value        = tempItem.GetDiscount().Amount;
                    this.dtpDiscountFrom.Value         = tempItem.GetDiscount().StartDate;
                    this.dtpDiscountTo.Value           = tempItem.GetDiscount().EndDate;
                    this.chkSetupDiscountTitle.Checked = true;
                }
                else
                {
                    this.nudDiscountPrice.Value = 0;
                    this.dtpDiscountFrom.ResetText();
                    this.dtpDiscountTo.ResetText();
                    this.chkSetupDiscountTitle.Checked = false;
                }
            }
        }