Esempio n. 1
0
        private void CbxSelectedItem_SelectedValueChanged(object sender, EventArgs e)
        {
            if (this.cbxSelectedItem.SelectedItem is DBItem)
            {
                if (this.cbxSelectedItem.SelectedItem is DBBook)
                {
                    this.lblItemSearchPrompt.Text = "Search by Title:";
                    //this.txtSearch.Text = (this.cbxSelectedItem.SelectedItem as DBBook).Title;
                }
                else if (this.cbxSelectedItem.SelectedItem is DBMap)
                {
                    this.lblItemSearchPrompt.Text = "Search by Location:";
                    //this.txtSearch.Text = (this.cbxSelectedItem.SelectedItem as DBMap).Location;
                }
                else if (this.cbxSelectedItem.SelectedItem is DBPeriodical)
                {
                    this.lblItemSearchPrompt.Text = "Search by Title:";
                    //this.txtSearch.Text = (this.cbxSelectedItem.SelectedItem as DBPeriodical).Title;
                }

                DBItem tempItem = (this.cbxSelectedItem.SelectedItem as DBItem);
                this.lblCondition.Text = tempItem.GetConditionType();
                this.UpdateTotalPrice();
                this.UpdateStock();
            }
        }
Esempio n. 2
0
 private void UpdateTotalPrice()
 {
     if (this.cbxSelectedItem.SelectedItem is DBItem)
     {
         DBItem tempItem = (this.cbxSelectedItem.SelectedItem as DBItem);
         this.lblTotalPrice.Text = tempItem.GetTotalPrice((int)this.nudQuantity.Value).ToString("C");
     }
 }
Esempio n. 3
0
        /// <summary>
        /// Updates the tag ids associated with the passed item id in the database
        /// </summary>
        /// <param name="itemID">The item id to update the tags for</param>
        /// <param name="tagIds">The tag ids to associate with the item id</param>
        /// <returns>If the tags were updated successfully</returns>
        public static bool UpdateItemTags(int itemID, List <int> tagIds)
        {
            bool result = false;

            DBItem.DeleteItemTags(itemID);
            if (DBItem.InsertItemTags(itemID, tagIds))
            {
                result = true;
            }

            return(result);
        }
 /// <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();
 }
