private void BtnAddItem_Click(object sender, EventArgs e) { MasterForm master = (this.Parent.Parent as MasterForm); master.SetScreen(master.screenAddItem, true); }
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 ViewPurchasesByCollectorScreen_ParentChanged(object sender, EventArgs e) { if (this.Parent != null) { MasterForm master = (this.Parent.Parent as MasterForm); master.CancelButton = (master.Controls.Find("btnBack", true)[0] as Button); try { using (var conn = new SqlConnection(Properties.Settings.Default.Britannicus_DBConnectionString)) { string conditionQuery = "SELECT conditionID, conditionType FROM conditions"; SqlDataAdapter da = new SqlDataAdapter(conditionQuery, conn); DataSet ds = new DataSet(); da.Fill(ds, "conditions"); da.Dispose(); string invoiceQuery = "SELECT invoiceID, customerID, invoiceDate FROM invoice"; SqlDataAdapter da2 = new SqlDataAdapter(invoiceQuery, conn); da2.Fill(ds, "invoice"); da2.Dispose(); string inventoryQuery = "SELECT itemID, conditionID, quantity FROM inventory"; SqlDataAdapter da3 = new SqlDataAdapter(inventoryQuery, conn); da3.Fill(ds, "inventory"); da3.Dispose(); string itemsQuery = "SELECT itemID, itemTypeID, price, edition FROM items"; SqlDataAdapter da5 = new SqlDataAdapter(itemsQuery, conn); da5.Fill(ds, "items"); da5.Dispose(); string itemTypesQuery = "SELECT itemTypeID, itemTypeName FROM itemTypes"; SqlDataAdapter da7 = new SqlDataAdapter(itemTypesQuery, conn); da7.Fill(ds, "itemTypes"); da7.Dispose(); string transactionQuery = "SELECT invoiceID, itemID, quantity, totalPrice FROM [transaction]"; SqlDataAdapter da8 = new SqlDataAdapter(transactionQuery, conn); da8.Fill(ds, "transaction"); da8.Dispose(); string collectorsQuery = "SELECT customerID, customerTypeID, firstName, lastName, phoneNumber FROM customers"; SqlDataAdapter da9 = new SqlDataAdapter(collectorsQuery, conn); da9.Fill(ds, "customers"); da9.Dispose(); string collectorTypes = "SELECT customerTypeID, customerTypeName FROM customerTypes"; SqlDataAdapter da10 = new SqlDataAdapter(collectorTypes, conn); da10.Fill(ds, "customerTypes"); da10.Dispose(); cryRpt.SetDataSource(ds); this.crvPurchasesByCollector.ReportSource = cryRpt; if (this.cbxSelectedCollector.SelectedItem is DBCollector) { //this.cryRpt.SetParameterValue(0, (int)this.cbxSelectedCollector.SelectedValue); } } } catch (Exception ex) { (this.Parent.Parent as MasterForm).SetStatus("Error! Failed to populate the report: " + ex.Message); } } }