示例#1
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
                string firstName       = this.txtFirstNameInput.Text.Trim();
                string lastName        = this.txtLastNameInput.Text.Trim();
                string phoneNumber     = this.mtxtPhoneNumberInput.Text.Trim();
                int    collectorTypeID = (int)this.cbxTypeInput.SelectedValue;

                string status = "";

                if (String.IsNullOrEmpty(status = DBCollector.Validate(firstName, lastName, phoneNumber)))
                {
                    object insertedID = DBCollector.InsertCollector(collectorTypeID, firstName, lastName, phoneNumber);

                    if (insertedID != null)
                    {
                        status = "Collector " + firstName + " " + lastName + " has been added." + Environment.NewLine;

                        List <int> bookTagValues = DBControlHelper.GetValuesFromCheckedControls(this.tlpBookTagsSelection);
                        if (bookTagValues.Count > 0 && DBCollector.InsertInterests((int)insertedID, 1, bookTagValues))
                        {
                            status += "Book interests added." + Environment.NewLine;
                        }
                        List <int> mapTagValues = DBControlHelper.GetValuesFromCheckedControls(this.tlpMapTagsSelection);
                        if (mapTagValues.Count > 0 && DBCollector.InsertInterests((int)insertedID, 2, mapTagValues))
                        {
                            status += "Map interests added." + Environment.NewLine;
                        }
                        List <int> periodicalTagValues = DBControlHelper.GetValuesFromCheckedControls(this.tlpPeriodicalTagsSelection);
                        if (periodicalTagValues.Count > 0 && DBCollector.InsertInterests((int)insertedID, 3, periodicalTagValues))
                        {
                            status += "Periodical interests added." + Environment.NewLine;
                        }
                    }
                }

                master.SetStatus(status);
            }
            catch (Exception ex)
            {
                master.SetStatus("Error! Add failed: " + 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    collectorID     = (int)nudCollectorId.Value;
                string firstName       = txtFirstName.Text.Trim();
                string lastName        = txtLastName.Text.Trim();
                int    collectorTypeID = (int)cbxType.SelectedValue;
                string phoneNumber     = mtxtPhoneNumber.Text.Trim();

                string status = "";

                if (String.IsNullOrEmpty(status = DBCollector.Validate(firstName, lastName, phoneNumber)))
                {
                    if (DBCollector.UpdateCollector(collectorID, collectorTypeID, firstName, lastName, phoneNumber))
                    {
                        status = "Collector " + firstName + " " + lastName + " has been saved." + Environment.NewLine;
                    }
                }

                if (DBCollector.UpdateInterests(collectorID, 1, DBControlHelper.GetValuesFromCheckedControls(this.tlpTagsBookSelection)))
                {
                    status += "Book interests have been updated." + Environment.NewLine;
                }
                if (DBCollector.UpdateInterests(collectorID, 2, DBControlHelper.GetValuesFromCheckedControls(this.tlpTagsMapSelection)))
                {
                    status += "Map interests have been updated." + Environment.NewLine;
                }
                if (DBCollector.UpdateInterests(collectorID, 3, DBControlHelper.GetValuesFromCheckedControls(this.tlpTagsPeriodicalSelection)))
                {
                    status += "Periodical interests have been updated." + Environment.NewLine;
                }

                master.SetStatus(status);
            }
            catch (Exception ex)
            {
                master.SetStatus("Error! Save failed: " + ex.Message);
            }
        }
示例#3
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);
            }
        }
        private void ShowItems()
        {
            if (rbnBook.Checked)
            {
                try
                {
                    BindingList <DBBook> filteredBooks = DBControlHelper.GetFilteredItems(this.books, this.txtSearch.Text, DBControlHelper.GetValuesFromCheckedControls(this.tlpTagSelection));
                    this.dgvItems.DataSource        = filteredBooks;
                    this.cbxSelectedItem.DataSource = filteredBooks;

                    //Setup combobox
                    this.cbxSelectedItem.DisplayMember = "ComboBoxDisplay";
                    this.cbxSelectedItem.ValueMember   = "BookID";

                    //Setup datagridview
                    this.dgvItems.Columns["BookID"].HeaderText        = "Book ID";
                    this.dgvItems.Columns["GenreName"].HeaderText     = "Genre";
                    this.dgvItems.Columns["PublishDate"].HeaderText   = "Publish Date";
                    this.dgvItems.Columns["ConditionType"].HeaderText = "Condition";
                    this.dgvItems.Columns["ComboBoxDisplay"].Visible  = false;
                    this.dgvItems.Columns["ShowDiscount"].Visible     = false;
                    this.lblSearchByTitlePrompt.Text = "Search by Title:";
                }
                catch (Exception ex)
                {
                    (this.Parent.Parent as MasterForm).SetStatus("Failed to show books: " + ex.Message);
                }
            }
            else if (rbnMap.Checked)
            {
                try
                {
                    BindingList <DBMap> filteredMaps = DBControlHelper.GetFilteredItems(this.maps, this.txtSearch.Text, DBControlHelper.GetValuesFromCheckedControls(this.tlpTagSelection));
                    this.dgvItems.DataSource        = filteredMaps;
                    this.cbxSelectedItem.DataSource = filteredMaps;

                    //Setup combobox
                    this.cbxSelectedItem.DisplayMember = "ComboBoxDisplay";
                    this.cbxSelectedItem.ValueMember   = "MapID";

                    //Setup datagridview
                    this.dgvItems.Columns["MapID"].HeaderText         = "Map ID";
                    this.dgvItems.Columns["ConditionType"].HeaderText = "Condition";
                    this.dgvItems.Columns["ComboBoxDisplay"].Visible  = false;
                    this.dgvItems.Columns["ShowDiscount"].Visible     = false;
                    this.lblSearchByTitlePrompt.Text = "Search by Location:";
                }
                catch (Exception ex)
                {
                    (this.Parent.Parent as MasterForm).SetStatus("Failed to show maps: " + ex.Message);
                }
            }
            else if (rbnPeriodical.Checked)
            {
                try
                {
                    BindingList <DBPeriodical> filteredPeriodicals = DBControlHelper.GetFilteredItems(this.periodicals, this.txtSearch.Text, DBControlHelper.GetValuesFromCheckedControls(this.tlpTagSelection));
                    this.dgvItems.DataSource        = filteredPeriodicals;
                    this.cbxSelectedItem.DataSource = filteredPeriodicals;

                    //Setup datagridview
                    this.dgvItems.Columns["PeriodicalID"].HeaderText  = "Periodical ID";
                    this.dgvItems.Columns["ConditionType"].HeaderText = "Condition";
                    this.dgvItems.Columns["GenreName"].HeaderText     = "Genre";
                    this.dgvItems.Columns["CompanyName"].HeaderText   = "Company";
                    this.dgvItems.Columns["PublishDate"].HeaderText   = "Publish Date";
                    this.dgvItems.Columns["ComboBoxDisplay"].Visible  = false;
                    this.dgvItems.Columns["ShowDiscount"].Visible     = false;
                    this.lblSearchByTitlePrompt.Text = "Search by Title:";

                    //Setup combobox
                    this.cbxSelectedItem.DisplayMember = "ComboBoxDisplay";
                    this.cbxSelectedItem.ValueMember   = "PeriodicalID";
                }
                catch (Exception ex)
                {
                    (this.Parent.Parent as MasterForm).SetStatus("Failed to show periodicals: " + ex.Message);
                }
            }
        }