Esempio n. 5
0
 private void UpdateStock()
 {
     if (this.cbxSelectedItem.SelectedItem is DBItem)
     {
         DBItem tempItem = (this.cbxSelectedItem.SelectedItem as DBItem);
         //int stock = tempItem.GetQuantity() - Cart.Invoice.GetQuantityBeingSold(tempItem.GetItemID());
         int stock = tempItem.GetQuantity();
         if ((int)this.nudQuantity.Value > stock)
         {
             this.nudQuantity.Value = stock;
         }
         this.nudQuantity.Maximum = stock;
     }
 }
        private void BtnRemoveItem_Click(object sender, EventArgs e)
        {
            MasterForm master = (this.Parent.Parent as MasterForm);

            if (this.cbxSelectedItem.SelectedItem is DBItem)
            {
                try
                {
                    DBItem tempItem = (this.cbxSelectedItem.SelectedItem as DBItem);

                    //Attempt to deactivate
                    if (tempItem.DeactivateItem())
                    {
                        //Deactivation successful

                        master.SetStatus("Item " + tempItem.GetDescription() + " has been deactivated");

                        //Remove all related datagridview rows
                        for (var i = 0; i < this.dgvItems.Rows.Count; i++)
                        {
                            if ((int)this.dgvItems.Rows[i].Cells[0].Value == tempItem.GetItemID())
                            {
                                this.dgvItems.Rows.RemoveAt(i);
                            }
                        }
                        if (rbnBook.Checked)
                        {
                            this.books.Remove(tempItem as DBBook);
                        }
                        else if (rbnMap.Checked)
                        {
                            this.maps.Remove(tempItem as DBMap);
                        }
                        else if (rbnPeriodical.Checked)
                        {
                            this.periodicals.Remove(tempItem as DBPeriodical);
                        }
                    }
                }
                catch (Exception ex)
                {
                    master.SetStatus("Error! Deactivation failed: " + ex.Message);
                }
            }
            else
            {
                master.SetStatus("Error! You must select an item to deactivate");
            }
        }
        /// <summary>
        /// Validates a periodical using the passed parameters and returns an error message if invalid
        /// </summary>
        /// <param name="price">The price of the periodical</param>
        /// <param name="description">The title of the periodical</param>
        /// <param name="companyName">The company name of the periodical</param>
        /// <param name="publishDate">The publish date of the periodical</param>
        /// <returns>An error message if invalid</returns>
        public static string Validate(decimal price, string description, string companyName, DateTime publishDate)
        {
            string errorMessage = DBItem.Validate(price, description);

            if (String.IsNullOrEmpty(companyName))
            {
                errorMessage += "Company name cannot be empty." + Environment.NewLine;
            }
            if (publishDate > DateTime.Now)
            {
                errorMessage += "Publish date cannot be greater than the current date." + Environment.NewLine;
            }

            return(errorMessage);
        }
        /// <summary>
        /// Validates a map using the passed arguments and returns an error message if invalid
        /// </summary>
        /// <param name="price">The price to validate</param>
        /// <param name="description">The description/location of the map to validate</param>
        /// <param name="year">The year to validate</param>
        /// <param name="publisher">The publisher to validate</param>
        /// <returns>An error message if invalid</returns>
        public static string Validate(decimal price, string description, int year, string publisher)
        {
            string errorMessage = DBItem.Validate(price, description);

            if (year > DateTime.Now.Year)
            {
                errorMessage += "Year cannot be greater than the current year." + Environment.NewLine;
            }
            if (String.IsNullOrEmpty(publisher))
            {
                errorMessage += "Publisher cannot be empty." + Environment.NewLine;
            }

            return(errorMessage);
        }
        private void BtnEndDiscount_Click(object sender, EventArgs e)
        {
            MasterForm master = (this.Parent.Parent as MasterForm);

            try
            {
                if (DBItem.DeleteDiscount((int)this.nudItemID.Value))
                {
                    this.dtpDiscountFrom.ResetText();
                    this.dtpDiscountTo.ResetText();
                    this.nudDiscountPrice.ResetText();
                    master.SetStatus("Discount has ended successfully.");
                }
            }
            catch (Exception ex)
            {
                master.SetStatus("Error! Failed to end discount: " + ex.Message);
            }
        }
        private void BtnDeactivate_Click(object sender, EventArgs e)
        {
            MasterForm master = (this.Parent.Parent as MasterForm);

            try
            {
                if (DBItem.DeactivateItem((int)this.nudItemID.Value))
                {
                    master.SetStatus("Item has been deactivated.");
                    if (this.nudItemID.Value > this.nudItemID.Minimum)
                    {
                        this.nudItemID.Value--;
                    }
                }
            }
            catch (Exception ex)
            {
                master.SetStatus("Error! Deactivation failed: " + ex.Message);
            }
        }
Esempio n. 11
0
        /// <summary>
        /// Validates a book with the passed arguments and returns an error message if invalid
        /// </summary>
        /// <param name="price">The price of the book</param>
        /// <param name="description">The title/description of the book</param>
        /// <param name="authorFirst">The first name of the author of the book</param>
        /// <param name="authorLast">The last name of the author of the book</param>
        /// <param name="publisher">The publisher of the book</param>
        /// <param name="publishDate">The date the book was published</param>
        /// <returns>An error message if invalid</returns>
        public static string Validate(decimal price, string description, string authorFirst, string authorLast, string publisher, DateTime publishDate)
        {
            string errorMessage = DBItem.Validate(price, description);

            if (String.IsNullOrEmpty(authorFirst))
            {
                errorMessage += "Author first name cannot be empty." + Environment.NewLine;
            }
            if (String.IsNullOrEmpty(authorLast))
            {
                errorMessage += "Author last name cannot be empty." + Environment.NewLine;
            }
            if (String.IsNullOrEmpty(publisher))
            {
                errorMessage += "Publisher cannot be empty." + Environment.NewLine;
            }
            if (publishDate > DateTime.Now)
            {
                errorMessage += "Publish date cannot be greater than the current date." + Environment.NewLine;
            }

            return(errorMessage);
        }
