Exemple #1
0
 /// <summary>
 /// Used to instantiate a new item with the passed arguments
 /// </summary>
 /// <param name="itemID">The unique identifier for this item</param>
 /// <param name="itemType">The type of item</param>
 /// <param name="description">The item description</param>
 /// <param name="price">The price of the item</param>
 /// <param name="edition">The item edition</param>
 /// <param name="quantity">The number of the item in stock</param>
 /// <param name="conditionID">The unique identifier for the item condition</param>
 public DBItem(int itemID, string itemType, string description, decimal price, byte edition, int quantity, int conditionID)
 {
     this.itemID        = itemID;
     this.itemType      = itemType;
     this.description   = description;
     this.price         = price;
     this.discount      = this.GetDBDiscount();
     this.edition       = edition;
     this.quantity      = quantity;
     this.conditionID   = conditionID;
     this.conditionType = this.GetDBConditionType();
     this.ShowDiscount  = true;
     this.Tags          = this.GetTags();
 }
Exemple #2
0
        /// <summary>
        /// Gets a discount associated with this item in the database
        /// </summary>
        /// <returns>The discount associated with this item</returns>
        public DBItemDiscount GetDBDiscount()
        {
            DBItemDiscount discount;
            string         query = "SELECT discountAmount, startDate, endDate FROM itemDiscounts WHERE discountID = '" + this.GetItemID() + "' AND GETDATE() < endDate";

            using (var conn = new SqlConnection(Properties.Settings.Default.Britannicus_DBConnectionString))
            {
                var command = new SqlCommand(query, conn);
                conn.Open();
                var reader = command.ExecuteReader();
                if (reader.Read())
                {
                    discount = new DBItemDiscount(this.GetItemID(), (decimal)reader["discountAmount"], (DateTime)reader["startDate"], (DateTime)reader["endDate"]);
                }
                else
                {
                    discount = new DBItemDiscount(this.GetItemID(), -1, DateTime.Now, DateTime.Now);
                }
            }
            return(discount);
        }
        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);
            }
        }