Пример #1
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);
        }
Пример #2
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);
            }
        }