Esempio n. 12
0
 /// <summary>
 /// Deactivates this item, excluding it from future select queries
 /// </summary>
 /// <returns>If it was deactivated successfully</returns>
 public bool DeactivateItem()
 {
     return(DBItem.DeactivateItem(this.itemID));
 }
Esempio n. 13
0
 /// <summary>
 /// Updates the tag ids associated with this item in the database
 /// </summary>
 /// <param name="tagIds">The tag ids to associate with this item</param>
 /// <returns>If the tags were updated successfully</returns>
 public bool UpdateItemTags(List <int> tagIds)
 {
     return(DBItem.UpdateItemTags(this.GetItemID(), tagIds));
 }
Esempio n. 14
0
 /// <summary>
 /// Gets a list of tag ids associated with this item
 /// </summary>
 /// <returns>A list of tag ids associated with this item</returns>
 public List <int> GetTags()
 {
     return(DBItem.GetTagsOfItemID(this.itemID));
 }
Esempio n. 15
0
        private void BtnAdd_Click(object sender, EventArgs e)
        {
            MasterForm master = (this.Parent.Parent as MasterForm);

            try
            {
                //Input data gathered here to improve readability and centralize any processing
                //that needs to be done before insertion
                decimal  price       = this.nudPrice.Value;
                string   publisher   = this.txtPublisher.Text.Trim();
                string   title       = this.txtTitle.Text.Trim();
                string   authorFirst = this.txtAuthorFirst.Text.Trim();
                string   authorLast  = this.txtAuthorLast.Text.Trim();
                string   location    = this.txtLocation.Text.Trim();
                string   companyName = this.txtCompanyName.Text.Trim();
                DateTime publishDate = this.dtpPublishDate.Value;
                int      year        = (int)this.nudYear.Value;
                int      genreID     = (int)this.cbxGenre.SelectedValue;
                int      conditionID = this.tkbCondition.Value;
                int      quantity    = (int)this.nudQuantity.Value;
                int      edition     = (int)this.nudEdition.Value;

                object insertedID = null;
                string status     = "";

                switch (this.cbxItemType.SelectedValue)
                {
                case 1:
                    if (String.IsNullOrEmpty(status = DBBook.Validate(price, title, authorFirst, authorLast, publisher, publishDate)))
                    {
                        insertedID = DBBook.InsertBook(title, price, edition, genreID, authorFirst, authorLast, publisher,
                                                       publishDate, conditionID, quantity);

                        if (insertedID != null)
                        {
                            status = "Book " + title + " has been added successfully";
                        }
                    }

                    break;

                case 2:
                    if (String.IsNullOrEmpty(status = DBMap.Validate(price, location, year, publisher)))
                    {
                        insertedID = DBMap.InsertMap(location, price, edition, publisher, year, conditionID, quantity);

                        if (insertedID != null)
                        {
                            status = "Map " + location + " has been added successfully";
                        }
                    }

                    break;

                case 3:
                    if (String.IsNullOrEmpty(status = DBPeriodical.Validate(price, title, companyName, publishDate)))
                    {
                        insertedID = DBPeriodical.InsertPeriodical(title, price, edition, companyName, genreID, publishDate,
                                                                   conditionID, quantity);

                        if (insertedID != null)
                        {
                            status = "Periodical " + title + " has been added successfully";
                        }
                    }

                    break;
                }

                if (insertedID != null)
                {
                    List <int> tagValues = DBControlHelper.GetValuesFromCheckedControls(this.tlpTagSelection);
                    if (tagValues.Count > 0 && DBItem.InsertItemTags((int)insertedID, tagValues))
                    {
                        status += Environment.NewLine + "Item tags added.";
                    }
                }

                master.SetStatus(status);
            }
            catch (Exception ex)
            {
                master.SetStatus("Error! Failed to add item: " + ex.Message);
            }
        }
        private void BtnUpdate_Click(object sender, EventArgs e)
        {
            MasterForm master = (this.Parent.Parent as MasterForm);

            try
            {
                //Input data gathered here to improve readability and centralize any processing
                //that needs to be done before insertion
                int      itemID        = (int)this.nudItemID.Value;
                decimal  price         = this.nudPrice.Value;
                string   publisher     = this.txtPublisher.Text.Trim();
                string   title         = this.txtTitle.Text.Trim();
                string   authorFirst   = this.txtAuthorFirst.Text.Trim();
                string   authorLast    = this.txtAuthorLast.Text.Trim();
                string   location      = this.txtLocation.Text.Trim();
                string   companyName   = this.txtCompanyName.Text.Trim();
                DateTime publishDate   = this.dtpPublishDate.Value;
                int      year          = (int)this.nudYear.Value;
                int      genreID       = (int)this.cbxGenre.SelectedValue;
                int      conditionID   = this.tkbCondition.Value;
                int      quantity      = (int)this.nudQuantity.Value;
                int      edition       = (int)this.nudEdition.Value;
                decimal  discountPrice = this.nudDiscountPrice.Value;
                DateTime discountFrom  = this.dtpDiscountFrom.Value;
                DateTime discountTo    = this.dtpDiscountTo.Value;

                string status = "";

                switch (cbxItemType.SelectedValue)
                {
                case 1:
                    if (String.IsNullOrEmpty(status = DBBook.Validate(price, title, authorFirst, authorLast, publisher, publishDate)))
                    {
                        if (DBBook.UpdateBook(itemID, title, price, edition, genreID, authorFirst, authorLast, publisher, publishDate,
                                              conditionID, quantity))
                        {
                            status = "Book " + title + " has been saved." + Environment.NewLine;
                        }
                    }
                    break;

                case 2:
                    if (String.IsNullOrEmpty(status = DBMap.Validate(price, location, year, publisher)))
                    {
                        if (DBMap.UpdateMap(itemID, location, price, edition, publisher, year, conditionID, quantity))
                        {
                            status = "Map " + location + " has been saved." + Environment.NewLine;
                        }
                    }
                    break;

                case 3:
                    if (String.IsNullOrEmpty(status = DBPeriodical.Validate(price, title, companyName, publishDate)))
                    {
                        if (DBPeriodical.UpdatePeriodical(itemID, title, price, edition, companyName, genreID, publishDate, conditionID,
                                                          quantity))
                        {
                            status = "Periodical " + title + " has been saved." + Environment.NewLine;
                        }
                    }
                    break;
                }

                if (quantity < Cart.Invoice.GetQuantityBeingSold(itemID))
                {
                    status += "Quantity cannot be less than the amount of the item currently being sold" + Environment.NewLine;
                }
                else
                {
                    for (var i = 0; i < Cart.Invoice.Transactions.Count; i++)
                    {
                        if (Cart.Invoice.Transactions[i].ItemID == itemID)
                        {
                            Cart.Invoice.Transactions[i].SetItemStock(quantity);
                        }
                    }
                }

                if (DBItem.UpdateItemTags(itemID, DBControlHelper.GetValuesFromCheckedControls(this.tlpTagSelection)))
                {
                    status += "Item tags have been saved." + Environment.NewLine;
                }

                if (this.chkSetupDiscountTitle.Checked)
                {
                    string discountError = DBItemDiscount.Validate(discountPrice, discountFrom, discountTo);
                    if (String.IsNullOrEmpty(discountError))
                    {
                        if (DBItem.SaveDiscount(itemID, discountPrice, discountFrom, discountTo))
                        {
                            status += "Discount has been saved." + Environment.NewLine;
                        }
                    }
                    else
                    {
                        status += discountError;
                    }
                }

                master.SetStatus(status);
            }
            catch (Exception ex)
            {
                master.SetStatus("Error! Update failed: " + ex.Message);
            }
        }
        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;
                }
            }
        }